diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index 111bc93014..128eff2ca1 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -51,6 +51,13 @@ EditorWrapper::EditorWrapper() m_editor->on_open = [](String path) { open_file(path); }; + + m_editor->on_change = [this] { + bool was_dirty = m_document_dirty; + m_document_dirty = true; + if (!was_dirty) + update_title(); + }; } EditorWrapper::~EditorWrapper() @@ -80,10 +87,28 @@ 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); + update_title(); +} + +void EditorWrapper::save() +{ + editor().write_to_file(filename()); + m_document_dirty = false; + update_title(); +} + +void EditorWrapper::update_title() +{ + StringBuilder title; + title.append(m_filename); + + if (m_document_dirty) + title.append(" (*)"); + m_filename_label->set_text(title.to_string()); } } diff --git a/Userland/DevTools/HackStudio/EditorWrapper.h b/Userland/DevTools/HackStudio/EditorWrapper.h index af0f9d0316..ea72912180 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.h +++ b/Userland/DevTools/HackStudio/EditorWrapper.h @@ -26,6 +26,8 @@ public: Editor& editor() { return *m_editor; } const Editor& editor() const { return *m_editor; } + void save(); + GUI::Label& filename_label() { return *m_filename_label; } const GUI::Label& filename_label() const { return *m_filename_label; } @@ -40,10 +42,13 @@ public: private: EditorWrapper(); + void update_title(); + String m_filename; RefPtr m_filename_label; RefPtr m_cursor_label; RefPtr m_editor; + bool m_document_dirty {false}; }; } diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 6bf740c92c..5f7f0e5d32 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -552,7 +552,7 @@ NonnullRefPtr HackStudioWidget::create_save_action() if (active_file().is_empty()) return; - current_editor().write_to_file(active_file()); + current_editor_wrapper().save(); if (m_git_widget->initialized()) m_git_widget->refresh();