Somewhat fixed the wxScintilla crap, but not entirely

Originally committed to SVN as r601.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-24 17:42:09 +00:00
parent 9023e039ff
commit 21dbd0633f
6 changed files with 40 additions and 301 deletions

View File

@ -1169,7 +1169,7 @@ void FrameMain::StatusTimeout(wxString text,int ms) {
///////////////////////////
// Setup accelerator table
void FrameMain::SetAccelerators() {
wxAcceleratorEntry entry[10];
wxAcceleratorEntry entry[11];
int i = 0;
entry[i++] = Hotkeys.GetAccelerator(_T("Video global prev frame"),Video_Prev_Frame);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global next frame"),Video_Next_Frame);
@ -1180,6 +1180,7 @@ void FrameMain::SetAccelerators() {
entry[i++] = Hotkeys.GetAccelerator(_T("Video global zoom in"),Menu_Video_Zoom_In);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global zoom out"),Menu_Video_Zoom_Out);
entry[i++] = Hotkeys.GetAccelerator(_T("Video global play"),Video_Play);
entry[i++] = Hotkeys.GetAccelerator(_T("Edit box commit"),Edit_Box_Commit);
wxAcceleratorEntry temp;
temp.Set(wxACCEL_CTRL | wxACCEL_ALT,WXK_F12,Kana_Game);
entry[i++] = temp;

View File

@ -187,6 +187,7 @@ private:
void OnJumpTo (wxCommandEvent &event);
void OnShift (wxCommandEvent &event);
void OnSort (wxCommandEvent &event);
void OnEditBoxCommit (wxCommandEvent &event);
void OnOpenProperties (wxCommandEvent &event);
void OnOpenStylesManager (wxCommandEvent &event);
void OnOpenAttachments (wxCommandEvent &event);
@ -365,6 +366,7 @@ enum {
Grid_Next_Line,
Grid_Prev_Line,
Grid_Toggle_Tags,
Edit_Box_Commit,
Video_Play,
Video_Play_Line,

View File

@ -210,6 +210,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Grid_Next_Line,FrameMain::OnNextLine)
EVT_MENU(Grid_Prev_Line,FrameMain::OnPrevLine)
EVT_MENU(Grid_Toggle_Tags,FrameMain::OnToggleTags)
EVT_MENU(Edit_Box_Commit,FrameMain::OnEditBoxCommit)
EVT_MENU(Kana_Game, FrameMain::OnKanaGame)
@ -1391,6 +1392,30 @@ void FrameMain::OnToggleTags(wxCommandEvent &event) {
}
/////////////////////////////
// Commit Edit Box's changes
void FrameMain::OnEditBoxCommit(wxCommandEvent &event) {
// Find focus
wxWindow *focus = FindFocus();
// Is the text edit
if (focus == EditBox->TextEdit) {
EditBox->CommitText();
SubsBox->ass->FlagAsModified();
SubsBox->CommitChanges();
}
// Other window
else {
wxKeyEvent keyevent;
keyevent.m_keyCode = WXK_RETURN;
keyevent.m_controlDown = true;
keyevent.SetEventType(wxEVT_KEY_DOWN);
focus->AddPendingEvent(keyevent);
}
}
//////////////
// Play video
void FrameMain::OnVideoPlay(wxCommandEvent &event) {

View File

@ -314,6 +314,7 @@ void HotkeyManager::LoadDefaults() {
SetHotkey(_("Exit"),_T("Alt-F4"));
SetHotkey(_("Help"),_T("F1"));
SetHotkey(_("Edit Box Commit"),_T("Ctrl-Enter"));
SetHotkey(_("Undo"),_T("Ctrl-Z"));
SetHotkey(_("Redo"),_T("Ctrl-Y"));
SetHotkey(_("Shift Times"),_T("Ctrl-I"));

View File

@ -40,6 +40,7 @@
#include <wx/colordlg.h>
#include <wx/fontdlg.h>
#include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h"
#include "ass_file.h"
#include "ass_dialogue.h"
@ -201,7 +202,7 @@ void SubsEditBox::Update (bool timeOnly) {
EndTime->SetTime(end);
Duration->SetTime(end-start);
if (!timeOnly) {
SetText(curdiag->Text);
TextEdit->SetTextTo(curdiag->Text);
Layer->SetValue(wxString::Format(_T("%i"),curdiag->Layer));
MarginL->SetValue(curdiag->GetMarginString(1));
MarginR->SetValue(curdiag->GetMarginString(2));
@ -292,130 +293,6 @@ void SubsEditBox::SetToLine(int n) {
}
/////////////////
// Style a range
void SubsEditBox::UpdateStyle(int start, int _length) {
// Styling enabled?
if (Options.AsBool(_T("Syntax Highlight Enabled")) == 0) return;
// Set variables
wxString text = TextEdit->GetText();
int len = _length;
if (len < 0) len = text.Length();
// Begin styling
TextEdit->StartStyling(0,31);
int ran = 0;
int depth = 0;
int curStyle = 0;
wxChar curChar = 0;
wxChar prevChar = 0;
// Loop through
for (int i=start;i<len;i++) {
// Current/previous characters
prevChar = curChar;
curChar = text[i];
// Erroneous
if (depth < 0 || depth > 1) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
curStyle = 4;
}
// Start override block
if (curChar == _T('{') && depth >= 0) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
depth++;
if (depth == 1) curStyle = 1;
else curStyle = 4;
}
// End override block
else if (curChar == _T('}') && depth <= 1) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
depth--;
if (depth == 0) curStyle = 1;
else curStyle = 4;
}
// Outside
else if (depth == 0 && curStyle != 0) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
curStyle = 0;
}
// Inside
else if (depth == 1) {
// Special character
if (curChar == _T('\\') || curChar == _T('(') || curChar == _T(')') || curChar == _T(',')) {
if (curStyle != 2) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
curStyle = 2;
}
}
// Number
else if ((curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&')) {
if (curStyle != 5) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
curStyle = 5;
}
}
// Tag name
else if (curStyle != 3) {
TextEdit->SetStyling(ran,curStyle);
ran = 0;
curStyle = 3;
}
}
// Increase ran length
ran++;
}
TextEdit->SetStyling(ran,curStyle);
}
///////////////////////////
// Set text to a new value
void SubsEditBox::SetText(const wxString _text) {
// Setup
textEditReady = false;
TextEdit->Freeze();
wxString text = _text;
text.Replace(_T("\r\n"),_T("\\N"));
text.Replace(_T("\n\r"),_T("\\N"));
text.Replace(_T("\r"),_T("\\N"));
text.Replace(_T("\n"),_T("\\N"));
// Prepare
int from=0,to=0;
TextEdit->GetSelection(&from,&to);
TextEdit->Clear();
// Set text
TextEdit->SetText(text);
// Style
UpdateStyle();
// Restore selection
TextEdit->SetSelection(from,to);
// Finish
TextEdit->Thaw();
textEditReady = true;
}
///////////////
// Event table
BEGIN_EVENT_TABLE(SubsEditBox, wxPanel)
@ -470,18 +347,18 @@ void SubsEditBox::OnNeedStyle(wxScintillaEvent &event) {
// Check if it needs to fix text
wxString text = TextEdit->GetText();
if (text.Contains(_T("\n")) || text.Contains(_T("\r"))) {
SetText(TextEdit->GetText());
TextEdit->SetTextTo(TextEdit->GetText());
}
// Just update style
else UpdateStyle();
else TextEdit->UpdateStyle();
}
/////////////////////////////
// Syntax highlight checkbox
void SubsEditBox::OnSyntaxBox(wxCommandEvent &event) {
SetText(TextEdit->GetText());
TextEdit->UpdateStyle();
Options.SetBool(_T("Syntax Highlight Enabled"),SyntaxHighlight->GetValue());
Options.Save();
event.Skip();
@ -558,7 +435,7 @@ void SubsEditBox::SetControlsState (bool state) {
// Clear values if it's false
if (state==false) {
TextEdit->SetText(_T(""));
TextEdit->SetTextTo(_T(""));
StartTime->SetTime(0);
EndTime->SetTime(0);
Layer->SetValue(_T(""));
@ -912,80 +789,6 @@ void SubsEditBox::CommitText() {
}
////////////////////////
// Edit box constructor
SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& wsize, long style, const wxValidator& validator, const wxString& name)
: wxScintilla(parent, id, pos, wsize, 0, value)
{
// Set properties
SetWrapMode(wxSCI_WRAP_WORD);
SetMarginWidth(1,0);
PushEventHandler(new SubsTextEditHandler(this,(SubsEditBox*)parent));
//CmdKeyAssign(wxSCI_KEY_RETURN,wxSCI_SCMOD_CTRL,wxSCI_CMD_NEWLINE);
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_CTRL);
CmdKeyClear(wxSCI_KEY_RETURN,wxSCI_SCMOD_NULL);
CmdKeyClear(wxSCI_KEY_TAB,wxSCI_SCMOD_NULL);
CmdKeyClear(wxSCI_KEY_TAB,wxSCI_SCMOD_SHIFT);
CmdKeyClear('D',wxSCI_SCMOD_CTRL);
CmdKeyClear('L',wxSCI_SCMOD_CTRL);
CmdKeyClear('L',wxSCI_SCMOD_CTRL | wxSCI_SCMOD_SHIFT);
CmdKeyClear('T',wxSCI_SCMOD_CTRL);
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")));
// Tag Number Parameters style
StyleSetFont(5,font);
StyleSetSize(5,size);
StyleSetForeground(5,Options.AsColour(_T("Syntax Highlight Numbers")));
}
////////////////////////
// Edit box event table
BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxScintilla)
EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent)
END_EVENT_TABLE()
//////////////////////////
// Edit box event handler
BEGIN_EVENT_TABLE(SubsTextEditHandler,wxEvtHandler)
EVT_KEY_DOWN(SubsTextEditHandler::OnKeyDown)
END_EVENT_TABLE()
///////////////////////////////
// Split line preserving times
void SubsEditBox::OnSplitLinePreserve (wxCommandEvent &event) {
@ -1039,70 +842,6 @@ void SubsEditBox::OnSelectAll(wxCommandEvent &event) {
}
///////////////
// Mouse event
void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) {
// Right click
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) {
if (control->linen >= 0) {
// Popup
wxMenu menu;
menu.Append(EDIT_MENU_UNDO,_("&Undo"))->Enable(CanUndo());
menu.AppendSeparator();
menu.Append(EDIT_MENU_CUT,_("Cu&t"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0);
menu.Append(EDIT_MENU_COPY,_("&Copy"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0);
menu.Append(EDIT_MENU_PASTE,_("&Paste"))->Enable(CanPaste());
menu.AppendSeparator();
menu.Append(EDIT_MENU_SELECT_ALL,_("Select &All"));
menu.AppendSeparator();
menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)"));
menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)"));
PopupMenu(&menu);
return;
}
}
event.Skip();
}
/////////////
// Key Event
SubsTextEditHandler::SubsTextEditHandler(wxScintilla *scint,SubsEditBox *edit) {
box = edit;
parent = scint;
//Connect(wxEVT_SCI_MODIFIED,wxCommandEventHandler(SubsTextEditHandler::OnChange));
}
void SubsTextEditHandler::OnKeyDown(wxKeyEvent &event) {
// Ctrl held?
int key = event.GetKeyCode();
if (event.GetModifiers() == wxMOD_CONTROL) {
if (key == 'C') {
parent->Copy();
event.StopPropagation();
return;
}
if (key == 'X') {
parent->Cut();
event.StopPropagation();
return;
}
if (key == 'V') {
parent->Paste();
event.StopPropagation();
return;
}
if (key == WXK_RETURN || key == WXK_NUMPAD_ENTER) {
return;
}
}
event.Skip();
}
//////////////////////////////////////
// Gets block number at text position
int SubsEditBox::BlockAtPos(int pos) {
@ -1330,7 +1069,7 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
int origStart = selstart;
selstart = selend + shift;
insert = insert2;
SetText(line->Text);
TextEdit->SetTextTo(line->Text);
blockn = BlockAtPos(selstart);
block = line->Blocks.at(blockn);
plain = AssDialogueBlock::GetAsPlain(block);
@ -1367,7 +1106,7 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
}
// Commit changes and shift selection
SetText(line->Text);
TextEdit->SetTextTo(line->Text);
line->ClearBlocks();
TextEdit->SetSelection(selstart+shift,selend+shift);
TextEdit->SetFocus();

View File

@ -40,7 +40,7 @@
////////////
// Includes
#include <wx/wxprec.h>
#include <wx/wxscintilla.h>
#include "subs_edit_ctrl.h"
//////////////
@ -54,38 +54,11 @@ class VideoDisplay;
class wxScintilla;
/////////////////
// Event handler
class SubsTextEditHandler : public wxEvtHandler {
private:
wxScintilla *parent;
SubsEditBox *box;
void OnKeyDown(wxKeyEvent &event);
public:
SubsTextEditHandler(wxScintilla *scint,SubsEditBox *editbox);
DECLARE_EVENT_TABLE()
};
////////////////////
// SubsTextEditCtrl
class SubsTextEditCtrl : public wxScintilla {
private:
void OnMouseEvent(wxMouseEvent &event);
public:
SubsEditBox *control;
SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
DECLARE_EVENT_TABLE()
};
//////////////////
// Edit box class
class SubsEditBox : public wxPanel {
friend class SubsTextEditHandler;
friend class SubsTextEditCtrl;
private:
bool enabled;
@ -174,8 +147,6 @@ public:
void SetStyleFlag (wxString tag,wxString preValue=_T(""),int pos=-1);
void CommitText();
void SetText(const wxString text);
void UpdateStyle(int start=0,int length=-1);
void Update(bool timeOnly=false);
void UpdateGlobals();
void SetToLine(int n);