mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Calendar/EventManager: Set m_dirty directly
This commit is contained in:
parent
887f040d0e
commit
75faa9239a
3 changed files with 8 additions and 8 deletions
|
@ -119,8 +119,6 @@ ErrorOr<void> AddEventDialog::add_event_to_calendar()
|
|||
.end = m_end_date_time,
|
||||
});
|
||||
|
||||
m_event_manager.set_dirty(true);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -26,26 +26,28 @@ OwnPtr<EventManager> EventManager::create()
|
|||
void EventManager::add_event(Event event)
|
||||
{
|
||||
m_events.append(move(event));
|
||||
set_dirty(true);
|
||||
m_dirty = true;
|
||||
on_events_change();
|
||||
}
|
||||
|
||||
void EventManager::set_events(Vector<Event> events)
|
||||
{
|
||||
m_events = move(events);
|
||||
m_dirty = true;
|
||||
on_events_change();
|
||||
}
|
||||
|
||||
ErrorOr<void> EventManager::save(FileSystemAccessClient::File& file)
|
||||
{
|
||||
set_filename(file.filename());
|
||||
set_dirty(false);
|
||||
|
||||
auto stream = file.release_stream();
|
||||
auto json = TRY(serialize_events());
|
||||
TRY(stream->write_some(json.to_byte_string().bytes()));
|
||||
stream->close();
|
||||
|
||||
m_dirty = false;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -95,13 +97,14 @@ ErrorOr<Vector<Event>> EventManager::deserialize_events(JsonArray const& json)
|
|||
ErrorOr<void> EventManager::load_file(FileSystemAccessClient::File& file)
|
||||
{
|
||||
set_filename(file.filename());
|
||||
set_dirty(false);
|
||||
|
||||
auto content = TRY(file.stream().read_until_eof());
|
||||
auto json = TRY(AK::JsonParser(content).parse());
|
||||
auto events = TRY(deserialize_events(json.as_array()));
|
||||
set_events(events);
|
||||
|
||||
m_dirty = false;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@ public:
|
|||
|
||||
String const& current_filename() const { return m_current_filename; }
|
||||
void set_filename(String const& filename) { m_current_filename = filename; }
|
||||
bool dirty() const { return m_dirty; }
|
||||
void set_dirty(bool dirty) { m_dirty = dirty; }
|
||||
|
||||
ErrorOr<void> save(FileSystemAccessClient::File& file);
|
||||
ErrorOr<void> load_file(FileSystemAccessClient::File& file);
|
||||
|
@ -41,6 +39,7 @@ public:
|
|||
void set_events(Vector<Event>);
|
||||
void clear() { m_events.clear(); }
|
||||
|
||||
bool is_dirty() const { return m_dirty; }
|
||||
Span<Event const> events() const { return m_events.span(); }
|
||||
|
||||
Function<void()> on_events_change;
|
||||
|
@ -53,8 +52,8 @@ private:
|
|||
|
||||
Vector<Event> m_events;
|
||||
|
||||
String m_current_filename;
|
||||
bool m_dirty { false };
|
||||
String m_current_filename;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue