summaryrefslogtreecommitdiff
path: root/Userland/DevTools/HackStudio
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-05-01 13:04:19 +0300
committerAndreas Kling <kling@serenityos.org>2021-05-02 22:49:25 +0200
commit7f2e1991cc91582a8cddf0092ca0fba375ce2035 (patch)
treebc33b4e9fd1486931660d400d6105f32421b848b /Userland/DevTools/HackStudio
parent790908ffc3a77dc140b301ee1765b614a94a65d3 (diff)
downloadserenity-7f2e1991cc91582a8cddf0092ca0fba375ce2035.zip
HackStudio: Get rid of m_currently_open_file member
It had the following FIXME: // FIXME: This doesn't seem compatible with multiple split editors In practice this member was used to get the filename of the currently active edtior. So we now get it directly from the currently active EditorWrapper.
Diffstat (limited to 'Userland/DevTools/HackStudio')
-rw-r--r--Userland/DevTools/HackStudio/EditorWrapper.cpp5
-rw-r--r--Userland/DevTools/HackStudio/EditorWrapper.h3
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.cpp36
-rw-r--r--Userland/DevTools/HackStudio/HackStudioWidget.h5
-rw-r--r--Userland/DevTools/HackStudio/main.cpp2
5 files changed, 26 insertions, 25 deletions
diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp
index 79ea5c2dea..111bc93014 100644
--- a/Userland/DevTools/HackStudio/EditorWrapper.cpp
+++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp
@@ -80,5 +80,10 @@ void EditorWrapper::set_mode_non_displayable()
editor().set_palette(palette);
editor().document().set_text("The contents of this file could not be displayed. Is it a binary file?");
}
+void EditorWrapper::set_filename(const String& filename)
+{
+ m_filename = filename;
+ m_filename_label->set_text(m_filename);
+}
}
diff --git a/Userland/DevTools/HackStudio/EditorWrapper.h b/Userland/DevTools/HackStudio/EditorWrapper.h
index 226c103015..af0f9d0316 100644
--- a/Userland/DevTools/HackStudio/EditorWrapper.h
+++ b/Userland/DevTools/HackStudio/EditorWrapper.h
@@ -34,10 +34,13 @@ public:
void set_mode_displayable();
void set_mode_non_displayable();
+ void set_filename(const String&);
+ const String& filename() const {return m_filename;}
private:
EditorWrapper();
+ String m_filename;
RefPtr<GUI::Label> m_filename_label;
RefPtr<GUI::Label> m_cursor_label;
RefPtr<Editor> m_editor;
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
index c79b7979fc..6bf740c92c 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp
@@ -215,15 +215,15 @@ bool HackStudioWidget::open_file(const String& full_filename)
if (Core::File::is_directory(filename) || !Core::File::exists(filename))
return false;
- if (!currently_open_file().is_empty()) {
+ if (!active_file().is_empty()) {
// Since the file is previously open, it should always be in m_open_files.
- VERIFY(m_open_files.find(currently_open_file()) != m_open_files.end());
- auto previous_open_project_file = m_open_files.get(currently_open_file()).value();
+ VERIFY(m_open_files.find(active_file()) != m_open_files.end());
+ auto previous_open_project_file = m_open_files.get(active_file()).value();
// Update the scrollbar values of the previous_open_project_file and save them to m_open_files.
previous_open_project_file->vertical_scroll_value(current_editor().vertical_scrollbar().value());
previous_open_project_file->horizontal_scroll_value(current_editor().horizontal_scrollbar().value());
- m_open_files.set(currently_open_file(), previous_open_project_file);
+ m_open_files.set(active_file(), previous_open_project_file);
}
RefPtr<ProjectFile> new_project_file = nullptr;
@@ -266,16 +266,14 @@ bool HackStudioWidget::open_file(const String& full_filename)
set_edit_mode(EditMode::Text);
}
- m_currently_open_file = filename;
-
- String relative_file_path = m_currently_open_file;
- if (m_currently_open_file.starts_with(m_project->root_path()))
- relative_file_path = m_currently_open_file.substring(m_project->root_path().length() + 1);
+ String relative_file_path = filename;
+ if (filename.starts_with(m_project->root_path()))
+ relative_file_path = filename.substring(m_project->root_path().length() + 1);
window()->set_title(String::formatted("{} - {} - Hack Studio", relative_file_path, m_project->name()));
m_project_tree_view->update();
- current_editor_wrapper().filename_label().set_text(filename);
+ current_editor_wrapper().set_filename(filename);
current_editor().set_focus(true);
return true;
@@ -551,10 +549,10 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_action()
NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_action()
{
return GUI::CommonActions::make_save_action([&](auto&) {
- if (m_currently_open_file.is_empty())
+ if (active_file().is_empty())
return;
- current_editor().write_to_file(m_currently_open_file);
+ current_editor().write_to_file(active_file());
if (m_git_widget->initialized())
m_git_widget->refresh();
@@ -716,16 +714,16 @@ String HackStudioWidget::get_project_executable_path() const
void HackStudioWidget::build(TerminalWrapper& wrapper)
{
- if (m_currently_open_file.ends_with(".js"))
- wrapper.run_command(String::formatted("js -A {}", m_currently_open_file));
+ if (active_file().ends_with(".js"))
+ wrapper.run_command(String::formatted("js -A {}", active_file()));
else
wrapper.run_command("make");
}
void HackStudioWidget::run(TerminalWrapper& wrapper)
{
- if (m_currently_open_file.ends_with(".js"))
- wrapper.run_command(String::formatted("js {}", m_currently_open_file));
+ if (active_file().ends_with(".js"))
+ wrapper.run_command(String::formatted("js {}", active_file()));
else
wrapper.run_command("make run");
}
@@ -1104,14 +1102,12 @@ void HackStudioWidget::handle_external_file_deletion(const String& filepath)
if (relative_editor_file_path == filepath) {
if (m_open_files_vector.is_empty()) {
editor.set_document(CodeDocument::create());
- editor_wrapper.filename_label().set_text(String { "Undefined" });
- m_currently_open_file = "";
+ 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.filename_label().set_text(first_path);
- m_currently_open_file = first_path;
+ editor_wrapper.set_filename(first_path);
}
}
}
diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.h b/Userland/DevTools/HackStudio/HackStudioWidget.h
index 312d138bf3..5d386712fa 100644
--- a/Userland/DevTools/HackStudio/HackStudioWidget.h
+++ b/Userland/DevTools/HackStudio/HackStudioWidget.h
@@ -41,7 +41,7 @@ public:
EditorWrapper& current_editor_wrapper();
void set_current_editor_wrapper(RefPtr<EditorWrapper>);
- String currently_open_file() const { return m_currently_open_file; }
+ const String& active_file() const { return m_current_editor_wrapper->filename(); }
void initialize_menubar(GUI::Menubar&);
Locator& locator()
@@ -116,9 +116,6 @@ private:
NonnullRefPtrVector<EditorWrapper> m_all_editor_wrappers;
RefPtr<EditorWrapper> m_current_editor_wrapper;
- // FIXME: This doesn't seem compatible with multiple split editors
- String m_currently_open_file;
-
HashMap<String, NonnullRefPtr<ProjectFile>> m_open_files;
HashMap<String, NonnullRefPtr<Core::FileWatcher>> m_file_watchers;
Vector<String> m_open_files_vector; // NOTE: This contains the keys from m_open_files and m_file_watchers
diff --git a/Userland/DevTools/HackStudio/main.cpp b/Userland/DevTools/HackStudio/main.cpp
index 547d69ad7a..0cb393c89b 100644
--- a/Userland/DevTools/HackStudio/main.cpp
+++ b/Userland/DevTools/HackStudio/main.cpp
@@ -159,7 +159,7 @@ String currently_open_file()
{
if (!s_hack_studio_widget)
return {};
- return s_hack_studio_widget->currently_open_file();
+ return s_hack_studio_widget->active_file();
}
void set_current_editor_wrapper(RefPtr<EditorWrapper> wrapper)