Disable the controls for mutally exclusive and unused options in the preferences dialog
Originally committed to SVN as r6519.
This commit is contained in:
parent
c4cba875b4
commit
70261b6466
3 changed files with 77 additions and 30 deletions
|
@ -155,7 +155,7 @@ Audio::Audio(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _(
|
||||||
wxArrayString choice_dtl(4, dtl_arr);
|
wxArrayString choice_dtl(4, dtl_arr);
|
||||||
OptionChoice(general, _("Show inactive lines"), choice_dtl, "Audio/Inactive Lines Display Mode");
|
OptionChoice(general, _("Show inactive lines"), choice_dtl, "Audio/Inactive Lines Display Mode");
|
||||||
CellSkip(general);
|
CellSkip(general);
|
||||||
OptionAdd(general, _("Include comments in inactive lines"), "Audio/Display/Draw/Inactive Comments");
|
OptionAdd(general, _("Include commented inactive lines"), "Audio/Display/Draw/Inactive Comments");
|
||||||
|
|
||||||
wxFlexGridSizer *display = PageSizer(_("Display Visual Options"));
|
wxFlexGridSizer *display = PageSizer(_("Display Visual Options"));
|
||||||
OptionAdd(display, _("Selection background"), "Audio/Display/Draw/Selection Background");
|
OptionAdd(display, _("Selection background"), "Audio/Display/Draw/Selection Background");
|
||||||
|
@ -196,10 +196,12 @@ Video::Video(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _(
|
||||||
OptionChoice(general, _("Screenshot save path"), scr_res, "Path/Screenshot");
|
OptionChoice(general, _("Screenshot save path"), scr_res, "Path/Screenshot");
|
||||||
|
|
||||||
wxFlexGridSizer *resolution = PageSizer(_("Script Resolution"));
|
wxFlexGridSizer *resolution = PageSizer(_("Script Resolution"));
|
||||||
OptionAdd(resolution, _("Use resolution of first video opened"), "Subtitle/Default Resolution/Auto");
|
wxControl *autocb = OptionAdd(resolution, _("Use resolution of first video opened"), "Subtitle/Default Resolution/Auto");
|
||||||
CellSkip(resolution);
|
CellSkip(resolution);
|
||||||
OptionAdd(resolution, _("Default width"), "Subtitle/Default Resolution/Width");
|
DisableIfChecked(autocb,
|
||||||
OptionAdd(resolution, _("Default height"), "Subtitle/Default Resolution/Height");
|
OptionAdd(resolution, _("Default width"), "Subtitle/Default Resolution/Width"));
|
||||||
|
DisableIfChecked(autocb,
|
||||||
|
OptionAdd(resolution, _("Default height"), "Subtitle/Default Resolution/Height"));
|
||||||
|
|
||||||
const wxString cres_arr[3] = { _("Never"), _("Ask"), _("Always") };
|
const wxString cres_arr[3] = { _("Never"), _("Ask"), _("Always") };
|
||||||
wxArrayString choice_res(3, cres_arr);
|
wxArrayString choice_res(3, cres_arr);
|
||||||
|
@ -456,16 +458,17 @@ void Interface_Hotkeys::OnClearFilter(wxCommandEvent &) {
|
||||||
/// Backup preferences page
|
/// Backup preferences page
|
||||||
Backup::Backup(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("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/Save");
|
wxControl *cb = OptionAdd(save, _("Enable"), "App/Auto/Save");
|
||||||
CellSkip(save);
|
CellSkip(save);
|
||||||
OptionAdd(save, _("Interval in seconds"), "App/Auto/Save Every Seconds", 1);
|
EnableIfChecked(cb,
|
||||||
OptionBrowse(save, _("Path"), "Path/Auto/Save");
|
OptionAdd(save, _("Interval in seconds"), "App/Auto/Save Every Seconds", 1));
|
||||||
|
OptionBrowse(save, _("Path"), "Path/Auto/Save", cb, true);
|
||||||
OptionAdd(save, _("Autosave after every change"), "App/Auto/Save on Every Change");
|
OptionAdd(save, _("Autosave after every change"), "App/Auto/Save on Every Change");
|
||||||
|
|
||||||
wxFlexGridSizer *backup = PageSizer(_("Automatic Backup"));
|
wxFlexGridSizer *backup = PageSizer(_("Automatic Backup"));
|
||||||
OptionAdd(backup, _("Enable"), "App/Auto/Backup");
|
cb = OptionAdd(backup, _("Enable"), "App/Auto/Backup");
|
||||||
CellSkip(backup);
|
CellSkip(backup);
|
||||||
OptionBrowse(backup, _("Path"), "Path/Auto/Backup");
|
OptionBrowse(backup, _("Path"), "Path/Auto/Backup", cb, true);
|
||||||
|
|
||||||
SetSizerAndFit(sizer);
|
SetSizerAndFit(sizer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,16 @@
|
||||||
#include "standard_paths.h"
|
#include "standard_paths.h"
|
||||||
#include "video_provider_manager.h"
|
#include "video_provider_manager.h"
|
||||||
|
|
||||||
#define OPTION_UPDATER(type, evttype, opt, body) \
|
#define OPTION_UPDATER(type, evttype, opt, body) \
|
||||||
class type { \
|
class type { \
|
||||||
std::string name; \
|
std::string name; \
|
||||||
Preferences *parent; \
|
Preferences *parent; \
|
||||||
public: \
|
public: \
|
||||||
type(std::string const& n, Preferences *p) : name(n), parent(p) {} \
|
type(std::string const& n, Preferences *p) : name(n), parent(p) { } \
|
||||||
void operator()(evttype& evt) { parent->SetOption(new agi::opt(name, body)); } \
|
void operator()(evttype& evt) { \
|
||||||
|
evt.Skip(); \
|
||||||
|
parent->SetOption(new agi::opt(name, body)); \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTION_UPDATER(StringUpdater, wxCommandEvent, OptionValueString, STD_STR(evt.GetString()));
|
OPTION_UPDATER(StringUpdater, wxCommandEvent, OptionValueString, STD_STR(evt.GetString()));
|
||||||
|
@ -69,12 +72,9 @@ public:
|
||||||
ColourUpdater(const char *n = "", Preferences *p = NULL) : name(n), parent(p) { }
|
ColourUpdater(const char *n = "", Preferences *p = NULL) : name(n), parent(p) { }
|
||||||
void operator()(wxCommandEvent& evt) {
|
void operator()(wxCommandEvent& evt) {
|
||||||
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
|
ColourButton *btn = static_cast<ColourButton*>(evt.GetClientData());
|
||||||
if (btn) {
|
if (btn)
|
||||||
parent->SetOption(new agi::OptionValueColour(name, STD_STR(btn->GetColour().GetAsString(wxC2S_CSS_SYNTAX))));
|
parent->SetOption(new agi::OptionValueColour(name, STD_STR(btn->GetColour().GetAsString(wxC2S_CSS_SYNTAX))));
|
||||||
}
|
evt.Skip();
|
||||||
else {
|
|
||||||
evt.Skip();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ void OptionPage::CellSkip(wxFlexGridSizer *flex) {
|
||||||
flex->Add(new wxStaticText(this, -1, ""), wxSizerFlags().Border());
|
flex->Add(new wxStaticText(this, -1, ""), wxSizerFlags().Border());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, double min, double max, double inc) {
|
wxControl *OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, double min, double max, double inc) {
|
||||||
const agi::OptionValue *opt = OPT_GET(opt_name);
|
const agi::OptionValue *opt = OPT_GET(opt_name);
|
||||||
|
|
||||||
switch (opt->GetType()) {
|
switch (opt->GetType()) {
|
||||||
|
@ -139,35 +139,35 @@ void OptionPage::OptionAdd(wxFlexGridSizer *flex, const wxString &name, const ch
|
||||||
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));
|
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, BoolUpdater(opt_name, parent));
|
||||||
break;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
case agi::OptionValue::Type_Int: {
|
case agi::OptionValue::Type_Int: {
|
||||||
wxSpinCtrl *sc = new wxSpinCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetInt());
|
wxSpinCtrl *sc = new wxSpinCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetInt());
|
||||||
sc->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, IntUpdater(opt_name, parent));
|
sc->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, IntUpdater(opt_name, parent));
|
||||||
Add(flex, name, sc);
|
Add(flex, name, sc);
|
||||||
break;
|
return sc;
|
||||||
}
|
}
|
||||||
|
|
||||||
case agi::OptionValue::Type_Double: {
|
case agi::OptionValue::Type_Double: {
|
||||||
wxSpinCtrlDouble *scd = new wxSpinCtrlDouble(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetDouble(), inc);
|
wxSpinCtrlDouble *scd = new wxSpinCtrlDouble(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, min, max, opt->GetDouble(), inc);
|
||||||
scd->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, DoubleUpdater(opt_name, parent));
|
scd->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, DoubleUpdater(opt_name, parent));
|
||||||
Add(flex, name, scd);
|
Add(flex, name, scd);
|
||||||
break;
|
return scd;
|
||||||
}
|
}
|
||||||
|
|
||||||
case agi::OptionValue::Type_String: {
|
case agi::OptionValue::Type_String: {
|
||||||
wxTextCtrl *text = new wxTextCtrl(this, -1 , lagi_wxString(opt->GetString()));
|
wxTextCtrl *text = new wxTextCtrl(this, -1 , lagi_wxString(opt->GetString()));
|
||||||
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
|
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
|
||||||
Add(flex, name, text);
|
Add(flex, name, text);
|
||||||
break;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
case agi::OptionValue::Type_Colour: {
|
case agi::OptionValue::Type_Colour: {
|
||||||
ColourButton *cb = new ColourButton(this, -1, wxSize(40,10), lagi_wxColour(opt->GetColour()));
|
ColourButton *cb = new ColourButton(this, -1, wxSize(40,10), lagi_wxColour(opt->GetColour()));
|
||||||
cb->Bind(wxEVT_COMMAND_BUTTON_CLICKED, ColourUpdater(opt_name, parent));
|
cb->Bind(wxEVT_COMMAND_BUTTON_CLICKED, ColourUpdater(opt_name, parent));
|
||||||
Add(flex, name, cb);
|
Add(flex, name, cb);
|
||||||
break;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -213,7 +213,7 @@ wxFlexGridSizer* OptionPage::PageSizer(wxString name) {
|
||||||
return flex;
|
return flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionPage::OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name) {
|
void OptionPage::OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, wxControl *enabler, bool do_enable) {
|
||||||
const agi::OptionValue *opt = OPT_GET(opt_name);
|
const agi::OptionValue *opt = OPT_GET(opt_name);
|
||||||
|
|
||||||
if (opt->GetType() != agi::OptionValue::Type_String)
|
if (opt->GetType() != agi::OptionValue::Type_String)
|
||||||
|
@ -230,6 +230,17 @@ void OptionPage::OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const
|
||||||
button_sizer->Add(browse, wxSizerFlags().Expand());
|
button_sizer->Add(browse, wxSizerFlags().Expand());
|
||||||
|
|
||||||
Add(flex, name, button_sizer);
|
Add(flex, name, button_sizer);
|
||||||
|
|
||||||
|
if (enabler) {
|
||||||
|
if (do_enable) {
|
||||||
|
EnableIfChecked(enabler, text);
|
||||||
|
EnableIfChecked(enabler, browse);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DisableIfChecked(enabler, text);
|
||||||
|
DisableIfChecked(enabler, browse);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionPage::OptionFont(wxSizer *sizer, std::string opt_prefix) {
|
void OptionPage::OptionFont(wxSizer *sizer, std::string opt_prefix) {
|
||||||
|
@ -252,3 +263,30 @@ void OptionPage::OptionFont(wxSizer *sizer, std::string opt_prefix) {
|
||||||
Add(sizer, _("Font Face"), button_sizer);
|
Add(sizer, _("Font Face"), button_sizer);
|
||||||
Add(sizer, _("Font Size"), font_size);
|
Add(sizer, _("Font Size"), font_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct disabler {
|
||||||
|
wxControl *ctrl;
|
||||||
|
bool enable;
|
||||||
|
|
||||||
|
disabler(wxControl *ctrl, bool enable) : ctrl(ctrl), enable(enable) { }
|
||||||
|
void operator()(wxCommandEvent &evt) {
|
||||||
|
ctrl->Enable(!!evt.GetInt() == enable);
|
||||||
|
evt.Skip();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void OptionPage::EnableIfChecked(wxControl *cbx, wxControl *ctrl) {
|
||||||
|
wxCheckBox *cb = dynamic_cast<wxCheckBox*>(cbx);
|
||||||
|
if (!cb) return;
|
||||||
|
|
||||||
|
ctrl->Enable(cb->IsChecked());
|
||||||
|
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, disabler(ctrl, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionPage::DisableIfChecked(wxControl *cbx, wxControl *ctrl) {
|
||||||
|
wxCheckBox *cb = dynamic_cast<wxCheckBox*>(cbx);
|
||||||
|
if (!cb) return;
|
||||||
|
|
||||||
|
ctrl->Enable(!cb->IsChecked());
|
||||||
|
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, disabler(ctrl, false));
|
||||||
|
}
|
||||||
|
|
|
@ -37,9 +37,15 @@ public:
|
||||||
OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style = PAGE_DEFAULT);
|
OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style = PAGE_DEFAULT);
|
||||||
|
|
||||||
wxFlexGridSizer* PageSizer(wxString name);
|
wxFlexGridSizer* PageSizer(wxString name);
|
||||||
|
|
||||||
void CellSkip(wxFlexGridSizer *flex);
|
void CellSkip(wxFlexGridSizer *flex);
|
||||||
void OptionAdd(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, double min=0, double max=100, double inc=1);
|
wxControl *OptionAdd(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, double min=0, double max=100, double inc=1);
|
||||||
void OptionChoice(wxFlexGridSizer *flex, const wxString &name, const wxArrayString &choices, 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);
|
void OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name, wxControl *enabler = 0, bool do_enable = false);
|
||||||
void OptionFont(wxSizer *sizer, std::string opt_prefix);
|
void OptionFont(wxSizer *sizer, std::string opt_prefix);
|
||||||
|
|
||||||
|
/// Enable ctrl only when cbx is checked
|
||||||
|
void EnableIfChecked(wxControl *cbx, wxControl *ctrl);
|
||||||
|
/// Enable ctrl only when cbx is not checked
|
||||||
|
void DisableIfChecked(wxControl *cbx, wxControl *ctrl);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue