Make the browse and font pick buttons in the preferences dialog actually work, and delete BrowseButton as it's no longer used by anything.

Originally committed to SVN as r5732.
This commit is contained in:
Thomas Goyne 2011-10-11 00:06:44 +00:00
parent 91ab2ee9ba
commit 306664d16e
10 changed files with 143 additions and 341 deletions

View File

@ -621,14 +621,6 @@
RelativePath="..\..\src\base_grid.h"
>
</File>
<File
RelativePath="..\..\src\browse_button.cpp"
>
</File>
<File
RelativePath="..\..\src\browse_button.h"
>
</File>
<File
RelativePath="..\..\src\colour_button.cpp"
>

View File

@ -94,7 +94,6 @@
<ClInclude Include="$(SrcDir)avisynth_wrap.h" />
<ClInclude Include="$(SrcDir)base_grid.h" />
<ClInclude Include="$(SrcDir)block_cache.h" />
<ClInclude Include="$(SrcDir)browse_button.h" />
<ClInclude Include="$(SrcDir)charset_conv.h" />
<ClInclude Include="$(SrcDir)charset_detect.h" />
<ClInclude Include="$(SrcDir)colorspace.h" />
@ -270,7 +269,6 @@
<ClCompile Include="$(SrcDir)auto4_lua_scriptreader.cpp" />
<ClCompile Include="$(SrcDir)avisynth_wrap.cpp" />
<ClCompile Include="$(SrcDir)base_grid.cpp" />
<ClCompile Include="$(SrcDir)browse_button.cpp" />
<ClCompile Include="$(SrcDir)charset_conv.cpp" />
<ClCompile Include="$(SrcDir)charset_detect.cpp" />
<ClCompile Include="$(SrcDir)colorspace.cpp" />

View File

@ -228,9 +228,6 @@
<ClInclude Include="$(SrcDir)command\command.h">
<Filter>Commands</Filter>
</ClInclude>
<ClInclude Include="$(SrcDir)browse_button.h">
<Filter>Controls</Filter>
</ClInclude>
<ClInclude Include="$(SrcDir)config.h">
<Filter>Config</Filter>
</ClInclude>
@ -737,9 +734,6 @@
<ClCompile Include="$(SrcDir)auto4_base.cpp">
<Filter>Automation</Filter>
</ClCompile>
<ClCompile Include="$(SrcDir)browse_button.cpp">
<Filter>Controls</Filter>
</ClCompile>
<ClCompile Include="$(SrcDir)command\command.cpp">
<Filter>Commands</Filter>
</ClCompile>

View File

@ -146,7 +146,6 @@ SRC += \
auto4_base.cpp \
avisynth_wrap.cpp \
base_grid.cpp \
browse_button.cpp \
charset_conv.cpp \
charset_detect.cpp \
colorspace.cpp \

View File

@ -1,118 +0,0 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Aegisub Project http://www.aegisub.org/
//
// $Id$
/// @file browse_button.cpp
/// @brief Push-button that opens a file browsing dialogue and sets value of a text edit when user confirms
/// @ingroup custom_control
///
///////////
// Headers
#include "config.h"
#ifndef AGI_PRE
#include <wx/filedlg.h>
#include <wx/fontdlg.h>
#include <wx/dirdlg.h> // Keep this last so wxDirDialog is set.
#endif
#include "browse_button.h"
#include "standard_paths.h"
#include "utils.h"
/// @brief Constructor
/// @param parent
/// @param id
/// @param text
/// @param _type
/// @param position
/// @param size
///
BrowseButton::BrowseButton(wxWindow *parent,int id,wxString text,BrowseType _type,wxPoint position,wxSize size)
: wxButton (parent,id,text == wxString("") ? wxString(_("Browse...")) : text,position,size)
{
type = _type;
ctrl[0] = NULL;
ctrl[1] = NULL;
Connect(GetId(),wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(BrowseButton::OnPressed));
}
/// @brief Bind
/// @param control
/// @param pos
///
void BrowseButton::Bind(wxTextCtrl *control,int pos) {
ctrl[pos] = control;
}
/// @brief Pressed
/// @param event
///
void BrowseButton::OnPressed(wxCommandEvent &event) {
// Folder
if (type == BROWSE_FOLDER) {
// For some reason I can't make this work on Mac... -jfs
wxString def = StandardPaths::DecodePathMaybeRelative(ctrl[0]->GetValue(), "?user/");
wxDirDialog dlg(0, _("Please choose the folder:"), def);
if (dlg.ShowModal() == wxID_OK) {
wxString dir = StandardPaths::EncodePath(dlg.GetPath());
if (dir != "") ctrl[0]->SetValue(dir);
}
}
// File
else if (type == BROWSE_FILE) {
}
// Font
else if (type == BROWSE_FONT) {
wxFont font;
long size;
ctrl[1]->GetValue().ToLong(&size);
font.SetFaceName(ctrl[0]->GetValue());
font.SetPointSize(size);
font = wxGetFontFromUser(NULL,font);
if (font.IsOk()) {
ctrl[0]->SetValue(font.GetFaceName());
ctrl[1]->SetValue(wxString::Format("%i",font.GetPointSize()));
}
}
}

View File

@ -1,84 +0,0 @@
// Copyright (c) 2007, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Aegisub Project http://www.aegisub.org/
//
// $Id$
/// @file browse_button.h
/// @see browse_button.cpp
/// @ingroup custom_control
///
////////////
// Includes
#ifndef AGI_PRE
#include <wx/button.h>
#include <wx/textctrl.h>
#endif
/// DOCME
enum BrowseType {
/// DOCME
BROWSE_FILE,
/// DOCME
BROWSE_FOLDER,
/// DOCME
BROWSE_FONT
};
/// DOCME
/// @class BrowseButton
/// @brief DOCME
///
/// DOCME
class BrowseButton : public wxButton {
private:
/// DOCME
wxTextCtrl *ctrl[2];
/// DOCME
BrowseType type;
void OnPressed(wxCommandEvent &event);
public:
BrowseButton(wxWindow *parent,int id=-1,wxString text="",BrowseType type=BROWSE_FILE,wxPoint position=wxDefaultPosition,wxSize size=wxDefaultSize);
void Bind(wxTextCtrl *control,int pos=0);
};

View File

@ -22,29 +22,33 @@
#ifndef AGI_PRE
#include <iterator>
#include <wx/any.h>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/event.h>
#include <wx/filefn.h>
#include <wx/listctrl.h>
#include <wx/sizer.h>
#include <wx/spinctrl.h>
#include <wx/stattext.h>
#include <wx/stdpaths.h>
#include <wx/treebook.h>
#include <wx/treebook.h>
#endif
#include <libaegisub/exception.h>
#include "preferences.h"
#include "colour_button.h"
#include "compat.h"
#include "libresrc/libresrc.h"
#include "preferences.h"
#include "main.h"
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "include/aegisub/subtitles_provider.h"
#include "video_provider_manager.h"
#include "libresrc/libresrc.h"
#include "main.h"
#include "preferences_base.h"
#include "video_provider_manager.h"
/// General preferences page
General::General(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("General")) {
@ -145,14 +149,12 @@ Video::Video(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _(
/// Interface preferences page
Interface::Interface(wxTreebook *book, Preferences *parent): OptionPage(book, parent, _("Interface")) {
wxFlexGridSizer *grid = PageSizer(_("Subtitle Grid"));
OptionBrowse(grid, _("Font face"), BROWSE_FONT, "Subtitle/Grid/Font Face");
OptionAdd(grid, _("Font size"), "Subtitle/Grid/Font Size", 3, 42);
OptionFont(grid, "Subtitle/Grid/");
OptionAdd(grid, _("Hide overrides symbol"), "Subtitle/Grid/Hide Overrides Char");
wxFlexGridSizer *edit_box = PageSizer(_("Edit Box"));
OptionBrowse(edit_box, _("Font face"), BROWSE_FONT, "Subtitle/Edit Box/Font Face");
OptionAdd(edit_box, _("Font size"), "Subtitle/Edit Box/Font Size", 3, 42);
OptionFont(edit_box, "Subtitle/Edit Box/");
SetSizerAndFit(sizer);
}
@ -245,13 +247,13 @@ Backup::Backup(wxTreebook *book, Preferences *parent): OptionPage(book, parent,
wxFlexGridSizer *save = PageSizer(_("Automatic Save"));
OptionAdd(save, _("Enable"), "App/Auto/Backup");
CellSkip(save);
OptionAdd(save, _("Interval in seconds."), "App/Auto/Save Every Seconds");
OptionBrowse(save, _("Path"), BROWSE_FOLDER, "Path/Auto/Save");
OptionAdd(save, _("Interval in seconds"), "App/Auto/Save Every Seconds");
OptionBrowse(save, _("Path"), "Path/Auto/Save");
wxFlexGridSizer *backup = PageSizer(_("Automatic Backup"));
CellSkip(backup);
OptionAdd(backup, _("Enable"), "App/Auto/Backup");
OptionBrowse(backup, _("Path"), BROWSE_FOLDER, "Path/Auto/Backup");
CellSkip(backup);
OptionBrowse(backup, _("Path"), "Path/Auto/Backup");
SetSizerAndFit(sizer);
}
@ -326,7 +328,7 @@ Advanced_Audio::Advanced_Audio(wxTreebook *book, Preferences *parent): OptionPag
wxArrayString ct_choice(3, ct_arr);
OptionChoice(cache, _("Cache type"), ct_choice, "Audio/Cache/Type");
OptionBrowse(cache, _("Path"), BROWSE_FOLDER, "Audio/Cache/HD/Location");
OptionBrowse(cache, _("Path"), "Audio/Cache/HD/Location");
OptionAdd(cache, _("File name"), "Audio/Cache/HD/Name");
wxFlexGridSizer *spectrum = PageSizer(_("Spectrum"));

View File

@ -22,13 +22,13 @@
#ifndef AGI_PRE
#include <map>
#include <wx/any.h>
#include <wx/dialog.h>
#include <wx/event.h>
#include <wx/treebook.h>
#include <wx/listctrl.h>
#endif
class wxAny;
class wxButton;
class wxTreebook;
class Preferences: public wxDialog {
wxTreebook *book;
wxButton *applyButton;
@ -43,7 +43,5 @@ public:
Preferences(wxWindow *parent);
~Preferences();
void SetOption(const char *name, wxAny value);
DECLARE_EVENT_TABLE()
void SetOption(std::string const& name, wxAny value);
};

View File

@ -20,31 +20,34 @@
#ifndef AGI_PRE
#include <wx/any.h>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/event.h>
#include <wx/filefn.h>
#include <wx/fontdlg.h>
#include <wx/listctrl.h>
#include <wx/sizer.h>
#include <wx/spinctrl.h>
#include <wx/stattext.h>
#include <wx/stdpaths.h>
#include <wx/treebook.h>
#include <wx/treebook.h>
#endif
#include <libaegisub/exception.h>
#include "colour_button.h"
#include "compat.h"
#include "libresrc/libresrc.h"
#include "preferences.h"
#include "main.h"
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "video_provider_manager.h"
#include "preferences_base.h"
/// Define make all platform-specific options visible in a single view.
#define SHOW_ALL 1
#include "colour_button.h"
#include "compat.h"
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "libresrc/libresrc.h"
#include "main.h"
#include "preferences.h"
#include "standard_paths.h"
#include "video_provider_manager.h"
DEFINE_BASE_EXCEPTION_NOINNER(PreferencesError, agi::Exception)
DEFINE_SIMPLE_EXCEPTION_NOINNER(PreferenceIncorrectType, PreferencesError, "preferences/incorrect_type")
@ -52,10 +55,10 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(PreferenceNotSupported, PreferencesError, "prefe
#define OPTION_UPDATER(type, evttype, body) \
class type { \
const char *name; \
std::string name; \
Preferences *parent; \
public: \
type(const char *n="",Preferences *p=NULL) : name(n),parent(p) {} \
type(std::string const& n, Preferences *p) : name(n),parent(p) {} \
void operator()(evttype& evt) { parent->SetOption(name, body); } \
}
@ -80,42 +83,60 @@ public:
}
};
static void browse_button(wxTextCtrl *ctrl) {
wxString def = StandardPaths::DecodePathMaybeRelative(ctrl->GetValue(), "?user/");
wxDirDialog dlg(0, _("Please choose the folder:"), def);
if (dlg.ShowModal() == wxID_OK) {
wxString dir = StandardPaths::EncodePath(dlg.GetPath());
if (!dir.empty())
ctrl->SetValue(dir);
}
}
static void font_button(Preferences *parent, wxTextCtrl *name, wxSpinCtrl *size) {
wxFont font;
font.SetFaceName(name->GetValue());
font.SetPointSize(size->GetValue());
font = wxGetFontFromUser(parent, font);
if (font.IsOk()) {
name->SetValue(font.GetFaceName());
size->SetValue(wxString::Format("%d", font.GetPointSize()));
}
}
OptionPage::OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style)
: wxScrolled<wxPanel>(book, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL)
: wxScrolled<wxPanel>(book, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL)
, parent(parent)
{
if (style & PAGE_SUB) {
if (style & PAGE_SUB)
book->AddSubPage(this, name, true);
} else {
else
book->AddPage(this, name, true);
}
if (style & PAGE_SCROLL) {
if (style & PAGE_SCROLL)
SetScrollbars(0, 20, 0, 50);
} else {
else
SetScrollbars(0, 0, 0, 0);
}
sizer = new wxBoxSizer(wxVERTICAL);
}
OptionPage::~OptionPage() {}
void OptionPage::CellSkip(wxFlexGridSizer *&flex) {
flex->Add(new wxStaticText(this, wxID_ANY , wxEmptyString), 0, wxALL, 5);
template<class T>
void OptionPage::Add(wxSizer *sizer, wxString const& label, T *control) {
sizer->Add(new wxStaticText(this, -1, label), 1, wxEXPAND | wxALIGN_CENTRE_VERTICAL);
sizer->Add(control);
}
void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const char *opt_name, double min, double max, double inc) {
void OptionPage::CellSkip(wxFlexGridSizer *flex) {
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) {
const agi::OptionValue *opt = OPT_GET(opt_name);
int type = opt->GetType();
switch (type) {
switch (opt->GetType()) {
case agi::OptionValue::Type_Bool: {
wxCheckBox *cb = new wxCheckBox(this, wxID_ANY, name);
wxCheckBox *cb = new wxCheckBox(this, -1, name);
flex->Add(cb, 1, wxEXPAND, 0);
cb->SetValue(opt->GetBool());
cb->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, BoolUpdater(opt_name, parent));
@ -123,35 +144,30 @@ void OptionPage::OptionAdd(wxFlexGridSizer *&flex, const wxString &name, const c
}
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());
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));
flex->Add(sc);
Add(flex, name, sc);
break;
}
case agi::OptionValue::Type_Double: {
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->GetDouble(), inc);
scd->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, DoubleUpdater(opt_name, parent));
flex->Add(scd);
case agi::OptionValue::Type_Double: {
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));
Add(flex, name, scd);
break;
}
case agi::OptionValue::Type_String: {
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);
flex->Add(text, 1, wxEXPAND);
wxTextCtrl *text = new wxTextCtrl(this, -1 , lagi_wxString(opt->GetString()));
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
Add(flex, name, text);
break;
}
case agi::OptionValue::Type_Colour: {
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
ColourButton *cb = new ColourButton(this, wxID_ANY, wxSize(40,10), lagi_wxColour(opt->GetColour()));
flex->Add(cb);
ColourButton *cb = new ColourButton(this, -1, wxSize(40,10), lagi_wxColour(opt->GetColour()));
cb->Bind(wxEVT_COMMAND_BUTTON_CLICKED, ColourUpdater(opt_name, parent));
Add(flex, name, cb);
break;
}
@ -160,13 +176,11 @@ 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) {
const agi::OptionValue *opt = OPT_GET(opt_name);
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);
flex->Add(cb, 1, wxEXPAND, 0);
wxComboBox *cb = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY | wxCB_DROPDOWN);
Add(flex, name, cb);
switch (opt->GetType()) {
case agi::OptionValue::Type_Int: {
@ -175,17 +189,16 @@ void OptionPage::OptionChoice(wxFlexGridSizer *&flex, const wxString &name, cons
cb->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, IntCBUpdater(opt_name, parent));
break;
}
case agi::OptionValue::Type_String: {
case agi::OptionValue::Type_String:
cb->SetValue(lagi_wxString(opt->GetString()));
cb->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, StringUpdater(opt_name, parent));
break;
}
default:
throw PreferenceNotSupported("Unsupported type");
}
}
wxFlexGridSizer* OptionPage::PageSizer(wxString name) {
wxSizer *tmp_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, name);
sizer->Add(tmp_sizer, 0,wxEXPAND, 5);
@ -196,30 +209,50 @@ wxFlexGridSizer* OptionPage::PageSizer(wxString name) {
return flex;
}
void OptionPage::OptionBrowse(wxFlexGridSizer *&flex, const wxString &name, BrowseType browse_type, const char *opt_name) {
void OptionPage::OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name) {
const agi::OptionValue *opt = OPT_GET(opt_name);
if (opt->GetType() != agi::OptionValue::Type_String)
throw PreferenceIncorrectType("Option must be agi::OptionValue::Type_String for BrowseButton.");
flex->Add(new wxStaticText(this, wxID_ANY, name), 1, wxALIGN_CENTRE_VERTICAL);
wxFlexGridSizer *button_flex = new wxFlexGridSizer(2,5,5);
button_flex->AddGrowableCol(0,1);
flex->Add(button_flex, 1, wxEXPAND, 5);
wxTextCtrl *text = new wxTextCtrl(this, wxID_ANY , opt->GetString(), wxDefaultPosition, wxDefaultSize);
button_flex->Add(text, 1, wxEXPAND);
BrowseButton *browse = new BrowseButton(this, wxID_ANY, wxEmptyString, browse_type);
browse->Bind(text);
button_flex->Add(browse, 1, wxEXPAND);
wxTextCtrl *text = new wxTextCtrl(this, -1 , opt->GetString());
text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent));
wxButton *browse = new wxButton(this, -1, _("Browse..."));
browse->Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(browse_button, text));
wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
button_sizer->Add(text, wxSizerFlags(1).Expand());
button_sizer->Add(browse, wxSizerFlags().Expand());
Add(flex, name, button_sizer);
}
void Preferences::SetOption(const char *name, wxAny value) {
void OptionPage::OptionFont(wxSizer *sizer, std::string opt_prefix) {
const agi::OptionValue *face_opt = OPT_GET(opt_prefix + "Font Face");
const agi::OptionValue *size_opt = OPT_GET(opt_prefix + "Font Size");
wxTextCtrl *font_name = new wxTextCtrl(this, -1, face_opt->GetString());
font_name->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(face_opt->GetName().c_str(), parent));
wxSpinCtrl *font_size = new wxSpinCtrl(this, -1, "", wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 3, 42, size_opt->GetInt());
font_size->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, IntUpdater(size_opt->GetName().c_str(), parent));
wxButton *pick_btn = new wxButton(this, -1, "Chose...");
pick_btn->Bind(wxEVT_COMMAND_BUTTON_CLICKED, std::tr1::bind(font_button, parent, font_name, font_size));
wxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
button_sizer->Add(font_name, wxSizerFlags(1).Expand());
button_sizer->Add(pick_btn, wxSizerFlags().Expand());
Add(sizer, _("Font Face"), button_sizer);
Add(sizer, _("Font Size"), font_size);
}
void Preferences::SetOption(std::string const& name, wxAny value) {
pending_changes[name] = value;
if (IsEnabled()) applyButton->Enable(true);
if (IsEnabled())
applyButton->Enable(true);
}
void Preferences::OnOK(wxCommandEvent &event) {
@ -227,7 +260,6 @@ void Preferences::OnOK(wxCommandEvent &event) {
EndModal(0);
}
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);
@ -256,11 +288,6 @@ void Preferences::OnApply(wxCommandEvent &event) {
config::opt->Flush();
}
void Preferences::OnCancel(wxCommandEvent &event) {
EndModal(0);
}
static void PageChanged(wxBookCtrlEvent& evt) {
OPT_SET("Tool/Preferences/Page")->SetInt(evt.GetSelection());
}
@ -291,35 +318,29 @@ Preferences::Preferences(wxWindow *parent): wxDialog(parent, -1, _("Preferences"
book->Bind(wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, &PageChanged);
// Bottom Buttons
wxStdDialogButtonSizer *stdButtonSizer = new wxStdDialogButtonSizer();
stdButtonSizer->AddButton(new wxButton(this,wxID_OK));
stdButtonSizer->AddButton(new wxButton(this,wxID_CANCEL));
stdButtonSizer->AddButton(applyButton = new wxButton(this,wxID_APPLY));
stdButtonSizer->Realize();
wxStdDialogButtonSizer *stdButtonSizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxAPPLY);
applyButton = stdButtonSizer->GetApplyButton();
wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton *defaultButton = new wxButton(this,2342,_("Restore Defaults"));
buttonSizer->Add(defaultButton,0,wxEXPAND);
wxButton *defaultButton = new wxButton(this, -1, _("Restore Defaults"));
buttonSizer->Add(defaultButton, wxSizerFlags(0).Expand());
buttonSizer->AddStretchSpacer(1);
buttonSizer->Add(stdButtonSizer,0,wxEXPAND);
buttonSizer->Add(stdButtonSizer, wxSizerFlags(0).Expand());
// Main Sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(book, 1 ,wxEXPAND | wxALL, 5);
mainSizer->Add(buttonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->Add(book, wxSizerFlags(1).Expand().Border());
mainSizer->Add(buttonSizer, wxSizerFlags(0).Expand().Border(wxALL & ~wxTOP));
SetSizerAndFit(mainSizer);
this->SetMinSize(wxSize(-1, 500));
this->SetMaxSize(wxSize(-1, 500));
SetMinSize(wxSize(-1, 500));
SetMaxSize(wxSize(-1, 500));
CenterOnParent();
applyButton->Enable(false);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Preferences::OnOK, this, wxID_OK);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Preferences::OnApply, this, wxID_APPLY);
}
Preferences::~Preferences() {
}
BEGIN_EVENT_TABLE(Preferences, wxDialog)
EVT_BUTTON(wxID_OK, Preferences::OnOK)
EVT_BUTTON(wxID_CANCEL, Preferences::OnCancel)
EVT_BUTTON(wxID_APPLY, Preferences::OnApply)
END_EVENT_TABLE()

View File

@ -19,11 +19,11 @@
/// @see preferences_base.cpp
/// @ingroup configuration_ui
#include "browse_button.h"
class Preferences;
class OptionPage: public wxScrolled<wxPanel> {
template<class T>
void Add(wxSizer *sizer, wxString const& label, T *control);
public:
enum Style {
PAGE_DEFAULT = 0x00000000,
@ -35,13 +35,13 @@ public:
Preferences *parent;
OptionPage(wxTreebook *book, Preferences *parent, wxString name, int style = PAGE_DEFAULT);
~OptionPage();
wxFlexGridSizer* PageSizer(wxString name);
void CellSkip(wxFlexGridSizer *&flex);
void 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 OptionBrowse(wxFlexGridSizer *&flex, const wxString &name, BrowseType browse_type, const char *opt_name);
void CellSkip(wxFlexGridSizer *flex);
void 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 OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const char *opt_name);
void OptionFont(wxSizer *sizer, std::string opt_prefix);
};
#define CLASS_PAGE(name) \