Path: blob/master/editor/settings/editor_command_palette.h
21024 views
/**************************************************************************/1/* editor_command_palette.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/gui/dialogs.h"3334class FilterLineEdit;35class Shortcut;36class Tree;3738class EditorCommandPalette : public ConfirmationDialog {39GDCLASS(EditorCommandPalette, ConfirmationDialog);4041static EditorCommandPalette *singleton;42FilterLineEdit *command_search_box = nullptr;43Tree *search_options = nullptr;4445struct Command {46Callable callable;47String name;48Ref<Shortcut> shortcut;49String shortcut_text;50int last_used = 0; // Store time as int, because doubles have problems with text serialization.51};5253struct CommandEntry {54String key_name;55String display_name;56String shortcut_text;57int last_used = 0;58float score = 0;59};6061struct CommandEntryComparator {62_FORCE_INLINE_ bool operator()(const CommandEntry &A, const CommandEntry &B) const {63return A.score > B.score;64}65};6667struct CommandHistoryComparator {68_FORCE_INLINE_ bool operator()(const CommandEntry &A, const CommandEntry &B) const {69if (A.last_used == B.last_used) {70return A.display_name < B.display_name;71} else {72return A.last_used > B.last_used;73}74}75};7677HashMap<String, Command> commands;78HashMap<String, Pair<String, Ref<Shortcut>>> unregistered_shortcuts;7980void _update_command_search(const String &search_text);81float _score_path(const String &p_search, const String &p_path);82void _confirmed();83void _add_command(String p_command_name, String p_key_name, Callable p_binded_action, String p_shortcut_text = "None");84void _save_history() const;8586EditorCommandPalette();8788protected:89static void _bind_methods();90void _notification(int p_what);9192public:93void open_popup();94void get_actions_list(List<String> *p_list) const;95void add_command(String p_command_name, String p_key_name, Callable p_action, Vector<Variant> arguments, const Ref<Shortcut> &p_shortcut);96void execute_command(const String &p_command_name);97void register_shortcuts_as_command();98Ref<Shortcut> add_shortcut_command(const String &p_command, const String &p_key, Ref<Shortcut> p_shortcut);99void remove_command(String p_key_name);100static EditorCommandPalette *get_singleton();101};102103Ref<Shortcut> ED_SHORTCUT_AND_COMMAND(const String &p_path, const String &p_name, Key p_keycode = Key::NONE, String p_command = "");104Ref<Shortcut> ED_SHORTCUT_ARRAY_AND_COMMAND(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, String p_command = "");105106107