mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 02:12:09 -05:00
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.
This commit is contained in:
parent
790908ffc3
commit
7f2e1991cc
5 changed files with 26 additions and 25 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue