mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 03:37:34 +00:00
HackStudio: Reuse TextDocument::is_modified()
Previously, the modification tag in the editor file label was unset only after a file was saved. This commit will also unset the tag if you undo the stack (for example by hitting Ctrl+Z) to the last saved state.
This commit is contained in:
parent
2c22ff94b4
commit
cf71805aa8
3 changed files with 7 additions and 19 deletions
|
@ -42,13 +42,8 @@ EditorWrapper::EditorWrapper()
|
||||||
open_file(path);
|
open_file(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_editor->on_change = [this] {
|
m_editor->on_modified_change = [this](bool) {
|
||||||
if (this->on_change)
|
update_title();
|
||||||
this->on_change();
|
|
||||||
bool was_dirty = m_document_dirty;
|
|
||||||
m_document_dirty = true;
|
|
||||||
if (!was_dirty)
|
|
||||||
update_title();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +86,6 @@ void EditorWrapper::set_filename(const String& filename)
|
||||||
void EditorWrapper::save()
|
void EditorWrapper::save()
|
||||||
{
|
{
|
||||||
editor().write_to_file(filename());
|
editor().write_to_file(filename());
|
||||||
m_document_dirty = false;
|
|
||||||
update_title();
|
|
||||||
update_diff();
|
update_diff();
|
||||||
editor().update();
|
editor().update();
|
||||||
}
|
}
|
||||||
|
@ -128,7 +121,7 @@ void EditorWrapper::update_title()
|
||||||
else
|
else
|
||||||
title.append(m_filename);
|
title.append(m_filename);
|
||||||
|
|
||||||
if (m_document_dirty)
|
if (editor().document().is_modified())
|
||||||
title.append(" (*)");
|
title.append(" (*)");
|
||||||
m_filename_label->set_text(title.to_string());
|
m_filename_label->set_text(title.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ public:
|
||||||
void set_debug_mode(bool);
|
void set_debug_mode(bool);
|
||||||
void set_filename(const String&);
|
void set_filename(const String&);
|
||||||
const String& filename() const { return m_filename; }
|
const String& filename() const { return m_filename; }
|
||||||
bool document_dirty() const { return m_document_dirty; }
|
|
||||||
|
|
||||||
Optional<LexicalPath> const& project_root() const { return m_project_root; }
|
Optional<LexicalPath> const& project_root() const { return m_project_root; }
|
||||||
void set_project_root(LexicalPath const& project_root);
|
void set_project_root(LexicalPath const& project_root);
|
||||||
|
@ -64,7 +63,6 @@ private:
|
||||||
String m_filename;
|
String m_filename;
|
||||||
RefPtr<GUI::Label> m_filename_label;
|
RefPtr<GUI::Label> m_filename_label;
|
||||||
RefPtr<Editor> m_editor;
|
RefPtr<Editor> m_editor;
|
||||||
bool m_document_dirty { false };
|
|
||||||
|
|
||||||
Optional<LexicalPath> m_project_root;
|
Optional<LexicalPath> m_project_root;
|
||||||
RefPtr<GitRepo> m_git_repo;
|
RefPtr<GitRepo> m_git_repo;
|
||||||
|
|
|
@ -1253,7 +1253,7 @@ HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(const
|
||||||
|
|
||||||
if (result == GUI::MessageBox::ExecYes) {
|
if (result == GUI::MessageBox::ExecYes) {
|
||||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
||||||
if (editor_wrapper.document_dirty()) {
|
if (editor_wrapper.editor().document().is_modified()) {
|
||||||
editor_wrapper.save();
|
editor_wrapper.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1264,12 +1264,9 @@ HackStudioWidget::ContinueDecision HackStudioWidget::warn_unsaved_changes(const
|
||||||
|
|
||||||
bool HackStudioWidget::any_document_is_dirty() const
|
bool HackStudioWidget::any_document_is_dirty() const
|
||||||
{
|
{
|
||||||
for (auto& editor_wrapper : m_all_editor_wrappers) {
|
return any_of(m_all_editor_wrappers, [](auto& editor_wrapper) {
|
||||||
if (editor_wrapper.document_dirty()) {
|
return editor_wrapper.editor().document().is_modified();
|
||||||
return true;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HackStudioWidget::update_gml_preview()
|
void HackStudioWidget::update_gml_preview()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue