mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:07:35 +00:00
HackStudio: Add a "document dirty" indicator to the EditorWrapper
This commit is contained in:
parent
7f2e1991cc
commit
672b14b70d
3 changed files with 32 additions and 2 deletions
|
@ -51,6 +51,13 @@ EditorWrapper::EditorWrapper()
|
||||||
m_editor->on_open = [](String path) {
|
m_editor->on_open = [](String path) {
|
||||||
open_file(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()
|
EditorWrapper::~EditorWrapper()
|
||||||
|
@ -80,10 +87,28 @@ void EditorWrapper::set_mode_non_displayable()
|
||||||
editor().set_palette(palette);
|
editor().set_palette(palette);
|
||||||
editor().document().set_text("The contents of this file could not be displayed. Is it a binary file?");
|
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)
|
void EditorWrapper::set_filename(const String& filename)
|
||||||
{
|
{
|
||||||
m_filename = 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ public:
|
||||||
Editor& editor() { return *m_editor; }
|
Editor& editor() { return *m_editor; }
|
||||||
const Editor& editor() const { return *m_editor; }
|
const Editor& editor() const { return *m_editor; }
|
||||||
|
|
||||||
|
void save();
|
||||||
|
|
||||||
GUI::Label& filename_label() { return *m_filename_label; }
|
GUI::Label& filename_label() { return *m_filename_label; }
|
||||||
const GUI::Label& filename_label() const { return *m_filename_label; }
|
const GUI::Label& filename_label() const { return *m_filename_label; }
|
||||||
|
|
||||||
|
@ -40,10 +42,13 @@ public:
|
||||||
private:
|
private:
|
||||||
EditorWrapper();
|
EditorWrapper();
|
||||||
|
|
||||||
|
void update_title();
|
||||||
|
|
||||||
String m_filename;
|
String m_filename;
|
||||||
RefPtr<GUI::Label> m_filename_label;
|
RefPtr<GUI::Label> m_filename_label;
|
||||||
RefPtr<GUI::Label> m_cursor_label;
|
RefPtr<GUI::Label> m_cursor_label;
|
||||||
RefPtr<Editor> m_editor;
|
RefPtr<Editor> m_editor;
|
||||||
|
bool m_document_dirty {false};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -552,7 +552,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_action()
|
||||||
if (active_file().is_empty())
|
if (active_file().is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
current_editor().write_to_file(active_file());
|
current_editor_wrapper().save();
|
||||||
|
|
||||||
if (m_git_widget->initialized())
|
if (m_git_widget->initialized())
|
||||||
m_git_widget->refresh();
|
m_git_widget->refresh();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue