mirror of https://github.com/godotengine/godot
Minor tweaks/fixes for the Command Palette
This commit is contained in:
parent
01675eb75a
commit
9819be7562
|
|
@ -70,8 +70,12 @@ void EditorCommandPalette::_update_command_search(const String &search_text) {
|
||||||
r.key_name = command_keys[i];
|
r.key_name = command_keys[i];
|
||||||
r.display_name = commands[r.key_name].name;
|
r.display_name = commands[r.key_name].name;
|
||||||
r.shortcut_text = commands[r.key_name].shortcut;
|
r.shortcut_text = commands[r.key_name].shortcut;
|
||||||
|
|
||||||
if (search_text.is_subsequence_ofi(r.display_name)) {
|
if (search_text.is_subsequence_ofi(r.display_name)) {
|
||||||
r.score = _score_path(search_text, r.display_name.to_lower());
|
if (!search_text.is_empty()) {
|
||||||
|
r.score = _score_path(search_text, r.display_name.to_lower());
|
||||||
|
}
|
||||||
|
|
||||||
entries.push_back(r);
|
entries.push_back(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -81,60 +85,55 @@ void EditorCommandPalette::_update_command_search(const String &search_text) {
|
||||||
TreeItem *root = search_options->get_root();
|
TreeItem *root = search_options->get_root();
|
||||||
root->clear_children();
|
root->clear_children();
|
||||||
|
|
||||||
if (entries.size() > 0) {
|
if (entries.is_empty()) {
|
||||||
if (!search_text.is_empty()) {
|
get_ok_button()->set_disabled(true);
|
||||||
SortArray<CommandEntry, CommandEntryComparator> sorter;
|
|
||||||
sorter.sort(entries.ptrw(), entries.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
const int entry_limit = MIN(entries.size(), 300);
|
return;
|
||||||
for (int i = 0; i < entry_limit; i++) {
|
}
|
||||||
String section_name = entries[i].key_name.get_slice("/", 0);
|
|
||||||
TreeItem *section;
|
|
||||||
|
|
||||||
if (sections.has(section_name)) {
|
if (!search_text.is_empty()) {
|
||||||
section = sections[section_name];
|
SortArray<CommandEntry, CommandEntryComparator> sorter;
|
||||||
} else {
|
sorter.sort(entries.ptrw(), entries.size());
|
||||||
section = search_options->create_item(root);
|
}
|
||||||
|
|
||||||
if (!first_section) {
|
const int entry_limit = MIN(entries.size(), 300);
|
||||||
first_section = section;
|
for (int i = 0; i < entry_limit; i++) {
|
||||||
}
|
String section_name = entries[i].key_name.get_slice("/", 0);
|
||||||
|
TreeItem *section;
|
||||||
|
|
||||||
String item_name = section_name.capitalize();
|
if (sections.has(section_name)) {
|
||||||
section->set_text(0, item_name);
|
section = sections[section_name];
|
||||||
|
} else {
|
||||||
|
section = search_options->create_item(root);
|
||||||
|
|
||||||
sections[section_name] = section;
|
if (!first_section) {
|
||||||
section->set_custom_bg_color(0, search_options->get_theme_color("prop_subsection", "Editor"));
|
first_section = section;
|
||||||
section->set_custom_bg_color(1, search_options->get_theme_color("prop_subsection", "Editor"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem *ti = search_options->create_item(section);
|
String item_name = section_name.capitalize();
|
||||||
String shortcut_text = entries[i].shortcut_text == "None" ? "" : entries[i].shortcut_text;
|
section->set_text(0, item_name);
|
||||||
ti->set_text(0, entries[i].display_name);
|
section->set_selectable(0, false);
|
||||||
ti->set_metadata(0, entries[i].key_name);
|
section->set_selectable(1, false);
|
||||||
ti->set_text_align(1, TreeItem::TextAlign::ALIGN_RIGHT);
|
section->set_custom_bg_color(0, search_options->get_theme_color("prop_subsection", "Editor"));
|
||||||
ti->set_text(1, shortcut_text);
|
section->set_custom_bg_color(1, search_options->get_theme_color("prop_subsection", "Editor"));
|
||||||
Color c = Color(1, 1, 1, 0.5);
|
|
||||||
ti->set_custom_color(1, c);
|
sections[section_name] = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeItem *to_select = first_section->get_first_child();
|
TreeItem *ti = search_options->create_item(section);
|
||||||
to_select->select(0);
|
String shortcut_text = entries[i].shortcut_text == "None" ? "" : entries[i].shortcut_text;
|
||||||
to_select->set_as_cursor(0);
|
ti->set_text(0, entries[i].display_name);
|
||||||
search_options->scroll_to_item(to_select);
|
ti->set_metadata(0, entries[i].key_name);
|
||||||
|
ti->set_text_align(1, TreeItem::TextAlign::ALIGN_RIGHT);
|
||||||
get_ok_button()->set_disabled(false);
|
ti->set_text(1, shortcut_text);
|
||||||
} else {
|
Color c = Color(1, 1, 1, 0.5);
|
||||||
TreeItem *ti = search_options->create_item(root);
|
ti->set_custom_color(1, c);
|
||||||
ti->set_text(0, TTR("No matching commands found"));
|
|
||||||
ti->set_metadata(0, "");
|
|
||||||
Color c = Color(0.5, 0.5, 0.5, 0.5);
|
|
||||||
ti->set_custom_color(0, c);
|
|
||||||
search_options->deselect_all();
|
|
||||||
|
|
||||||
get_ok_button()->set_disabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TreeItem *to_select = first_section->get_first_child();
|
||||||
|
to_select->select(0);
|
||||||
|
to_select->set_as_cursor(0);
|
||||||
|
search_options->ensure_cursor_is_visible();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorCommandPalette::_bind_methods() {
|
void EditorCommandPalette::_bind_methods() {
|
||||||
|
|
@ -169,8 +168,11 @@ void EditorCommandPalette::_confirmed() {
|
||||||
|
|
||||||
void EditorCommandPalette::open_popup() {
|
void EditorCommandPalette::open_popup() {
|
||||||
popup_centered_clamped(Size2i(600, 440), 0.8f);
|
popup_centered_clamped(Size2i(600, 440), 0.8f);
|
||||||
|
|
||||||
command_search_box->clear();
|
command_search_box->clear();
|
||||||
command_search_box->grab_focus();
|
command_search_box->grab_focus();
|
||||||
|
|
||||||
|
search_options->scroll_to_item(search_options->get_root());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorCommandPalette::get_actions_list(List<String> *p_list) const {
|
void EditorCommandPalette::get_actions_list(List<String> *p_list) const {
|
||||||
|
|
@ -258,6 +260,9 @@ EditorCommandPalette *EditorCommandPalette::get_singleton() {
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorCommandPalette::EditorCommandPalette() {
|
EditorCommandPalette::EditorCommandPalette() {
|
||||||
|
set_hide_on_ok(false);
|
||||||
|
connect("confirmed", callable_mp(this, &EditorCommandPalette::_confirmed));
|
||||||
|
|
||||||
VBoxContainer *vbc = memnew(VBoxContainer);
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
||||||
vbc->connect("theme_changed", callable_mp(this, &EditorCommandPalette::_theme_changed));
|
vbc->connect("theme_changed", callable_mp(this, &EditorCommandPalette::_theme_changed));
|
||||||
add_child(vbc);
|
add_child(vbc);
|
||||||
|
|
@ -275,18 +280,15 @@ EditorCommandPalette::EditorCommandPalette() {
|
||||||
|
|
||||||
search_options = memnew(Tree);
|
search_options = memnew(Tree);
|
||||||
search_options->connect("item_activated", callable_mp(this, &EditorCommandPalette::_confirmed));
|
search_options->connect("item_activated", callable_mp(this, &EditorCommandPalette::_confirmed));
|
||||||
|
search_options->connect("item_selected", callable_mp((BaseButton *)get_ok_button(), &BaseButton::set_disabled), varray(false));
|
||||||
|
search_options->connect("nothing_selected", callable_mp((BaseButton *)get_ok_button(), &BaseButton::set_disabled), varray(true));
|
||||||
search_options->create_item();
|
search_options->create_item();
|
||||||
search_options->set_hide_root(true);
|
search_options->set_hide_root(true);
|
||||||
search_options->set_hide_folding(true);
|
|
||||||
search_options->add_theme_constant_override("draw_guides", 1);
|
|
||||||
search_options->set_columns(2);
|
search_options->set_columns(2);
|
||||||
search_options->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
search_options->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||||
search_options->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
search_options->set_h_size_flags(Control::SIZE_EXPAND_FILL);
|
||||||
search_options->set_column_custom_minimum_width(0, int(8 * EDSCALE));
|
search_options->set_column_custom_minimum_width(0, int(8 * EDSCALE));
|
||||||
vbc->add_child(search_options, true);
|
vbc->add_child(search_options, true);
|
||||||
|
|
||||||
connect("confirmed", callable_mp(this, &EditorCommandPalette::_confirmed));
|
|
||||||
set_hide_on_ok(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Shortcut> ED_SHORTCUT_AND_COMMAND(const String &p_path, const String &p_name, Key p_keycode, String p_command_name) {
|
Ref<Shortcut> ED_SHORTCUT_AND_COMMAND(const String &p_path, const String &p_name, Key p_keycode, String p_command_name) {
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,8 @@ void EditorSettingsDialog::_update_shortcuts() {
|
||||||
|
|
||||||
sections["Common"] = common_section;
|
sections["Common"] = common_section;
|
||||||
common_section->set_text(0, TTR("Common"));
|
common_section->set_text(0, TTR("Common"));
|
||||||
|
common_section->set_selectable(0, false);
|
||||||
|
common_section->set_selectable(1, false);
|
||||||
if (collapsed.has("Common")) {
|
if (collapsed.has("Common")) {
|
||||||
common_section->set_collapsed(collapsed["Common"]);
|
common_section->set_collapsed(collapsed["Common"]);
|
||||||
}
|
}
|
||||||
|
|
@ -343,14 +345,16 @@ void EditorSettingsDialog::_update_shortcuts() {
|
||||||
|
|
||||||
String item_name = section_name.capitalize();
|
String item_name = section_name.capitalize();
|
||||||
section->set_text(0, item_name);
|
section->set_text(0, item_name);
|
||||||
|
section->set_selectable(0, false);
|
||||||
|
section->set_selectable(1, false);
|
||||||
|
section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
|
||||||
|
section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
|
||||||
|
|
||||||
if (collapsed.has(item_name)) {
|
if (collapsed.has(item_name)) {
|
||||||
section->set_collapsed(collapsed[item_name]);
|
section->set_collapsed(collapsed[item_name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sections[section_name] = section;
|
sections[section_name] = section;
|
||||||
section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
|
|
||||||
section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't match unassigned shortcuts when searching for assigned keys in search results.
|
// Don't match unassigned shortcuts when searching for assigned keys in search results.
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
#include "core/os/keyboard.h"
|
#include "core/os/keyboard.h"
|
||||||
|
|
||||||
void Shortcut::set_event(const Ref<InputEvent> &p_event) {
|
void Shortcut::set_event(const Ref<InputEvent> &p_event) {
|
||||||
ERR_FAIL_COND(Object::cast_to<InputEventShortcut>(*p_event));
|
ERR_FAIL_COND_MSG(Object::cast_to<InputEventShortcut>(*p_event), "Cannot set a shortcut event to an instance of InputEventShortcut.");
|
||||||
event = p_event;
|
event = p_event;
|
||||||
emit_changed();
|
emit_changed();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue