From a230524c4668c72b5a519a8f441637f54bee6654 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 22 Aug 2021 19:38:05 +0200 Subject: HackStudio: Update the tree view cursor on editor change and 'Save as' The more important thing here is to update the tree view on 'Save As..', as we want to drop every connection from an old file. Updating the tree view on current editor change is just a cool small bonus. :^) --- Userland/DevTools/HackStudio/HackStudioWidget.cpp | 13 +++++++++++++ Userland/DevTools/HackStudio/HackStudioWidget.h | 1 + 2 files changed, 14 insertions(+) (limited to 'Userland/DevTools') diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 4932b6ddec..bf715e6e9b 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -690,6 +690,9 @@ NonnullRefPtr HackStudioWidget::create_save_as_action() m_open_files_vector.append(relative_file_path); update_window_title(); + + m_project->model().invalidate(); + update_tree_view(); }); } @@ -887,6 +890,7 @@ void HackStudioWidget::set_current_editor_wrapper(RefPtr editor_w { m_current_editor_wrapper = editor_wrapper; update_window_title(); + update_tree_view(); } void HackStudioWidget::configure_project_tree_view() @@ -1257,6 +1261,15 @@ void HackStudioWidget::update_gml_preview() m_gml_preview_widget->load_gml(gml_content); } +void HackStudioWidget::update_tree_view() +{ + auto index = m_project->model().index(m_current_editor_wrapper->filename(), GUI::FileSystemModel::Column::Name); + if (index.is_valid()) { + m_project_tree_view->expand_all_parents_of(index); + m_project_tree_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set); + } +} + void HackStudioWidget::update_window_title() { window()->set_title(String::formatted("{} - {} - Hack Studio", m_current_editor_wrapper->filename_label().text(), m_project->name())); diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h index 8703eeb312..b690676e5e 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.h +++ b/Userland/DevTools/HackStudio/HackStudioWidget.h @@ -125,6 +125,7 @@ private: bool any_document_is_dirty() const; void update_gml_preview(); + void update_tree_view(); void update_window_title(); NonnullRefPtrVector m_all_editor_wrappers; -- cgit v1.2.3