summaryrefslogtreecommitdiff
path: root/Userland/DevTools
diff options
context:
space:
mode:
authorLennon Donaghy <donaghylennon@gmail.com>2021-08-01 13:01:49 +0100
committerAndreas Kling <kling@serenityos.org>2021-08-22 10:30:06 +0200
commitd48bd490025db62e3d2a0801c3fb745fff013891 (patch)
treeddf613c72d441aadda0b78b34727e4d6156f521f /Userland/DevTools
parent219206725bcd962730e7ab7352a39eac28b4c3de (diff)
downloadserenity-d48bd490025db62e3d2a0801c3fb745fff013891.zip
HackStudio: Move handle_external_file_deletion logic into own method
Added a close_file_in_all_editors method to HackStudioWidget and moved the code from handle_external_file_deletion into it so that it can be reused elsewhere to close files.
Diffstat (limited to 'Userland/DevTools')
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp51
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.h1
2 files changed, 29 insertions, 23 deletions
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index bba00cf6c8..3ec2c9455c 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -301,6 +301,33 @@ bool HackStudioWidget::open_file(const String& full_filename)
return true;
}
+void HackStudioWidget::close_file_in_all_editors(String const& filename)
+{
+ m_open_files.remove(filename);
+ m_open_files_vector.remove_all_matching(
+ [&filename](String const& element) { return element == filename; });
+
+ for (auto& editor_wrapper : m_all_editor_wrappers) {
+ Editor& editor = editor_wrapper.editor();
+ String editor_file_path = editor.code_document().file_path();
+ String relative_editor_file_path = LexicalPath::relative_path(editor_file_path, project().root_path());
+
+ if (relative_editor_file_path == filename) {
+ if (m_open_files_vector.is_empty()) {
+ editor.set_document(CodeDocument::create());
+ editor_wrapper.set_filename("");
+ } else {
+ auto& first_path = m_open_files_vector[0];
+ auto& document = m_open_files.get(first_path).value()->code_document();
+ editor.set_document(document);
+ editor_wrapper.set_filename(first_path);
+ }
+ }
+ }
+
+ m_open_files_view->model()->invalidate();
+}
+
EditorWrapper& HackStudioWidget::current_editor_wrapper()
{
VERIFY(m_current_editor_wrapper);
@@ -1121,29 +1148,7 @@ void HackStudioWidget::update_statusbar()
void HackStudioWidget::handle_external_file_deletion(const String& filepath)
{
- m_open_files.remove(filepath);
- m_open_files_vector.remove_all_matching(
- [&filepath](const String& element) { return element == filepath; });
-
- for (auto& editor_wrapper : m_all_editor_wrappers) {
- Editor& editor = editor_wrapper.editor();
- String editor_file_path = editor.code_document().file_path();
- String relative_editor_file_path = LexicalPath::relative_path(editor_file_path, project().root_path());
-
- if (relative_editor_file_path == filepath) {
- if (m_open_files_vector.is_empty()) {
- editor.set_document(CodeDocument::create());
- editor_wrapper.set_filename("");
- } else {
- auto& first_path = m_open_files_vector[0];
- auto& document = m_open_files.get(first_path).value()->code_document();
- editor.set_document(document);
- editor_wrapper.set_filename(first_path);
- }
- }
- }
-
- m_open_files_view->model()->invalidate();
+ close_file_in_all_editors(filepath);
}
HackStudioWidget::~HackStudioWidget()
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h
index 19fe065c2f..c6ddd85ea1 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.h
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.h
@@ -35,6 +35,7 @@ class HackStudioWidget : public GUI::Widget {
public:
virtual ~HackStudioWidget() override;
bool open_file(const String& filename);
+ void close_file_in_all_editors(String const& filename);
void update_actions();
Project& project();