Refactor disabling scene tab context menu options
This commit is contained in:
parent
80bfca20c6
commit
a949f1b4b5
@ -142,38 +142,53 @@ void EditorSceneTabs::_update_context_menu() {
|
||||
scene_tabs_context_menu->reset_size();
|
||||
|
||||
int tab_id = scene_tabs->get_hovered_tab();
|
||||
bool no_root_node = !EditorNode::get_editor_data().get_edited_scene_root(tab_id);
|
||||
|
||||
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/new_scene"), EditorNode::FILE_NEW_SCENE);
|
||||
if (tab_id >= 0) {
|
||||
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/save_scene"), EditorNode::FILE_SAVE_SCENE);
|
||||
_disable_menu_option_if(EditorNode::FILE_SAVE_SCENE, no_root_node);
|
||||
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/save_scene_as"), EditorNode::FILE_SAVE_AS_SCENE);
|
||||
_disable_menu_option_if(EditorNode::FILE_SAVE_AS_SCENE, no_root_node);
|
||||
}
|
||||
|
||||
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/save_all_scenes"), EditorNode::FILE_SAVE_ALL_SCENES);
|
||||
bool can_save_all_scenes = false;
|
||||
for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) {
|
||||
if (!EditorNode::get_editor_data().get_scene_path(i).is_empty() && EditorNode::get_editor_data().get_edited_scene_root(i)) {
|
||||
can_save_all_scenes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_disable_menu_option_if(EditorNode::FILE_SAVE_ALL_SCENES, !can_save_all_scenes);
|
||||
|
||||
if (tab_id >= 0) {
|
||||
scene_tabs_context_menu->add_separator();
|
||||
scene_tabs_context_menu->add_item(TTR("Show in FileSystem"), EditorNode::FILE_SHOW_IN_FILESYSTEM);
|
||||
_disable_menu_option_if(EditorNode::FILE_SHOW_IN_FILESYSTEM, !ResourceLoader::exists(EditorNode::get_editor_data().get_scene_path(tab_id)));
|
||||
scene_tabs_context_menu->add_item(TTR("Play This Scene"), EditorNode::FILE_RUN_SCENE);
|
||||
_disable_menu_option_if(EditorNode::FILE_RUN_SCENE, no_root_node);
|
||||
|
||||
scene_tabs_context_menu->add_separator();
|
||||
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/close_scene"), EditorNode::FILE_CLOSE);
|
||||
scene_tabs_context_menu->set_item_text(scene_tabs_context_menu->get_item_index(EditorNode::FILE_CLOSE), TTR("Close Tab"));
|
||||
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/reopen_closed_scene"), EditorNode::FILE_OPEN_PREV);
|
||||
scene_tabs_context_menu->set_item_text(scene_tabs_context_menu->get_item_index(EditorNode::FILE_OPEN_PREV), TTR("Undo Close Tab"));
|
||||
if (!EditorNode::get_singleton()->has_previous_scenes()) {
|
||||
scene_tabs_context_menu->set_item_disabled(scene_tabs_context_menu->get_item_index(EditorNode::FILE_OPEN_PREV), true);
|
||||
}
|
||||
_disable_menu_option_if(EditorNode::FILE_OPEN_PREV, !EditorNode::get_singleton()->has_previous_scenes());
|
||||
scene_tabs_context_menu->add_item(TTR("Close Other Tabs"), EditorNode::FILE_CLOSE_OTHERS);
|
||||
if (EditorNode::get_editor_data().get_edited_scene_count() <= 1) {
|
||||
scene_tabs_context_menu->set_item_disabled(scene_tabs_context_menu->get_item_index(EditorNode::FILE_CLOSE_OTHERS), true);
|
||||
}
|
||||
_disable_menu_option_if(EditorNode::FILE_CLOSE_OTHERS, EditorNode::get_editor_data().get_edited_scene_count() <= 1);
|
||||
scene_tabs_context_menu->add_item(TTR("Close Tabs to the Right"), EditorNode::FILE_CLOSE_RIGHT);
|
||||
if (EditorNode::get_editor_data().get_edited_scene_count() == tab_id + 1) {
|
||||
scene_tabs_context_menu->set_item_disabled(scene_tabs_context_menu->get_item_index(EditorNode::FILE_CLOSE_RIGHT), true);
|
||||
}
|
||||
_disable_menu_option_if(EditorNode::FILE_CLOSE_RIGHT, EditorNode::get_editor_data().get_edited_scene_count() == tab_id + 1);
|
||||
scene_tabs_context_menu->add_item(TTR("Close All Tabs"), EditorNode::FILE_CLOSE_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSceneTabs::_disable_menu_option_if(int p_option, bool p_condition) {
|
||||
if (p_condition) {
|
||||
scene_tabs_context_menu->set_item_disabled(scene_tabs_context_menu->get_item_index(p_option), true);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This REALLY should be done in a better way than replacing all tabs after almost EVERY action.
|
||||
void EditorSceneTabs::update_scene_tabs() {
|
||||
tab_preview_panel->hide();
|
||||
|
@ -66,6 +66,7 @@ class EditorSceneTabs : public MarginContainer {
|
||||
|
||||
void _reposition_active_tab(int p_to_index);
|
||||
void _update_context_menu();
|
||||
void _disable_menu_option_if(int p_option, bool p_condition);
|
||||
|
||||
void _tab_preview_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user