Skip to content

Commit

Permalink
Implement Floating Script Editor Window
Browse files Browse the repository at this point in the history
I've been working on a solution to make the script editor a floating window.
  • Loading branch information
SirQuartz committed Jun 24, 2022
1 parent faae246 commit 7d28e5a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
45 changes: 44 additions & 1 deletion editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,9 +1264,11 @@ void ScriptEditor::_menu_option(int p_option) {
if (_test_script_times_on_disk()) {
return;
}

save_all_scripts();
} break;
case FLOAT_WINDOW: {
_on_float_window_requested();
} break;
case SEARCH_IN_FILES: {
_on_find_in_files_requested("");
} break;
Expand Down Expand Up @@ -3526,6 +3528,40 @@ void ScriptEditor::_script_changed() {
NodeDock::get_singleton()->update_lists();
}

void ScriptEditor::_on_float_window_requested() {
Control *base_editor = script_editor;

// Script editor current position
Point2 script_window_pos = base_editor->get_global_position() + get_tree()->get_root()->get_position();

// Create a new window
Window *window = memnew(Window);
window->set_title("Script Editor");
// Set the window size to the current script editor size
window->set_size(base_editor->get_size());
EditorNode::get_singleton()->get_main_control()->remove_child(script_editor);
base_editor->set_anchors_and_offsets_preset(LayoutPreset::PRESET_WIDE);
// Add the script editor to the window
window->add_child(base_editor);
window->set_wrap_controls(true);
window->set_position(script_window_pos); // Set the window position to match where the script editor is
window->set_transient(true);
window->connect("close_requested", callable_mp(this, &ScriptEditor::_script_floating_close_request), varray(base_editor));
// Add the window to the editor
EditorNode::get_singleton()->get_gui_base()->add_child(window);
}

void ScriptEditor::_script_floating_close_request(Control *p_control) {
// First, get the floating script editor window
Window *window = static_cast<Window *>(p_control->get_parent());
// Then remove the script editor from the window
window->remove_child(p_control);
// Next, add it back to the main window GUI
EditorNode::get_singleton()->get_main_control()->add_child(p_control);
// Now we can close the sub-window
window->queue_delete();
}

void ScriptEditor::_on_find_in_files_requested(String text) {
find_in_files_dialog->set_find_in_files_mode(FindInFilesDialog::SEARCH_MODE);
find_in_files_dialog->set_search_text(text);
Expand Down Expand Up @@ -3829,6 +3865,13 @@ ScriptEditor::ScriptEditor() {
menu_hb->add_child(debug_menu);
debug_menu->hide(); // Handled by EditorDebuggerNode below.

float_window = memnew(Button);
float_window->set_flat(true);
float_window->set_text(TTR("Float Window"));
float_window->connect("pressed", callable_mp(this, &ScriptEditor::_menu_option), varray(FLOAT_WINDOW));
menu_hb->add_child(float_window);
float_window->set_tooltip(TTR("Make script editor a floating window."));

EditorDebuggerNode *debugger = EditorDebuggerNode::get_singleton();
debugger->set_script_debug_button(debug_menu);
debugger->connect("goto_script_line", callable_mp(this, &ScriptEditor::_goto_script_line));
Expand Down
4 changes: 4 additions & 0 deletions editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class ScriptEditor : public PanelContainer {
FILE_THEME,
FILE_RUN,
FILE_CLOSE,
FLOAT_WINDOW,
CLOSE_DOCS,
CLOSE_ALL,
CLOSE_OTHER_TABS,
Expand Down Expand Up @@ -254,6 +255,7 @@ class ScriptEditor : public PanelContainer {
PopupMenu *theme_submenu = nullptr;

Button *help_search = nullptr;
Button *float_window = nullptr;
Button *site_search = nullptr;
EditorHelpSearch *help_search_dialog = nullptr;

Expand Down Expand Up @@ -448,6 +450,8 @@ class ScriptEditor : public PanelContainer {
void _update_modified_scripts_for_external_editor(Ref<Script> p_for_script = Ref<Script>());

void _script_changed();
void _on_float_window_requested();
void _script_floating_close_request(Control *p_control);
int file_dialog_option;
void _file_dialog_action(String p_file);

Expand Down

0 comments on commit 7d28e5a

Please sign in to comment.