mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
ThemeEditor: Add 'Open file' menu action
This commit is contained in:
parent
f878e4464f
commit
23137f0a8d
3 changed files with 19 additions and 0 deletions
|
@ -97,6 +97,16 @@ void PreviewWidget::set_preview_palette(const Gfx::Palette& palette)
|
||||||
update();
|
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)
|
void PreviewWidget::paint_event(GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
GUI::Frame::paint_event(event);
|
GUI::Frame::paint_event(event);
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
|
|
||||||
const Gfx::Palette& preview_palette() const { return m_preview_palette; }
|
const Gfx::Palette& preview_palette() const { return m_preview_palette; }
|
||||||
void set_preview_palette(const Gfx::Palette&);
|
void set_preview_palette(const Gfx::Palette&);
|
||||||
|
void set_theme_from_file(String const& path, int fd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit PreviewWidget(const Gfx::Palette&);
|
explicit PreviewWidget(const Gfx::Palette&);
|
||||||
|
|
|
@ -143,6 +143,14 @@ int main(int argc, char** argv)
|
||||||
theme->sync();
|
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&) {
|
file_menu.add_action(GUI::CommonActions::make_save_action([&](auto&) {
|
||||||
if (path.has_value()) {
|
if (path.has_value()) {
|
||||||
save_to_result(FileSystemAccessClient::Client::the().request_file(window->window_id(), *path, Core::OpenMode::WriteOnly | Core::OpenMode::Truncate));
|
save_to_result(FileSystemAccessClient::Client::the().request_file(window->window_id(), *path, Core::OpenMode::WriteOnly | Core::OpenMode::Truncate));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue