Move Theme options to submenu

This commit is contained in:
Chaosus 2018-06-21 12:10:43 +03:00
parent a9acdd84b7
commit 7a18b95906
2 changed files with 57 additions and 37 deletions

View file

@ -804,12 +804,12 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Script> p_for_script) {
void ScriptEditor::_file_dialog_action(String p_file) { void ScriptEditor::_file_dialog_action(String p_file) {
switch (file_dialog_option) { switch (file_dialog_option) {
case FILE_SAVE_THEME_AS: { case THEME_SAVE_AS: {
if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) { if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) {
editor->show_warning(TTR("Error while saving theme"), TTR("Error saving")); editor->show_warning(TTR("Error while saving theme"), TTR("Error saving"));
} }
} break; } break;
case FILE_IMPORT_THEME: { case THEME_IMPORT: {
if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) { if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) {
editor->show_warning(TTR("Error importing theme"), TTR("Error importing")); editor->show_warning(TTR("Error importing theme"), TTR("Error importing"));
} }
@ -859,33 +859,6 @@ void ScriptEditor::_menu_option(int p_option) {
save_all_scripts(); save_all_scripts();
} break; } break;
case FILE_IMPORT_THEME: {
file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog_option = FILE_IMPORT_THEME;
file_dialog->clear_filters();
file_dialog->add_filter("*.tet");
file_dialog->popup_centered_ratio();
file_dialog->set_title(TTR("Import Theme"));
} break;
case FILE_RELOAD_THEME: {
EditorSettings::get_singleton()->load_text_editor_theme();
} break;
case FILE_SAVE_THEME: {
if (!EditorSettings::get_singleton()->save_text_editor_theme()) {
editor->show_warning(TTR("Error while saving theme"), TTR("Error saving"));
}
} break;
case FILE_SAVE_THEME_AS: {
file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog_option = FILE_SAVE_THEME_AS;
file_dialog->clear_filters();
file_dialog->add_filter("*.tet");
file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme")));
file_dialog->popup_centered_ratio();
file_dialog->set_title(TTR("Save Theme As..."));
} break;
case SEARCH_HELP: { case SEARCH_HELP: {
help_search_dialog->popup(); help_search_dialog->popup();
@ -1143,6 +1116,38 @@ void ScriptEditor::_menu_option(int p_option) {
} }
} }
void ScriptEditor::_theme_option(int p_option) {
switch (p_option) {
case THEME_IMPORT: {
file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog_option = THEME_IMPORT;
file_dialog->clear_filters();
file_dialog->add_filter("*.tet");
file_dialog->popup_centered_ratio();
file_dialog->set_title(TTR("Import Theme"));
} break;
case THEME_RELOAD: {
EditorSettings::get_singleton()->load_text_editor_theme();
} break;
case THEME_SAVE: {
if (!EditorSettings::get_singleton()->save_text_editor_theme()) {
editor->show_warning(TTR("Error while saving theme"), TTR("Error saving"));
}
} break;
case THEME_SAVE_AS: {
file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
file_dialog_option = THEME_SAVE_AS;
file_dialog->clear_filters();
file_dialog->add_filter("*.tet");
file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme")));
file_dialog->popup_centered_ratio();
file_dialog->set_title(TTR("Save Theme As..."));
} break;
}
}
void ScriptEditor::_tab_changed(int p_which) { void ScriptEditor::_tab_changed(int p_which) {
ensure_select_current(); ensure_select_current();
@ -2591,6 +2596,7 @@ void ScriptEditor::_bind_methods() {
ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs); ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs);
ClassDB::bind_method("_close_other_tabs", &ScriptEditor::_close_other_tabs); ClassDB::bind_method("_close_other_tabs", &ScriptEditor::_close_other_tabs);
ClassDB::bind_method("_open_recent_script", &ScriptEditor::_open_recent_script); ClassDB::bind_method("_open_recent_script", &ScriptEditor::_open_recent_script);
ClassDB::bind_method("_theme_option", &ScriptEditor::_theme_option);
ClassDB::bind_method("_editor_play", &ScriptEditor::_editor_play); ClassDB::bind_method("_editor_play", &ScriptEditor::_editor_play);
ClassDB::bind_method("_editor_pause", &ScriptEditor::_editor_pause); ClassDB::bind_method("_editor_pause", &ScriptEditor::_editor_pause);
ClassDB::bind_method("_editor_stop", &ScriptEditor::_editor_stop); ClassDB::bind_method("_editor_stop", &ScriptEditor::_editor_stop);
@ -2763,10 +2769,18 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Prev"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Prev"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_next", TTR("History Next"), KEY_MASK_ALT | KEY_RIGHT), WINDOW_NEXT); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_next", TTR("History Next"), KEY_MASK_ALT | KEY_RIGHT), WINDOW_NEXT);
file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme")), FILE_IMPORT_THEME);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), FILE_RELOAD_THEME); file_menu->get_popup()->add_submenu_item(TTR("Theme"), "Theme", FILE_THEME);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTR("Save Theme")), FILE_SAVE_THEME);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As")), FILE_SAVE_THEME_AS); theme_submenu = memnew(PopupMenu);
theme_submenu->set_name("Theme");
file_menu->get_popup()->add_child(theme_submenu);
theme_submenu->connect("id_pressed", this, "_theme_option");
theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme")), THEME_IMPORT);
theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), THEME_RELOAD);
theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTR("Save Theme")), THEME_SAVE);
theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As")), THEME_SAVE_AS);
file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE);

View file

@ -134,10 +134,7 @@ class ScriptEditor : public PanelContainer {
FILE_SAVE, FILE_SAVE,
FILE_SAVE_AS, FILE_SAVE_AS,
FILE_SAVE_ALL, FILE_SAVE_ALL,
FILE_IMPORT_THEME, FILE_THEME,
FILE_RELOAD_THEME,
FILE_SAVE_THEME,
FILE_SAVE_THEME_AS,
FILE_RUN, FILE_RUN,
FILE_CLOSE, FILE_CLOSE,
CLOSE_DOCS, CLOSE_DOCS,
@ -168,6 +165,13 @@ class ScriptEditor : public PanelContainer {
WINDOW_SELECT_BASE = 100 WINDOW_SELECT_BASE = 100
}; };
enum {
THEME_IMPORT,
THEME_RELOAD,
THEME_SAVE,
THEME_SAVE_AS
};
enum ScriptSortBy { enum ScriptSortBy {
SORT_BY_NAME, SORT_BY_NAME,
SORT_BY_PATH, SORT_BY_PATH,
@ -190,6 +194,7 @@ class ScriptEditor : public PanelContainer {
uint64_t idle; uint64_t idle;
PopupMenu *recent_scripts; PopupMenu *recent_scripts;
PopupMenu *theme_submenu;
Button *help_search; Button *help_search;
Button *site_search; Button *site_search;
@ -251,6 +256,7 @@ class ScriptEditor : public PanelContainer {
void _tab_changed(int p_which); void _tab_changed(int p_which);
void _menu_option(int p_option); void _menu_option(int p_option);
void _theme_option(int p_option);
Tree *disk_changed_list; Tree *disk_changed_list;
ConfirmationDialog *disk_changed; ConfirmationDialog *disk_changed;