From 893955d7736da3b1080cb4280fe9760068f9bdf2 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Tue, 2 Jan 2007 18:09:56 +0000 Subject: [PATCH] Mostly working call tip code Originally committed to SVN as r681. --- aegisub/subs_edit_box.cpp | 8 +++ aegisub/subs_edit_box.h | 1 + aegisub/subs_edit_ctrl.cpp | 142 +++++++++++++++++++++++++++++++------ aegisub/subs_edit_ctrl.h | 2 + 4 files changed, 130 insertions(+), 23 deletions(-) diff --git a/aegisub/subs_edit_box.cpp b/aegisub/subs_edit_box.cpp index 15197745b..818cad050 100644 --- a/aegisub/subs_edit_box.cpp +++ b/aegisub/subs_edit_box.cpp @@ -349,6 +349,7 @@ BEGIN_EVENT_TABLE(SubsEditBox, wxPanel) EVT_SCI_STYLENEEDED(EDIT_BOX,SubsEditBox::OnNeedStyle) EVT_SCI_KEY(EDIT_BOX,SubsEditBox::OnKeyDown) EVT_SCI_CHARADDED(EDIT_BOX,SubsEditBox::OnCharAdded) + EVT_SCI_UPDATEUI(EDIT_BOX,SubsEditBox::OnUpdateUI) EVT_CHECKBOX(SYNTAX_BOX, SubsEditBox::OnSyntaxBox) EVT_RADIOBUTTON(RADIO_TIME_BY_FRAME, SubsEditBox::OnFrameRadio) @@ -398,6 +399,13 @@ void SubsEditBox::OnEditText(wxScintillaEvent &event) { } +////////////////////////// +// User Interface updated +void SubsEditBox::OnUpdateUI(wxScintillaEvent &event) { + TextEdit->UpdateCallTip(); +} + + ////////////// // Need style void SubsEditBox::OnNeedStyle(wxScintillaEvent &event) { diff --git a/aegisub/subs_edit_box.h b/aegisub/subs_edit_box.h index 6be24180b..bcd08e51c 100644 --- a/aegisub/subs_edit_box.h +++ b/aegisub/subs_edit_box.h @@ -110,6 +110,7 @@ private: void OnEditText(wxScintillaEvent &event); void OnNeedStyle(wxScintillaEvent &event); void OnCharAdded(wxScintillaEvent &event); + void OnUpdateUI(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 2924af53d..7a67b8e09 100644 --- a/aegisub/subs_edit_ctrl.cpp +++ b/aegisub/subs_edit_ctrl.cpp @@ -123,6 +123,57 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri // Delimiters delim = _T(" .,;:!?żĄ-(){}[]\"/\\"); + + // Prototypes for call tips + 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")); } @@ -319,7 +370,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) { StyleSpellCheck(start,_length); // Call tip - //UpdateCallTip(); + UpdateCallTip(); } @@ -330,15 +381,17 @@ void SubsTextEditCtrl::UpdateCallTip() { const unsigned int pos = GetReverseUnicodePosition(GetCurrentPos()); wxString text = GetText(); - // Find the start of current tag + // Find the start and end of current tag wxChar curChar = 0; + wxChar prevChar = 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; + if (i >= pos && depth == 0) { + tagEnd = i-1; break; } continue; @@ -371,18 +424,21 @@ void SubsTextEditCtrl::UpdateCallTip() { // Not inside parenthesis if (inDepth == 0) { - if (curChar == _T('\\')) { + if (prevChar == _T('\\')) { // Found start if (i <= pos) tagStart = i; // Found end else { - tagEnd = i-1; + tagEnd = i-2; break; } } } } + + // Previous character + prevChar = curChar; } // Calculate length @@ -391,14 +447,15 @@ void SubsTextEditCtrl::UpdateCallTip() { else len = text.Length() - tagStart; // No tag available - if (tagStart == -1 || len == 0) { + int textLen = text.Length(); + unsigned int posInTag = pos - tagStart; + if (tagStart+len > textLen || len <= 0 || tagStart < 0 || posInTag < 0) { CallTipCancel(); return; } // Current tag wxString tag = text.Mid(tagStart,len); - unsigned int posInTag = pos - tagStart; // Metrics in tag int tagCommas = 0; @@ -409,6 +466,7 @@ void SubsTextEditCtrl::UpdateCallTip() { wxString tagName = tag; for (unsigned int i=0;i 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 if (proto[i].Freq(_T(',')) >= tagCommas) { + // Found useProto = proto[i]; break; } @@ -462,19 +553,24 @@ void SubsTextEditCtrl::UpdateCallTip() { return; } + // Parameter number for tags without "()," + if (semiProto && parPos == 0 && posInTag >= protoName.Length()) parPos = 1; + // Highlight start/end int highStart = useProto.Length(); int highEnd = -1; parN = 0; + int delta = 0; for (unsigned int i=0;i