summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2021-08-25 22:37:15 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-12 11:49:52 +0200
commit23137f0a8dbdb03cf995fc28d55ee45cb3a394da (patch)
tree11e62a10cec547bb567ecf3ed9769b3f8a34167e
parentf878e4464fba0d4e4ba4c9677316a62479866e21 (diff)
downloadserenity-23137f0a8dbdb03cf995fc28d55ee45cb3a394da.zip
ThemeEditor: Add 'Open file' menu action
-rw-r--r--Userland/Applications/ThemeEditor/PreviewWidget.cpp10
-rw-r--r--Userland/Applications/ThemeEditor/PreviewWidget.h1
-rw-r--r--Userland/Applications/ThemeEditor/main.cpp8
3 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.cpp b/Userland/Applications/ThemeEditor/PreviewWidget.cpp
index 0c2fe956b6..cc4f2696fc 100644
--- a/Userland/Applications/ThemeEditor/PreviewWidget.cpp
+++ b/Userland/Applications/ThemeEditor/PreviewWidget.cpp
@@ -97,6 +97,16 @@ void PreviewWidget::set_preview_palette(const Gfx::Palette& palette)
update();
}
+void PreviewWidget::set_theme_from_file(String const& path, int fd)
+{
+ auto file = Core::ConfigFile::open(path, fd);
+ auto theme = Gfx::load_system_theme(file);
+ VERIFY(theme.is_valid());
+
+ m_preview_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme));
+ set_preview_palette(m_preview_palette);
+}
+
void PreviewWidget::paint_event(GUI::PaintEvent& event)
{
GUI::Frame::paint_event(event);
diff --git a/Userland/Applications/ThemeEditor/PreviewWidget.h b/Userland/Applications/ThemeEditor/PreviewWidget.h
index 2a1ab0ca9e..10be2f0339 100644
--- a/Userland/Applications/ThemeEditor/PreviewWidget.h
+++ b/Userland/Applications/ThemeEditor/PreviewWidget.h
@@ -21,6 +21,7 @@ public:
const Gfx::Palette& preview_palette() const { return m_preview_palette; }
void set_preview_palette(const Gfx::Palette&);
+ void set_theme_from_file(String const& path, int fd);
private:
explicit PreviewWidget(const Gfx::Palette&);
diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp
index 4b8444ddbe..56f181d5e5 100644
--- a/Userland/Applications/ThemeEditor/main.cpp
+++ b/Userland/Applications/ThemeEditor/main.cpp
@@ -143,6 +143,14 @@ int main(int argc, char** argv)
theme->sync();
};
+ file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
+ auto result = FileSystemAccessClient::Client::the().open_file(window->window_id(), "Select theme file", "/res/themes");
+ if (result.error != 0)
+ return;
+
+ preview_widget.set_theme_from_file(*result.chosen_file, *result.fd);
+ }));
+
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));