Skip to content

Commit 869e059

Browse files
committed
Merge pull request #98074 from YeldhamDev/stop_moving_will_ya
Add a pin toggle to prevent involuntary bottom editor switching
2 parents 0d47b84 + bb07b2d commit 869e059

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

doc/classes/EditorSettings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,11 @@
10911091
</member>
10921092
<member name="run/bottom_panel/action_on_play" type="int" setter="" getter="">
10931093
The action to execute on the bottom panel when running the project.
1094+
[b]Note:[/b] This option won't do anything if the bottom panel switching is locked using the pin button in the corner of the bottom panel.
10941095
</member>
10951096
<member name="run/bottom_panel/action_on_stop" type="int" setter="" getter="">
10961097
The action to execute on the bottom panel when stopping the project.
1098+
[b]Note:[/b] This option won't do anything if the bottom panel switching is locked using the pin button in the corner of the bottom panel.
10971099
</member>
10981100
<member name="run/output/always_clear_output_on_play" type="bool" setter="" getter="">
10991101
If [code]true[/code], the editor will clear the Output panel when running the project.

editor/gui/editor_bottom_panel.cpp

+31-11
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,35 @@
3131
#include "editor_bottom_panel.h"
3232

3333
#include "editor/debugger/editor_debugger_node.h"
34-
#include "editor/editor_about.h"
3534
#include "editor/editor_command_palette.h"
3635
#include "editor/editor_node.h"
3736
#include "editor/editor_string_names.h"
38-
#include "editor/engine_update_label.h"
3937
#include "editor/gui/editor_toaster.h"
4038
#include "editor/gui/editor_version_button.h"
4139
#include "editor/themes/editor_scale.h"
4240
#include "scene/gui/box_container.h"
4341
#include "scene/gui/button.h"
42+
#include "scene/gui/split_container.h"
4443

4544
void EditorBottomPanel::_notification(int p_what) {
4645
switch (p_what) {
4746
case NOTIFICATION_THEME_CHANGED: {
47+
pin_button->set_button_icon(get_editor_theme_icon(SNAME("Pin")));
4848
expand_button->set_button_icon(get_editor_theme_icon(SNAME("ExpandBottomDock")));
4949
} break;
5050
}
5151
}
5252

53-
void EditorBottomPanel::_switch_by_control(bool p_visible, Control *p_control) {
53+
void EditorBottomPanel::_switch_by_control(bool p_visible, Control *p_control, bool p_ignore_lock) {
5454
for (int i = 0; i < items.size(); i++) {
5555
if (items[i].control == p_control) {
56-
_switch_to_item(p_visible, i);
56+
_switch_to_item(p_visible, i, p_ignore_lock);
5757
return;
5858
}
5959
}
6060
}
6161

62-
void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx) {
62+
void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx, bool p_ignore_lock) {
6363
ERR_FAIL_INDEX(p_idx, items.size());
6464

6565
if (items[p_idx].control->is_visible() == p_visible) {
@@ -70,6 +70,10 @@ void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx) {
7070
ERR_FAIL_NULL(center_split);
7171

7272
if (p_visible) {
73+
if (!p_ignore_lock && lock_panel_switching && pin_button->is_visible()) {
74+
return;
75+
}
76+
7377
for (int i = 0; i < items.size(); i++) {
7478
items[i].button->set_pressed_no_signal(i == p_idx);
7579
items[i].control->set_visible(i == p_idx);
@@ -80,18 +84,23 @@ void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx) {
8084
} else {
8185
add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
8286
}
87+
8388
center_split->set_dragger_visibility(SplitContainer::DRAGGER_VISIBLE);
8489
center_split->set_collapsed(false);
90+
pin_button->show();
91+
92+
expand_button->show();
8593
if (expand_button->is_pressed()) {
8694
EditorNode::get_top_split()->hide();
8795
}
88-
expand_button->show();
8996
} else {
9097
add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles)));
9198
items[p_idx].button->set_pressed_no_signal(false);
9299
items[p_idx].control->set_visible(false);
93100
center_split->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN);
94101
center_split->set_collapsed(true);
102+
pin_button->hide();
103+
95104
expand_button->hide();
96105
if (expand_button->is_pressed()) {
97106
EditorNode::get_top_split()->show();
@@ -101,13 +110,17 @@ void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx) {
101110
last_opened_control = items[p_idx].control;
102111
}
103112

