mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:18:11 +00:00

This is quite a radical change. The previous UI was very easy to add new properties to (just add to the FooRole enum and it automatically works), but not so nice to use: A ComboBox for selecting a property, and then a box to edit that property's value. This makes it difficult to compare different properties or edit multiple together without a lot of back-and-forth. This new design gives each property its own editing widgets, with those categorized into several tabs. To try and avoid increasing the maintenance burden for this, the UI is generated from the `windows_tab`, `widgets_tab` and `syntax_highlighting_tab` variables, which are basically just lists of which properties go in that tab. One of the `FooProperty.gml` files is loaded to create each property's widgets.
73 lines
2.4 KiB
C++
73 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, Jakob-Niklas See <git@nwex.de>
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
|
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
|
* Copyright (c) 2022, Filiph Sandström <filiph.sandstrom@filfatstudios.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "MainWidget.h"
|
|
#include "PreviewWidget.h"
|
|
#include <LibCore/ArgsParser.h>
|
|
#include <LibCore/System.h>
|
|
#include <LibFileSystemAccessClient/Client.h>
|
|
#include <LibGUI/Application.h>
|
|
#include <LibGUI/Icon.h>
|
|
#include <LibGUI/Menu.h>
|
|
#include <LibGUI/Menubar.h>
|
|
#include <LibGUI/Window.h>
|
|
#include <LibMain/Main.h>
|
|
#include <unistd.h>
|
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|
{
|
|
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath cpath wpath unix"));
|
|
|
|
auto app = TRY(GUI::Application::try_create(arguments));
|
|
|
|
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(arguments);
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd thread rpath unix"));
|
|
TRY(Core::System::unveil("/tmp/portal/filesystemaccess", "rw"));
|
|
TRY(Core::System::unveil("/res", "r"));
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
|
|
|
auto app_icon = GUI::Icon::default_icon("app-theme-editor");
|
|
|
|
Gfx::Palette startup_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();
|
|
|
|
auto main_widget = TRY(window->try_set_main_widget<ThemeEditor::MainWidget>(path, startup_preview_palette));
|
|
TRY(main_widget->initialize_menubar(window));
|
|
main_widget->update_title();
|
|
|
|
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
|
|
return main_widget->request_close();
|
|
};
|
|
|
|
window->resize(820, 520);
|
|
window->set_resizable(false);
|
|
window->show();
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
|
return app->exec();
|
|
}
|