Make the preferences dialog actually update the configuration

Originally committed to SVN as r4761.
This commit is contained in:
Thomas Goyne 2010-08-26 18:38:20 +00:00
parent 5721003219
commit 069581b9be
6 changed files with 148 additions and 94 deletions

View file

@ -47,8 +47,15 @@
ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col) ColourButton::ColourButton(wxWindow* parent, wxWindowID id, const wxSize& size, wxColour col)
: wxBitmapButton(parent, id, wxBitmap(size)) : wxBitmapButton(parent, id, wxBitmap(size))
, bmp(GetBitmapLabel()) , bmp(GetBitmapLabel())
, colour(col)
{ {
SetColour(col); {
wxMemoryDC dc;
dc.SelectObject(bmp);
dc.SetBrush(wxBrush(colour));
dc.DrawRectangle(0,0,bmp.GetWidth(),bmp.GetHeight());
}
SetBitmapLabel(bmp);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ColourButton::OnClick, this); Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ColourButton::OnClick, this);
} }

View file

@ -891,6 +891,7 @@ wxColour GetColorFromUser(wxWindow *parent, wxColour original, ColorCallback cal
{ {
DialogColorPicker dialog(parent, original, callback, userdata); DialogColorPicker dialog(parent, original, callback, userdata);
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {
if (callback) callback(userdata, dialog.GetColor());
return dialog.GetColor(); return dialog.GetColor();
} else { } else {
if (callback) callback(userdata, original); if (callback) callback(userdata, original);

View file

@ -50,7 +50,7 @@
#include "preferences_base.h" #include "preferences_base.h"
/// General preferences page /// General preferences page
General::General(wxTreebook *book): OptionPage(book, _("General")) { General::General(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("General")) {
wxFlexGridSizer *startup = PageSizer(_("Startup")); wxFlexGridSizer *startup = PageSizer(_("Startup"));
OptionAdd(startup, _("Check for updates"), "App/Auto/Check For Updates"); OptionAdd(startup, _("Check for updates"), "App/Auto/Check For Updates");
@ -69,7 +69,7 @@ General::General(wxTreebook *book): OptionPage(book, _("General")) {
/// Subtitles preferences page /// Subtitles preferences page
Subtitles::Subtitles(wxTreebook *book): OptionPage(book, _("Subtitles")) { Subtitles::Subtitles(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Subtitles")) {
wxFlexGridSizer *general = PageSizer(_("Options")); wxFlexGridSizer *general = PageSizer(_("Options"));
OptionAdd(general, _("Enable call tips"), "App/Call Tips"); OptionAdd(general, _("Enable call tips"), "App/Call Tips");
@ -86,7 +86,7 @@ Subtitles::Subtitles(wxTreebook *book): OptionPage(book, _("Subtitles")) {
/// Audio preferences page /// Audio preferences page
Audio::Audio(wxTreebook *book): OptionPage(book, _("Audio")) { Audio::Audio(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Audio")) {
wxFlexGridSizer *general = PageSizer(_("Options")); wxFlexGridSizer *general = PageSizer(_("Options"));
OptionAdd(general, _("Grab times from line upon selection"), "Audio/Grab Times on Select"); OptionAdd(general, _("Grab times from line upon selection"), "Audio/Grab Times on Select");
@ -119,7 +119,7 @@ Audio::Audio(wxTreebook *book): OptionPage(book, _("Audio")) {
/// Video preferences page /// Video preferences page
Video::Video(wxTreebook *book): OptionPage(book, _("Video")) { Video::Video(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Video")) {
wxFlexGridSizer *general = PageSizer(_("Options")); wxFlexGridSizer *general = PageSizer(_("Options"));
OptionAdd(general, _("Show keyframes in slider"), "Video/Slider/Show Keyframes"); OptionAdd(general, _("Show keyframes in slider"), "Video/Slider/Show Keyframes");
@ -144,7 +144,7 @@ Video::Video(wxTreebook *book): OptionPage(book, _("Video")) {
/// Interface preferences page /// Interface preferences page
Interface::Interface(wxTreebook *book): OptionPage(book, _("Interface")) { Interface::Interface(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Interface")) {
wxFlexGridSizer *grid = PageSizer(_("Subtitle Grid")); wxFlexGridSizer *grid = PageSizer(_("Subtitle Grid"));
OptionBrowse(grid, _("Font face"), BROWSE_FONT, "Subtitle/Grid/Font Face"); OptionBrowse(grid, _("Font face"), BROWSE_FONT, "Subtitle/Grid/Font Face");
@ -157,7 +157,7 @@ Interface::Interface(wxTreebook *book): OptionPage(book, _("Interface")) {
/// Interface Colours preferences subpage /// Interface Colours preferences subpage
Interface_Colours::Interface_Colours(wxTreebook *book): OptionPage(book, _("Colours"), PAGE_SCROLL|PAGE_SUB) { Interface_Colours::Interface_Colours(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Colours"), PAGE_SCROLL|PAGE_SUB) {
delete sizer; delete sizer;
wxSizer *main_sizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *main_sizer = new wxBoxSizer(wxHORIZONTAL);
sizer = new wxBoxSizer(wxVERTICAL); sizer = new wxBoxSizer(wxVERTICAL);
@ -214,7 +214,7 @@ Interface_Colours::Interface_Colours(wxTreebook *book): OptionPage(book, _("Colo
/// Interface Hotkeys preferences subpage /// Interface Hotkeys preferences subpage
Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book): OptionPage(book, _("Hotkeys"), PAGE_SUB) { Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Hotkeys"), PAGE_SUB) {
wxFlexGridSizer *hotkeys = PageSizer(_("Hotkeys")); wxFlexGridSizer *hotkeys = PageSizer(_("Hotkeys"));
hotkeys->Add(new wxStaticText(this, wxID_ANY, _T("To be added after hotkey rewrite.")), 0, wxALL, 5); hotkeys->Add(new wxStaticText(this, wxID_ANY, _T("To be added after hotkey rewrite.")), 0, wxALL, 5);
@ -223,7 +223,7 @@ Interface_Hotkeys::Interface_Hotkeys(wxTreebook *book): OptionPage(book, _("Hotk
/// Paths preferences page class Paths: public OptionPage { public: /// Paths preferences page class Paths: public OptionPage { public:
Paths::Paths(wxTreebook *book): OptionPage(book, _("Paths")) { Paths::Paths(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Paths")) {
wxFlexGridSizer *general = PageSizer(_("General")); wxFlexGridSizer *general = PageSizer(_("General"));
general->Add(new wxStaticText(this, wxID_ANY, _T("TBD..")), 0, wxALL, 5); general->Add(new wxStaticText(this, wxID_ANY, _T("TBD..")), 0, wxALL, 5);
@ -233,7 +233,7 @@ Paths::Paths(wxTreebook *book): OptionPage(book, _("Paths")) {
/// File Associations preferences page /// File Associations preferences page
File_Associations::File_Associations(wxTreebook *book): OptionPage(book, _("File Associations")) { File_Associations::File_Associations(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("File Associations")) {
wxFlexGridSizer *assoc = PageSizer(_("General")); wxFlexGridSizer *assoc = PageSizer(_("General"));
assoc->Add(new wxStaticText(this, wxID_ANY, _T("TBD..")), 0, wxALL, 5); assoc->Add(new wxStaticText(this, wxID_ANY, _T("TBD..")), 0, wxALL, 5);
@ -243,7 +243,7 @@ File_Associations::File_Associations(wxTreebook *book): OptionPage(book, _("File
/// Backup preferences page /// Backup preferences page
Backup::Backup(wxTreebook *book): OptionPage(book, _("Backup")) { Backup::Backup(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Backup")) {
wxFlexGridSizer *save = PageSizer(_("Automatic Save")); wxFlexGridSizer *save = PageSizer(_("Automatic Save"));
OptionAdd(save, _("Enable"), "App/Auto/Backup"); OptionAdd(save, _("Enable"), "App/Auto/Backup");
CellSkip(save); CellSkip(save);
@ -261,7 +261,7 @@ Backup::Backup(wxTreebook *book): OptionPage(book, _("Backup")) {
/// Automation preferences page /// Automation preferences page
Automation::Automation(wxTreebook *book): OptionPage(book, _("Automation")) { Automation::Automation(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Automation")) {
wxFlexGridSizer *general = PageSizer(_("General")); wxFlexGridSizer *general = PageSizer(_("General"));
OptionAdd(general, _("Base path"), "Path/Automation/Base"); OptionAdd(general, _("Base path"), "Path/Automation/Base");
@ -285,7 +285,7 @@ Automation::Automation(wxTreebook *book): OptionPage(book, _("Automation")) {
/// Advanced preferences page /// Advanced preferences page
Advanced::Advanced(wxTreebook *book): OptionPage(book, _("Advanced")) { Advanced::Advanced(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Advanced")) {
wxFlexGridSizer *general = PageSizer(_("General")); wxFlexGridSizer *general = PageSizer(_("General"));
wxStaticText *warning = new wxStaticText(this, wxID_ANY ,_("Changing these settings might result in bugs and/or crashes. Do not touch these unless you know what you're doing.")); wxStaticText *warning = new wxStaticText(this, wxID_ANY ,_("Changing these settings might result in bugs and/or crashes. Do not touch these unless you know what you're doing."));
@ -299,7 +299,7 @@ Advanced::Advanced(wxTreebook *book): OptionPage(book, _("Advanced")) {
/// Advanced Interface preferences subpage /// Advanced Interface preferences subpage
Advanced_Interface::Advanced_Interface(wxTreebook *book): OptionPage(book, _("Backup"), PAGE_SUB) { Advanced_Interface::Advanced_Interface(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Backup"), PAGE_SUB) {
wxFlexGridSizer *interface_ = PageSizer(_("Interface")); wxFlexGridSizer *interface_ = PageSizer(_("Interface"));
interface_->Add(new wxStaticText(this, wxID_ANY, _T("TBD..")), 0, wxALL, 5); interface_->Add(new wxStaticText(this, wxID_ANY, _T("TBD..")), 0, wxALL, 5);
@ -314,7 +314,7 @@ static wxArrayString vec_to_arrstr(std::vector<std::string> const& vec) {
} }
/// Advanced Audio preferences subpage /// Advanced Audio preferences subpage
Advanced_Audio::Advanced_Audio(wxTreebook *book): OptionPage(book, _("Audio"), PAGE_SUB) { Advanced_Audio::Advanced_Audio(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Audio"), PAGE_SUB) {
wxFlexGridSizer *expert = PageSizer(_("Expert")); wxFlexGridSizer *expert = PageSizer(_("Expert"));
wxArrayString ap_choice = vec_to_arrstr(AudioProviderFactory::GetClasses()); wxArrayString ap_choice = vec_to_arrstr(AudioProviderFactory::GetClasses());
@ -353,7 +353,7 @@ Advanced_Audio::Advanced_Audio(wxTreebook *book): OptionPage(book, _("Audio"), P
/// Advanced Video preferences subpage /// Advanced Video preferences subpage
Advanced_Video::Advanced_Video(wxTreebook *book): OptionPage(book, _("Video"), PAGE_SUB) { Advanced_Video::Advanced_Video(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Video"), PAGE_SUB) {
wxFlexGridSizer *expert = PageSizer(_("Expert")); wxFlexGridSizer *expert = PageSizer(_("Expert"));
wxArrayString vp_choice = vec_to_arrstr(VideoProviderFactory::GetClasses()); wxArrayString vp_choice = vec_to_arrstr(VideoProviderFactory::GetClasses());

View file

@ -20,57 +20,30 @@
/// @ingroup configuration_ui /// @ingroup configuration_ui
#ifndef AGI_PRE #ifndef AGI_PRE
#include <map>
#include <wx/any.h>
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/event.h> #include <wx/event.h>
#include <wx/treebook.h> #include <wx/treebook.h>
#include <wx/listctrl.h> #include <wx/listctrl.h>
#endif #endif
#include "browse_button.h"
class General;
class Subtitles;
class Audio;
class Video;
class Interface;
class Interface_Colours;
class Interface_Hotkeys;
class Paths;
class File_Associations;
class Backup;
class Automation;
class Advanced;
class Advanced_Interface;
class Advanced_Audio;
class Advanced_Video;
class Preferences: public wxDialog { class Preferences: public wxDialog {
wxTreebook *book; wxTreebook *book;
wxButton *applyButton;
std::map<std::string, wxAny> pending_changes;
void OnOK(wxCommandEvent &event); void OnOK(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event); void OnCancel(wxCommandEvent &event);
void OnApply(wxCommandEvent &event); void OnApply(wxCommandEvent &event);
General *general;
Subtitles *subtitles;
Audio *audio;
Video *video;
Interface *interface_;
Interface_Colours *interface_colours;
Interface_Hotkeys *interface_hotkeys;
Paths *paths;
File_Associations *file_associations;
Backup *backup;
Automation *automation;
Advanced *advanced;
Advanced_Interface *advanced_interface;
Advanced_Audio *advanced_audio;
Advanced_Video *advanced_video;
public: public:
Preferences(wxWindow *parent); Preferences(wxWindow *parent);
~Preferences(); ~Preferences();
void SetOption(const char *name, wxAny value);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View file

@ -50,10 +50,40 @@ DEFINE_BASE_EXCEPTION_NOINNER(PreferencesError, agi::Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(PreferenceIncorrectType, PreferencesError, "preferences/incorrect_type") DEFINE_SIMPLE_EXCEPTION_NOINNER(PreferenceIncorrectType, PreferencesError, "preferences/incorrect_type")
DEFINE_SIMPLE_EXCEPTION_NOINNER(PreferenceNotSupported, PreferencesError, "preferences/not_supported") DEFINE_SIMPLE_EXCEPTION_NOINNER(PreferenceNotSupported, PreferencesError, "preferences/not_supported")
#define OPTION_UPDATER(type, evttype, body) \
class type { \
const char *name; \
Preferences *parent; \
public: \
type(const char *n="",Preferences *p=NULL) : name(n),parent(p) {} \
void operator()(evttype& evt) { parent->SetOption(name, body); } \
}
OPTION_UPDATER(StringUpdater, wxCommandEvent, STD_STR(evt.GetString()));
OPTION_UPDATER(IntUpdater, wxSpinEvent, evt.GetInt());
OPTION_UPDATER(IntCBUpdater, wxCommandEvent, evt.GetInt());
OPTION_UPDATER(DoubleUpdater, wxSpinEvent, evt.GetInt());
OPTION_UPDATER(BoolUpdater, wxCommandEvent, !!evt.GetInt());
class ColourUpdater {
const char *name;
Preferences *parent;
public:
ColourUpdater(const char *n = "", Preferences *p = NULL) : name(n), parent(p) { }
void operator()(wxCommandEvent& evt) {
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
if (btn) {
parent->SetOption(name, STD_STR(btn->GetColour().GetAsString(wxC2S_CSS_SYNTAX)));
}
else {
evt.Skip();
}
}
};
OptionPage::OptionPage(wxTreebook *book, wxString name, int style): OptionPage::OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style)
wxScrolled<wxPanel>(book, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL) { : wxScrolled<wxPanel>(book, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL)
, parent(parent)
{
if (style & PAGE_SUB) { if (style & PAGE_SUB) {
book->AddSubPage(this, name, true); book->AddSubPage(this, name, true);
@ -88,13 +118,22 @@ void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const c
wxCheckBox *cb = new wxCheckBox(this, wxID_ANY, name); wxCheckBox *cb = new wxCheckBox(this, wxID_ANY, name);
flex->Add(cb, 1, wxEXPAND, 0); flex->Add(cb, 1, wxEXPAND, 0);
cb->SetValue(opt->GetBool()); cb->SetValue(opt->GetBool());
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, BoolUpdater(opt_name, parent));
break; break;
} }
case agi::OptionValue::Type_Int: case agi::OptionValue::Type_Int: {
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
wxSpinCtrl *sc = new wxSpinCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetInt());
sc->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, IntUpdater(opt_name, parent));
flex->Add(sc);
break;
}
case agi::OptionValue::Type_Double: { case agi::OptionValue::Type_Double: {
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL); flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
wxSpinCtrlDouble *scd = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetInt(), inc); wxSpinCtrlDouble *scd = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetDouble(), inc);
scd->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, DoubleUpdater(opt_name, parent));
flex->Add(scd); flex->Add(scd);
break; break;
@ -104,12 +143,15 @@ void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const c
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL); flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY , lagi_wxString(opt->GetString()), wxDefaultPosition, wxDefaultSize); wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY , lagi_wxString(opt->GetString()), wxDefaultPosition, wxDefaultSize);
flex->Add(text, 1, wxEXPAND); flex->Add(text, 1, wxEXPAND);
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
break; break;
} }
case agi::OptionValue::Type_Colour: { case agi::OptionValue::Type_Colour: {
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL); flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
flex->Add(new ColourButton(this, wxID_ANY, wxSize(40,10), lagi_wxColour(opt->GetColour()))); ColourButton *cb = new ColourButton(this, wxID_ANY, wxSize(40,10), lagi_wxColour(opt->GetColour()));
flex->Add(cb);
cb->Bind(wxEVT_COMMAND_BUTTON_CLICKED, ColourUpdater(opt_name, parent));
break; break;
} }
@ -122,26 +164,24 @@ void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const c
void OptionPage::OptionChoice(wxFlexGridSizer *&flex, const wxString &name, const wxArrayString &choices, const char *opt_name) { void OptionPage::OptionChoice(wxFlexGridSizer *&flex, const wxString &name, const wxArrayString &choices, const char *opt_name) {
agi::OptionValue *opt = OPT_GET(opt_name); agi::OptionValue *opt = OPT_GET(opt_name);
int type = opt->GetType(); flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
wxString selection; wxComboBox *cb = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY | wxCB_DROPDOWN);
flex->Add(cb, 1, wxEXPAND, 0);
switch (type) { switch (opt->GetType()) {
case agi::OptionValue::Type_Int: { case agi::OptionValue::Type_Int: {
selection = choices.Item(opt->GetInt()); cb->SetValue(choices[opt->GetInt()]);
cb->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, IntCBUpdater(opt_name, parent));
break; break;
} }
case agi::OptionValue::Type_String: { case agi::OptionValue::Type_String: {
selection.assign(opt->GetString()); cb->SetValue(lagi_wxString(opt->GetString()));
cb->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, StringUpdater(opt_name, parent));
break; break;
} }
default: default:
throw PreferenceNotSupported("Unsupported type"); throw PreferenceNotSupported("Unsupported type");
} }
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
wxComboBox *cb = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY | wxCB_DROPDOWN);
cb->SetValue(selection);
flex->Add(cb, 1, wxEXPAND, 0);
} }
@ -157,7 +197,6 @@ wxFlexGridSizer* OptionPage::PageSizer(wxString name) {
void OptionPage::OptionBrowse(wxFlexGridSizer *&flex, const wxString &name, BrowseType browse_type, const char *opt_name) { void OptionPage::OptionBrowse(wxFlexGridSizer *&flex, const wxString &name, BrowseType browse_type, const char *opt_name) {
agi::OptionValue *opt = OPT_GET(opt_name); agi::OptionValue *opt = OPT_GET(opt_name);
if (opt->GetType() != agi::OptionValue::Type_String) if (opt->GetType() != agi::OptionValue::Type_String)
@ -174,15 +213,46 @@ void OptionPage::OptionBrowse(wxFlexGridSizer *&flex, const wxString &name, Brow
BrowseButton *browse = new BrowseButton(this, wxID_ANY, wxEmptyString, browse_type); BrowseButton *browse = new BrowseButton(this, wxID_ANY, wxEmptyString, browse_type);
browse->Bind(text); browse->Bind(text);
button_flex->Add(browse, 1, wxEXPAND); button_flex->Add(browse, 1, wxEXPAND);
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
} }
void Preferences::SetOption(const char *name, wxAny value) {
pending_changes[name] = value;
if (IsEnabled()) applyButton->Enable(true);
}
void Preferences::OnOK(wxCommandEvent &event) { void Preferences::OnOK(wxCommandEvent &event) {
OnApply(event);
EndModal(0); EndModal(0);
} }
void Preferences::OnApply(wxCommandEvent &event) { void Preferences::OnApply(wxCommandEvent &event) {
for (std::map<std::string, wxAny>::iterator cur = pending_changes.begin(); cur != pending_changes.end(); ++cur) {
agi::OptionValue *opt = OPT_SET(cur->first);
switch (opt->GetType()) {
case agi::OptionValue::Type_Bool:
opt->SetBool(cur->second.As<bool>());
break;
case agi::OptionValue::Type_Colour:
opt->SetColour(cur->second.As<agi::Colour>());
break;
case agi::OptionValue::Type_Double:
opt->SetDouble(cur->second.As<double>());
break;
case agi::OptionValue::Type_Int:
opt->SetInt(cur->second.As<int>());
break;
case agi::OptionValue::Type_String:
opt->SetString(cur->second.As<std::string>());
break;
default:
throw PreferenceNotSupported("Unsupported type");
}
}
pending_changes.clear();
applyButton->Enable(false);
config::opt->Flush();
} }
@ -194,21 +264,21 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences"
// SetIcon(BitmapToIcon(GETIMAGE(options_button_24))); // SetIcon(BitmapToIcon(GETIMAGE(options_button_24)));
book = new wxTreebook(this, -1, wxDefaultPosition, wxDefaultSize); book = new wxTreebook(this, -1, wxDefaultPosition, wxDefaultSize);
general = new General(book); new General(book, this);
subtitles = new Subtitles(book); new Subtitles(book, this);
audio = new Audio(book); new Audio(book, this);
video = new Video(book); new Video(book, this);
interface_ = new Interface(book); new Interface(book, this);
interface_colours = new Interface_Colours(book); new Interface_Colours(book, this);
interface_hotkeys = new Interface_Hotkeys(book); new Interface_Hotkeys(book, this);
paths = new Paths(book); new Paths(book, this);
file_associations = new File_Associations(book); new File_Associations(book, this);
backup = new Backup(book); new Backup(book, this);
automation = new Automation(book); new Automation(book, this);
advanced = new Advanced(book); new Advanced(book, this);
advanced_interface = new Advanced_Interface(book); new Advanced_Interface(book, this);
advanced_audio = new Advanced_Audio(book); new Advanced_Audio(book, this);
advanced_video = new Advanced_Video(book); new Advanced_Video(book, this);
book->Fit(); book->Fit();
@ -219,7 +289,7 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences"
wxStdDialogButtonSizer *stdButtonSizer = new wxStdDialogButtonSizer(); wxStdDialogButtonSizer *stdButtonSizer = new wxStdDialogButtonSizer();
stdButtonSizer->AddButton(new wxButton(this,wxID_OK)); stdButtonSizer->AddButton(new wxButton(this,wxID_OK));
stdButtonSizer->AddButton(new wxButton(this,wxID_CANCEL)); stdButtonSizer->AddButton(new wxButton(this,wxID_CANCEL));
stdButtonSizer->AddButton(new wxButton(this,wxID_APPLY)); stdButtonSizer->AddButton(applyButton = new wxButton(this,wxID_APPLY));
stdButtonSizer->Realize(); stdButtonSizer->Realize();
wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL); wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton *defaultButton = new wxButton(this,2342,_("Restore Defaults")); wxButton *defaultButton = new wxButton(this,2342,_("Restore Defaults"));
@ -237,14 +307,12 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences"
this->SetMaxSize(wxSize(-1, 500)); this->SetMaxSize(wxSize(-1, 500));
CenterOnParent(); CenterOnParent();
applyButton->Enable(false);
} }
Preferences::~Preferences() { Preferences::~Preferences() {
} }
BEGIN_EVENT_TABLE(Preferences, wxDialog) BEGIN_EVENT_TABLE(Preferences, wxDialog)
EVT_BUTTON(wxID_OK, Preferences::OnOK) EVT_BUTTON(wxID_OK, Preferences::OnOK)
EVT_BUTTON(wxID_CANCEL, Preferences::OnCancel) EVT_BUTTON(wxID_CANCEL, Preferences::OnCancel)

View file

@ -19,6 +19,10 @@
/// @see preferences_base.cpp /// @see preferences_base.cpp
/// @ingroup configuration_ui /// @ingroup configuration_ui
#include "browse_button.h"
class Preferences;
class OptionPage: public wxScrolled<wxPanel> { class OptionPage: public wxScrolled<wxPanel> {
public: public:
enum Style { enum Style {
@ -28,8 +32,9 @@ public:
}; };
wxSizer *sizer; wxSizer *sizer;
Preferences *parent;
OptionPage(wxTreebook *book, wxString name, int style = PAGE_DEFAULT); OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style = PAGE_DEFAULT);
~OptionPage(); ~OptionPage();
wxFlexGridSizer* PageSizer(wxString name); wxFlexGridSizer* PageSizer(wxString name);
@ -42,7 +47,7 @@ public:
#define CLASS_PAGE(name) \ #define CLASS_PAGE(name) \
class name: public OptionPage { \ class name: public OptionPage { \
public: \ public: \
name(wxTreebook *book); \ name(wxTreebook *book, Preferences *parent); \
}; };
CLASS_PAGE(General) CLASS_PAGE(General)