From d8b54b7dd0e186cebf849352e2888694ab8891d9 Mon Sep 17 00:00:00 2001 From: Marco Cutecchia Date: Mon, 12 Sep 2022 22:32:27 +0200 Subject: [PATCH] HackStudio: Open files in dedicated tabs Previously when trying to open a file from the tree view the file would open in the currently selected tab, substituting the file we were previously reading. This change makes it so that clicking on a file from the tree view opens it in a new tab, or selects the tab containing that file if it's already open in the selected editor group. --- Userland/DevTools/HackStudio/HackStudioWidget.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 30bb875ef31..99a2bc3e674 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -311,6 +311,17 @@ bool HackStudioWidget::open_file(String const& full_filename, size_t line, size_ if (Core::File::is_directory(filename) || !Core::File::exists(filename)) return false; + auto editor_wrapper_or_none = m_all_editor_wrappers.first_matching([&](auto& wrapper) { + return wrapper->filename() == filename; + }); + + if (editor_wrapper_or_none.has_value()) { + set_current_editor_wrapper(editor_wrapper_or_none.release_value()); + return true; + } else { + add_new_editor(*m_current_editor_tab_widget); + } + if (!active_file().is_empty()) { // Since the file is previously open, it should always be in m_open_files. VERIFY(m_open_files.find(active_file()) != m_open_files.end()); @@ -1175,6 +1186,7 @@ void HackStudioWidget::set_current_editor_wrapper(RefPtr editor_w update_current_editor_title(); update_tree_view(); set_current_editor_tab_widget(static_cast(m_current_editor_wrapper->parent())); + m_current_editor_tab_widget->set_active_widget(editor_wrapper); update_statusbar(); }