diff options
author | networkException <git@nwex.de> | 2021-08-19 00:07:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-22 01:32:25 +0200 |
commit | d51072629d89a5c49b05533021969a0a1b96c0e5 (patch) | |
tree | 54a55220abbbd115fd0bbe426c24f2cb51e816a9 /Userland | |
parent | acde7d12b0d2870feba3ebaaaf2ef99ac6fb41b3 (diff) | |
download | serenity-d51072629d89a5c49b05533021969a0a1b96c0e5.zip |
ThemeEditor: Add Actions to save preview_palette to theme file
This patch adds a save and save as Action to the file menu allowing
to export all colors into an ini file.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/ThemeEditor/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Applications/ThemeEditor/main.cpp | 48 |
2 files changed, 43 insertions, 7 deletions
diff --git a/Userland/Applications/ThemeEditor/CMakeLists.txt b/Userland/Applications/ThemeEditor/CMakeLists.txt index bb5a32087f..64a7f1614b 100644 --- a/Userland/Applications/ThemeEditor/CMakeLists.txt +++ b/Userland/Applications/ThemeEditor/CMakeLists.txt @@ -9,4 +9,4 @@ set(SOURCES ) serenity_app(ThemeEditor ICON app-theme-editor) -target_link_libraries(ThemeEditor LibGUI) +target_link_libraries(ThemeEditor LibGUI LibFileSystemAccessClient) diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index accce0e93a..8e1dfd99af 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -1,10 +1,13 @@ /* * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2021, Jakob-Niklas See <git@nwex.de> * * SPDX-License-Identifier: BSD-2-Clause */ #include "PreviewWidget.h" +#include <LibCore/ConfigFile.h> +#include <LibFileSystemAccessClient/Client.h> #include <LibGUI/Application.h> #include <LibGUI/BoxLayout.h> #include <LibGUI/ColorInput.h> @@ -55,11 +58,16 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); - if (pledge("stdio recvfd sendfd thread rpath", nullptr) < 0) { + if (pledge("stdio recvfd sendfd thread rpath unix", nullptr) < 0) { perror("pledge"); return 1; } + if (unveil("/tmp/portal/filesystemaccess", "rw") < 0) { + perror("unveil"); + return 1; + } + if (unveil("/res", "r") < 0) { perror("unveil"); return 1; @@ -76,9 +84,42 @@ int main(int argc, char** argv) auto window = GUI::Window::construct(); + Vector<Gfx::ColorRole> color_roles; +#define __ENUMERATE_COLOR_ROLE(role) color_roles.append(Gfx::ColorRole::role); + ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE) +#undef __ENUMERATE_COLOR_ROLE + auto& file_menu = window->add_menu("&File"); file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); + Optional<String> path = {}; + + auto save_to_result = [&](FileSystemAccessClient::Result result) { + if (result.error != 0) + return; + + path = result.chosen_file; + + auto theme = Core::ConfigFile::open(*result.chosen_file, *result.fd); + for (auto role : color_roles) { + theme->write_entry("Colors", to_string(role), preview_palette.color(role).to_string()); + } + + theme->sync(); + }; + + file_menu.add_action(GUI::CommonActions::make_save_action([&](auto&) { + if (path.has_value()) { + save_to_result(FileSystemAccessClient::Client::the().request_file(window->window_id(), *path, Core::OpenMode::WriteOnly | Core::OpenMode::Truncate)); + } else { + save_to_result(FileSystemAccessClient::Client::the().save_file(window->window_id(), "Theme", "ini")); + } + })); + + file_menu.add_action(GUI::CommonActions::make_save_as_action([&](auto&) { + save_to_result(FileSystemAccessClient::Client::the().save_file(window->window_id(), "Theme", "ini")); + })); + auto& help_menu = window->add_menu("&Help"); help_menu.add_action(GUI::CommonActions::make_about_action("Theme Editor", app_icon, window)); @@ -96,11 +137,6 @@ int main(int argc, char** argv) auto& combo_box = horizontal_container.add<GUI::ComboBox>(); auto& color_input = horizontal_container.add<GUI::ColorInput>(); - Vector<Gfx::ColorRole> color_roles; -#define __ENUMERATE_COLOR_ROLE(role) color_roles.append(Gfx::ColorRole::role); - ENUMERATE_COLOR_ROLES(__ENUMERATE_COLOR_ROLE) -#undef __ENUMERATE_COLOR_ROLE - combo_box.set_only_allow_values_from_model(true); combo_box.set_model(adopt_ref(*new ColorRoleModel(color_roles))); combo_box.on_change = [&](auto&, auto& index) { |