"Apply" button to options dialog, and made subs edit box refresh when its options are changed in the dialog.

Originally committed to SVN as r699.
This commit is contained in:
Rodrigo Braz Monteiro 2007-01-03 21:49:13 +00:00
parent 637dfda62c
commit f221bc1a1f
6 changed files with 114 additions and 57 deletions

View file

@ -46,6 +46,8 @@
#include "main.h"
#include "validators.h"
#include "colour_button.h"
#include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
///////////////
@ -56,6 +58,7 @@ DialogOptions::DialogOptions(wxWindow *parent)
#ifdef wxUSE_TREEBOOK
// Create book
book = new wxTreebook(this,-1,wxDefaultPosition,wxSize(100,100));
needsRestart = false;
// Image list
//wxImageList *imgList = new wxImageList(16,15);
@ -193,7 +196,7 @@ DialogOptions::DialogOptions(wxWindow *parent)
// Second static box
wxControl *control;
wxString labels2[9] = { _("Normal"), _("Brackets"), _("Slashes"), _("Tags"), _("Parameters") , _("Error"), _("Error Background"), _("Line Break"), _("Modified Background") };
wxString labels2[9] = { _("Normal"), _("Brackets"), _("Slashes and Parentheses"), _("Tags"), _("Parameters") , _("Error"), _("Error Background"), _("Line Break"), _("Modified Background") };
wxString options2[11] = { _T("Normal"), _T("Brackets"), _T("Slashes"), _T("Tags"), _T("Parameters") , _T("Error"), _T("Error Background"), _T("Line Break"), _T("Edit box need enter background"), _T("Font Face"), _T("Font Size") };
for (int i=0;i<9;i++) {
wxString caption = labels2[i]+_T(": ");
@ -243,6 +246,7 @@ DialogOptions::DialogOptions(wxWindow *parent)
buttonSizer->AddStretchSpacer(1);
buttonSizer->Add(new wxButton(this,wxID_OK),0,wxRIGHT,5);
buttonSizer->Add(new wxButton(this,wxID_CANCEL),0,wxRIGHT,5);
buttonSizer->Add(new wxButton(this,wxID_APPLY),0,wxRIGHT,5);
// Main Sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
@ -278,16 +282,33 @@ void DialogOptions::Bind(wxControl *ctrl, wxString option) {
BEGIN_EVENT_TABLE(DialogOptions,wxDialog)
EVT_BUTTON(wxID_OK,DialogOptions::OnOK)
EVT_BUTTON(wxID_CANCEL,DialogOptions::OnCancel)
EVT_BUTTON(wxID_APPLY,DialogOptions::OnApply)
END_EVENT_TABLE()
//////
// OK
void DialogOptions::OnOK(wxCommandEvent &event) {
WriteToOptions();
Options.SetInt(_T("Options page"),book->GetSelection());
Options.Save();
WriteToOptions();
EndModal(0);
// Restart
if (needsRestart) {
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);
}
}
}
/////////
// Apply
void DialogOptions::OnApply(wxCommandEvent &event) {
Options.SetInt(_T("Options page"),book->GetSelection());
WriteToOptions(true);
}
@ -297,15 +318,25 @@ void DialogOptions::OnCancel(wxCommandEvent &event) {
Options.SetInt(_T("Options page"),book->GetSelection());
Options.Save();
EndModal(0);
// Restart
if (needsRestart) {
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);
}
}
}
////////////////////
// Write to options
void DialogOptions::WriteToOptions() {
void DialogOptions::WriteToOptions(bool justApply) {
// Flags
bool mustRestart = false;
bool editBox = false;
// For each bound item
for (unsigned int i=0;i<binds.size();i++) {
@ -361,6 +392,7 @@ void DialogOptions::WriteToOptions() {
if (modified) {
ModType type = Options.GetModType(binds[i].option);
if (type == MOD_RESTART) mustRestart = true;
if (type == MOD_EDIT_BOX) editBox = true;
}
}
@ -369,10 +401,22 @@ void DialogOptions::WriteToOptions() {
// 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) {
if (justApply) needsRestart = true;
else {
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);
}
}
}
// Other modifications
if (!mustRestart || justApply) {
if (editBox) {
FrameMain *frame = (FrameMain*) GetParent();
if (frame->Close()) wxExecute(AegisubApp::fullPath);
frame->EditBox->TextEdit->SetStyles();
frame->EditBox->TextEdit->UpdateStyle();
}
}
}

View file

