diff options
author | Karol Kosek <krkk@krkk.ct8.pl> | 2021-09-05 13:23:38 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-12 11:49:52 +0200 |
commit | 09314ad611786086679164658afa44c264c57dcf (patch) | |
tree | 6a485edc5b4d826fd4d91078aa1cf6f3d88366e1 /Userland | |
parent | 8c47f38ca5e250b054d76dfb0c1a3c8836a1277d (diff) | |
download | serenity-09314ad611786086679164658afa44c264c57dcf.zip |
ThemeEditor: Open files from an argument
This commit allows you to open a theme file from an argument, i.e.
`ThemeEditor Theme.ini`.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/ThemeEditor/main.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index 41d858f6ea..4b8444ddbe 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -6,6 +6,7 @@ */ #include "PreviewWidget.h" +#include <LibCore/ArgsParser.h> #include <LibCore/ConfigFile.h> #include <LibFileSystemAccessClient/Client.h> #include <LibGUI/Application.h> @@ -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<String> 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<GUI::VerticalBoxLayout>(); - auto& preview_widget = main_widget.add<ThemeEditor::PreviewWidget>(app->palette()); + auto& preview_widget = main_widget.add<ThemeEditor::PreviewWidget>(preview_palette); preview_widget.set_fixed_size(480, 360); auto& horizontal_container = main_widget.add<GUI::Widget>(); @@ -109,8 +129,6 @@ int main(int argc, char** argv) auto& file_menu = window->add_menu("&File"); - Optional<String> path = {}; - auto save_to_result = [&](FileSystemAccessClient::Result const& result) { if (result.error != 0) return; |