mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
ThemeEditor: Port to Core::Stream
This commit is contained in:
parent
a5d5b970ff
commit
8377adfde0
3 changed files with 19 additions and 19 deletions
|
@ -238,36 +238,36 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
|
||||||
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
||||||
if (request_close() == GUI::Window::CloseRequestDecision::StayOpen)
|
if (request_close() == GUI::Window::CloseRequestDecision::StayOpen)
|
||||||
return;
|
return;
|
||||||
auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window, "Select theme file", "/res/themes"sv);
|
auto response = FileSystemAccessClient::Client::the().open_file(&window, "Select theme file", "/res/themes"sv);
|
||||||
if (response.is_error())
|
if (response.is_error())
|
||||||
return;
|
return;
|
||||||
auto load_from_file_result = load_from_file(*response.value());
|
auto load_from_file_result = load_from_file(response.value().filename(), response.value().release_stream());
|
||||||
if (load_from_file_result.is_error()) {
|
if (load_from_file_result.is_error()) {
|
||||||
GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value()->filename(), load_from_file_result.error()));
|
GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value().filename(), load_from_file_result.error()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
|
|
||||||
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
|
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
|
||||||
if (m_path.has_value()) {
|
if (m_path.has_value()) {
|
||||||
auto result = FileSystemAccessClient::Client::the().try_request_file_deprecated(&window, *m_path, Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
|
auto result = FileSystemAccessClient::Client::the().request_file(&window, *m_path, Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return;
|
return;
|
||||||
save_to_file(result.value());
|
save_to_file(result.value().filename(), result.value().release_stream());
|
||||||
} else {
|
} else {
|
||||||
auto result = FileSystemAccessClient::Client::the().try_save_file_deprecated(&window, "Theme", "ini", Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
|
auto result = FileSystemAccessClient::Client::the().save_file(&window, "Theme", "ini", Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return;
|
return;
|
||||||
save_to_file(result.value());
|
save_to_file(result.value().filename(), result.value().release_stream());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
TRY(file_menu->try_add_action(*m_save_action));
|
TRY(file_menu->try_add_action(*m_save_action));
|
||||||
|
|
||||||
TRY(file_menu->try_add_action(GUI::CommonActions::make_save_as_action([&](auto&) {
|
TRY(file_menu->try_add_action(GUI::CommonActions::make_save_as_action([&](auto&) {
|
||||||
auto result = FileSystemAccessClient::Client::the().try_save_file_deprecated(&window, "Theme", "ini", Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
|
auto result = FileSystemAccessClient::Client::the().save_file(&window, "Theme", "ini", Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return;
|
return;
|
||||||
save_to_file(result.value());
|
save_to_file(result.value().filename(), result.value().release_stream());
|
||||||
})));
|
})));
|
||||||
|
|
||||||
TRY(file_menu->try_add_separator());
|
TRY(file_menu->try_add_separator());
|
||||||
|
@ -315,9 +315,9 @@ void MainWidget::set_path(DeprecatedString path)
|
||||||
update_title();
|
update_title();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::save_to_file(Core::File& file)
|
void MainWidget::save_to_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file)
|
||||||
{
|
{
|
||||||
auto theme = Core::ConfigFile::open(file.filename(), file.leak_fd()).release_value_but_fixme_should_propagate_errors();
|
auto theme = Core::ConfigFile::open(filename.to_deprecated_string(), move(file)).release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
#define __ENUMERATE_ALIGNMENT_ROLE(role) theme->write_entry("Alignments", to_string(Gfx::AlignmentRole::role), to_string(m_current_palette.alignment(Gfx::AlignmentRole::role)));
|
#define __ENUMERATE_ALIGNMENT_ROLE(role) theme->write_entry("Alignments", to_string(Gfx::AlignmentRole::role), to_string(m_current_palette.alignment(Gfx::AlignmentRole::role)));
|
||||||
ENUMERATE_ALIGNMENT_ROLES(__ENUMERATE_ALIGNMENT_ROLE)
|
ENUMERATE_ALIGNMENT_ROLES(__ENUMERATE_ALIGNMENT_ROLE)
|
||||||
|
@ -344,7 +344,7 @@ void MainWidget::save_to_file(Core::File& file)
|
||||||
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to save theme file: {}", sync_result.error()));
|
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to save theme file: {}", sync_result.error()));
|
||||||
} else {
|
} else {
|
||||||
m_last_modified_time = Time::now_monotonic();
|
m_last_modified_time = Time::now_monotonic();
|
||||||
set_path(file.filename());
|
set_path(filename.to_deprecated_string());
|
||||||
window()->set_modified(false);
|
window()->set_modified(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -601,15 +601,15 @@ void MainWidget::show_path_picker_dialog(StringView property_display_name, GUI::
|
||||||
path_input.set_text(*result);
|
path_input.set_text(*result);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> MainWidget::load_from_file(Core::File& file)
|
ErrorOr<void> MainWidget::load_from_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file)
|
||||||
{
|
{
|
||||||
auto config_file = TRY(Core::ConfigFile::open(file.filename(), file.leak_fd()));
|
auto config_file = TRY(Core::ConfigFile::open(filename.to_deprecated_string(), move(file)));
|
||||||
auto theme = TRY(Gfx::load_system_theme(config_file));
|
auto theme = TRY(Gfx::load_system_theme(config_file));
|
||||||
VERIFY(theme.is_valid());
|
VERIFY(theme.is_valid());
|
||||||
|
|
||||||
auto new_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme));
|
auto new_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme));
|
||||||
set_palette(move(new_palette));
|
set_palette(move(new_palette));
|
||||||
set_path(file.filename());
|
set_path(filename.to_deprecated_string());
|
||||||
|
|
||||||
#define __ENUMERATE_ALIGNMENT_ROLE(role) \
|
#define __ENUMERATE_ALIGNMENT_ROLE(role) \
|
||||||
if (auto alignment_input = m_alignment_inputs[to_underlying(Gfx::AlignmentRole::role)]) \
|
if (auto alignment_input = m_alignment_inputs[to_underlying(Gfx::AlignmentRole::role)]) \
|
||||||
|
|
|
@ -86,12 +86,12 @@ public:
|
||||||
ErrorOr<void> initialize_menubar(GUI::Window&);
|
ErrorOr<void> initialize_menubar(GUI::Window&);
|
||||||
GUI::Window::CloseRequestDecision request_close();
|
GUI::Window::CloseRequestDecision request_close();
|
||||||
void update_title();
|
void update_title();
|
||||||
ErrorOr<void> load_from_file(Core::File&);
|
ErrorOr<void> load_from_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit MainWidget(NonnullRefPtr<AlignmentModel>);
|
explicit MainWidget(NonnullRefPtr<AlignmentModel>);
|
||||||
|
|
||||||
void save_to_file(Core::File&);
|
void save_to_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file);
|
||||||
ErrorOr<Core::AnonymousBuffer> encode();
|
ErrorOr<Core::AnonymousBuffer> encode();
|
||||||
void set_path(DeprecatedString);
|
void set_path(DeprecatedString);
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
// Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed.
|
// Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed.
|
||||||
app->event_loop().deferred_invoke(
|
app->event_loop().deferred_invoke(
|
||||||
[&window, &path, &main_widget]() {
|
[&window, &path, &main_widget]() {
|
||||||
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, path.value());
|
auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value());
|
||||||
if (response.is_error())
|
if (response.is_error())
|
||||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
||||||
else {
|
else {
|
||||||
auto load_from_file_result = main_widget->load_from_file(response.release_value());
|
auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream());
|
||||||
if (load_from_file_result.is_error())
|
if (load_from_file_result.is_error())
|
||||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error()));
|
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue