Early options dialog

Originally committed to SVN as r689.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-03 03:47:08 +00:00
parent cb08347bdc
commit 74d54d3272
6 changed files with 247 additions and 37 deletions

View file

@ -40,6 +40,9 @@
#ifdef wxUSE_TREEBOOK
#include <wx/treebook.h>
#endif
#include "options.h"
#include "frame_main.h"
#include "main.h"
///////////////
@ -49,17 +52,64 @@ DialogOptions::DialogOptions(wxWindow *parent)
{
#ifdef wxUSE_TREEBOOK
// Create book
book = new wxTreebook(this,-1,wxDefaultPosition,wxSize(500,300));
book = new wxTreebook(this,-1,wxDefaultPosition,wxSize(100,100));
// Image list
//wxImageList *imgList = new wxImageList(16,15);
//imgList->Add(wxBITMAP(resample_toolbutton));
//book->AssignImageList(imgList);
// Panels
wxPanel *generalPage = new wxPanel(book,-1);
wxPanel *filePage = new wxPanel(book,-1);
wxPanel *gridPage = new wxPanel(book,-1);
wxPanel *editPage = new wxPanel(book,-1);
wxPanel *videoPage = new wxPanel(book,-1);
wxPanel *audioPage = new wxPanel(book,-1);
wxPanel *displayPage = new wxPanel(book,-1);
wxPanel *autoPage = new wxPanel(book,-1);
// General page
{
wxSizer *genMainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *genSizer1 = new wxStaticBoxSizer(wxHORIZONTAL,generalPage,_("Startup"));
wxCheckBox *box1 = new wxCheckBox(generalPage,-1,_("Show Splash Screen"));
Bind(box1,_T("Show splash"));
wxCheckBox *box2 = new wxCheckBox(generalPage,-1,_("Show Tip of the Day"));
Bind(box2,_T("Tips enabled"));
genSizer1->Add(box1,1,wxALL,5);
genSizer1->Add(box2,1,wxALL,5);
wxSizer *genSizer2 = new wxStaticBoxSizer(wxVERTICAL,generalPage,_("Limits for Levels and Recent Files"));
wxFlexGridSizer *genSizer3 = new wxFlexGridSizer(8,2,5,5);
wxString options[8] = { _T("Undo levels"), _T("Recent timecodes max"), _T("Recent keyframes max"), _T("Recent sub max"), _T("Recent vid max"), _T("Recent aud max"), _T("Recent find max"), _T("Recent replace max") };
wxString labels[8] = { _T("Maximum undo levels"), _T("Maximum recent timecode files"), _T("Maximum recent keyframe files"), _T("Maximum recent subtitle files"), _T("Maximum recent video files"), _T("Maximum recent audio files"), _T("Maximum recent find strings"), _T("Maximum recent replace strings") };
for (int i=0;i<8;i++) {
wxSpinCtrl *spin = new wxSpinCtrl(generalPage,-1,_T(""),wxDefaultPosition,wxSize(70,-1),wxSP_ARROW_KEYS,0,32,0);
Bind(spin,options[i]);
genSizer3->Add(new wxStaticText(generalPage,-1,labels[i] + _T(": ")),1,wxALIGN_CENTRE_VERTICAL);
genSizer3->Add(spin,0);
}
genSizer3->AddGrowableCol(0,1);
genSizer2->Add(genSizer3,1,wxEXPAND | wxALL,5);
genMainSizer->Add(genSizer1,0,wxEXPAND | wxBOTTOM,5);
genMainSizer->Add(genSizer2,0,wxEXPAND,0);
genMainSizer->AddStretchSpacer(1);
genMainSizer->Fit(generalPage);
generalPage->SetSizer(genMainSizer);
}
//
// List book
book->AddPage(new wxPanel(book,-1),_T("General"),true);
book->AddSubPage(new wxPanel(book,-1),_T("File Save/Load"),true);
book->AddSubPage(new wxPanel(book,-1),_T("Subtitles Grid"),true);
book->AddSubPage(new wxPanel(book,-1),_T("Subtitles Edit Box"),true);
book->AddPage(new wxPanel(book,-1),_T("Video"),true);
book->AddPage(new wxPanel(book,-1),_T("Audio"),true);
book->AddSubPage(new wxPanel(book,-1),_T("Display"),true);
book->AddPage(new wxPanel(book,-1),_T("Automation"),true);
book->AddPage(generalPage,_T("General"),true);
book->AddSubPage(filePage,_T("File Save/Load"),true);
book->AddSubPage(gridPage,_T("Subtitles Grid"),true);
book->AddSubPage(editPage,_T("Subtitles Edit Box"),true);
book->AddPage(videoPage,_T("Video"),true);
book->AddPage(audioPage,_T("Audio"),true);
book->AddSubPage(displayPage,_T("Display"),true);
book->AddPage(autoPage,_T("Automation"),true);
book->ChangeSelection(0);
// Buttons Sizer
wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
@ -71,7 +121,11 @@ DialogOptions::DialogOptions(wxWindow *parent)
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(book,1,wxEXPAND | wxALL,5);
mainSizer->Add(buttonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
// Read
ReadFromOptions();
#endif
}
@ -80,3 +134,94 @@ DialogOptions::DialogOptions(wxWindow *parent)
// Destructor
DialogOptions::~DialogOptions() {
}
//////////////////////////
// Bind control to option
void DialogOptions::Bind(wxControl *ctrl, wxString option) {
OptionsBind bind;
bind.ctrl = ctrl;
bind.option = option;
binds.push_back(bind);
}
///////////////
// Event table
BEGIN_EVENT_TABLE(DialogOptions,wxDialog)
EVT_BUTTON(wxID_OK,DialogOptions::OnOK)
END_EVENT_TABLE()
//////
// OK
void DialogOptions::OnOK(wxCommandEvent &event) {
WriteToOptions();
EndModal(0);
}
////////////////////
// Write to options
void DialogOptions::WriteToOptions() {
// Flags
bool mustRestart = false;
// For each bound item
for (unsigned int i=0;i<binds.size();i++) {
// Modified?
bool modified = false;
// Checkbox
if (binds[i].ctrl->IsKindOf(CLASSINFO(wxCheckBox))) {
wxCheckBox *check = (wxCheckBox*) binds[i].ctrl;
if (Options.AsBool(binds[i].option) != check->GetValue()) {
Options.SetBool(binds[i].option,check->GetValue());
modified = true;
}
}
// Spin control
if (binds[i].ctrl->IsKindOf(CLASSINFO(wxSpinCtrl))) {
wxSpinCtrl *spin = (wxSpinCtrl*) binds[i].ctrl;
if (spin->GetValue() != Options.AsInt(binds[i].option)) {
Options.SetInt(binds[i].option,spin->GetValue());
modified = true;
}
}
// Set modification type
if (modified) {
ModType type = Options.GetModType(binds[i].option);
if (type == MOD_RESTART) mustRestart = true;
}
}
// Need restart?
if (mustRestart) {
int answer = wxMessageBox(_("Aegisub must restart for the changes to take effect. Restart now?"),_("Restart Aegisub"),wxYES_NO);
if (answer == wxYES) {
FrameMain *frame = (FrameMain*) GetParent();
if (frame->Close()) wxExecute(AegisubApp::fullPath);
}
}
}
/////////////////////
// Read form options
void DialogOptions::ReadFromOptions() {
for (unsigned int i=0;i<binds.size();i++) {
// Checkbox
if (binds[i].ctrl->IsKindOf(CLASSINFO(wxCheckBox))) {
wxCheckBox *check = (wxCheckBox*) binds[i].ctrl;
check->SetValue(Options.AsBool(binds[i].option));
}
// Spin control
if (binds[i].ctrl->IsKindOf(CLASSINFO(wxSpinCtrl))) {
wxSpinCtrl *spin = (wxSpinCtrl*) binds[i].ctrl;
spin->SetValue(Options.AsInt(binds[i].option));
}
}
}

View file

@ -40,22 +40,44 @@
////////////
// Includes
#include <wx/wxprec.h>
#include <vector>
#include "options.h"
//////////////
// Prototypes
#ifdef wxUSE_TREEBOOK
class wxTreebook;
#else
typedef wxNotebook wxTreebook;
#endif
/////////////
// Bind pair
class OptionsBind {
public:
wxControl *ctrl;
wxString option;
};
////////////////////////
// Options screen class
class DialogOptions: public wxDialog {
private:
#ifdef wxUSE_TREEBOOK
wxTreebook *book;
#endif
std::vector<OptionsBind> binds;
void Bind(wxControl *ctrl,wxString option);
void WriteToOptions();
void ReadFromOptions();
void OnOK(wxCommandEvent &event);
public:
DialogOptions(wxWindow *parent);
~DialogOptions();
DECLARE_EVENT_TABLE()
};

View file

@ -89,6 +89,7 @@ FrameMain::FrameMain (wxArrayString args)
local_scripts = new Automation4::ScriptManager();
// Create menu and tool bars
if (Options.AsBool(_T("Maximized"))) Maximize(true);
InitToolbar();
InitMenu();
@ -101,7 +102,6 @@ FrameMain::FrameMain (wxArrayString args)
// Contents
curMode = -1;
InitContents();
if (Options.AsBool(_T("Maximized"))) Maximize(true);
Show();
// Splash screen
@ -375,7 +375,7 @@ void FrameMain::InitMenu() {
// Create view menu
viewMenu = new wxMenu();
AppendBitmapMenuItem(viewMenu,Menu_View_Language, _T("&Language..."), _("Select Aegisub interface language"), wxBITMAP(blank_button));
AppendBitmapMenuItem(viewMenu,Menu_Tools_Options, _("&Options..."), _("Configure Aegisub"), wxBITMAP(options_button));
AppendBitmapMenuItem(viewMenu,Menu_Tools_Options, _("&Options...") + wxString(_T("\t")) + Hotkeys.GetText(_T("Options")), _("Configure Aegisub"), wxBITMAP(options_button));
AppendBitmapMenuItem(viewMenu,Menu_Tools_Hotkeys, _("&Hotkeys..."), _("Remap hotkeys"), wxBITMAP(hotkeys_button));
viewMenu->AppendSeparator();
viewMenu->AppendRadioItem(Menu_View_Subs, _("Subs only view"), _("Display subtitles only"));

View file

@ -317,6 +317,7 @@ void HotkeyManager::LoadDefaults() {
SetHotkey(_("Save subtitles"),_T("Ctrl-S"));
SetHotkey(_("Exit"),_T("Alt-F4"));
SetHotkey(_("Help"),_T("F1"));
SetHotkey(_("Options"),_T("Alt-O"));
SetHotkey(_("Edit Box Commit"),_T("Ctrl-Enter"));
SetHotkey(_("Undo"),_T("Ctrl-Z"));

View file

@ -70,9 +70,10 @@ void OptionsManager::LoadDefaults() {
// Here go the options that can be edited by the options menu
// General
SetModificationType(MOD_AUTOMATIC);
SetBool(_T("Tips enabled"),true);
SetBool(_T("Show splash"),true);
SetBool(_T("Link Time Boxes Commit"),true);
SetModificationType(MOD_RESTART);
SetInt(_T("Undo Levels"),8);
SetInt(_T("Recent timecodes max"),16);
SetInt(_T("Recent keyframes max"),16);
@ -83,22 +84,43 @@ void OptionsManager::LoadDefaults() {
SetInt(_T("Recent replace max"),16);
// File Save/Load
SetText(_T("Save Charset"),_T("UTF-8"));
SetBool(_T("Use nonstandard Milisecond Times"),false);
SetBool(_T("Auto backup"),true);
SetInt(_T("Auto save every seconds"),60);
SetBool(_T("Auto save on every change"),false);
SetModificationType(MOD_AUTOMATIC);
SetText(_T("Auto backup path"),_T("autoback"));
SetText(_T("Auto save path"),_T("autosave"));
SetText(_T("Auto recovery path"),_T("recovered"));
SetInt(_T("Autoload linked files"),2);
SetText(_T("Text actor separator"),_T(":"));
SetText(_T("Text comment starter"),_T("#"));
SetBool(_T("Auto save on every change"),false);
SetText(_T("Save Charset"),_T("UTF-8"));
SetBool(_T("Use nonstandard Milisecond Times"),false);
// Dictionary
// Edit Box
SetText(_T("Dictionaries path"),_T("dictionaries"));
SetText(_T("Spell checker language"),_T("en_US"));
SetText(_T("Thesaurus language"),_T("en_US"));
SetBool(_T("Link Time Boxes Commit"),true);
// Edit box cosmetic
SetBool(_T("Call Tips Enabled"),true);
SetBool(_T("Syntax Highlight Enabled"),true);
SetColour(_T("Syntax Highlight Normal"),wxColour(0,0,0));
SetColour(_T("Syntax Highlight Brackets"),wxColour(20,50,255));
SetColour(_T("Syntax Highlight Slashes"),wxColour(255,0,200));
SetColour(_T("Syntax Highlight Tags"),wxColour(90,90,90));
SetColour(_T("Syntax Highlight Parameters"),wxColour(40,90,40));
SetColour(_T("Syntax Highlight Error"),wxColour(200,0,0));
SetColour(_T("Syntax Highlight Error Background"),wxColour(255,200,200));
SetColour(_T("Syntax Highlight Line Break"),wxColour(160,160,160));
SetColour(_T("Edit Box Need Enter Background"),wxColour(192,192,255));
#if defined(__WINDOWS__)
SetInt(_T("Font Size"),9);
#else
SetInt(_T("Font Size"),11);
#endif
SetText(_T("Font Face"),_T(""));
// Video Options
SetInt(_T("Video Check Script Res"), 0);
@ -137,25 +159,6 @@ void OptionsManager::LoadDefaults() {
SetText(_T("Automation Autoload Path"), AegisubApp::folderName + _T("automation/autoload/"));
SetInt(_T("Automation Trace Level"), 3);
// Edit box cosmetic
SetBool(_T("Call Tips Enabled"),true);
SetBool(_T("Syntax Highlight Enabled"),true);
SetColour(_T("Syntax Highlight Normal"),wxColour(0,0,0));
SetColour(_T("Syntax Highlight Brackets"),wxColour(20,50,255));
SetColour(_T("Syntax Highlight Slashes"),wxColour(255,0,200));
SetColour(_T("Syntax Highlight Tags"),wxColour(90,90,90));
SetColour(_T("Syntax Highlight Parameters"),wxColour(40,90,40));
SetColour(_T("Syntax Highlight Error"),wxColour(200,0,0));
SetColour(_T("Syntax Highlight Error Background"),wxColour(255,200,200));
SetColour(_T("Syntax Highlight Line Break"),wxColour(160,160,160));
SetColour(_T("Edit Box Need Enter Background"),wxColour(192,192,255));
#if defined(__WINDOWS__)
SetInt(_T("Font Size"),9);
#else
SetInt(_T("Font Size"),11);
#endif
SetText(_T("Font Face"),_T(""));
// Generate colors
wxColour tempCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
float r = tempCol.Red() / 255.0;
@ -217,6 +220,7 @@ void OptionsManager::LoadDefaults() {
SetInt(_T("Audio Line boundaries Thickness"), 2);
SetBool(_T("Audio Draw Secondary Lines"), true);
SetBool(_T("Audio Draw Selection Background"), true);
SetModificationType(MOD_OFF);
@ -367,6 +371,7 @@ void OptionsManager::Load() {
// Write int
void OptionsManager::SetInt(wxString key,int param) {
opt[key.Lower()].SetInt(param);
if (curModType != MOD_OFF) optType[key.Lower()] = curModType;
modified = true;
}
@ -375,6 +380,7 @@ void OptionsManager::SetInt(wxString key,int param) {
// Write float
void OptionsManager::SetFloat(wxString key,double param) {
opt[key.Lower()].SetFloat(param);
if (curModType != MOD_OFF) optType[key.Lower()] = curModType;
modified = true;
}
@ -383,6 +389,7 @@ void OptionsManager::SetFloat(wxString key,double param) {
// Write string
void OptionsManager::SetText(wxString key,wxString param) {
opt[key.Lower()].SetText(param);
if (curModType != MOD_OFF) optType[key.Lower()] = curModType;
modified = true;
}
@ -391,6 +398,7 @@ void OptionsManager::SetText(wxString key,wxString param) {
// Write boolean
void OptionsManager::SetBool(wxString key,bool param) {
opt[key.Lower()].SetBool(param);
if (curModType != MOD_OFF) optType[key.Lower()] = curModType;
modified = true;
}
@ -399,6 +407,7 @@ void OptionsManager::SetBool(wxString key,bool param) {
// Write colour
void OptionsManager::SetColour(wxString key,wxColour param) {
opt[key.Lower()].SetColour(param);
if (curModType != MOD_OFF) optType[key.Lower()] = curModType;
modified = true;
}
@ -463,6 +472,18 @@ wxColour OptionsManager::AsColour(wxString key) {
}
/////////////////////
// Modification type
ModType OptionsManager::GetModType(wxString key) {
std::map<wxString,ModType>::iterator cur;
cur = (optType.find(key.Lower()));
if (cur != optType.end()) {
return (*cur).second;
}
else return MOD_AUTOMATIC;
}
///////////////
// Is defined?
bool OptionsManager::IsDefined(wxString key) {
@ -522,6 +543,13 @@ wxArrayString OptionsManager::GetRecentList (wxString list) {
}
/////////////////////////
// Set modification type
void OptionsManager::SetModificationType(ModType type) {
curModType = type;
}
///////////////////
// Global instance
OptionsManager Options;

View file

@ -44,13 +44,26 @@
#include "variable_data.h"
//////////////////////
// Modification types
enum ModType {
MOD_OFF = -1,
MOD_AUTOMATIC,
MOD_RESTART
};
/////////////////////////////
// Class that stores options
class OptionsManager {
private:
ModType curModType;
bool modified;
wxString filename;
std::map<wxString,VariableData> opt;
std::map<wxString,ModType> optType;
void SetModificationType(ModType type);
public:
OptionsManager();
@ -75,6 +88,7 @@ public:
bool AsBool(wxString key);
wxString AsText(wxString key);
wxColour AsColour(wxString key);
ModType GetModType(wxString key);
};