2006-12-24 22:52:54 +01:00
|
|
|
// Copyright (c) 2005, 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
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
////////////
|
|
|
|
// Includes
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-01-01 05:53:55 +01:00
|
|
|
#include <wx/wxprec.h>
|
|
|
|
#include <wx/intl.h>
|
2006-12-24 22:52:54 +01:00
|
|
|
#include "subs_edit_ctrl.h"
|
|
|
|
#include "subs_edit_box.h"
|
|
|
|
#include "options.h"
|
2006-12-25 06:43:00 +01:00
|
|
|
#include "subs_grid.h"
|
|
|
|
#include "utils.h"
|
2007-08-19 04:18:00 +02:00
|
|
|
#include "ass_dialogue.h"
|
2006-12-24 22:52:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////
|
|
|
|
// 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)
|
2007-06-23 01:43:21 +02:00
|
|
|
: ScintillaTextCtrl(parent, id, value, pos, wsize, style, validator, name)
|
2006-12-24 22:52:54 +01:00
|
|
|
{
|
|
|
|
// Set properties
|
2007-04-22 01:16:38 +02:00
|
|
|
SetWrapMode(wxSTC_WRAP_WORD);
|
2006-12-24 22:52:54 +01:00
|
|
|
SetMarginWidth(1,0);
|
2006-12-25 22:56:56 +01:00
|
|
|
UsePopUp(false);
|
2007-01-03 22:49:13 +01:00
|
|
|
SetStyles();
|
2006-12-25 04:42:44 +01:00
|
|
|
|
|
|
|
// Set hotkeys
|
2007-04-22 01:16:38 +02:00
|
|
|
CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_SCMOD_CTRL);
|
|
|
|
CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_SCMOD_NORM);
|
|
|
|
CmdKeyClear(wxSTC_KEY_TAB,wxSTC_SCMOD_NORM);
|
|
|
|
CmdKeyClear(wxSTC_KEY_TAB,wxSTC_SCMOD_SHIFT);
|
|
|
|
CmdKeyClear('D',wxSTC_SCMOD_CTRL);
|
|
|
|
CmdKeyClear('L',wxSTC_SCMOD_CTRL);
|
|
|
|
CmdKeyClear('L',wxSTC_SCMOD_CTRL | wxSTC_SCMOD_SHIFT);
|
|
|
|
CmdKeyClear('T',wxSTC_SCMOD_CTRL);
|
|
|
|
CmdKeyClear('T',wxSTC_SCMOD_CTRL | wxSTC_SCMOD_SHIFT);
|
|
|
|
CmdKeyClear('U',wxSTC_SCMOD_CTRL);
|
2006-12-24 22:52:54 +01:00
|
|
|
|
|
|
|
// Set spellchecker
|
2008-03-07 03:32:29 +01:00
|
|
|
spellchecker = SpellCheckerFactoryManager::GetSpellChecker();
|
2006-12-25 22:56:56 +01:00
|
|
|
|
|
|
|
// Set thesaurus
|
|
|
|
thesaurus = Thesaurus::GetThesaurus();
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2007-01-02 19:09:56 +01:00
|
|
|
// Prototypes for call tips
|
2007-01-02 19:15:17 +01:00
|
|
|
tipProtoN = -1;
|
2007-01-02 19:09:56 +01:00
|
|
|
proto.Add(_T("move(x1,y1,x2,y2)"));
|
|
|
|
proto.Add(_T("move(x1,y1,x2,y2,startTime,endTime)"));
|
|
|
|
proto.Add(_T("fn;FontName"));
|
|
|
|
proto.Add(_T("bord;Width"));
|
|
|
|
proto.Add(_T("shad;Depth"));
|
|
|
|
proto.Add(_T("be;1/0"));
|
|
|
|
proto.Add(_T("fscx;Scale"));
|
|
|
|
proto.Add(_T("fscy;Scale"));
|
|
|
|
proto.Add(_T("fsp;Spacing"));
|
|
|
|
proto.Add(_T("fs;FontSize"));
|
|
|
|
proto.Add(_T("fe;Encoding"));
|
|
|
|
proto.Add(_T("frx;Angle"));
|
|
|
|
proto.Add(_T("fry;Angle"));
|
|
|
|
proto.Add(_T("frz;Angle"));
|
|
|
|
proto.Add(_T("fr;Angle"));
|
|
|
|
proto.Add(_T("pbo;Offset"));
|
|
|
|
proto.Add(_T("clip(command)"));
|
|
|
|
proto.Add(_T("clip(scale,command)"));
|
|
|
|
proto.Add(_T("clip(x1,y1,x2,y2)"));
|
|
|
|
proto.Add(_T("t(acceleration,tags)"));
|
|
|
|
proto.Add(_T("t(startTime,endTime,tags)"));
|
|
|
|
proto.Add(_T("t(startTime,endTime,acceleration,tags)"));
|
|
|
|
proto.Add(_T("pos(x,y)"));
|
|
|
|
proto.Add(_T("p;Exponent"));
|
|
|
|
proto.Add(_T("org(x,y)"));
|
|
|
|
proto.Add(_T("fade(startAlpha,middleAlpha,endAlpha,startIn,endIn,startOut,endOut)"));
|
|
|
|
proto.Add(_T("fad(startTime,endTime)"));
|
|
|
|
proto.Add(_T("c;Colour"));
|
|
|
|
proto.Add(_T("1c;Colour"));
|
|
|
|
proto.Add(_T("2c;Colour"));
|
|
|
|
proto.Add(_T("3c;Colour"));
|
|
|
|
proto.Add(_T("4c;Colour"));
|
|
|
|
proto.Add(_T("alpha;Alpha"));
|
|
|
|
proto.Add(_T("1a;Alpha"));
|
|
|
|
proto.Add(_T("2a;Alpha"));
|
|
|
|
proto.Add(_T("3a;Alpha"));
|
|
|
|
proto.Add(_T("4a;Alpha"));
|
|
|
|
proto.Add(_T("an;Alignment"));
|
|
|
|
proto.Add(_T("a;Alignment"));
|
|
|
|
proto.Add(_T("b;Weight"));
|
|
|
|
proto.Add(_T("i;1/0"));
|
|
|
|
proto.Add(_T("u;1/0"));
|
|
|
|
proto.Add(_T("s;1/0"));
|
|
|
|
proto.Add(_T("kf;Duration"));
|
|
|
|
proto.Add(_T("ko;Duration"));
|
|
|
|
proto.Add(_T("k;Duration"));
|
|
|
|
proto.Add(_T("K;Duration"));
|
|
|
|
proto.Add(_T("q;WarpStyle"));
|
|
|
|
proto.Add(_T("r;Style"));
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Destructor
|
|
|
|
SubsTextEditCtrl::~SubsTextEditCtrl() {
|
|
|
|
delete spellchecker;
|
|
|
|
spellchecker = NULL;
|
2006-12-25 22:56:56 +01:00
|
|
|
delete thesaurus;
|
|
|
|
thesaurus = NULL;
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-02 06:00:55 +01:00
|
|
|
///////////////////////
|
|
|
|
// Control event table
|
2007-04-22 01:16:38 +02:00
|
|
|
BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl)
|
2007-01-02 06:00:55 +01:00
|
|
|
EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent)
|
2007-01-14 00:34:04 +01:00
|
|
|
EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus)
|
2007-01-02 06:00:55 +01:00
|
|
|
|
|
|
|
EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve)
|
|
|
|
EVT_MENU(EDIT_MENU_SPLIT_ESTIMATE,SubsTextEditCtrl::OnSplitLineEstimate)
|
|
|
|
EVT_MENU(EDIT_MENU_CUT,SubsTextEditCtrl::OnCut)
|
|
|
|
EVT_MENU(EDIT_MENU_COPY,SubsTextEditCtrl::OnCopy)
|
|
|
|
EVT_MENU(EDIT_MENU_PASTE,SubsTextEditCtrl::OnPaste)
|
|
|
|
EVT_MENU(EDIT_MENU_UNDO,SubsTextEditCtrl::OnUndo)
|
|
|
|
EVT_MENU(EDIT_MENU_SELECT_ALL,SubsTextEditCtrl::OnSelectAll)
|
|
|
|
EVT_MENU(EDIT_MENU_ADD_TO_DICT,SubsTextEditCtrl::OnAddToDictionary)
|
|
|
|
EVT_MENU_RANGE(EDIT_MENU_SUGGESTIONS,EDIT_MENU_THESAURUS-1,SubsTextEditCtrl::OnUseSuggestion)
|
|
|
|
EVT_MENU_RANGE(EDIT_MENU_THESAURUS_SUGS,EDIT_MENU_DIC_LANGUAGE-1,SubsTextEditCtrl::OnUseThesaurusSuggestion)
|
|
|
|
EVT_MENU_RANGE(EDIT_MENU_DIC_LANGS,EDIT_MENU_THES_LANGUAGE-1,SubsTextEditCtrl::OnSetDicLanguage)
|
|
|
|
EVT_MENU_RANGE(EDIT_MENU_THES_LANGS,EDIT_MENU_THES_LANGS+100,SubsTextEditCtrl::OnSetThesLanguage)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2007-01-14 00:34:04 +01:00
|
|
|
//////////////
|
|
|
|
// Lose focus
|
|
|
|
void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) {
|
|
|
|
CallTipCancel();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-03 22:49:13 +01:00
|
|
|
//////////////
|
|
|
|
// Set styles
|
|
|
|
void SubsTextEditCtrl::SetStyles() {
|
|
|
|
// Styles
|
|
|
|
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2007-01-03 23:43:05 +01:00
|
|
|
wxString fontname = Options.AsText(_T("Edit Font Face"));
|
2007-01-03 22:49:13 +01:00
|
|
|
if (fontname != _T("")) font.SetFaceName(fontname);
|
2007-01-03 23:43:05 +01:00
|
|
|
int size = Options.AsInt(_T("Edit Font Size"));
|
2007-01-03 22:49:13 +01:00
|
|
|
|
|
|
|
// 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")));
|
|
|
|
|
2007-08-06 16:29:43 +02:00
|
|
|
// Karaoke template code block style
|
|
|
|
StyleSetFont(7,font);
|
|
|
|
StyleSetSize(7,size);
|
|
|
|
StyleSetBold(7,true);
|
|
|
|
//StyleSetItalic(7,true);
|
|
|
|
StyleSetForeground(7,Options.AsColour(_T("Syntax Highlight Karaoke Template")));
|
|
|
|
|
2007-01-03 22:49:13 +01:00
|
|
|
// Misspelling indicator
|
2007-04-22 01:16:38 +02:00
|
|
|
IndicatorSetStyle(0,wxSTC_INDIC_SQUIGGLE);
|
2007-01-03 22:49:13 +01:00
|
|
|
IndicatorSetForeground(0,wxColour(255,0,0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-24 22:52:54 +01:00
|
|
|
/////////////////
|
|
|
|
// Style a range
|
|
|
|
void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
|
|
|
|
// Styling enabled?
|
|
|
|
if (Options.AsBool(_T("Syntax Highlight Enabled")) == 0) return;
|
|
|
|
|
2007-08-29 00:52:23 +02:00
|
|
|
// Check if it's a template line
|
|
|
|
AssDialogue *diag = control->grid->GetDialogue(control->linen);
|
|
|
|
bool templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith(_T("template"));
|
2007-09-12 01:22:26 +02:00
|
|
|
//bool templateCodeLine = diag && diag->Comment && diag->Effect.Lower().StartsWith(_T("code"));
|
2007-08-29 00:52:23 +02:00
|
|
|
|
|
|
|
// Template code lines get Lua highlighting instead of ASS highlighting
|
|
|
|
// This is broken and needs some extra work
|
|
|
|
/*if (templateCodeLine) {
|
|
|
|
SetLexer(wxSTC_LEX_LUA);
|
|
|
|
Colourise(start, start+_length);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetLexer(wxSTC_LEX_CONTAINER);
|
2007-08-29 00:54:25 +02:00
|
|
|
}*/
|
2007-08-29 00:52:23 +02:00
|
|
|
|
2006-12-24 22:52:54 +01:00
|
|
|
// Set variables
|
|
|
|
wxString text = GetText();
|
2006-12-24 23:46:20 +01:00
|
|
|
int end = start + _length;
|
|
|
|
if (_length < 0) end = text.Length();
|
2006-12-24 22:52:54 +01:00
|
|
|
|
2007-01-02 03:33:42 +01:00
|
|
|
// Flags
|
|
|
|
bool numMode = false; // everything is considered a number/parameter until this is unset
|
|
|
|
bool drawingMode = false; // for \p1 -> \p0 stuff
|
|
|
|
|
2006-12-24 22:52:54 +01:00
|
|
|
// Begin styling
|
2006-12-25 04:42:44 +01:00
|
|
|
StartStyling(0,255);
|
2007-08-06 16:29:43 +02:00
|
|
|
int ran = 0; // length of current range
|
|
|
|
int depth = 0; // brace nesting depth
|
|
|
|
int curStyle = 0; // style to apply to current range
|
|
|
|
int curPos = 0; // start of current range?
|
2006-12-24 22:52:54 +01:00
|
|
|
wxChar curChar = 0;
|
|
|
|
wxChar prevChar = 0;
|
2006-12-25 06:43:00 +01:00
|
|
|
wxChar nextChar = 0;
|
2006-12-24 22:52:54 +01:00
|
|
|
|
|
|
|
// Loop through
|
2006-12-24 23:46:20 +01:00
|
|
|
for (int i=start;i<end;i++) {
|
2006-12-24 22:52:54 +01:00
|
|
|
// Current/previous characters
|
|
|
|
prevChar = curChar;
|
|
|
|
curChar = text[i];
|
2006-12-25 06:43:00 +01:00
|
|
|
if (i<end-1) nextChar = text[i+1];
|
|
|
|
else nextChar = 0;
|
2006-12-24 22:52:54 +01:00
|
|
|
|
|
|
|
// Erroneous
|
|
|
|
if (depth < 0 || depth > 1) {
|
2006-12-25 04:42:44 +01:00
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
2006-12-24 22:52:54 +01:00
|
|
|
ran = 0;
|
|
|
|
curStyle = 4;
|
2007-01-02 03:24:23 +01:00
|
|
|
numMode = false;
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start override block
|
|
|
|
if (curChar == _T('{') && depth >= 0) {
|
2006-12-25 04:42:44 +01:00
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
2006-12-24 22:52:54 +01:00
|
|
|
ran = 0;
|
|
|
|
depth++;
|
|
|
|
if (depth == 1) curStyle = 1;
|
|
|
|
else curStyle = 4;
|
2007-01-02 03:24:23 +01:00
|
|
|
numMode = false;
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// End override block
|
|
|
|
else if (curChar == _T('}') && depth <= 1) {
|
2006-12-25 04:42:44 +01:00
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
2006-12-24 22:52:54 +01:00
|
|
|
ran = 0;
|
|
|
|
depth--;
|
|
|
|
if (depth == 0) curStyle = 1;
|
|
|
|
else curStyle = 4;
|
2007-01-02 03:24:23 +01:00
|
|
|
numMode = false;
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
2007-08-06 16:29:43 +02:00
|
|
|
// Karaoke template block
|
2007-08-19 04:18:00 +02:00
|
|
|
else if (templateLine && curChar == _T('!')) {
|
2007-08-06 16:29:43 +02:00
|
|
|
// Apply previous style
|
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
|
|
|
ran = -1; // such that ran++ later on resets it to 0 !
|
|
|
|
// Eat entire template block
|
|
|
|
int endPos = i+1;
|
|
|
|
while (endPos < end && text[endPos] != _T('!'))
|
|
|
|
endPos++;
|
|
|
|
SetUnicodeStyling(curPos,endPos-curPos+1,7);
|
|
|
|
curPos = endPos+1;
|
|
|
|
i = endPos+0;
|
|
|
|
}
|
|
|
|
// Karaoke template variable
|
2007-08-19 04:18:00 +02:00
|
|
|
else if (templateLine && curChar == _T('$')) {
|
2007-08-06 16:29:43 +02:00
|
|
|
// Apply previous style
|
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
|
|
|
ran = -1; // such that ran++ later on resets it to 0 !
|
|
|
|
// Eat entire variable
|
|
|
|
int endPos = i+1;
|
|
|
|
while (endPos < end) {
|
|
|
|
wxChar ch = text[endPos];
|
|
|
|
if ((ch >= _T('A') && ch <= _T('Z')) || (ch >= _T('a') && ch <= _T('z')) || ch == _T('_'))
|
|
|
|
endPos++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SetUnicodeStyling(curPos,endPos-curPos,7);
|
|
|
|
curPos = endPos;
|
|
|
|
i = curPos-1;
|
|
|
|
}
|
|
|
|
|
2006-12-24 22:52:54 +01:00
|
|
|
// Outside
|
2006-12-25 06:43:00 +01:00
|
|
|
else if (depth == 0) {
|
2007-01-02 03:24:23 +01:00
|
|
|
// Reset number mode
|
|
|
|
numMode = false;
|
|
|
|
|
2006-12-25 06:43:00 +01:00
|
|
|
// Is \n, \N or \h?
|
|
|
|
if (curChar == _T('\\') && (nextChar == 'n' || nextChar == 'N' || nextChar == 'h')) {
|
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
2006-12-26 02:30:30 +01:00
|
|
|
curPos += ran;
|
2006-12-25 06:43:00 +01:00
|
|
|
ran = 1;
|
|
|
|
curStyle = 6;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal text
|
|
|
|
else if (curStyle != 0) {
|
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
|
|
|
ran = 0;
|
2007-01-02 03:33:42 +01:00
|
|
|
if (drawingMode) curStyle = 6;
|
|
|
|
else curStyle = 0;
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inside
|
|
|
|
else if (depth == 1) {
|
|
|
|
// Special character
|
|
|
|
if (curChar == _T('\\') || curChar == _T('(') || curChar == _T(')') || curChar == _T(',')) {
|
|
|
|
if (curStyle != 2) {
|
2006-12-25 04:42:44 +01:00
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
2006-12-24 22:52:54 +01:00
|
|
|
ran = 0;
|
|
|
|
curStyle = 2;
|
2007-01-02 03:24:23 +01:00
|
|
|
numMode = false;
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-02 03:24:23 +01:00
|
|
|
else {
|
|
|
|
// Number
|
|
|
|
if (prevChar != _T('\\') && (numMode || (curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&'))) {
|
|
|
|
if (curStyle != 5) {
|
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
|
|
|
ran = 0;
|
|
|
|
curStyle = 5;
|
|
|
|
numMode = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tag name
|
|
|
|
else if (curStyle != 3) {
|
2006-12-25 04:42:44 +01:00
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
|
|
|
curPos += ran;
|
2006-12-24 22:52:54 +01:00
|
|
|
ran = 0;
|
2007-01-02 03:24:23 +01:00
|
|
|
curStyle = 3;
|
|
|
|
|
|
|
|
// Set parameter if it's \fn or \r
|
|
|
|
int tagLen = 0;
|
|
|
|
if (text.Mid(curPos,2) == _T("fn")) tagLen = 2;
|
|
|
|
else if (text.Mid(curPos,1) == _T("r")) tagLen = 1;
|
|
|
|
if (tagLen) {
|
|
|
|
numMode = true;
|
|
|
|
ran = tagLen-1;
|
|
|
|
i+=ran;
|
|
|
|
}
|
2007-01-02 03:33:42 +01:00
|
|
|
|
|
|
|
// Set drawing mode if it's \p
|
|
|
|
if (text.Mid(curPos,1) == _T("p")) {
|
|
|
|
if (curPos+2 < (signed) text.Length()) {
|
2007-01-02 06:00:55 +01:00
|
|
|
// Disable
|
2007-01-02 03:33:42 +01:00
|
|
|
wxChar nextNext = text[curPos+2];
|
2007-01-02 06:00:55 +01:00
|
|
|
if ((nextNext == _T('\\') || nextNext == _T('}')) && nextChar == _T('0')) drawingMode = false;
|
|
|
|
|
|
|
|
// Enable
|
|
|
|
if (nextChar >= _T('1') && nextChar <= _T('9')) {
|
|
|
|
for(int testPos = curPos+2;testPos < (signed) text.Length();testPos++) {
|
|
|
|
nextNext = text[testPos];
|
|
|
|
if (nextNext == _T('\\') || nextNext == _T('}')) {
|
|
|
|
drawingMode = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nextNext < _T('0') || nextNext > _T('9')) break;
|
|
|
|
}
|
2007-01-02 03:33:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increase ran length
|
|
|
|
ran++;
|
|
|
|
}
|
2006-12-25 04:42:44 +01:00
|
|
|
SetUnicodeStyling(curPos,ran,curStyle);
|
2006-12-24 23:46:20 +01:00
|
|
|
|
|
|
|
// Spell check
|
|
|
|
StyleSpellCheck(start,_length);
|
2007-01-02 06:00:55 +01:00
|
|
|
|
|
|
|
// Call tip
|
2007-01-02 19:09:56 +01:00
|
|
|
UpdateCallTip();
|
2007-01-02 06:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
// Update call tip
|
|
|
|
void SubsTextEditCtrl::UpdateCallTip() {
|
2007-01-02 23:10:45 +01:00
|
|
|
// Enabled?
|
|
|
|
if (!Options.AsBool(_T("Call tips enabled"))) return;
|
|
|
|
|
2007-01-02 06:00:55 +01:00
|
|
|
// Get position and text
|
|
|
|
const unsigned int pos = GetReverseUnicodePosition(GetCurrentPos());
|
|
|
|
wxString text = GetText();
|
|
|
|
|
2007-01-02 19:09:56 +01:00
|
|
|
// Find the start and end of current tag
|
2007-01-02 06:00:55 +01:00
|
|
|
wxChar curChar = 0;
|
2007-01-02 19:09:56 +01:00
|
|
|
wxChar prevChar = 0;
|
2007-01-02 06:00:55 +01:00
|
|
|
int depth = 0;
|
|
|
|
int inDepth = 0;
|
|
|
|
int tagStart = -1;
|
|
|
|
int tagEnd = -1;
|
2007-01-02 19:09:56 +01:00
|
|
|
for (unsigned int i=0;i<text.Length()+1;i++) {
|
2007-01-02 06:00:55 +01:00
|
|
|
// Get character
|
2007-01-02 19:09:56 +01:00
|
|
|
if (i<text.Length()) curChar = text[i];
|
|
|
|
else curChar = 0;
|
2007-01-02 06:00:55 +01:00
|
|
|
|
|
|
|
// Change depth
|
|
|
|
if (curChar == _T('{')) {
|
|
|
|
depth++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (curChar == _T('}')) {
|
|
|
|
depth--;
|
2007-01-02 19:09:56 +01:00
|
|
|
if (i >= pos && depth == 0) {
|
|
|
|
tagEnd = i-1;
|
2007-01-02 06:00:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Outside
|
|
|
|
if (depth == 0) {
|
|
|
|
tagStart = -1;
|
|
|
|
if (i == pos) break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inside overrides
|
|
|
|
if (depth == 1) {
|
|
|
|
// Inner depth
|
|
|
|
if (tagStart != -1) {
|
|
|
|
if (curChar == _T('(')) inDepth++;
|
|
|
|
else if (curChar == _T(')')) inDepth--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not inside parenthesis
|
|
|
|
if (inDepth == 0) {
|
2007-01-02 19:09:56 +01:00
|
|
|
if (prevChar == _T('\\')) {
|
2007-01-02 06:00:55 +01:00
|
|
|
// Found start
|
|
|
|
if (i <= pos) tagStart = i;
|
|
|
|
|
|
|
|
// Found end
|
|
|
|
else {
|
2007-01-02 19:09:56 +01:00
|
|
|
tagEnd = i-2;
|
2007-01-02 06:00:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-02 19:09:56 +01:00
|
|
|
|
|
|
|
// Previous character
|
|
|
|
prevChar = curChar;
|
2007-01-02 06:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate length
|
|
|
|
int len;
|
|
|
|
if (tagEnd != -1) len = tagEnd - tagStart + 1;
|
|
|
|
else len = text.Length() - tagStart;
|
|
|
|
|
|
|
|
// No tag available
|
2007-01-02 19:09:56 +01:00
|
|
|
int textLen = text.Length();
|
|
|
|
unsigned int posInTag = pos - tagStart;
|
2007-04-04 22:42:44 +02:00
|
|
|
if (tagStart+len > textLen || len <= 0 || tagStart < 0) {
|
2007-01-02 06:00:55 +01:00
|
|
|
CallTipCancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Current tag
|
|
|
|
wxString tag = text.Mid(tagStart,len);
|
|
|
|
|
|
|
|
// Metrics in tag
|
|
|
|
int tagCommas = 0;
|
|
|
|
int tagParenthesis = 0;
|
|
|
|
int parN = 0;
|
|
|
|
int parPos = -1;
|
|
|
|
bool gotName = false;
|
|
|
|
wxString tagName = tag;
|
|
|
|
for (unsigned int i=0;i<tag.Length();i++) {
|
|
|
|
wxChar curChar = tag[i];
|
2007-01-02 19:09:56 +01:00
|
|
|
bool isEnd = false;
|
2007-01-02 06:00:55 +01:00
|
|
|
|
|
|
|
// Commas
|
|
|
|
if (curChar == _T(',')) {
|
|
|
|
tagCommas++;
|
|
|
|
parN++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parenthesis
|
2007-01-02 19:09:56 +01:00
|
|
|
else if (curChar == _T('(')) {
|
|
|
|
tagParenthesis++;
|
|
|
|
parN++;
|
|
|
|
}
|
|
|
|
else if (curChar == _T(')')) {
|
2007-01-02 06:00:55 +01:00
|
|
|
tagParenthesis++;
|
|
|
|
parN++;
|
2007-01-02 19:09:56 +01:00
|
|
|
isEnd = true;
|
2007-01-02 06:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tag name
|
|
|
|
if (parN == 1 && !gotName) {
|
|
|
|
tagName = tag.Left(i);
|
|
|
|
gotName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parameter it's on
|
2007-01-02 19:09:56 +01:00
|
|
|
if (i == posInTag) {
|
|
|
|
parPos = parN;
|
|
|
|
if (curChar == _T(',') || curChar == _T('(') || curChar == _T(')')) {
|
|
|
|
parPos--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isEnd) {
|
|
|
|
parN = 1000;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-02 06:00:55 +01:00
|
|
|
}
|
|
|
|
if (parPos == -1) parPos = parN;
|
|
|
|
|
|
|
|
// Tag name
|
|
|
|
if (tagName.IsEmpty()) {
|
|
|
|
CallTipCancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find matching prototype
|
|
|
|
wxString useProto;
|
2007-01-02 19:09:56 +01:00
|
|
|
wxString cleanProto;
|
|
|
|
wxString protoName;
|
2007-01-24 04:54:32 +01:00
|
|
|
int protoN = 0;
|
2007-01-02 19:09:56 +01:00
|
|
|
bool semiProto = false;
|
2007-01-02 06:00:55 +01:00
|
|
|
for (unsigned int i=0;i<proto.Count();i++) {
|
2007-01-02 19:09:56 +01:00
|
|
|
// Get prototype name
|
|
|
|
int div = proto[i].Find(_T(';'));
|
|
|
|
if (div != wxNOT_FOUND) protoName = proto[i].Left(div);
|
|
|
|
else {
|
|
|
|
div = proto[i].Find(_T('('));
|
|
|
|
protoName = proto[i].Left(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix name
|
|
|
|
semiProto = false;
|
|
|
|
cleanProto = proto[i];
|
|
|
|
if (cleanProto.Freq(_T(';')) > 0) {
|
|
|
|
cleanProto.Replace(_T(";"),_T(""));
|
|
|
|
semiProto = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prototype match
|
|
|
|
wxString temp;
|
|
|
|
if (semiProto) temp = tagName.Left(protoName.Length());
|
|
|
|
else temp = tagName;
|
|
|
|
if (protoName == temp) {
|
|
|
|
// Parameter count match
|
2007-01-02 06:00:55 +01:00
|
|
|
if (proto[i].Freq(_T(',')) >= tagCommas) {
|
2007-01-02 19:09:56 +01:00
|
|
|
// Found
|
2007-01-02 06:00:55 +01:00
|
|
|
useProto = proto[i];
|
2007-01-02 19:15:17 +01:00
|
|
|
protoN = i;
|
2007-01-02 06:00:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No matching prototype
|
|
|
|
if (useProto.IsEmpty()) {
|
|
|
|
CallTipCancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-02 19:09:56 +01:00
|
|
|
// Parameter number for tags without "(),"
|
|
|
|
if (semiProto && parPos == 0 && posInTag >= protoName.Length()) parPos = 1;
|
|
|
|
|
2007-01-02 06:00:55 +01:00
|
|
|
// Highlight start/end
|
|
|
|
int highStart = useProto.Length();
|
|
|
|
int highEnd = -1;
|
|
|
|
parN = 0;
|
2007-01-02 19:09:56 +01:00
|
|
|
int delta = 0;
|
2007-01-02 06:00:55 +01:00
|
|
|
for (unsigned int i=0;i<useProto.Length();i++) {
|
|
|
|
wxChar curChar = useProto[i];
|
2007-01-02 19:09:56 +01:00
|
|
|
if (i == 0 || curChar == _T(',') || curChar == _T(';') || curChar == _T('(') || curChar == _T(')')) {
|
|
|
|
if (curChar == _T(';')) delta++;
|
|
|
|
if (parN == parPos) highStart = i+1-delta;
|
2007-01-02 06:00:55 +01:00
|
|
|
else if (parN == parPos+1) highEnd = i;
|
|
|
|
parN++;
|
|
|
|
}
|
|
|
|
}
|
2007-01-02 19:09:56 +01:00
|
|
|
if (highStart <= 1) highStart = 0;
|
2007-01-02 06:00:55 +01:00
|
|
|
if (highEnd == -1) highEnd = useProto.Length();
|
|
|
|
|
|
|
|
// Calltip is over
|
2007-01-24 04:54:32 +01:00
|
|
|
if (highStart == (signed) useProto.Length()) {
|
2007-01-02 06:00:55 +01:00
|
|
|
CallTipCancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show calltip
|
2007-01-02 19:15:17 +01:00
|
|
|
if (!CallTipActive() || tipProtoN != protoN) CallTipShow(GetUnicodePosition(tagStart),cleanProto);
|
|
|
|
tipProtoN = protoN;
|
2007-01-02 06:00:55 +01:00
|
|
|
CallTipSetHighlight(highStart,highEnd);
|
2006-12-24 23:46:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Spell check
|
|
|
|
void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
|
|
|
|
// See if it has a spellchecker
|
|
|
|
if (!spellchecker) return;
|
|
|
|
|
2007-04-14 17:26:46 +02:00
|
|
|
// Results
|
2006-12-24 23:46:20 +01:00
|
|
|
wxString text = GetText();
|
2007-04-14 17:26:46 +02:00
|
|
|
IntPairVector results;
|
|
|
|
GetWordBoundaries(text,results,start,(len == -1) ? len : start+len);
|
2006-12-24 23:46:20 +01:00
|
|
|
|
|
|
|
// Style
|
2007-04-14 17:26:46 +02:00
|
|
|
int count = results.size();
|
2006-12-24 23:46:20 +01:00
|
|
|
for (int i=0;i<count;i++) {
|
|
|
|
// Get current word
|
2007-04-14 17:26:46 +02:00
|
|
|
int s = results[i].first;
|
|
|
|
int e = results[i].second;
|
|
|
|
wxString curWord = text.Mid(s,e-s);
|
2006-12-24 23:46:20 +01:00
|
|
|
|
|
|
|
// Check if it's valid
|
|
|
|
if (!spellchecker->CheckWord(curWord)) {
|
2006-12-25 04:42:44 +01:00
|
|
|
// Get length before it
|
2007-04-14 17:26:46 +02:00
|
|
|
int utf8len = GetUnicodePosition(s);
|
2006-12-25 04:42:44 +01:00
|
|
|
|
|
|
|
// Set styling
|
|
|
|
StartStyling(utf8len,32);
|
2007-04-14 17:26:46 +02:00
|
|
|
SetUnicodeStyling(s,e-s,32);
|
|
|
|
}
|
|
|
|
}
|
2008-06-01 05:44:41 +02:00
|
|
|
|
|
|
|
// It seems like wxStyledTextCtrl wants you to finish styling at the end of the text.
|
|
|
|
// I don't really understand why, it's not documented anywhere I can find, but this fixes bug #595.
|
|
|
|
StartUnicodeStyling(text.Length(), 0);
|
|
|
|
SetUnicodeStyling(text.Length(), 0, 0);
|
2007-04-14 17:26:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-24 22:52:54 +01:00
|
|
|
///////////////////////////
|
|
|
|
// Set text to a new value
|
|
|
|
void SubsTextEditCtrl::SetTextTo(const wxString _text) {
|
|
|
|
// Setup
|
|
|
|
control->textEditReady = false;
|
|
|
|
Freeze();
|
|
|
|
wxString text = _text;
|
|
|
|
text.Replace(_T("\r\n"),_T("\\N"));
|
2007-09-12 01:22:26 +02:00
|
|
|
//text.Replace(_T("\n\r"),_T("\\N")); // never a valid linebreak
|
2006-12-24 22:52:54 +01:00
|
|
|
text.Replace(_T("\r"),_T("\\N"));
|
|
|
|
text.Replace(_T("\n"),_T("\\N"));
|
|
|
|
|
|
|
|
// Prepare
|
|
|
|
int from=0,to=0;
|
|
|
|
GetSelection(&from,&to);
|
|
|
|
Clear();
|
|
|
|
|
|
|
|
// Set text
|
|
|
|
SetText(text);
|
|
|
|
|
|
|
|
// Style
|
|
|
|
UpdateStyle();
|
|
|
|
|
|
|
|
// Restore selection
|
2006-12-26 02:20:58 +01:00
|
|
|
SetSelectionU(GetReverseUnicodePosition(from),GetReverseUnicodePosition(to));
|
2006-12-24 22:52:54 +01:00
|
|
|
|
|
|
|
// Finish
|
|
|
|
Thaw();
|
|
|
|
control->textEditReady = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Mouse event
|
|
|
|
void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) {
|
|
|
|
// Right click
|
|
|
|
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) {
|
|
|
|
if (control->linen >= 0) {
|
2006-12-25 06:43:00 +01:00
|
|
|
int pos = PositionFromPoint(event.GetPosition());
|
|
|
|
ShowPopupMenu(pos);
|
2006-12-24 22:52:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2007-07-03 03:18:00 +02:00
|
|
|
GetParent()->AddPendingEvent(event);
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
2006-12-25 06:43:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
// Show popup menu
|
|
|
|
void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
|
|
|
|
// Menu
|
|
|
|
wxMenu menu;
|
|
|
|
|
|
|
|
// Position
|
|
|
|
if (activePos == -1) activePos = GetCurrentPos();
|
2006-12-26 02:08:46 +01:00
|
|
|
activePos = GetReverseUnicodePosition(activePos);
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2006-12-25 22:56:56 +01:00
|
|
|
// Get current word under cursor
|
|
|
|
currentWord = GetWordAtPosition(activePos);
|
|
|
|
currentWordPos = activePos;
|
|
|
|
|
2006-12-25 06:43:00 +01:00
|
|
|
// Spell check
|
2007-01-24 04:54:32 +01:00
|
|
|
//int style = GetStyleAt(activePos);
|
2006-12-26 00:10:23 +01:00
|
|
|
if (spellchecker && currentWord.Length()) {
|
|
|
|
// Spelled right?
|
|
|
|
bool rightSpelling = spellchecker->CheckWord(currentWord);
|
|
|
|
|
2006-12-25 06:52:29 +01:00
|
|
|
// Set font
|
|
|
|
wxFont font;
|
|
|
|
font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
|
2006-12-25 22:56:56 +01:00
|
|
|
// Get suggestions
|
|
|
|
sugs.Clear();
|
|
|
|
sugs = spellchecker->GetSuggestions(currentWord);
|
|
|
|
int nSugs = sugs.Count();
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2006-12-26 00:10:23 +01:00
|
|
|
// Spelled wrong
|
|
|
|
if (!rightSpelling) {
|
|
|
|
// No suggestions
|
|
|
|
if (!nSugs) menu.Append(EDIT_MENU_SUGGESTION,_("No correction suggestions"))->Enable(false);
|
2006-12-25 06:52:29 +01:00
|
|
|
|
2006-12-26 00:10:23 +01:00
|
|
|
// Build menu
|
2007-01-03 23:05:43 +01:00
|
|
|
for (int i=0;i<nSugs;i++) {
|
2007-04-04 22:42:44 +02:00
|
|
|
wxMenuItem *itm;
|
|
|
|
itm = menu.Append(EDIT_MENU_SUGGESTIONS+i,sugs[i]);
|
2007-01-11 04:52:17 +01:00
|
|
|
#if wxCHECK_VERSION(2, 8, 0) && defined(__WINDOWS__)
|
2007-01-03 23:05:43 +01:00
|
|
|
itm->SetFont(font);
|
|
|
|
#endif
|
|
|
|
}
|
2006-12-26 00:10:23 +01:00
|
|
|
|
|
|
|
// Append "add word"
|
2006-12-26 02:08:46 +01:00
|
|
|
menu.Append(EDIT_MENU_ADD_TO_DICT,wxString::Format(_("Add \"%s\" to dictionary"),currentWord.c_str()))->Enable(spellchecker->CanAddWord(currentWord));
|
2006-12-26 00:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Spelled right
|
|
|
|
else {
|
|
|
|
// No suggestions
|
|
|
|
if (!nSugs) menu.Append(EDIT_MENU_SUGGESTION,_("No spell checker suggestions"))->Enable(false);
|
|
|
|
|
|
|
|
// Has suggestions
|
|
|
|
else {
|
|
|
|
// Build list
|
|
|
|
wxMenu *subMenu = new wxMenu();
|
|
|
|
for (int i=0;i<nSugs;i++) subMenu->Append(EDIT_MENU_SUGGESTIONS+i,sugs[i]);
|
2007-01-03 22:51:09 +01:00
|
|
|
menu.Append(-1,wxString::Format(_("Spell checker suggestions for \"%s\""),currentWord.c_str()), subMenu);
|
2006-12-26 00:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Separator
|
2007-01-01 05:53:55 +01:00
|
|
|
//if (!thesaurus) menu.AppendSeparator();
|
2006-12-26 00:10:23 +01:00
|
|
|
}
|
2007-01-01 05:53:55 +01:00
|
|
|
|
|
|
|
// Language list
|
|
|
|
wxArrayString langs = spellchecker->GetLanguageList(); // This probably should be cached...
|
2007-01-02 00:47:09 +01:00
|
|
|
|
|
|
|
// Current language
|
|
|
|
wxString curLang = Options.AsText(_T("Spell checker language"));
|
|
|
|
|
|
|
|
// Languages
|
|
|
|
wxMenu *languageMenu = new wxMenu();
|
|
|
|
wxMenuItem *cur;
|
|
|
|
wxString name;
|
|
|
|
const wxLanguageInfo *info;
|
|
|
|
|
|
|
|
// Insert "Disable"
|
|
|
|
cur = languageMenu->AppendCheckItem(EDIT_MENU_DIC_LANGS,_("Disable"));
|
|
|
|
if (curLang.IsEmpty()) cur->Check();
|
|
|
|
|
|
|
|
// Each language found
|
|
|
|
for (unsigned int i=0;i<langs.Count();i++) {
|
|
|
|
info = wxLocale::FindLanguageInfo(langs[i]);
|
|
|
|
if (info) name = info->Description;
|
|
|
|
else name = langs[i];
|
|
|
|
cur = languageMenu->AppendCheckItem(EDIT_MENU_DIC_LANGS+i+1,name);
|
|
|
|
if (langs[i] == curLang) cur->Check();
|
2007-01-01 05:53:55 +01:00
|
|
|
}
|
2007-01-02 00:47:09 +01:00
|
|
|
|
|
|
|
// Append language list
|
2007-01-03 22:51:09 +01:00
|
|
|
menu.Append(-1,_("Spell checker language"), languageMenu);
|
2007-01-01 05:53:55 +01:00
|
|
|
menu.AppendSeparator();
|
2006-12-25 22:56:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Thesaurus
|
2006-12-26 00:10:23 +01:00
|
|
|
if (thesaurus && currentWord.Length()) {
|
2006-12-25 23:21:44 +01:00
|
|
|
// Get results
|
|
|
|
ThesaurusEntryArray result;
|
|
|
|
thesaurus->Lookup(currentWord,result);
|
|
|
|
|
|
|
|
// Compile list
|
2006-12-25 22:56:56 +01:00
|
|
|
thesSugs.Clear();
|
2006-12-25 23:21:44 +01:00
|
|
|
for (unsigned int i=0;i<result.size();i++) {
|
|
|
|
for (unsigned int j=0;j<result[i].words.Count();j++) {
|
|
|
|
thesSugs.Add(result[i].words[j]);
|
|
|
|
}
|
|
|
|
}
|
2006-12-25 22:56:56 +01:00
|
|
|
|
2006-12-25 23:52:21 +01:00
|
|
|
// Has suggestions
|
|
|
|
if (result.size()) {
|
2006-12-26 00:10:23 +01:00
|
|
|
// Set font
|
2006-12-25 23:52:21 +01:00
|
|
|
wxFont font;
|
|
|
|
font.SetStyle(wxFONTSTYLE_ITALIC);
|
|
|
|
|
2006-12-26 00:10:23 +01:00
|
|
|
// Create thesaurus menu
|
|
|
|
wxMenu *thesMenu = new wxMenu();
|
2006-12-25 23:21:44 +01:00
|
|
|
|
2006-12-26 00:10:23 +01:00
|
|
|
// Build menu
|
|
|
|
int curThesEntry = 0;
|
|
|
|
for (unsigned int i=0;i<result.size();i++) {
|
|
|
|
// Single word, insert directly
|
|
|
|
if (result[i].words.Count() == 1) {
|
|
|
|
thesMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry,result[i].name);
|
2006-12-25 23:21:44 +01:00
|
|
|
curThesEntry++;
|
|
|
|
}
|
|
|
|
|
2006-12-26 00:10:23 +01:00
|
|
|
// Multiple, create submenu
|
|
|
|
else {
|
|
|
|
// Insert entries
|
|
|
|
wxMenu *subMenu = new wxMenu();
|
|
|
|
for (unsigned int j=0;j<result[i].words.Count();j++) {
|
|
|
|
subMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry,result[i].words[j]);
|
|
|
|
curThesEntry++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert submenu
|
2007-01-03 22:51:09 +01:00
|
|
|
thesMenu->Append(-1, result[i].name, subMenu);
|
2006-12-26 00:10:23 +01:00
|
|
|
}
|
2006-12-25 23:21:44 +01:00
|
|
|
}
|
2006-12-26 00:10:23 +01:00
|
|
|
|
|
|
|
// Thesaurus menu
|
2007-01-03 22:51:09 +01:00
|
|
|
menu.Append(-1,wxString::Format(_("Thesaurus suggestions for \"%s\""),currentWord.c_str()), thesMenu);
|
2006-12-25 23:21:44 +01:00
|
|
|
}
|
2006-12-25 22:56:56 +01:00
|
|
|
|
|
|
|
// No suggestions
|
2006-12-25 23:21:44 +01:00
|
|
|
if (!result.size()) menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false);
|
2006-12-25 22:56:56 +01:00
|
|
|
|
2007-01-01 06:15:05 +01:00
|
|
|
// Language list
|
|
|
|
wxArrayString langs = thesaurus->GetLanguageList(); // This probably should be cached...
|
2007-01-02 00:47:09 +01:00
|
|
|
|
|
|
|
// Current language
|
|
|
|
wxString curLang = Options.AsText(_T("Thesaurus language"));
|
|
|
|
|
|
|
|
// Languages
|
|
|
|
wxMenu *languageMenu = new wxMenu();
|
|
|
|
wxMenuItem *cur;
|
|
|
|
wxString name;
|
|
|
|
const wxLanguageInfo *info;
|
|
|
|
|
|
|
|
// Insert "Disable"
|
|
|
|
cur = languageMenu->AppendCheckItem(EDIT_MENU_THES_LANGS,_("Disable"));
|
|
|
|
if (curLang.IsEmpty()) cur->Check();
|
|
|
|
|
|
|
|
// Each language found
|
|
|
|
for (unsigned int i=0;i<langs.Count();i++) {
|
|
|
|
info = wxLocale::FindLanguageInfo(langs[i]);
|
|
|
|
if (info) name = info->Description;
|
|
|
|
else name = langs[i];
|
|
|
|
cur = languageMenu->AppendCheckItem(EDIT_MENU_THES_LANGS+i+1,name);
|
|
|
|
if (langs[i] == curLang) cur->Check();
|
2007-01-01 06:15:05 +01:00
|
|
|
}
|
|
|
|
|
2007-01-02 00:47:09 +01:00
|
|
|
// Append language list
|
2007-01-03 22:51:09 +01:00
|
|
|
menu.Append(-1, _("Thesaurus language"), languageMenu);
|
2006-12-25 22:56:56 +01:00
|
|
|
menu.AppendSeparator();
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
|
|
|
|
2006-12-25 06:52:29 +01:00
|
|
|
// Standard actions
|
|
|
|
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"));
|
|
|
|
|
|
|
|
// Split
|
|
|
|
menu.AppendSeparator();
|
|
|
|
menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)"));
|
|
|
|
menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)"));
|
|
|
|
|
2006-12-25 06:43:00 +01:00
|
|
|
// Pop the menu
|
|
|
|
PopupMenu(&menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
// Split line preserving times
|
|
|
|
void SubsTextEditCtrl::OnSplitLinePreserve (wxCommandEvent &event) {
|
|
|
|
int from,to;
|
|
|
|
GetSelection(&from, &to);
|
2006-12-26 02:30:30 +01:00
|
|
|
from = GetReverseUnicodePosition(from);
|
|
|
|
to = GetReverseUnicodePosition(to);
|
2008-01-12 23:40:04 +01:00
|
|
|
// Call SplitLine() with the text currently in the editbox.
|
|
|
|
// This makes sure we split what the user sees, not the committed line.
|
|
|
|
control->grid->SplitLine(control->linen,from,0,GetText());
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////
|
|
|
|
// Split line estimating times
|
|
|
|
void SubsTextEditCtrl::OnSplitLineEstimate (wxCommandEvent &event) {
|
|
|
|
int from,to;
|
|
|
|
GetSelection(&from, &to);
|
2006-12-26 02:30:30 +01:00
|
|
|
from = GetReverseUnicodePosition(from);
|
|
|
|
to = GetReverseUnicodePosition(to);
|
2008-01-12 23:40:04 +01:00
|
|
|
// Call SplitLine() with the text currently in the editbox.
|
|
|
|
// This makes sure we split what the user sees, not the committed line.
|
|
|
|
control->grid->SplitLine(control->linen,from,1,GetText());
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////
|
|
|
|
// Cut
|
|
|
|
void SubsTextEditCtrl::OnCut(wxCommandEvent &event) {
|
|
|
|
Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////
|
|
|
|
// Copy
|
|
|
|
void SubsTextEditCtrl::OnCopy(wxCommandEvent &event) {
|
|
|
|
Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////
|
|
|
|
// Paste
|
|
|
|
void SubsTextEditCtrl::OnPaste(wxCommandEvent &event) {
|
|
|
|
Paste();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////
|
|
|
|
// Undo
|
|
|
|
void SubsTextEditCtrl::OnUndo(wxCommandEvent &event) {
|
|
|
|
Undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////
|
|
|
|
// Select All
|
|
|
|
void SubsTextEditCtrl::OnSelectAll(wxCommandEvent &event) {
|
|
|
|
SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
// Add word to dictionary
|
|
|
|
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &event) {
|
|
|
|
if (spellchecker) spellchecker->AddWord(currentWord);
|
2008-01-14 03:01:50 +01:00
|
|
|
UpdateStyle();
|
2006-12-25 06:43:00 +01:00
|
|
|
SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Use suggestion
|
|
|
|
void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
|
|
|
|
// Get suggestion
|
|
|
|
wxString suggestion = sugs[event.GetId()-EDIT_MENU_SUGGESTIONS];
|
|
|
|
|
|
|
|
// Get boundaries of text being replaced
|
|
|
|
int start,end;
|
|
|
|
GetBoundsOfWordAtPosition(currentWordPos,start,end);
|
|
|
|
|
|
|
|
// Replace
|
|
|
|
wxString text = GetText();
|
|
|
|
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
|
|
|
|
|
|
|
|
// Set selection
|
2006-12-26 02:20:58 +01:00
|
|
|
SetSelectionU(start,start+suggestion.Length());
|
2006-12-25 06:43:00 +01:00
|
|
|
SetFocus();
|
|
|
|
}
|
2006-12-25 23:21:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////
|
|
|
|
// Use thesaurus suggestion
|
|
|
|
void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) {
|
|
|
|
// Get suggestion
|
|
|
|
wxString suggestion = thesSugs[event.GetId()-EDIT_MENU_THESAURUS_SUGS];
|
2006-12-25 23:30:11 +01:00
|
|
|
|
|
|
|
// Stripe suggestion of parenthesis
|
|
|
|
int pos = suggestion.Find(_T("("));
|
|
|
|
if (pos != wxNOT_FOUND) {
|
|
|
|
suggestion = suggestion.Left(pos-1);
|
|
|
|
}
|
2006-12-25 23:21:44 +01:00
|
|
|
|
|
|
|
// Get boundaries of text being replaced
|
|
|
|
int start,end;
|
|
|
|
GetBoundsOfWordAtPosition(currentWordPos,start,end);
|
|
|
|
|
|
|
|
// Replace
|
|
|
|
wxString text = GetText();
|
|
|
|
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
|
|
|
|
|
|
|
|
// Set selection
|
2006-12-26 02:20:58 +01:00
|
|
|
SetSelectionU(start,start+suggestion.Length());
|
2006-12-25 23:21:44 +01:00
|
|
|
SetFocus();
|
|
|
|
}
|
2006-12-26 02:20:58 +01:00
|
|
|
|
|
|
|
|
2007-01-01 05:53:55 +01:00
|
|
|
///////////////////////////
|
|
|
|
// Set dictionary language
|
|
|
|
void SubsTextEditCtrl::OnSetDicLanguage(wxCommandEvent &event) {
|
|
|
|
// Get language list
|
|
|
|
wxArrayString langs = spellchecker->GetLanguageList();
|
|
|
|
|
|
|
|
// Set dictionary
|
2007-01-02 00:47:09 +01:00
|
|
|
int index = event.GetId() - EDIT_MENU_DIC_LANGS - 1;
|
|
|
|
wxString lang;
|
|
|
|
if (index >= 0) lang = langs[index];
|
|
|
|
spellchecker->SetLanguage(lang);
|
|
|
|
Options.SetText(_T("Spell checker language"),lang);
|
2007-01-01 05:53:55 +01:00
|
|
|
Options.Save();
|
|
|
|
|
|
|
|
// Update styling
|
|
|
|
UpdateStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////
|
|
|
|
// Set thesaurus language
|
|
|
|
void SubsTextEditCtrl::OnSetThesLanguage(wxCommandEvent &event) {
|
|
|
|
// Get language list
|
|
|
|
wxArrayString langs = thesaurus->GetLanguageList();
|
|
|
|
|
|
|
|
// Set language
|
2007-01-02 00:47:09 +01:00
|
|
|
int index = event.GetId() - EDIT_MENU_THES_LANGS - 1;
|
|
|
|
wxString lang;
|
|
|
|
if (index >= 0) lang = langs[index];
|
|
|
|
thesaurus->SetLanguage(lang);
|
|
|
|
Options.SetText(_T("Thesaurus language"),lang);
|
2007-01-01 05:53:55 +01:00
|
|
|
Options.Save();
|
|
|
|
|
|
|
|
// Update styling
|
|
|
|
UpdateStyle();
|
|
|
|
}
|