From 09314ad611786086679164658afa44c264c57dcf Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sun, 5 Sep 2021 13:23:38 +0200 Subject: [PATCH] ThemeEditor: Open files from an argument This commit allows you to open a theme file from an argument, i.e. `ThemeEditor Theme.ini`. --- Userland/Applications/ThemeEditor/main.cpp | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index 41d858f6ea3..4b8444ddbe2 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -6,6 +6,7 @@ */ #include "PreviewWidget.h" +#include #include #include #include @@ -46,6 +47,25 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); + char const* file_to_edit = nullptr; + + Core::ArgsParser parser; + parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No); + parser.parse(argc, argv); + + Optional path = {}; + + if (file_to_edit) { + path = Core::File::absolute_path(file_to_edit); + if (Core::File::exists(*path)) { + dbgln("unveil for: {}", *path); + if (unveil(path->characters(), "r") < 0) { + perror("unveil"); + return 1; + } + } + } + if (pledge("stdio recvfd sendfd thread rpath unix", nullptr) < 0) { perror("pledge"); return 1; @@ -68,7 +88,7 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-theme-editor"); - Gfx::Palette preview_palette = app->palette(); + Gfx::Palette preview_palette = file_to_edit ? Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(Gfx::load_system_theme(*path))) : app->palette(); auto window = GUI::Window::construct(); @@ -81,7 +101,7 @@ int main(int argc, char** argv) main_widget.set_fill_with_background_color(true); main_widget.set_layout(); - auto& preview_widget = main_widget.add(app->palette()); + auto& preview_widget = main_widget.add(preview_palette); preview_widget.set_fixed_size(480, 360); auto& horizontal_container = main_widget.add(); @@ -109,8 +129,6 @@ int main(int argc, char** argv) auto& file_menu = window->add_menu("&File"); - Optional path = {}; - auto save_to_result = [&](FileSystemAccessClient::Result const& result) { if (result.error != 0) return;