mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:37:45 +00: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,
|
.end = m_end_date_time,
|
||||||
});
|
});
|
||||||
|
|
||||||
m_event_manager.set_dirty(true);
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,26 +26,28 @@ OwnPtr<EventManager> EventManager::create()
|
||||||
void EventManager::add_event(Event event)
|
void EventManager::add_event(Event event)
|
||||||
{
|
{
|
||||||
m_events.append(move(event));
|
m_events.append(move(event));
|
||||||
set_dirty(true);
|
m_dirty = true;
|
||||||
on_events_change();
|
on_events_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventManager::set_events(Vector<Event> events)
|
void EventManager::set_events(Vector<Event> events)
|
||||||
{
|
{
|
||||||
m_events = move(events);
|
m_events = move(events);
|
||||||
|
m_dirty = true;
|
||||||
on_events_change();
|
on_events_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> EventManager::save(FileSystemAccessClient::File& file)
|
ErrorOr<void> EventManager::save(FileSystemAccessClient::File& file)
|
||||||
{
|
{
|
||||||
set_filename(file.filename());
|
set_filename(file.filename());
|
||||||
set_dirty(false);
|
|
||||||
|
|
||||||
auto stream = file.release_stream();
|
auto stream = file.release_stream();
|
||||||
auto json = TRY(serialize_events());
|
auto json = TRY(serialize_events());
|
||||||
TRY(stream->write_some(json.to_byte_string().bytes()));
|
TRY(stream->write_some(json.to_byte_string().bytes()));
|
||||||
stream->close();
|
stream->close();
|
||||||
|
|
||||||
|
m_dirty = false;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,13 +97,14 @@ ErrorOr<Vector<Event>> EventManager::deserialize_events(JsonArray const& json)
|
||||||
ErrorOr<void> EventManager::load_file(FileSystemAccessClient::File& file)
|
ErrorOr<void> EventManager::load_file(FileSystemAccessClient::File& file)
|
||||||
{
|
{
|
||||||
set_filename(file.filename());
|
set_filename(file.filename());
|
||||||
set_dirty(false);
|
|
||||||
|
|
||||||
auto content = TRY(file.stream().read_until_eof());
|
auto content = TRY(file.stream().read_until_eof());
|
||||||
auto json = TRY(AK::JsonParser(content).parse());
|
auto json = TRY(AK::JsonParser(content).parse());
|
||||||
auto events = TRY(deserialize_events(json.as_array()));
|
auto events = TRY(deserialize_events(json.as_array()));
|
||||||
set_events(events);
|
set_events(events);
|
||||||
|
|
||||||
|
m_dirty = false;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,6 @@ public:
|
||||||
|
|
||||||
String const& current_filename() const { return m_current_filename; }
|
String const& current_filename() const { return m_current_filename; }
|
||||||
void set_filename(String const& filename) { m_current_filename = 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> save(FileSystemAccessClient::File& file);
|
||||||
ErrorOr<void> load_file(FileSystemAccessClient::File& file);
|
ErrorOr<void> load_file(FileSystemAccessClient::File& file);
|
||||||
|
@ -41,6 +39,7 @@ public:
|
||||||
void set_events(Vector<Event>);
|
void set_events(Vector<Event>);
|
||||||
void clear() { m_events.clear(); }
|
void clear() { m_events.clear(); }
|
||||||
|
|
||||||
|
bool is_dirty() const { return m_dirty; }
|
||||||
Span<Event const> events() const { return m_events.span(); }
|
Span<Event const> events() const { return m_events.span(); }
|
||||||
|
|
||||||
Function<void()> on_events_change;
|
Function<void()> on_events_change;
|
||||||
|
@ -53,8 +52,8 @@ private:
|
||||||
|
|
||||||
Vector<Event> m_events;
|
Vector<Event> m_events;
|
||||||
|
|
||||||
String m_current_filename;
|
|
||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
|
String m_current_filename;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue