From 451c6751deed748f81737eb4b78c1920acb72927 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 3 May 2014 22:23:01 +0200 Subject: [PATCH] Preferences page for default style catalogs --- src/preferences.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/preferences.cpp b/src/preferences.cpp index 40570d783..368c0ffc3 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -42,9 +42,12 @@ #endif #include +#include #include +#include #include +#include #include #include @@ -65,6 +68,7 @@ public: \ }; CLASS_PAGE(General) +CLASS_PAGE(General_DefaultStyles) CLASS_PAGE(Audio) CLASS_PAGE(Video) CLASS_PAGE(Interface) @@ -107,6 +111,47 @@ General::General(wxTreebook *book, Preferences *parent): OptionPage(book, parent SetSizerAndFit(sizer); } +General_DefaultStyles::General_DefaultStyles(wxTreebook *book, Preferences *parent) : OptionPage(book, parent, _("Default styles"), PAGE_SUB) { + auto staticbox = new wxStaticBoxSizer(wxVERTICAL, this, _("Default style catalogs")); + sizer->Add(staticbox, 0, wxEXPAND, 5); + sizer->AddSpacer(8); + + wxStaticText *instructions = new wxStaticText(this, wxID_ANY, _("The chosen style catalogs will be loaded when you start a new file or import files in the various formats.\n\nYou can set up style catalogs in the Style Manager.")); + sizer->Fit(this); + instructions->Wrap(400); + staticbox->Add(instructions, 0, wxALL, 5); + staticbox->AddSpacer(16); + + auto general = new wxFlexGridSizer(2, 5, 5); + general->AddGrowableCol(0, 1); + staticbox->Add(general, 1, wxEXPAND, 5); + + // Build a list of available style catalogs, and wished-available ones + std::unordered_set catalogs_set; + // Always include one named "Default" even if it doesn't exist (ensure there is at least one on the list) + catalogs_set.insert("Default"); + // Include all catalog files that exist + for (auto const& file : agi::fs::DirectoryIterator(config::path->Decode("?user/catalog/"), "*.sty")) + catalogs_set.insert(agi::fs::path(file).stem().string()); + // Include all catalogs named in the existing configuration + static const char *formats[] = { "ASS", "SRT", "TTXT", "TXT" }; + for (auto formatname : formats) + catalogs_set.insert(OPT_GET("Subtitle Format/" + std::string(formatname) + "/Default Style Catalog")->GetString()); + // Sorted version + wxArrayString catalogs; + for (auto const& cn : catalogs_set) + catalogs.Add(to_wx(cn)); + catalogs.Sort(); + + OptionChoice(general, _("New files"), catalogs, "Subtitle Format/ASS/Default Style Catalog"); + //CellSkip(general); + OptionChoice(general, _("SRT import"), catalogs, "Subtitle Format/SRT/Default Style Catalog"); + OptionChoice(general, _("TTXT import"), catalogs, "Subtitle Format/TTXT/Default Style Catalog"); + OptionChoice(general, _("Plain text import"), catalogs, "Subtitle Format/TXT/Default Style Catalog"); + + SetSizerAndFit(sizer); +} + /// Audio preferences page Audio::Audio(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Audio")) { wxFlexGridSizer *general = PageSizer(_("Options")); @@ -650,6 +695,7 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences" book = new wxTreebook(this, -1, wxDefaultPosition, wxDefaultSize); new General(book, this); + new General_DefaultStyles(book, this); new Audio(book, this); new Video(book, this); new Interface(book, this);