113+
void EditorBottomPanel::_pin_button_toggled(bool p_pressed) {
114+
lock_panel_switching = p_pressed;
115+
}
116+
104117
void EditorBottomPanel::_expand_button_toggled(bool p_pressed) {
105118
EditorNode::get_top_split()->set_visible(!p_pressed);
106119
}
107120

108121
bool EditorBottomPanel::_button_drag_hover(const Vector2 &, const Variant &, Button *p_button, Control *p_control) {
109122
if (!p_button->is_pressed()) {
110-
_switch_by_control(true, p_control);
123+
_switch_by_control(true, p_control, true);
111124
}
112125
return false;
113126
}
@@ -149,7 +162,7 @@ void EditorBottomPanel::load_layout_from_config(Ref<ConfigFile> p_config_file, c
149162
Button *EditorBottomPanel::add_item(String p_text, Control *p_item, const Ref<Shortcut> &p_shortcut, bool p_at_front) {
150163
Button *tb = memnew(Button);
151164
tb->set_theme_type_variation("BottomPanelButton");
152-
tb->connect(SceneStringName(toggled), callable_mp(this, &EditorBottomPanel::_switch_by_control).bind(p_item));
165+
tb->connect(SceneStringName(toggled), callable_mp(this, &EditorBottomPanel::_switch_by_control).bind(p_item, true));
153166
tb->set_drag_forwarding(Callable(), callable_mp(this, &EditorBottomPanel::_button_drag_hover).bind(tb, p_item), Callable());
154167
tb->set_text(p_text);
155168
tb->set_shortcut(p_shortcut);
@@ -231,10 +244,10 @@ void EditorBottomPanel::toggle_last_opened_bottom_panel() {
231244
// Select by control instead of index, so that the last bottom panel is opened correctly
232245
// if it's been reordered since.
233246
if (last_opened_control) {
234-
_switch_by_control(!last_opened_control->is_visible(), last_opened_control);
247+
_switch_by_control(!last_opened_control->is_visible(), last_opened_control, true);
235248
} else {
236249
// Open the first panel in the list if no panel was opened this session.
237-
_switch_to_item(true, 0);
250+
_switch_to_item(true, 0, true);
238251
}
239252
}
240253

@@ -263,10 +276,17 @@ EditorBottomPanel::EditorBottomPanel() {
263276
Control *h_spacer = memnew(Control);
264277
bottom_hbox->add_child(h_spacer);
265278

279+
pin_button = memnew(Button);
280+
bottom_hbox->add_child(pin_button);
281+
pin_button->hide();
282+
pin_button->set_theme_type_variation("FlatMenuButton");
283+
pin_button->set_toggle_mode(true);
284+
pin_button->set_tooltip_text(TTR("Pin Bottom Panel Switching"));
285+
pin_button->connect(SceneStringName(toggled), callable_mp(this, &EditorBottomPanel::_pin_button_toggled));
286+
266287
expand_button = memnew(Button);
267288
bottom_hbox->add_child(expand_button);
268289
expand_button->hide();
269-
expand_button->set_flat(false);
270290
expand_button->set_theme_type_variation("FlatMenuButton");
271291
expand_button->set_toggle_mode(true);
272292
expand_button->set_shortcut(ED_SHORTCUT_AND_COMMAND("editor/bottom_panel_expand", TTR("Expand Bottom Panel"), KeyModifierMask::SHIFT | Key::F12));

editor/gui/editor_bottom_panel.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,19 @@ class EditorBottomPanel : public PanelContainer {
4949
};
5050

5151
Vector<BottomPanelItem> items;
52+
bool lock_panel_switching = false;
5253

5354
VBoxContainer *item_vbox = nullptr;
5455
HBoxContainer *bottom_hbox = nullptr;
5556
HBoxContainer *button_hbox = nullptr;
5657
EditorToaster *editor_toaster = nullptr;
58+
Button *pin_button = nullptr;
5759
Button *expand_button = nullptr;
5860
Control *last_opened_control = nullptr;
5961

60-
void _switch_by_control(bool p_visible, Control *p_control);
61-
void _switch_to_item(bool p_visible, int p_idx);
62+
void _switch_by_control(bool p_visible, Control *p_control, bool p_ignore_lock = false);
63+
void _switch_to_item(bool p_visible, int p_idx, bool p_ignore_lock = false);
64+
void _pin_button_toggled(bool p_pressed);
6265
void _expand_button_toggled(bool p_pressed);
6366

6467
bool _button_drag_hover(const Vector2 &, const Variant &, Button *p_button, Control *p_control);

0 commit comments

Comments
 (0)