From d06a31968deedf2b114196e35386c0368e829f5d Mon Sep 17 00:00:00 2001 From: arch1t3cht Date: Thu, 8 Jun 2023 18:41:12 +0200 Subject: [PATCH] vapoursynth: Add buttons to set default scripts to default --- libaegisub/include/libaegisub/option_value.h | 15 +++++++++++++ src/preferences.cpp | 22 ++++++++++++++++---- src/preferences_base.cpp | 2 +- src/preferences_base.h | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/libaegisub/include/libaegisub/option_value.h b/libaegisub/include/libaegisub/option_value.h index 63870419c..04947086f 100644 --- a/libaegisub/include/libaegisub/option_value.h +++ b/libaegisub/include/libaegisub/option_value.h @@ -84,6 +84,12 @@ public: Color const& GetColor() const; bool const& GetBool() const; + std::string const& GetDefaultString() const; + int64_t const& GetDefaultInt() const; + double const& GetDefaultDouble() const; + Color const& GetDefaultColor() const; + bool const& GetDefaultBool() const; + void SetString(const std::string); void SetInt(const int64_t); void SetDouble(const double); @@ -96,6 +102,12 @@ public: std::vector const& GetListColor() const; std::vector const& GetListBool() const; + std::vector const& GetDefaultListString() const; + std::vector const& GetDefaultListInt() const; + std::vector const& GetDefaultListDouble() const; + std::vector const& GetDefaultListColor() const; + std::vector const& GetDefaultListBool() const; + void SetListString(std::vector); void SetListInt(std::vector); void SetListDouble(std::vector); @@ -117,6 +129,7 @@ public: : OptionValue(std::move(member_name)) \ , value(member_value), value_default(member_value) { } \ type const& GetValue() const { return value; } \ + type const& GetDefault() const { return value_default; } \ void SetValue(type new_val) { value = std::move(new_val); NotifyChanged(); } \ OptionType GetType() const { return OptionType::type_name; } \ void Reset() { value = value_default; NotifyChanged(); } \ @@ -141,6 +154,7 @@ CONFIG_OPTIONVALUE(Bool, bool) : OptionValue(std::move(name)) \ , array(value), array_default(value) { } \ std::vector const& GetValue() const { return array; } \ + std::vector const& GetDefault() const { return array_default; } \ void SetValue(std::vector val) { array = std::move(val); NotifyChanged(); } \ OptionType GetType() const { return OptionType::List##type_name; } \ void Reset() { array = array_default; NotifyChanged(); } \ @@ -156,6 +170,7 @@ CONFIG_OPTIONVALUE_LIST(Bool, bool) #define CONFIG_OPTIONVALUE_ACCESSORS(ReturnType, Type) \ inline ReturnType const& OptionValue::Get##Type() const { return As(OptionType::Type)->GetValue(); } \ + inline ReturnType const& OptionValue::GetDefault##Type() const { return As(OptionType::Type)->GetDefault(); } \ inline void OptionValue::Set##Type(ReturnType v) { As(OptionType::Type)->SetValue(std::move(v)); } CONFIG_OPTIONVALUE_ACCESSORS(std::string, String) diff --git a/src/preferences.cpp b/src/preferences.cpp index b6ef356b6..ff468f000 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -480,22 +480,36 @@ void VapourSynth(wxTreebook *book, Preferences *parent) { auto video = p->PageSizer(_("Default Video Script")); + auto make_default_button = [=](std::string optname, wxTextCtrl *ctrl) { + auto showdefault = new wxButton(p, -1, _("Set to Default")); + showdefault->Bind(wxEVT_BUTTON, [=](auto e) { + ctrl->SetValue(OPT_GET(optname)->GetDefaultString()); + }); + return showdefault; + }; + auto vhint = new wxStaticText(p, wxID_ANY, _("This script will be executed to load video files that aren't\nVapourSynth scripts (i.e. end in .py or .vpy).\nThe filename variable stores the path to the file.")); p->sizer->Fit(p); vhint->Wrap(400); video->Add(vhint, 0, wxALL, 5); - video->AddSpacer(16); + p->CellSkip(video); - p->OptionAddMultiline(video, "Provider/Video/VapourSynth/Default Script"); + auto vdef = p->OptionAddMultiline(video, "Provider/Video/VapourSynth/Default Script"); + p->CellSkip(video); + + video->Add(make_default_button("Provider/Video/VapourSynth/Default Script", vdef), wxSizerFlags().Right()); auto audio = p->PageSizer(_("Default Audio Script")); auto ahint = new wxStaticText(p, wxID_ANY, _("This script will be executed to load audio files that aren't\nVapourSynth scripts (i.e. end in .py or .vpy).\nThe filename variable stores the path to the file.")); p->sizer->Fit(p); ahint->Wrap(400); audio->Add(ahint, 0, wxALL, 5); - audio->AddSpacer(16); + p->CellSkip(audio); - p->OptionAddMultiline(audio, "Provider/Audio/VapourSynth/Default Script"); + auto adef = p->OptionAddMultiline(audio, "Provider/Audio/VapourSynth/Default Script"); + p->CellSkip(audio); + + audio->Add(make_default_button("Provider/Audio/VapourSynth/Default Script", adef), wxSizerFlags().Right()); p->SetSizerAndFit(p->sizer); #endif diff --git a/src/preferences_base.cpp b/src/preferences_base.cpp index b0c345c2f..5b052ebb6 100644 --- a/src/preferences_base.cpp +++ b/src/preferences_base.cpp @@ -156,7 +156,7 @@ wxControl *OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, co } } -wxControl *OptionPage::OptionAddMultiline(wxSizer *sizer, const char *opt_name) { +wxTextCtrl *OptionPage::OptionAddMultiline(wxSizer *sizer, const char *opt_name) { parent->AddChangeableOption(opt_name); const auto opt = OPT_GET(opt_name); diff --git a/src/preferences_base.h b/src/preferences_base.h index 6581f2d0d..3bf098f64 100644 --- a/src/preferences_base.h +++ b/src/preferences_base.h @@ -43,7 +43,7 @@ public: void CellSkip(wxFlexGridSizer *flex); wxControl *OptionAdd(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, double min=0, double max=INT_MAX, double inc=1); - wxControl *OptionAddMultiline(wxSizer *flex, const char *opt_name); + wxTextCtrl *OptionAddMultiline(wxSizer *flex, const char *opt_name); void OptionChoice(wxFlexGridSizer *flex, const wxString &name, const wxArrayString &choices, const char *opt_name); void OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, wxControl *enabler = nullptr, bool do_enable = false); void OptionFont(wxSizer *sizer, std::string opt_prefix);