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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file subs_edit_ctrl.cpp
|
|
|
|
/// @brief Main subtitle editing text control
|
|
|
|
/// @ingroup main_ui
|
|
|
|
///
|
2006-12-24 22:52:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-07-20 05:11:11 +02:00
|
|
|
#include <functional>
|
2012-09-25 01:35:27 +02:00
|
|
|
|
2011-10-28 22:15:10 +02:00
|
|
|
#include <wx/clipbrd.h>
|
2007-01-01 05:53:55 +01:00
|
|
|
#include <wx/intl.h>
|
2012-01-12 23:32:20 +01:00
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/settings.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2012-01-11 20:19:30 +01:00
|
|
|
#include "subs_edit_ctrl.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_dialogue.h"
|
2012-01-11 20:19:30 +01:00
|
|
|
#include "ass_file.h"
|
2012-10-30 20:32:47 +01:00
|
|
|
#include "command/command.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
|
|
|
#include "main.h"
|
2012-01-11 20:19:30 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2010-08-02 08:31:38 +02:00
|
|
|
#include "include/aegisub/spellchecker.h"
|
2010-12-08 04:36:10 +01:00
|
|
|
#include "selection_controller.h"
|
2010-07-20 05:11:11 +02:00
|
|
|
#include "thesaurus.h"
|
2006-12-25 06:43:00 +01:00
|
|
|
#include "utils.h"
|
2006-12-24 22:52:54 +01:00
|
|
|
|
2012-10-30 01:33:16 +01:00
|
|
|
#include <libaegisub/ass/dialogue_parser.h>
|
2012-10-30 16:59:47 +01:00
|
|
|
#include <libaegisub/spellchecker.h>
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
/// Event ids
|
|
|
|
enum {
|
|
|
|
EDIT_MENU_SPLIT_PRESERVE = 1400,
|
|
|
|
EDIT_MENU_SPLIT_ESTIMATE,
|
|
|
|
EDIT_MENU_CUT,
|
|
|
|
EDIT_MENU_COPY,
|
|
|
|
EDIT_MENU_PASTE,
|
|
|
|
EDIT_MENU_SELECT_ALL,
|
|
|
|
EDIT_MENU_ADD_TO_DICT,
|
|
|
|
EDIT_MENU_SUGGESTION,
|
|
|
|
EDIT_MENU_SUGGESTIONS,
|
|
|
|
EDIT_MENU_THESAURUS = 1450,
|
|
|
|
EDIT_MENU_THESAURUS_SUGS,
|
|
|
|
EDIT_MENU_DIC_LANGUAGE = 1600,
|
|
|
|
EDIT_MENU_DIC_LANGS,
|
|
|
|
EDIT_MENU_THES_LANGUAGE = 1700,
|
|
|
|
EDIT_MENU_THES_LANGS
|
|
|
|
};
|
|
|
|
|
2012-01-11 20:19:30 +01:00
|
|
|
SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, agi::Context *context)
|
2011-09-29 06:38:15 +02:00
|
|
|
: ScintillaTextCtrl(parent, -1, "", wxDefaultPosition, wsize, style)
|
2010-08-02 08:31:38 +02:00
|
|
|
, spellchecker(SpellCheckerFactory::GetSpellChecker())
|
2012-01-11 20:19:30 +01:00
|
|
|
, context(context)
|
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
|
|
|
|
2007-01-02 19:09:56 +01:00
|
|
|
// Prototypes for call tips
|
2007-01-02 19:15:17 +01:00
|
|
|
tipProtoN = -1;
|
2011-09-28 21:43:11 +02:00
|
|
|
proto.Add("move(x1,y1,x2,y2)");
|
|
|
|
proto.Add("move(x1,y1,x2,y2,startTime,endTime)");
|
|
|
|
proto.Add("fn;FontName");
|
|
|
|
proto.Add("bord;Width");
|
|
|
|
proto.Add("xbord;Width");
|
|
|
|
proto.Add("ybord;Width");
|
|
|
|
proto.Add("shad;Depth");
|
|
|
|
proto.Add("xshad;Depth");
|
|
|
|
proto.Add("yshad;Depth");
|
|
|
|
proto.Add("be;Strength");
|
|
|
|
proto.Add("blur;Strength");
|
|
|
|
proto.Add("fscx;Scale");
|
|
|
|
proto.Add("fscy;Scale");
|
|
|
|
proto.Add("fsp;Spacing");
|
|
|
|
proto.Add("fs;FontSize");
|
|
|
|
proto.Add("fe;Encoding");
|
|
|
|
proto.Add("frx;Angle");
|
|
|
|
proto.Add("fry;Angle");
|
|
|
|
proto.Add("frz;Angle");
|
|
|
|
proto.Add("fr;Angle");
|
|
|
|
proto.Add("pbo;Offset");
|
|
|
|
proto.Add("clip(command)");
|
|
|
|
proto.Add("clip(scale,command)");
|
|
|
|
proto.Add("clip(x1,y1,x2,y2)");
|
|
|
|
proto.Add("iclip(command)");
|
|
|
|
proto.Add("iclip(scale,command)");
|
|
|
|
proto.Add("iclip(x1,y1,x2,y2)");
|
|
|
|
proto.Add("t(acceleration,tags)");
|
|
|
|
proto.Add("t(startTime,endTime,tags)");
|
|
|
|
proto.Add("t(startTime,endTime,acceleration,tags)");
|
|
|
|
proto.Add("pos(x,y)");
|
|
|
|
proto.Add("p;Exponent");
|
|
|
|
proto.Add("org(x,y)");
|
|
|
|
proto.Add("fade(startAlpha,middleAlpha,endAlpha,startIn,endIn,startOut,endOut)");
|
|
|
|
proto.Add("fad(startTime,endTime)");
|
|
|
|
proto.Add("c;Colour");
|
|
|
|
proto.Add("1c;Colour");
|
|
|
|
proto.Add("2c;Colour");
|
|
|
|
proto.Add("3c;Colour");
|
|
|
|
proto.Add("4c;Colour");
|
|
|
|
proto.Add("alpha;Alpha");
|
|
|
|
proto.Add("1a;Alpha");
|
|
|
|
proto.Add("2a;Alpha");
|
|
|
|
proto.Add("3a;Alpha");
|
|
|
|
proto.Add("4a;Alpha");
|
|
|
|
proto.Add("an;Alignment");
|
|
|
|
proto.Add("a;Alignment");
|
|
|
|
proto.Add("b;Weight");
|
|
|
|
proto.Add("i;1/0");
|
|
|
|
proto.Add("u;1/0");
|
|
|
|
proto.Add("s;1/0");
|
|
|
|
proto.Add("kf;Duration");
|
|
|
|
proto.Add("ko;Duration");
|
|
|
|
proto.Add("k;Duration");
|
|
|
|
proto.Add("K;Duration");
|
|
|
|
proto.Add("q;WrapStyle");
|
|
|
|
proto.Add("r;Style");
|
|
|
|
proto.Add("fax;Factor");
|
|
|
|
proto.Add("fay;Factor");
|
2010-07-20 05:11:11 +02:00
|
|
|
|
2012-09-25 01:35:27 +02:00
|
|
|
using std::bind;
|
2010-07-20 05:11:11 +02:00
|
|
|
|
2012-05-28 16:18:07 +02:00
|
|
|
Bind(wxEVT_CHAR_HOOK, &SubsTextEditCtrl::OnKeyDown, this);
|
|
|
|
|
2012-03-13 00:34:45 +01:00
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::Cut, this), EDIT_MENU_CUT);
|
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::Copy, this), EDIT_MENU_COPY);
|
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::Paste, this), EDIT_MENU_PASTE);
|
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SelectAll, this), EDIT_MENU_SELECT_ALL);
|
|
|
|
|
|
|
|
if (context) {
|
2012-10-30 20:32:47 +01:00
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&cmd::call, "edit/line/split/preserve", context), EDIT_MENU_SPLIT_PRESERVE);
|
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&cmd::call, "edit/line/split/estimate", context), EDIT_MENU_SPLIT_ESTIMATE);
|
2012-03-13 00:34:45 +01:00
|
|
|
}
|
2010-07-20 05:11:11 +02:00
|
|
|
|
|
|
|
Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this);
|
2010-08-26 20:38:37 +02:00
|
|
|
|
2011-08-31 06:17:37 +02:00
|
|
|
Bind(wxEVT_CONTEXT_MENU, &SubsTextEditCtrl::OnContextMenu, this);
|
|
|
|
|
2010-12-07 20:09:15 +01:00
|
|
|
OPT_SUB("Subtitle/Edit Box/Font Face", &SubsTextEditCtrl::SetStyles, this);
|
|
|
|
OPT_SUB("Subtitle/Edit Box/Font Size", &SubsTextEditCtrl::SetStyles, this);
|
2011-09-28 21:44:34 +02:00
|
|
|
Subscribe("Normal");
|
|
|
|
Subscribe("Comment");
|
|
|
|
Subscribe("Drawing");
|
|
|
|
Subscribe("Brackets");
|
|
|
|
Subscribe("Slashes");
|
|
|
|
Subscribe("Tags");
|
|
|
|
Subscribe("Error");
|
|
|
|
Subscribe("Parameters");
|
|
|
|
Subscribe("Line Break");
|
|
|
|
Subscribe("Karaoke Template");
|
|
|
|
Subscribe("Karaoke Variable");
|
|
|
|
|
|
|
|
OPT_SUB("Subtitle/Highlight/Syntax", &SubsTextEditCtrl::UpdateStyle, this);
|
2010-08-26 20:38:37 +02:00
|
|
|
static wxStyledTextEvent evt;
|
2012-09-25 03:15:20 +02:00
|
|
|
OPT_SUB("App/Call Tips", &SubsTextEditCtrl::UpdateCallTip, this, std::ref(evt));
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SubsTextEditCtrl::~SubsTextEditCtrl() {
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:34 +02:00
|
|
|
void SubsTextEditCtrl::Subscribe(std::string const& name) {
|
|
|
|
OPT_SUB("Colour/Subtitle/Syntax/" + name, &SubsTextEditCtrl::SetStyles, this);
|
|
|
|
OPT_SUB("Colour/Subtitle/Syntax/Background/" + name, &SubsTextEditCtrl::SetStyles, this);
|
|
|
|
OPT_SUB("Colour/Subtitle/Syntax/Bold/" + name, &SubsTextEditCtrl::SetStyles, this);
|
|
|
|
}
|
|
|
|
|
2007-04-22 01:16:38 +02:00
|
|
|
BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl)
|
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_ADD_TO_DICT,SubsTextEditCtrl::OnAddToDictionary)
|
|
|
|
EVT_MENU_RANGE(EDIT_MENU_SUGGESTIONS,EDIT_MENU_THESAURUS-1,SubsTextEditCtrl::OnUseSuggestion)
|
2010-07-20 05:11:11 +02:00
|
|
|
EVT_MENU_RANGE(EDIT_MENU_THESAURUS_SUGS,EDIT_MENU_DIC_LANGUAGE-1,SubsTextEditCtrl::OnUseSuggestion)
|
2007-01-02 06:00:55 +01:00
|
|
|
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
|
|
|
void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) {
|
|
|
|
CallTipCancel();
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2012-05-28 16:18:07 +02:00
|
|
|
void SubsTextEditCtrl::OnKeyDown(wxKeyEvent &event) {
|
|
|
|
// Workaround for wxSTC eating tabs.
|
|
|
|
if (event.GetKeyCode() == WXK_TAB) {
|
|
|
|
Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward);
|
|
|
|
}
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2011-12-28 22:27:22 +01:00
|
|
|
void SubsTextEditCtrl::SetSyntaxStyle(int id, wxFont &font, std::string const& name) {
|
2011-09-28 21:44:34 +02:00
|
|
|
StyleSetFont(id, font);
|
|
|
|
StyleSetBold(id, OPT_GET("Colour/Subtitle/Syntax/Bold/" + name)->GetBool());
|
2012-10-26 16:09:14 +02:00
|
|
|
StyleSetForeground(id, to_wx(OPT_GET("Colour/Subtitle/Syntax/" + name)->GetColor()));
|
2011-09-28 21:44:34 +02:00
|
|
|
const agi::OptionValue *background = OPT_GET("Colour/Subtitle/Syntax/Background/" + name);
|
2012-10-26 16:09:14 +02:00
|
|
|
if (background->GetType() == agi::OptionValue::Type_Color)
|
|
|
|
StyleSetBackground(id, to_wx(background->GetColor()));
|
2011-09-28 21:44:34 +02:00
|
|
|
}
|
|
|
|
|
2007-01-03 22:49:13 +01:00
|
|
|
void SubsTextEditCtrl::SetStyles() {
|
|
|
|
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
2009-12-27 20:49:27 +01:00
|
|
|
font.SetEncoding(wxFONTENCODING_DEFAULT); // this solves problems with some fonts not working properly
|
2010-05-21 03:13:36 +02:00
|
|
|
wxString fontname = lagi_wxString(OPT_GET("Subtitle/Edit Box/Font Face")->GetString());
|
2010-07-20 05:11:11 +02:00
|
|
|
if (!fontname.empty()) font.SetFaceName(fontname);
|
2011-09-28 21:44:34 +02:00
|
|
|
font.SetPointSize(OPT_GET("Subtitle/Edit Box/Font Size")->GetInt());
|
|
|
|
|
2012-10-30 01:33:16 +01:00
|
|
|
namespace ss = agi::ass::SyntaxStyle;
|
|
|
|
SetSyntaxStyle(ss::NORMAL, font, "Normal");
|
|
|
|
SetSyntaxStyle(ss::COMMENT, font, "Comment");
|
|
|
|
SetSyntaxStyle(ss::DRAWING, font, "Drawing");
|
|
|
|
SetSyntaxStyle(ss::OVERRIDE, font, "Brackets");
|
|
|
|
SetSyntaxStyle(ss::PUNCTUATION, font, "Slashes");
|
|
|
|
SetSyntaxStyle(ss::TAG, font, "Tags");
|
|
|
|
SetSyntaxStyle(ss::ERROR, font, "Error");
|
|
|
|
SetSyntaxStyle(ss::PARAMETER, font, "Parameters");
|
|
|
|
SetSyntaxStyle(ss::LINE_BREAK, font, "Line Break");
|
|
|
|
SetSyntaxStyle(ss::KARAOKE_TEMPLATE, font, "Karaoke Template");
|
|
|
|
SetSyntaxStyle(ss::KARAOKE_VARIABLE, font, "Karaoke Variable");
|
2007-08-06 16:29:43 +02:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:34 +02:00
|
|
|
void SubsTextEditCtrl::UpdateStyle() {
|
|
|
|
StartStyling(0,255);
|
|
|
|
|
2012-09-25 03:15:20 +02:00
|
|
|
std::string text = GetTextRaw().data();
|
2011-08-27 08:52:35 +02:00
|
|
|
|
2010-08-26 20:38:37 +02:00
|
|
|
if (!OPT_GET("Subtitle/Highlight/Syntax")->GetBool()) {
|
2011-09-28 21:44:34 +02:00
|
|
|
SetStyling(text.size(), 0);
|
2010-08-26 20:38:37 +02:00
|
|
|
return;
|
|
|
|
}
|
2006-12-24 22:52:54 +01:00
|
|
|
|
2011-09-28 21:44:34 +02:00
|
|
|
if (text.empty()) return;
|
|
|
|
|
2012-03-13 00:34:45 +01:00
|
|
|
AssDialogue *diag = context ? context->selectionController->GetActiveLine() : 0;
|
2012-10-30 01:33:16 +01:00
|
|
|
bool template_line = diag && diag->Comment && diag->Effect.Lower().StartsWith("template");
|
2012-02-22 23:36:45 +01:00
|
|
|
|
2012-10-30 01:33:16 +01:00
|
|
|
std::vector<agi::ass::DialogueToken> tokens = agi::ass::TokenizeDialogueBody(text);
|
|
|
|
std::vector<agi::ass::DialogueToken> style_ranges = agi::ass::SyntaxHighlight(text, tokens, template_line, spellchecker.get());
|
|
|
|
for (size_t i = 0; i < style_ranges.size(); ++i) {
|
|
|
|
SetStyling(style_ranges[i].length, style_ranges[i].type);
|
2006-12-24 22:52:54 +01:00
|
|
|
}
|
2007-01-02 06:00:55 +01:00
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Update call tip
|
2010-07-20 05:11:11 +02:00
|
|
|
void SubsTextEditCtrl::UpdateCallTip(wxStyledTextEvent &) {
|
2011-10-10 22:59:04 +02:00
|
|
|
UpdateStyle();
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
if (!OPT_GET("App/Call Tips")->GetBool()) return;
|
2007-01-02 23:10:45 +01:00
|
|
|
|
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
|
|
|
|
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++) {
|
2011-12-26 23:20:49 +01:00
|
|
|
wxChar curChar = i < text.size() ? text[i] : 0;
|
2007-01-02 06:00:55 +01:00
|
|
|
|
|
|
|
// Change depth
|
2010-07-20 05:11:11 +02:00
|
|
|
if (curChar == '{') {
|
2007-01-02 06:00:55 +01:00
|
|
|
depth++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-20 05:11:11 +02:00
|
|
|
if (curChar == '}') {
|
2007-01-02 06:00:55 +01:00
|
|
|
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;
|
|
|
|
}
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2007-01-02 06:00:55 +01:00
|
|
|
// Inside overrides
|
|
|
|
if (depth == 1) {
|
|
|
|
// Inner depth
|
|
|
|
if (tagStart != -1) {
|
2010-07-20 05:11:11 +02:00
|
|
|
if (curChar == '(') inDepth++;
|
|
|
|
else if (curChar == ')') inDepth--;
|
2007-01-02 06:00:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not inside parenthesis
|
|
|
|
if (inDepth == 0) {
|
2011-09-28 21:43:11 +02:00
|
|
|
if (prevChar == '\\') {
|
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
|
2010-07-20 05:11:11 +02:00
|
|
|
if (curChar == ',') {
|
2007-01-02 06:00:55 +01:00
|
|
|
tagCommas++;
|
|
|
|
parN++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parenthesis
|
2010-07-20 05:11:11 +02:00
|
|
|
else if (curChar == '(') {
|
2007-01-02 19:09:56 +01:00
|
|
|
tagParenthesis++;
|
|
|
|
parN++;
|
|
|
|
}
|
2010-07-20 05:11:11 +02:00
|
|
|
else if (curChar == ')') {
|
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) {
|
2012-03-25 06:05:06 +02:00
|
|
|
tagName = tag.Left(i);
|
2007-01-02 06:00:55 +01:00
|
|
|
gotName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parameter it's on
|
2007-01-02 19:09:56 +01:00
|
|
|
if (i == posInTag) {
|
|
|
|
parPos = parN;
|
2010-07-20 05:11:11 +02:00
|
|
|
if (curChar == ',' || curChar == '(' || curChar == ')') {
|
2007-01-02 19:09:56 +01:00
|
|
|
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
|
2010-07-20 05:11:11 +02:00
|
|
|
int div = proto[i].Find(';');
|
2007-01-02 19:09:56 +01:00
|
|
|
if (div != wxNOT_FOUND) protoName = proto[i].Left(div);
|
|
|
|
else {
|
2010-07-20 05:11:11 +02:00
|
|
|
div = proto[i].Find('(');
|
2007-01-02 19:09:56 +01:00
|
|
|
protoName = proto[i].Left(div);
|
|
|
|
}
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2007-01-02 19:09:56 +01:00
|
|
|
// Fix name
|
|
|
|
semiProto = false;
|
|
|
|
cleanProto = proto[i];
|
2010-07-20 05:11:11 +02:00
|
|
|
if (cleanProto.Freq(';') > 0) {
|
2011-09-28 21:43:11 +02:00
|
|
|
cleanProto.Replace(";","");
|
2007-01-02 19:09:56 +01:00
|
|
|
semiProto = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prototype match
|
|
|
|
wxString temp;
|
|
|
|
if (semiProto) temp = tagName.Left(protoName.Length());
|
|
|
|
else temp = tagName;
|
|
|
|
if (protoName == temp) {
|
|
|
|
// Parameter count match
|
2010-07-20 05:11:11 +02:00
|
|
|
if (proto[i].Freq(',') >= 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];
|
2010-07-20 05:11:11 +02:00
|
|
|
if (i == 0 || curChar == ',' || curChar == ';' || curChar == '(' || curChar == ')') {
|
|
|
|
if (curChar == ';') delta++;
|
2007-01-02 19:09:56 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
void SubsTextEditCtrl::SetTextTo(wxString text) {
|
|
|
|
SetEvtHandlerEnabled(false);
|
2006-12-24 22:52:54 +01:00
|
|
|
Freeze();
|
|
|
|
|
|
|
|
int from=0,to=0;
|
|
|
|
GetSelection(&from,&to);
|
|
|
|
|
|
|
|
SetText(text);
|
|
|
|
UpdateStyle();
|
|
|
|
|
|
|
|
// Restore selection
|
2011-10-10 22:59:04 +02:00
|
|
|
SetSelectionU(GetReverseUnicodePosition(from), GetReverseUnicodePosition(to));
|
2006-12-24 22:52:54 +01:00
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
SetEvtHandlerEnabled(true);
|
2006-12-24 22:52:54 +01:00
|
|
|
Thaw();
|
|
|
|
}
|
|
|
|
|
2011-10-10 22:59:04 +02:00
|
|
|
|
|
|
|
void SubsTextEditCtrl::Paste() {
|
2012-10-25 17:13:13 +02:00
|
|
|
wxString data = GetClipboard();
|
2011-10-10 22:59:04 +02:00
|
|
|
|
|
|
|
data.Replace("\r\n", "\\N");
|
|
|
|
data.Replace("\n", "\\N");
|
|
|
|
data.Replace("\r", "\\N");
|
|
|
|
|
|
|
|
int from = GetReverseUnicodePosition(GetSelectionStart());
|
|
|
|
int to = GetReverseUnicodePosition(GetSelectionEnd());
|
|
|
|
|
|
|
|
wxString old = GetText();
|
|
|
|
SetText(old.Left(from) + data + old.Mid(to));
|
|
|
|
|
|
|
|
int sel_start = GetUnicodePosition(from + data.size());
|
|
|
|
SetSelectionStart(sel_start);
|
|
|
|
SetSelectionEnd(sel_start);
|
|
|
|
UpdateStyle();
|
|
|
|
}
|
|
|
|
|
2011-08-31 06:17:37 +02:00
|
|
|
void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) {
|
|
|
|
wxPoint pos = event.GetPosition();
|
|
|
|
int activePos;
|
|
|
|
if (pos == wxDefaultPosition) {
|
|
|
|
activePos = GetCurrentPos();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
activePos = PositionFromPoint(ScreenToClient(pos));
|
|
|
|
}
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
currentWordPos = GetReverseUnicodePosition(activePos);
|
2012-10-30 16:59:47 +01:00
|
|
|
currentWord = from_wx(GetWordAtPosition(currentWordPos));
|
2006-12-25 22:56:56 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
wxMenu menu;
|
|
|
|
if (!currentWord.empty()) {
|
2012-01-11 20:19:30 +01:00
|
|
|
if (spellchecker)
|
2012-01-11 20:18:45 +01:00
|
|
|
AddSpellCheckerEntries(menu);
|
2012-04-17 01:54:47 +02:00
|
|
|
AddThesaurusEntries(menu);
|
2012-01-11 20:18:45 +01:00
|
|
|
}
|
2006-12-26 00:10:23 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
// Standard actions
|
|
|
|
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"));
|
2006-12-25 06:43:00 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
// Split
|
2012-03-13 00:34:45 +01:00
|
|
|
if (context) {
|
|
|
|
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:52:29 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
PopupMenu(&menu);
|
|
|
|
}
|
2006-12-26 00:10:23 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
void SubsTextEditCtrl::AddSpellCheckerEntries(wxMenu &menu) {
|
|
|
|
sugs = spellchecker->GetSuggestions(currentWord);
|
|
|
|
if (spellchecker->CheckWord(currentWord)) {
|
|
|
|
if (sugs.empty())
|
|
|
|
menu.Append(EDIT_MENU_SUGGESTION,_("No spell checker suggestions"))->Enable(false);
|
2006-12-26 00:10:23 +01:00
|
|
|
else {
|
2012-01-11 20:18:45 +01:00
|
|
|
wxMenu *subMenu = new wxMenu;
|
|
|
|
for (size_t i = 0; i < sugs.size(); ++i)
|
2012-10-30 16:59:47 +01:00
|
|
|
subMenu->Append(EDIT_MENU_SUGGESTIONS+i, to_wx(sugs[i]));
|
2007-01-02 00:47:09 +01:00
|
|
|
|
2012-10-30 16:59:47 +01:00
|
|
|
menu.Append(-1, wxString::Format(_("Spell checker suggestions for \"%s\""), to_wx(currentWord)), subMenu);
|
2007-01-01 05:53:55 +01:00
|
|
|
}
|
2006-12-25 22:56:56 +01:00
|
|
|
}
|
2012-01-11 20:18:45 +01:00
|
|
|
else {
|
|
|
|
if (sugs.empty())
|
|
|
|
menu.Append(EDIT_MENU_SUGGESTION,_("No correction suggestions"))->Enable(false);
|
2006-12-25 22:56:56 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
for (size_t i = 0; i < sugs.size(); ++i)
|
2012-10-30 16:59:47 +01:00
|
|
|
menu.Append(EDIT_MENU_SUGGESTIONS+i, to_wx(sugs[i]));
|
2006-12-26 00:10:23 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
// Append "add word"
|
2012-10-30 16:59:47 +01:00
|
|
|
menu.Append(EDIT_MENU_ADD_TO_DICT, wxString::Format(_("Add \"%s\" to dictionary"), to_wx(currentWord)))->Enable(spellchecker->CanAddWord(currentWord));
|
2012-01-11 20:18:45 +01:00
|
|
|
}
|
2010-01-21 01:24:59 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
// Append language list
|
|
|
|
menu.Append(-1,_("Spell checker language"), GetLanguagesMenu(
|
|
|
|
EDIT_MENU_DIC_LANGS,
|
|
|
|
lagi_wxString(OPT_GET("Tool/Spell Checker/Language")->GetString()),
|
2012-10-30 16:59:47 +01:00
|
|
|
to_wx(spellchecker->GetLanguageList())));
|
2012-01-11 20:18:45 +01:00
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
2006-12-25 22:56:56 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
void SubsTextEditCtrl::AddThesaurusEntries(wxMenu &menu) {
|
2012-04-17 01:54:47 +02:00
|
|
|
if (!thesaurus)
|
|
|
|
thesaurus.reset(new Thesaurus);
|
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
std::vector<Thesaurus::Entry> result;
|
|
|
|
thesaurus->Lookup(currentWord, &result);
|
2006-12-25 22:56:56 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
thesSugs.clear();
|
2007-01-02 00:47:09 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
if (result.size()) {
|
|
|
|
wxMenu *thesMenu = new wxMenu;
|
2007-01-02 00:47:09 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
int curThesEntry = 0;
|
|
|
|
for (size_t i = 0; i < result.size(); ++i) {
|
|
|
|
// Single word, insert directly
|
|
|
|
if (result[i].second.size() == 1) {
|
|
|
|
thesMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result[i].first));
|
|
|
|
thesSugs.push_back(result[i].first);
|
|
|
|
++curThesEntry;
|
|
|
|
}
|
|
|
|
// Multiple, create submenu
|
|
|
|
else {
|
|
|
|
wxMenu *subMenu = new wxMenu;
|
|
|
|
for (size_t j = 0; j < result[i].second.size(); ++j) {
|
|
|
|
subMenu->Append(EDIT_MENU_THESAURUS_SUGS+curThesEntry, lagi_wxString(result[i].second[j]));
|
|
|
|
thesSugs.push_back(result[i].second[j]);
|
|
|
|
++curThesEntry;
|
|
|
|
}
|
2007-01-02 00:47:09 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
thesMenu->Append(-1, lagi_wxString(result[i].first), subMenu);
|
|
|
|
}
|
2007-01-01 06:15:05 +01:00
|
|
|
}
|
|
|
|
|
2012-10-30 16:59:47 +01:00
|
|
|
menu.Append(-1, wxString::Format(_("Thesaurus suggestions for \"%s\""), to_wx(currentWord)), thesMenu);
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
2012-01-11 20:18:45 +01:00
|
|
|
else
|
|
|
|
menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false);
|
|
|
|
|
|
|
|
// Append language list
|
|
|
|
menu.Append(-1,_("Thesaurus language"), GetLanguagesMenu(
|
|
|
|
EDIT_MENU_THES_LANGS,
|
|
|
|
lagi_wxString(OPT_GET("Tool/Thesaurus/Language")->GetString()),
|
2012-10-30 16:59:47 +01:00
|
|
|
to_wx(thesaurus->GetLanguageList())));
|
2006-12-25 06:52:29 +01:00
|
|
|
menu.AppendSeparator();
|
2012-01-11 20:18:45 +01:00
|
|
|
}
|
2006-12-25 06:52:29 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
wxMenu *SubsTextEditCtrl::GetLanguagesMenu(int base_id, wxString const& curLang, wxArrayString const& langs) {
|
|
|
|
wxMenu *languageMenu = new wxMenu;
|
2012-04-21 17:13:51 +02:00
|
|
|
languageMenu->AppendRadioItem(base_id, _("Disable"))->Check(curLang.empty());
|
2006-12-25 06:52:29 +01:00
|
|
|
|
2012-01-11 20:18:45 +01:00
|
|
|
for (size_t i = 0; i < langs.size(); ++i) {
|
|
|
|
const wxLanguageInfo *info = wxLocale::FindLanguageInfo(langs[i]);
|
2012-04-21 17:13:51 +02:00
|
|
|
languageMenu->AppendRadioItem(base_id + i + 1, info ? info->Description : langs[i])->Check(langs[i] == curLang);
|
2012-01-11 20:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return languageMenu;
|
2006-12-25 06:43:00 +01:00
|
|
|
}
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) {
|
2012-01-11 20:19:30 +01:00
|
|
|
if (spellchecker) spellchecker->AddWord(currentWord);
|
2008-01-14 03:01:50 +01:00
|
|
|
UpdateStyle();
|
2006-12-25 06:43:00 +01:00
|
|
|
SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
|
2012-10-30 16:59:47 +01:00
|
|
|
std::string suggestion;
|
2010-07-20 05:11:11 +02:00
|
|
|
int sugIdx = event.GetId() - EDIT_MENU_THESAURUS_SUGS;
|
|
|
|
if (sugIdx >= 0) {
|
2012-01-08 02:36:50 +01:00
|
|
|
suggestion = lagi_wxString(thesSugs[sugIdx]);
|
2010-07-20 05:11:11 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
suggestion = sugs[event.GetId() - EDIT_MENU_SUGGESTIONS];
|
|
|
|
}
|
2006-12-25 23:30:11 +01:00
|
|
|
|
2012-10-30 16:59:47 +01:00
|
|
|
// Strip suggestion of parenthesis
|
|
|
|
size_t pos = suggestion.find("(");
|
|
|
|
if (pos != suggestion.npos)
|
|
|
|
suggestion.resize(pos - 1);
|
2010-07-20 05:11:11 +02:00
|
|
|
|
2006-12-25 23:21:44 +01:00
|
|
|
// Get boundaries of text being replaced
|
2012-01-11 20:18:54 +01:00
|
|
|
int start, end;
|
|
|
|
GetBoundsOfWordAtPosition(currentWordPos, start, end);
|
2006-12-25 23:21:44 +01:00
|
|
|
|
|
|
|
wxString text = GetText();
|
2012-10-30 16:59:47 +01:00
|
|
|
SetText(text.Left(std::max(0, start)) + to_wx(suggestion) + text.Mid(end));
|
2006-12-25 23:21:44 +01:00
|
|
|
|
|
|
|
// Set selection
|
2012-10-30 16:59:47 +01:00
|
|
|
SetSelectionU(start, start+suggestion.size());
|
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
|
|
|
void SubsTextEditCtrl::OnSetDicLanguage(wxCommandEvent &event) {
|
2012-10-30 16:59:47 +01:00
|
|
|
std::vector<std::string> langs = spellchecker->GetLanguageList();
|
2007-01-01 05:53:55 +01:00
|
|
|
|
2007-01-02 00:47:09 +01:00
|
|
|
int index = event.GetId() - EDIT_MENU_DIC_LANGS - 1;
|
2012-10-30 16:59:47 +01:00
|
|
|
std::string lang;
|
2012-01-11 20:19:21 +01:00
|
|
|
if (index >= 0)
|
|
|
|
lang = langs[index];
|
|
|
|
|
2012-10-30 16:59:47 +01:00
|
|
|
OPT_SET("Tool/Spell Checker/Language")->SetString(lang);
|
2007-01-01 05:53:55 +01:00
|
|
|
|
|
|
|
UpdateStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubsTextEditCtrl::OnSetThesLanguage(wxCommandEvent &event) {
|
2012-04-17 01:54:47 +02:00
|
|
|
if (!thesaurus) return;
|
|
|
|
|
2012-10-30 16:59:47 +01:00
|
|
|
std::vector<std::string> langs = thesaurus->GetLanguageList();
|
2007-01-01 05:53:55 +01:00
|
|
|
|
2007-01-02 00:47:09 +01:00
|
|
|
int index = event.GetId() - EDIT_MENU_THES_LANGS - 1;
|
2012-10-30 16:59:47 +01:00
|
|
|
std::string lang;
|
2012-01-08 02:36:50 +01:00
|
|
|
if (index >= 0) lang = langs[index];
|
2012-10-30 16:59:47 +01:00
|
|
|
OPT_SET("Tool/Thesaurus/Language")->SetString(lang);
|
2007-01-01 05:53:55 +01:00
|
|
|
|
|
|
|
UpdateStyle();
|
|
|
|
}
|