mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 16:18:12 +00:00
LibGUI: Track modified state in GUI::TextDocument
Until now, this has been hackishly tracked by the TextEditor app's main widget. Let's do it in GUI::TextDocument instead, so that anyone who uses this class can know whether it's modified or not.
This commit is contained in:
parent
443775754f
commit
5b68a76c77
2 changed files with 14 additions and 0 deletions
|
@ -26,6 +26,7 @@ TextDocument::TextDocument(Client* client)
|
|||
if (client)
|
||||
m_clients.set(client);
|
||||
append_line(make<TextDocumentLine>(*this));
|
||||
set_modified(false);
|
||||
|
||||
// TODO: Instead of a repating timer, this we should call a delayed 2 sec timer when the user types.
|
||||
m_undo_timer = Core::Timer::construct(
|
||||
|
@ -91,6 +92,9 @@ bool TextDocument::set_text(const StringView& text)
|
|||
client->document_did_set_text();
|
||||
|
||||
clear_text_guard.disarm();
|
||||
|
||||
// FIXME: Should the modified state be cleared on some of the earlier returns as well?
|
||||
set_modified(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -305,6 +309,8 @@ void TextDocument::update_views(Badge<TextDocumentLine>)
|
|||
|
||||
void TextDocument::notify_did_change()
|
||||
{
|
||||
set_modified(true);
|
||||
|
||||
if (m_client_notifications_enabled) {
|
||||
for (auto* client : m_clients)
|
||||
client->document_did_change();
|
||||
|
@ -878,4 +884,9 @@ const TextDocumentSpan* TextDocument::span_at(const TextPosition& position) cons
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void TextDocument::set_modified(bool modified)
|
||||
{
|
||||
m_modified = modified;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue