diff --git a/data/gui.xml b/data/gui.xml index 06a9f0f01..50d05a93f 100644 --- a/data/gui.xml +++ b/data/gui.xml @@ -1078,16 +1078,18 @@ + - + + + + - - diff --git a/data/strings/en.ini b/data/strings/en.ini index 2f82ed1a3..c0819c6fe 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -1318,9 +1318,10 @@ ryb_color_wheel = RYB Color Wheel normal_map_color_wheel = Normal Map Color Wheel load_palette = L&oad Palette save_palette = S&ave Palette +save_palette_as_preset = Save Palette as Preset load_default_palette = Load Default Palette -save_as_default_palette = Save as Default Palette -create_palette_from_current_sprite = Create Palette from Current Sprite +save_as_default_palette = Save Palette as Default +create_palette_from_current_sprite = New Palette from Sprite [palette_size] title = Palette Size diff --git a/src/app/app.h b/src/app/app.h index f255fae2a..e178ee519 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -124,6 +124,7 @@ namespace app { obs::signal Exit; obs::signal PaletteChange; obs::signal ColorSpaceChange; + obs::signal PalettePresetsChange; private: class CoreModules; diff --git a/src/app/commands/cmd_save_palette.cpp b/src/app/commands/cmd_save_palette.cpp index 429599162..05be7186d 100644 --- a/src/app/commands/cmd_save_palette.cpp +++ b/src/app/commands/cmd_save_palette.cpp @@ -8,6 +8,7 @@ #include "config.h" #endif +#include "app/app.h" #include "app/commands/cmd_set_palette.h" #include "app/commands/commands.h" #include "app/commands/params.h" @@ -35,6 +36,7 @@ protected: private: std::string m_preset; + bool m_saveAsPreset = false; }; SavePaletteCommand::SavePaletteCommand() @@ -45,6 +47,7 @@ SavePaletteCommand::SavePaletteCommand() void SavePaletteCommand::onLoadParams(const Params& params) { m_preset = params.get("preset"); + m_saveAsPreset = (params.get("saveAsPreset") == "true"); } void SavePaletteCommand::onExecute(Context* context) @@ -58,8 +61,9 @@ void SavePaletteCommand::onExecute(Context* context) else { base::paths exts = get_writable_palette_extensions(); base::paths selFilename; + std::string initialPath = (m_saveAsPreset ? get_preset_palettes_dir(): ""); if (!app::show_file_selector( - "Save Palette", "", exts, + "Save Palette", initialPath, exts, FileSelectorType::Save, selFilename)) return; @@ -74,6 +78,9 @@ void SavePaletteCommand::onExecute(Context* context) if (!context->activeDocument()) set_current_palette(palette, false); } + if (m_saveAsPreset) { + App::instance()->PalettePresetsChange(); + } } Command* CommandFactory::createSavePaletteCommand() diff --git a/src/app/modules/palettes.cpp b/src/app/modules/palettes.cpp index f6d515851..cd79a3a1c 100644 --- a/src/app/modules/palettes.cpp +++ b/src/app/modules/palettes.cpp @@ -161,12 +161,7 @@ bool set_current_palette(const Palette *_palette, bool forced) std::string get_preset_palette_filename(const std::string& preset, const std::string& dot_extension) { - ResourceFinder rf; - rf.includeUserDir(base::join_path("palettes", ".").c_str()); - std::string palettesDir = rf.getFirstOrCreateDefault(); - - if (!base::is_directory(palettesDir)) - base::make_directory(palettesDir); + std::string palettesDir = get_preset_palettes_dir(); return base::join_path(palettesDir, preset + dot_extension); } @@ -176,4 +171,16 @@ std::string get_default_palette_preset_name() return "default"; } +std::string get_preset_palettes_dir() +{ + ResourceFinder rf; + rf.includeUserDir(base::join_path("palettes", ".").c_str()); + std::string palettesDir = rf.getFirstOrCreateDefault(); + + if (!base::is_directory(palettesDir)) + base::make_directory(palettesDir); + + return palettesDir; +} + } // namespace app diff --git a/src/app/modules/palettes.h b/src/app/modules/palettes.h index 551b4bedf..52f953766 100644 --- a/src/app/modules/palettes.h +++ b/src/app/modules/palettes.h @@ -33,6 +33,7 @@ namespace app { std::string get_preset_palette_filename(const std::string& preset, const std::string& dot_extension); std::string get_default_palette_preset_name(); + std::string get_preset_palettes_dir(); } // namespace app diff --git a/src/app/ui/palette_popup.cpp b/src/app/ui/palette_popup.cpp index 31e6bb032..6179203d4 100644 --- a/src/app/ui/palette_popup.cpp +++ b/src/app/ui/palette_popup.cpp @@ -42,6 +42,7 @@ PalettePopup::PalettePopup() addChild(m_popup); m_paletteListBox.DoubleClickItem.connect(base::Bind(&PalettePopup::onLoadPal, this)); + m_paletteListBox.FinishLoading.connect(base::Bind(&PalettePopup::onSearchChange, this)); m_popup->search()->Change.connect(base::Bind(&PalettePopup::onSearchChange, this)); m_popup->loadPal()->Click.connect(base::Bind(&PalettePopup::onLoadPal, this)); m_popup->openFolder()->Click.connect(base::Bind(&PalettePopup::onOpenFolder, this)); diff --git a/src/app/ui/palettes_listbox.cpp b/src/app/ui/palettes_listbox.cpp index e23896d82..8cbe66b01 100644 --- a/src/app/ui/palettes_listbox.cpp +++ b/src/app/ui/palettes_listbox.cpp @@ -124,6 +124,9 @@ PalettesListBox::PalettesListBox() m_extPaletteChanges = App::instance()->extensions().PalettesChange.connect( base::Bind(&PalettesListBox::reload, this)); + m_extPresetsChanges = + App::instance()->PalettePresetsChange.connect( + base::Bind(&PalettesListBox::reload, this)); } doc::Palette* PalettesListBox::selectedPalette() diff --git a/src/app/ui/palettes_listbox.h b/src/app/ui/palettes_listbox.h index 57af50fa5..26247148b 100644 --- a/src/app/ui/palettes_listbox.h +++ b/src/app/ui/palettes_listbox.h @@ -34,6 +34,7 @@ namespace app { ui::TooltipManager m_tooltips; obs::scoped_connection m_extPaletteChanges; + obs::scoped_connection m_extPresetsChanges; }; } // namespace app diff --git a/src/app/ui/resources_listbox.cpp b/src/app/ui/resources_listbox.cpp index 2c8e23d46..1b95ac44c 100644 --- a/src/app/ui/resources_listbox.cpp +++ b/src/app/ui/resources_listbox.cpp @@ -211,8 +211,10 @@ void ResourcesListBox::onTick() listItem.release(); } - if (m_resourcesLoader->isDone()) + if (m_resourcesLoader->isDone()) { + FinishLoading(); stop(); + } } void ResourcesListBox::stop() diff --git a/src/app/ui/resources_listbox.h b/src/app/ui/resources_listbox.h index aa8a38d61..418e705ca 100644 --- a/src/app/ui/resources_listbox.h +++ b/src/app/ui/resources_listbox.h @@ -9,6 +9,7 @@ #pragma once #include "app/res/resources_loader.h" +#include "obs/signal.h" #include "ui/listbox.h" #include "ui/listitem.h" #include "ui/timer.h" @@ -43,6 +44,8 @@ class ResourceListItem : public ui::ListItem { void reload(); + obs::signal FinishLoading; + protected: virtual bool onProcessMessage(ui::Message* msg) override; virtual void onChange() override;