Disable ScriptEditor's menu items when they do nothing
This commit is contained in:
parent
08cabf2a36
commit
061ee6cdb3
2 changed files with 57 additions and 2 deletions
|
@ -468,6 +468,7 @@ void ScriptEditor::_update_recent_scripts() {
|
|||
|
||||
recent_scripts->add_separator();
|
||||
recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Files")));
|
||||
recent_scripts->set_item_disabled(recent_scripts->get_item_id(recent_scripts->get_item_count() - 1), rc.empty());
|
||||
|
||||
recent_scripts->set_as_minsize();
|
||||
}
|
||||
|
@ -1358,6 +1359,51 @@ void ScriptEditor::_show_save_theme_as_dialog() {
|
|||
file_dialog->set_title(TTR("Save Theme As..."));
|
||||
}
|
||||
|
||||
bool ScriptEditor::_has_docs_tab() const {
|
||||
const int child_count = tab_container->get_child_count();
|
||||
for (int i = 0; i < child_count; i++) {
|
||||
if (Object::cast_to<EditorHelp>(tab_container->get_child(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ScriptEditor::_has_script_tab() const {
|
||||
const int child_count = tab_container->get_child_count();
|
||||
for (int i = 0; i < child_count; i++) {
|
||||
if (Object::cast_to<ScriptEditorBase>(tab_container->get_child(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptEditor::_prepare_file_menu() {
|
||||
PopupMenu *menu = file_menu->get_popup();
|
||||
const bool current_is_doc = _get_current_editor() == nullptr;
|
||||
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_REOPEN_CLOSED), previous_scripts.empty());
|
||||
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_SAVE), current_is_doc);
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_SAVE_AS), current_is_doc);
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_SAVE_ALL), !_has_script_tab());
|
||||
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_TOOL_RELOAD_SOFT), current_is_doc);
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_COPY_PATH), current_is_doc);
|
||||
menu->set_item_disabled(menu->get_item_index(SHOW_IN_FILE_SYSTEM), current_is_doc);
|
||||
|
||||
menu->set_item_disabled(menu->get_item_index(WINDOW_PREV), history_pos <= 0);
|
||||
menu->set_item_disabled(menu->get_item_index(WINDOW_NEXT), history_pos >= history.size() - 1);
|
||||
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_CLOSE), tab_container->get_child_count() < 1);
|
||||
menu->set_item_disabled(menu->get_item_index(CLOSE_ALL), tab_container->get_child_count() < 1);
|
||||
menu->set_item_disabled(menu->get_item_index(CLOSE_OTHER_TABS), tab_container->get_child_count() <= 1);
|
||||
menu->set_item_disabled(menu->get_item_index(CLOSE_DOCS), !_has_docs_tab());
|
||||
|
||||
menu->set_item_disabled(menu->get_item_index(FILE_RUN), current_is_doc);
|
||||
}
|
||||
|
||||
void ScriptEditor::_tab_changed(int p_which) {
|
||||
ensure_select_current();
|
||||
}
|
||||
|
@ -1909,8 +1955,6 @@ void ScriptEditor::_update_script_names() {
|
|||
_update_members_overview_visibility();
|
||||
_update_help_overview_visibility();
|
||||
_update_script_colors();
|
||||
|
||||
file_menu->get_popup()->set_item_disabled(file_menu->get_popup()->get_item_index(FILE_REOPEN_CLOSED), previous_scripts.empty());
|
||||
}
|
||||
|
||||
void ScriptEditor::_update_script_connections() {
|
||||
|
@ -2689,6 +2733,12 @@ void ScriptEditor::_make_script_list_context_menu() {
|
|||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_sort"), WINDOW_SORT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/toggle_scripts_panel"), TOGGLE_SCRIPTS_PANEL);
|
||||
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_ALL), tab_container->get_child_count() <= 0);
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(CLOSE_OTHER_TABS), tab_container->get_child_count() <= 1);
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_MOVE_UP), tab_container->get_current_tab() <= 0);
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_MOVE_DOWN), tab_container->get_current_tab() >= tab_container->get_child_count() - 1);
|
||||
context_menu->set_item_disabled(context_menu->get_item_index(WINDOW_SORT), tab_container->get_child_count() <= 1);
|
||||
|
||||
context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
|
||||
context_menu->set_size(Vector2(1, 1));
|
||||
context_menu->popup();
|
||||
|
@ -3135,6 +3185,7 @@ void ScriptEditor::_bind_methods() {
|
|||
ClassDB::bind_method("_help_search", &ScriptEditor::_help_search);
|
||||
ClassDB::bind_method("_save_history", &ScriptEditor::_save_history);
|
||||
ClassDB::bind_method("_copy_script_path", &ScriptEditor::_copy_script_path);
|
||||
ClassDB::bind_method("_prepare_file_menu", &ScriptEditor::_prepare_file_menu);
|
||||
|
||||
ClassDB::bind_method("_breaked", &ScriptEditor::_breaked);
|
||||
ClassDB::bind_method("_show_debugger", &ScriptEditor::_show_debugger);
|
||||
|
@ -3350,6 +3401,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
|
|||
file_menu->get_popup()->add_separator();
|
||||
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL);
|
||||
file_menu->get_popup()->connect("id_pressed", this, "_menu_option");
|
||||
file_menu->get_popup()->connect("about_to_show", this, "_prepare_file_menu");
|
||||
|
||||
script_search_menu = memnew(MenuButton);
|
||||
menu_hb->add_child(script_search_menu);
|
||||
|
|
|
@ -270,6 +270,9 @@ class ScriptEditor : public PanelContainer {
|
|||
void _update_debug_options();
|
||||
void _theme_option(int p_option);
|
||||
void _show_save_theme_as_dialog();
|
||||
bool _has_docs_tab() const;
|
||||
bool _has_script_tab() const;
|
||||
void _prepare_file_menu();
|
||||
|
||||
Tree *disk_changed_list;
|
||||
ConfirmationDialog *disk_changed;
|
||||
|
|
Loading…
Reference in a new issue