1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:17:35 +00:00

HackStudio: Add a "document dirty" indicator to the EditorWrapper

This commit is contained in:
Itamar 2021-05-01 13:29:30 +03:00 committed by Andreas Kling
parent 7f2e1991cc
commit 672b14b70d
3 changed files with 32 additions and 2 deletions

View file

@ -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());
}
}