Skip to content

Commit

Permalink
Added Pin Tab button gui to tab bar of Debugger bottom panel. Include…
Browse files Browse the repository at this point in the history
…s two private variables to track the pinned tab index(and a public method to get that variable), and the pin button index. Added several private methods to update the logic. The button forces a tab open upon project start and overrides related editor settings. The button is updated to always be the last tab on the Debugger's tab bar.
  • Loading branch information
Wierdox committed Oct 12, 2023
1 parent b137180 commit 82e0679
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
4 changes: 3 additions & 1 deletion editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ Error EditorDebuggerNode::start(const String &p_uri) {
}
stop(true);
current_uri = p_uri;
if (EDITOR_GET("run/output/always_open_output_on_play")) {

int debugger_tab_pin_idx = EditorDebuggerNode::get_singleton()->get_current_debugger()->get_debugger_tab_pin_idx();
if (EDITOR_GET("run/output/always_open_output_on_play") && debugger_tab_pin_idx == -1) {
EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorNode::get_log());
} else {
EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
Expand Down
89 changes: 88 additions & 1 deletion editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ void ScriptEditorDebugger::update_tabs() {
tabs->set_tab_icon(tabs->get_tab_idx_from_control(errors_tab), get_editor_theme_icon(SNAME("Warning")));
}
}
if (tab_pin_button_idx != tabs->get_tab_count() - 1) {
// Ensure pin button is last in debugger tabs.
Control *pin_button = tabs->get_tab_control(tab_pin_button_idx);
tabs->remove_child(pin_button);
tabs->add_child(pin_button);
tab_pin_button_idx = tabs->get_tab_count() - 1;
if (tab_pin_idx == -1 || tabs->get_current_tab() != tab_pin_idx) {
_tab_pin_button_enable_pin();
} else {
_tab_pin_button_enable_unpin();
}
}
}

void ScriptEditorDebugger::clear_style() {
Expand Down Expand Up @@ -1006,7 +1018,11 @@ void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
set_process(true);
camera_override = CameraOverride::OVERRIDE_NONE;

tabs->set_current_tab(0);
if (tab_pin_idx >= 0) {
tabs->set_current_tab(tab_pin_idx);
} else {
tabs->set_current_tab(0);
}
_set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS);
_update_buttons_state();
emit_signal(SNAME("started"));
Expand Down Expand Up @@ -1723,6 +1739,66 @@ void ScriptEditorDebugger::_tab_changed(int p_tab) {
// "Video RAM" tab was clicked, refresh the data it's displaying when entering the tab.
_video_mem_request();
}
if (p_tab == tab_pin_button_idx) {
// This tab acts as a button, so always send user back to previous tab.
tabs->set_current_tab(tabs->get_previous_tab());
_tab_button_pressed(tab_pin_button_idx);
return;
}
// Update context of tab pin button.
if (p_tab == tab_pin_idx) {
_tab_pin_button_enable_unpin();
} else {
_tab_pin_button_enable_pin();
}

}

void ScriptEditorDebugger::_tab_button_pressed(int p_tab) {
{ //pinned tabs
if (p_tab == tab_pin_button_idx) {
if (tabs->get_tab_icon(tab_pin_button_idx) == get_editor_theme_icon(SNAME("PinJoint3D"))) {
// Unpin a tab.
tabs->set_tab_button_icon(tab_pin_idx, nullptr);
tab_pin_idx = -1;
_tab_pin_button_enable_pin();
} else if (tab_pin_idx == -1) {
// Pin a tab.
tab_pin_idx = tabs->get_current_tab();
tabs->set_tab_button_icon(tab_pin_idx, get_editor_theme_icon(SNAME("PinJoint2D")));
_tab_pin_button_enable_unpin();
} else {
// Shift pin from an already pinned tab.
tabs->set_tab_button_icon(tab_pin_idx, nullptr);
tab_pin_idx = tabs->get_current_tab();
tabs->set_tab_button_icon(tab_pin_idx, get_editor_theme_icon(SNAME("PinJoint2D")));
_tab_pin_button_enable_unpin();
}
return;
}
if (tabs->get_tab_button_icon(p_tab) == nullptr) {
// For some reason tabs without a texture can still emit tab_button_pressed, so ignore.
return;
}
// Unpin a tab with its button.
tabs->set_tab_button_icon(p_tab, nullptr);
tab_pin_idx = -1;
_tab_pin_button_enable_pin();
}
}

