From 6b702b0666a03c47c8d9984dadc3375c3e2f2819 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Tue, 2 Jan 2007 05:00:55 +0000 Subject: [PATCH] Early call tip code Originally committed to SVN as r680. --- aegisub/subs_edit_box.cpp | 15 ++- aegisub/subs_edit_box.h | 1 + aegisub/subs_edit_ctrl.cpp | 225 +++++++++++++++++++++++++++++++++---- aegisub/subs_edit_ctrl.h | 1 + 4 files changed, 218 insertions(+), 24 deletions(-) diff --git a/aegisub/subs_edit_box.cpp b/aegisub/subs_edit_box.cpp index f0202075f..15197745b 100644 --- a/aegisub/subs_edit_box.cpp +++ b/aegisub/subs_edit_box.cpp @@ -345,9 +345,11 @@ void SubsEditBox::SetToLine(int n) { /////////////// // Event table BEGIN_EVENT_TABLE(SubsEditBox, wxPanel) - //EVT_SCI_MODIFIED(EDIT_BOX,SubsEditBox::OnEditText) + EVT_SCI_MODIFIED(EDIT_BOX,SubsEditBox::OnEditText) EVT_SCI_STYLENEEDED(EDIT_BOX,SubsEditBox::OnNeedStyle) EVT_SCI_KEY(EDIT_BOX,SubsEditBox::OnKeyDown) + EVT_SCI_CHARADDED(EDIT_BOX,SubsEditBox::OnCharAdded) + EVT_CHECKBOX(SYNTAX_BOX, SubsEditBox::OnSyntaxBox) EVT_RADIOBUTTON(RADIO_TIME_BY_FRAME, SubsEditBox::OnFrameRadio) EVT_RADIOBUTTON(RADIO_TIME_BY_TIME, SubsEditBox::OnTimeRadio) @@ -389,6 +391,10 @@ void SubsEditBox::OnSize(wxSizeEvent &event) { ///////////////////// // Text edited event void SubsEditBox::OnEditText(wxScintillaEvent &event) { + int modType = event.GetModificationType(); + if (modType == (wxSCI_MOD_INSERTTEXT | wxSCI_PERFORMED_USER) || modType == (wxSCI_MOD_DELETETEXT | wxSCI_PERFORMED_USER)) { + //TextEdit->UpdateCallTip(); + } } @@ -406,6 +412,13 @@ void SubsEditBox::OnNeedStyle(wxScintillaEvent &event) { } +/////////////////// +// Character added +void SubsEditBox::OnCharAdded(wxScintillaEvent &event) { + int character = event.GetKey(); +} + + ///////////////////////////// // Syntax highlight checkbox void SubsEditBox::OnSyntaxBox(wxCommandEvent &event) { diff --git a/aegisub/subs_edit_box.h b/aegisub/subs_edit_box.h index c2dec88f7..6be24180b 100644 --- a/aegisub/subs_edit_box.h +++ b/aegisub/subs_edit_box.h @@ -109,6 +109,7 @@ private: void OnEditText(wxScintillaEvent &event); void OnNeedStyle(wxScintillaEvent &event); + void OnCharAdded(wxScintillaEvent &event); void OnButtonColor1(wxCommandEvent &event); void OnButtonColor2(wxCommandEvent &event); diff --git a/aegisub/subs_edit_ctrl.cpp b/aegisub/subs_edit_ctrl.cpp index 516ea01c0..2924af53d 100644 --- a/aegisub/subs_edit_ctrl.cpp +++ b/aegisub/subs_edit_ctrl.cpp @@ -136,6 +136,26 @@ SubsTextEditCtrl::~SubsTextEditCtrl() { } +/////////////////////// +// Control event table +BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxScintilla) + EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent) + + 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() + + ///////////////// // Style a range void SubsTextEditCtrl::UpdateStyle(int start, int _length) { @@ -269,10 +289,20 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) { // Set drawing mode if it's \p if (text.Mid(curPos,1) == _T("p")) { if (curPos+2 < (signed) text.Length()) { + // Disable wxChar nextNext = text[curPos+2]; - if (nextNext == _T('\\') || nextNext == _T('}')) { - if (nextChar == _T('0')) drawingMode = false; - if (nextChar == _T('1')) drawingMode = true; + 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; + } } } } @@ -287,6 +317,175 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) { // Spell check StyleSpellCheck(start,_length); + + // Call tip + //UpdateCallTip(); +} + + +/////////////////// +// Update call tip +void SubsTextEditCtrl::UpdateCallTip() { + // Get position and text + const unsigned int pos = GetReverseUnicodePosition(GetCurrentPos()); + wxString text = GetText(); + + // Find the start of current tag + wxChar curChar = 0; + int depth = 0; + int inDepth = 0; + int tagStart = -1; + int tagEnd = -1; + for (unsigned int i=0;i pos && depth == 0) { + tagEnd = i=1; + 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) { + if (curChar == _T('\\')) { + // Found start + if (i <= pos) tagStart = i; + + // Found end + else { + tagEnd = i-1; + break; + } + } + } + } + } + + // Calculate length + int len; + if (tagEnd != -1) len = tagEnd - tagStart + 1; + else len = text.Length() - tagStart; + + // No tag available + if (tagStart == -1 || len == 0) { + CallTipCancel(); + return; + } + + // Current tag + wxString tag = text.Mid(tagStart,len); + unsigned int posInTag = pos - tagStart; + + // 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= tagCommas) { + useProto = proto[i]; + break; + } + } + } + + // No matching prototype + if (useProto.IsEmpty()) { + CallTipCancel(); + return; + } + + // Highlight start/end + int highStart = useProto.Length(); + int highEnd = -1; + parN = 0; + for (unsigned int i=0;i