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