@ -66,15 +66,18 @@ public:
// Options screen class
class DialogOptions: public wxDialog {
private:
bool needsRestart;
wxTreebook *book;
std::vector<OptionsBind> binds;
void Bind(wxControl *ctrl,wxString option);
void WriteToOptions();
void WriteToOptions(bool justApply=false);
void ReadFromOptions();
void OnOK(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event);
void OnApply(wxCommandEvent &event);
public:
DialogOptions(wxWindow *parent);

View file

@ -100,6 +100,7 @@ void OptionsManager::LoadDefaults() {
// Edit Box
SetText(_T("Dictionaries path"),_T("dictionaries"));
SetBool(_T("Link Time Boxes Commit"),true);
SetModificationType(MOD_EDIT_BOX);
SetBool(_T("Call Tips Enabled"),true);
SetBool(_T("Syntax Highlight Enabled"),true);
@ -121,6 +122,7 @@ void OptionsManager::LoadDefaults() {
SetText(_T("Font Face"),_T(""));
// Video Options
SetModificationType(MOD_AUTOMATIC);
SetInt(_T("Video Check Script Res"), 0);
SetInt(_T("Video Default Zoom"), 7);
SetInt(_T("Video Fast Jump Step"), 10);

View file

@ -49,7 +49,8 @@
enum ModType {
MOD_OFF = -1,
MOD_AUTOMATIC,
MOD_RESTART
MOD_RESTART,
MOD_EDIT_BOX
};

View file

@ -54,6 +54,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
SetWrapMode(wxSCI_WRAP_WORD);
SetMarginWidth(1,0);
UsePopUp(false);
SetStyles();
// Set hotkeys
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_CTRL);
@ -67,54 +68,6 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
CmdKeyClear('T',wxSCI_SCMOD_CTRL | wxSCI_SCMOD_SHIFT);
CmdKeyClear('U',wxSCI_SCMOD_CTRL);
// Styles
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
wxString fontname = Options.AsText(_T("Font Face"));
if (fontname != _T("")) font.SetFaceName(fontname);
int size = Options.AsInt(_T("Font Size"));
// Normal style
StyleSetFont(0,font);
StyleSetSize(0,size);
StyleSetForeground(0,Options.AsColour(_T("Syntax Highlight Normal")));
// Brackets style
StyleSetFont(1,font);
StyleSetSize(1,size);
StyleSetForeground(1,Options.AsColour(_T("Syntax Highlight Brackets")));
// Slashes/Parenthesis/Comma style
StyleSetFont(2,font);
StyleSetSize(2,size);
StyleSetForeground(2,Options.AsColour(_T("Syntax Highlight Slashes")));
// Tags style
StyleSetFont(3,font);
StyleSetSize(3,size);
StyleSetBold(3,true);
StyleSetForeground(3,Options.AsColour(_T("Syntax Highlight Tags")));
// Error style
StyleSetFont(4,font);
StyleSetSize(4,size);
StyleSetForeground(4,Options.AsColour(_T("Syntax Highlight Error")));
StyleSetBackground(4,Options.AsColour(_T("Syntax Highlight Error Background")));
// Tag Parameters style
StyleSetFont(5,font);
StyleSetSize(5,size);
StyleSetForeground(5,Options.AsColour(_T("Syntax Highlight Parameters")));
// Line breaks style
StyleSetFont(6,font);
StyleSetSize(6,size);
StyleSetBold(6,true);
StyleSetForeground(6,Options.AsColour(_T("Syntax Highlight Line Break")));
// Misspelling indicator
IndicatorSetStyle(0,wxSCI_INDIC_SQUIGGLE);
IndicatorSetForeground(0,wxColour(255,0,0));
// Set spellchecker
spellchecker = SpellChecker::GetSpellChecker();
@ -208,6 +161,59 @@ BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxScintilla)
END_EVENT_TABLE()
//////////////
// Set styles
void SubsTextEditCtrl::SetStyles() {
// Styles
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
wxString fontname = Options.AsText(_T("Font Face"));
if (fontname != _T("")) font.SetFaceName(fontname);
int size = Options.AsInt(_T("Font Size"));
// Normal style
StyleSetFont(0,font);
StyleSetSize(0,size);
StyleSetForeground(0,Options.AsColour(_T("Syntax Highlight Normal")));
// Brackets style
StyleSetFont(1,font);
StyleSetSize(1,size);
StyleSetForeground(1,Options.AsColour(_T("Syntax Highlight Brackets")));
// Slashes/Parenthesis/Comma style
StyleSetFont(2,font);
StyleSetSize(2,size);
StyleSetForeground(2,Options.AsColour(_T("Syntax Highlight Slashes")));
// Tags style
StyleSetFont(3,font);
StyleSetSize(3,size);
StyleSetBold(3,true);
StyleSetForeground(3,Options.AsColour(_T("Syntax Highlight Tags")));
// Error style
StyleSetFont(4,font);
StyleSetSize(4,size);
StyleSetForeground(4,Options.AsColour(_T("Syntax Highlight Error")));
StyleSetBackground(4,Options.AsColour(_T("Syntax Highlight Error Background")));
// Tag Parameters style
StyleSetFont(5,font);
StyleSetSize(5,size);
StyleSetForeground(5,Options.AsColour(_T("Syntax Highlight Parameters")));
// Line breaks style
StyleSetFont(6,font);
StyleSetSize(6,size);
StyleSetBold(6,true);
StyleSetForeground(6,Options.AsColour(_T("Syntax Highlight Line Break")));
// Misspelling indicator
IndicatorSetStyle(0,wxSCI_INDIC_SQUIGGLE);
IndicatorSetForeground(0,wxColour(255,0,0));
}
/////////////////
// Style a range
void SubsTextEditCtrl::UpdateStyle(int start, int _length) {

View file

@ -99,6 +99,7 @@ public:
void UpdateStyle(int start=0,int length=-1);
void StyleSpellCheck(int start=0,int length=-1);
void UpdateCallTip();
void SetStyles();
DECLARE_EVENT_TABLE()
};