Skip to content

Commit a5d4261

Browse files
committed
Right-click on scene tab without selecting it
1 parent 3f5b871 commit a5d4261

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

editor/editor_node.cpp

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ void EditorNode::_dialog_action(String p_file) {
25852585
case SCENE_SAVE_SCENE:
25862586
case SCENE_MULTI_SAVE_AS_SCENE:
25872587
case SCENE_SAVE_AS_SCENE: {
2588-
int scene_idx = (current_menu_option == SCENE_SAVE_SCENE || current_menu_option == SCENE_SAVE_AS_SCENE || current_menu_option == SCENE_MULTI_SAVE_AS_SCENE) ? -1 : tab_closing_idx;
2588+
int scene_idx = (current_menu_option == SCENE_MULTI_SAVE_AS_SCENE) ? -1 : tab_context_idx;
25892589

25902590
if (file->get_file_mode() == EditorFileDialog::FILE_MODE_SAVE_FILE) {
25912591
bool same_open_scene = false;
@@ -2617,6 +2617,7 @@ void EditorNode::_dialog_action(String p_file) {
26172617
_proceed_save_asing_scene_tabs();
26182618
}
26192619

2620+
tab_context_idx = -1;
26202621
} break;
26212622

26222623
case SAVE_AND_RUN: {
@@ -2640,7 +2641,7 @@ void EditorNode::_dialog_action(String p_file) {
26402641

26412642
case SAVE_AND_SET_MAIN_SCENE: {
26422643
_save_scene(p_file);
2643-
_menu_option_confirm(SCENE_SET_MAIN_SCENE, true);
2644+
_menu_option_confirm(SCENE_TAB_SET_AS_MAIN_SCENE, true);
26442645
} break;
26452646

26462647
case FILE_EXPORT_MESH_LIBRARY: {
@@ -3232,6 +3233,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
32323233

32333234
switch (p_option) {
32343235
case SCENE_NEW_SCENE: {
3236+
tab_context_idx = -1; // Don't use a specific tab as context.
32353237
new_scene();
32363238

32373239
} break;
@@ -3263,14 +3265,17 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
32633265
quick_open_dialog->popup_dialog({ "Script" }, callable_mp(this, &EditorNode::_quick_opened));
32643266
} break;
32653267
case SCENE_OPEN_PREV: {
3268+
tab_context_idx = -1; // Don't use a specific tab as context.
32663269
if (!prev_closed_scenes.is_empty()) {
32673270
load_scene(prev_closed_scenes.back()->get());
32683271
}
32693272
} break;
32703273
case EditorSceneTabs::SCENE_CLOSE_OTHERS: {
32713274
tab_closing_menu_option = -1;
3275+
int selected_tab = tab_context_idx >= 0 ? tab_context_idx : editor_data.get_edited_scene();
3276+
tab_context_idx = -1;
32723277
for (int i = 0; i < editor_data.get_edited_scene_count(); i++) {
3273-
if (i == editor_data.get_edited_scene()) {
3278+
if (i == selected_tab) {
32743279
continue;
32753280
}
32763281
tabs_to_close.push_back(editor_data.get_scene_path(i));
@@ -3279,7 +3284,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
32793284
} break;
32803285
case EditorSceneTabs::SCENE_CLOSE_RIGHT: {
32813286
tab_closing_menu_option = -1;
3282-
for (int i = editor_data.get_edited_scene() + 1; i < editor_data.get_edited_scene_count(); i++) {
3287+
int selected_tab = tab_context_idx >= 0 ? tab_context_idx : editor_data.get_edited_scene();
3288+
tab_context_idx = -1;
3289+
for (int i = selected_tab + 1; i < editor_data.get_edited_scene_count(); i++) {
32833290
tabs_to_close.push_back(editor_data.get_scene_path(i));
32843291
}
32853292
_proceed_closing_scene_tabs();
@@ -3292,11 +3299,13 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
32923299
_proceed_closing_scene_tabs();
32933300
} break;
32943301
case SCENE_CLOSE: {
3295-
_scene_tab_closed(editor_data.get_edited_scene());
3302+
int scene_to_close = tab_context_idx >= 0 ? tab_context_idx : editor_data.get_edited_scene();
3303+
tab_context_idx = -1;
3304+
_scene_tab_closed(scene_to_close);
32963305
} break;
32973306
case SCENE_TAB_CLOSE:
32983307
case SCENE_SAVE_SCENE: {
3299-
int scene_idx = (p_option == SCENE_SAVE_SCENE) ? -1 : tab_closing_idx;
3308+
int scene_idx = (p_option == SCENE_SAVE_SCENE && tab_context_idx < 0) ? -1 : tab_context_idx;
33003309
Node *scene = editor_data.get_edited_scene_root(scene_idx);
33013310
if (scene && !scene->get_scene_file_path().is_empty()) {
33023311
if (DirAccess::exists(scene->get_scene_file_path().get_base_dir())) {
@@ -3313,13 +3322,14 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
33133322
} else {
33143323
show_save_accept(vformat(TTR("%s no longer exists! Please specify a new save location."), scene->get_scene_file_path().get_base_dir()), TTR("OK"));
33153324
}
3325+
tab_context_idx = -1;
33163326
break;
33173327
}
33183328
[[fallthrough]];
33193329
}
33203330
case SCENE_MULTI_SAVE_AS_SCENE:
33213331
case SCENE_SAVE_AS_SCENE: {
3322-
int scene_idx = (p_option == SCENE_SAVE_SCENE || p_option == SCENE_SAVE_AS_SCENE || p_option == SCENE_MULTI_SAVE_AS_SCENE) ? -1 : tab_closing_idx;
3332+
int scene_idx = (p_option == SCENE_MULTI_SAVE_AS_SCENE) ? -1 : tab_context_idx;
33233333

33243334
Node *scene = editor_data.get_edited_scene_root(scene_idx);
33253335

@@ -3375,25 +3385,38 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
33753385

33763386
} break;
33773387

3378-
case SCENE_SET_MAIN_SCENE: {
3379-
const String scene_path = editor_data.get_scene_path(editor_data.get_edited_scene());
3388+
case SCENE_TAB_SET_AS_MAIN_SCENE: {
3389+
int selected_tab = tab_context_idx >= 0 ? tab_context_idx : editor_data.get_edited_scene();
3390+
const String scene_path = editor_data.get_scene_path(selected_tab);
33803391
if (scene_path.is_empty()) {
33813392
current_menu_option = SAVE_AND_SET_MAIN_SCENE;
33823393
_menu_option_confirm(SCENE_SAVE_AS_SCENE, true);
33833394
file->set_title(TTR("Save new main scene..."));
3395+
// tab_context_idx will be reset when the dialog completes.
33843396
} else {
3397+
tab_context_idx = -1;
33853398
ProjectSettings::get_singleton()->set("application/run/main_scene", ResourceUID::path_to_uid(scene_path));
33863399
ProjectSettings::get_singleton()->save();
33873400
FileSystemDock::get_singleton()->update_all();
33883401
}
33893402
} break;
33903403

33913404
case SCENE_SAVE_ALL_SCENES: {
3405+
tab_context_idx = -1; // Don't use a specific tab as context.
33923406
_save_all_scenes();
33933407
} break;
33943408

33953409
case EditorSceneTabs::SCENE_RUN: {
3396-
project_run_bar->play_current_scene();
3410+
if (tab_context_idx >= 0 && tab_context_idx != editor_data.get_edited_scene()) {
3411+
String scene_path = editor_data.get_scene_path(tab_context_idx);
3412+
tab_context_idx = -1;
3413+
if (!scene_path.is_empty()) {
3414+
project_run_bar->play_custom_scene(scene_path);
3415+
}
3416+
} else {
3417+
tab_context_idx = -1;
3418+
project_run_bar->play_current_scene();
3419+
}
33973420
} break;
33983421

33993422
case PROJECT_EXPORT: {
@@ -3494,7 +3517,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
34943517
} break;
34953518

34963519
case EditorSceneTabs::SCENE_SHOW_IN_FILESYSTEM: {
3497-
String path = editor_data.get_scene_path(editor_data.get_edited_scene());
3520+
int selected_tab = tab_context_idx >= 0 ? tab_context_idx : editor_data.get_edited_scene();
3521+
String path = editor_data.get_scene_path(selected_tab);
3522+
tab_context_idx = -1;
34983523
if (!path.is_empty()) {
34993524
FileSystemDock::get_singleton()->navigate_to_path(path);
35003525
}
@@ -4016,14 +4041,14 @@ void EditorNode::_discard_changes(const String &p_str) {
40164041
switch (current_menu_option) {
40174042
case SCENE_CLOSE:
40184043
case SCENE_TAB_CLOSE: {
4019-
Node *scene = editor_data.get_edited_scene_root(tab_closing_idx);
4044+
Node *scene = editor_data.get_edited_scene_root(tab_context_idx);
40204045
if (scene != nullptr) {
40214046
_update_prev_closed_scenes(scene->get_scene_file_path(), true);
40224047
}
40234048

40244049
// Don't close tabs when exiting the editor (required for "restore_scenes_on_load" setting).
40254050
if (!_is_closing_editor()) {
4026-
_remove_scene(tab_closing_idx);
4051+
_remove_scene(tab_context_idx);
40274052
scene_tabs->update_scene_tabs();
40284053
}
40294054
_proceed_closing_scene_tabs();
@@ -5371,7 +5396,7 @@ bool EditorNode::close_scene() {
53715396
return false;
53725397
}
53735398

5374-
tab_closing_idx = tab_index;
5399+
tab_context_idx = tab_index;
53755400
current_menu_option = SCENE_CLOSE;
53765401
_discard_changes();
53775402
changing_scene = false;
@@ -6489,7 +6514,7 @@ void EditorNode::_restart_editor(bool p_goto_project_manager) {
64896514

64906515
void EditorNode::_scene_tab_closed(int p_tab) {
64916516
current_menu_option = SCENE_TAB_CLOSE;
6492-
tab_closing_idx = p_tab;
6517+
tab_context_idx = p_tab;
64936518
Node *scene = editor_data.get_edited_scene_root(p_tab);
64946519
if (!scene) {
64956520
_discard_changes();

editor/editor_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ class EditorNode : public Node {
148148
SCENE_SAVE_SCENE,
149149
SCENE_SAVE_AS_SCENE,
150150
SCENE_SAVE_ALL_SCENES,
151-
SCENE_SET_MAIN_SCENE,
152151
SCENE_MULTI_SAVE_AS_SCENE,
153152
SCENE_QUICK_OPEN,
154153
SCENE_QUICK_OPEN_SCENE,
@@ -215,6 +214,7 @@ class EditorNode : public Node {
215214

216215
// Non-menu options.
217216
SCENE_TAB_CLOSE,
217+
SCENE_TAB_SET_AS_MAIN_SCENE,
218218
SAVE_AND_RUN,
219219
SAVE_AND_RUN_MAIN_SCENE,
220220
SAVE_AND_SET_MAIN_SCENE,
@@ -310,7 +310,7 @@ class EditorNode : public Node {
310310
// Main tabs.
311311
EditorSceneTabs *scene_tabs = nullptr;
312312

313-
int tab_closing_idx = 0;
313+
int tab_context_idx = -1;
314314
List<String> tabs_to_close;
315315
List<int> scenes_to_save_as;
316316
int tab_closing_menu_option = -1;

editor/scene/editor_scene_tabs.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ void EditorSceneTabs::_update_context_menu() {
204204
DISABLE_LAST_OPTION_IF(!ResourceLoader::exists(scene_path));
205205
scene_tabs_context_menu->add_item(TTR("Play This Scene"), SCENE_RUN);
206206
DISABLE_LAST_OPTION_IF(no_root_node);
207-
scene_tabs_context_menu->add_item(TTR("Set as Main Scene"), EditorNode::SCENE_SET_MAIN_SCENE);
207+
scene_tabs_context_menu->add_item(TTR("Set as Main Scene"), EditorNode::
208+
SCENE_TAB_SET_AS_MAIN_SCENE);
208209
DISABLE_LAST_OPTION_IF(no_root_node || (!main_scene_path.is_empty() && ResourceUID::ensure_path(main_scene_path) == scene_path));
209210

210211
scene_tabs_context_menu->add_separator();
@@ -230,6 +231,12 @@ void EditorSceneTabs::_update_context_menu() {
230231
last_hovered_tab = tab_id;
231232
}
232233

234+
void EditorSceneTabs::_menu_option(int p_option) {
235+
// Set the tab context for menu operations.
236+
EditorNode::get_singleton()->tab_context_idx = last_hovered_tab;
237+
EditorNode::get_singleton()->trigger_menu_option(p_option, false);
238+
}
239+
233240
void EditorSceneTabs::_custom_menu_option(int p_option) {
234241
if (p_option >= EditorContextMenuPlugin::BASE_ID) {
235242
EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, p_option, last_hovered_tab >= 0 ? EditorNode::get_editor_data().get_scene_path(last_hovered_tab) : String());
@@ -428,7 +435,7 @@ EditorSceneTabs::EditorSceneTabs() {
428435
tabbar_panel->add_child(tabbar_container);
429436

430437
scene_tabs = memnew(TabBar);
431-
scene_tabs->set_select_with_rmb(true);
438+
scene_tabs->set_select_with_rmb(false);
432439
scene_tabs->add_tab("unsaved");
433440
scene_tabs->set_tab_close_display_policy((TabBar::CloseButtonDisplayPolicy)EDITOR_GET("interface/scene_tabs/display_close_button").operator int());
434441
scene_tabs->set_max_tab_width(int(EDITOR_GET("interface/scene_tabs/maximum_width")) * EDSCALE);
@@ -448,7 +455,7 @@ EditorSceneTabs::EditorSceneTabs() {
448455

449456
scene_tabs_context_menu = memnew(PopupMenu);
450457
tabbar_container->add_child(scene_tabs_context_menu);
451-
scene_tabs_context_menu->connect(SceneStringName(id_pressed), callable_mp(EditorNode::get_singleton(), &EditorNode::trigger_menu_option).bind(false));
458+
scene_tabs_context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorSceneTabs::_menu_option));
452459
scene_tabs_context_menu->connect(SceneStringName(id_pressed), callable_mp(this, &EditorSceneTabs::_custom_menu_option));
453460

454461
scene_tab_add = memnew(Button);

editor/scene/editor_scene_tabs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class EditorSceneTabs : public MarginContainer {
8080
void _update_tab_titles();
8181
void _reposition_active_tab(int p_to_index);
8282
void _update_context_menu();
83+
void _menu_option(int p_option);
8384
void _custom_menu_option(int p_option);
8485
void _update_scene_list();
8586

0 commit comments

Comments
 (0)