void ScriptEditorDebugger::_tab_pin_button_enable_pin() {
if (tab_pin_idx == -1) {
tabs->set_tab_title(tab_pin_button_idx, TTR("Pin Tab"));
} else {
tabs->set_tab_title(tab_pin_button_idx, TTR("Shift Pin"));
}
tabs->set_tab_icon(tab_pin_button_idx, get_editor_theme_icon(SNAME("PinJoint2D")));
}

void ScriptEditorDebugger::_tab_pin_button_enable_unpin() {
tabs->set_tab_title(tab_pin_button_idx, TTR("Unpin"));
tabs->set_tab_icon(tab_pin_button_idx, get_editor_theme_icon(SNAME("PinJoint3D")));
}

void ScriptEditorDebugger::_bind_methods() {
Expand Down Expand Up @@ -1773,6 +1849,10 @@ int ScriptEditorDebugger::get_current_debugger_tab() const {
return tabs->get_current_tab();
}

int ScriptEditorDebugger::get_debugger_tab_pin_idx() const {
return tab_pin_idx;
}

void ScriptEditorDebugger::switch_to_debugger(int p_debugger_tab_idx) {
tabs->set_current_tab(p_debugger_tab_idx);
}
Expand All @@ -1792,6 +1872,7 @@ ScriptEditorDebugger::ScriptEditorDebugger() {
tabs = memnew(TabContainer);
add_child(tabs);
tabs->connect("tab_changed", callable_mp(this, &ScriptEditorDebugger::_tab_changed));
tabs->connect("tab_button_pressed", callable_mp(this, &ScriptEditorDebugger::_tab_button_pressed));

InspectorDock::get_inspector_singleton()->connect("object_id_selected", callable_mp(this, &ScriptEditorDebugger::_remote_object_selected));

Expand Down Expand Up @@ -2111,6 +2192,12 @@ ScriptEditorDebugger::ScriptEditorDebugger() {
misc->add_child(buttons);
}

Button *pin_button = memnew(Button);
tabs->add_child(pin_button);
tab_pin_idx = -1;
tab_pin_button_idx = tabs->get_tab_count() - 1;
_tab_pin_button_enable_pin();

msgdialog = memnew(AcceptDialog);
add_child(msgdialog);

Expand Down
6 changes: 6 additions & 0 deletions editor/debugger/script_editor_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class ScriptEditorDebugger : public MarginContainer {
Ref<Script> stack_script;

TabContainer *tabs = nullptr;
int tab_pin_idx;
int tab_pin_button_idx;

Label *reason = nullptr;

Expand Down Expand Up @@ -221,6 +223,9 @@ class ScriptEditorDebugger : public MarginContainer {
void _error_tree_item_rmb_selected(const Vector2 &p_pos, MouseButton p_button);
void _item_menu_id_pressed(int p_option);
void _tab_changed(int p_tab);
void _tab_button_pressed(int p_tab);
void _tab_pin_button_enable_pin();
void _tab_pin_button_enable_unpin();

void _put_msg(String p_message, Array p_data, uint64_t p_thread_id = Thread::MAIN_ID);
void _export_csv();
Expand Down Expand Up @@ -309,6 +314,7 @@ class ScriptEditorDebugger : public MarginContainer {
void add_debugger_tab(Control *p_control);
void remove_debugger_tab(Control *p_control);
int get_current_debugger_tab() const;
int get_debugger_tab_pin_idx() const;
void switch_to_debugger(int p_debugger_tab_idx);

void send_message(const String &p_message, const Array &p_args);
Expand Down
5 changes: 4 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4147,7 +4147,10 @@ void EditorNode::_project_run_started() {
log->clear();
}

if (bool(EDITOR_GET("run/output/always_open_output_on_play"))) {
int debugger_tab_pin_idx = EditorDebuggerNode::get_singleton()->get_current_debugger()->get_debugger_tab_pin_idx();
if (debugger_tab_pin_idx >= 0) {
make_bottom_panel_item_visible(EditorDebuggerNode::get_singleton()->get_current_debugger());
} else if (bool(EDITOR_GET("run/output/always_open_output_on_play"))) {
make_bottom_panel_item_visible(log);
}
}
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/editor_debugger_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void EditorDebuggerSession::add_session_tab(Control *p_tab) {
ERR_FAIL_COND(!p_tab || !debugger);
debugger->add_debugger_tab(p_tab);
tabs.insert(p_tab);
debugger->update_tabs();
}

void EditorDebuggerSession::remove_session_tab(Control *p_tab) {
Expand Down

0 comments on commit 82e0679

Please sign in to comment.