mirror of https://github.com/odrling/Aegisub
Mostly working call tip code
Originally committed to SVN as r681.
This commit is contained in:
parent
6b702b0666
commit
893955d773
|
@ -349,6 +349,7 @@ BEGIN_EVENT_TABLE(SubsEditBox, wxPanel)
|
||||||
EVT_SCI_STYLENEEDED(EDIT_BOX,SubsEditBox::OnNeedStyle)
|
EVT_SCI_STYLENEEDED(EDIT_BOX,SubsEditBox::OnNeedStyle)
|
||||||
EVT_SCI_KEY(EDIT_BOX,SubsEditBox::OnKeyDown)
|
EVT_SCI_KEY(EDIT_BOX,SubsEditBox::OnKeyDown)
|
||||||
EVT_SCI_CHARADDED(EDIT_BOX,SubsEditBox::OnCharAdded)
|
EVT_SCI_CHARADDED(EDIT_BOX,SubsEditBox::OnCharAdded)
|
||||||
|
EVT_SCI_UPDATEUI(EDIT_BOX,SubsEditBox::OnUpdateUI)
|
||||||
|
|
||||||
EVT_CHECKBOX(SYNTAX_BOX, SubsEditBox::OnSyntaxBox)
|
EVT_CHECKBOX(SYNTAX_BOX, SubsEditBox::OnSyntaxBox)
|
||||||
EVT_RADIOBUTTON(RADIO_TIME_BY_FRAME, SubsEditBox::OnFrameRadio)
|
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
|
// Need style
|
||||||
void SubsEditBox::OnNeedStyle(wxScintillaEvent &event) {
|
void SubsEditBox::OnNeedStyle(wxScintillaEvent &event) {
|
||||||
|
|
|
@ -110,6 +110,7 @@ private:
|
||||||
void OnEditText(wxScintillaEvent &event);
|
void OnEditText(wxScintillaEvent &event);
|
||||||
void OnNeedStyle(wxScintillaEvent &event);
|
void OnNeedStyle(wxScintillaEvent &event);
|
||||||
void OnCharAdded(wxScintillaEvent &event);
|
void OnCharAdded(wxScintillaEvent &event);
|
||||||
|
void OnUpdateUI(wxScintillaEvent &event);
|
||||||
|
|
||||||
void OnButtonColor1(wxCommandEvent &event);
|
void OnButtonColor1(wxCommandEvent &event);
|
||||||
void OnButtonColor2(wxCommandEvent &event);
|
void OnButtonColor2(wxCommandEvent &event);
|
||||||
|
|
|
@ -123,6 +123,57 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
|
||||||
|
|
||||||
// Delimiters
|
// Delimiters
|
||||||
delim = _T(" .,;:!?¿¡-(){}[]\"/\\");
|
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);
|
StyleSpellCheck(start,_length);
|
||||||
|
|
||||||
// Call tip
|
// Call tip
|
||||||
//UpdateCallTip();
|
UpdateCallTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -330,15 +381,17 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
const unsigned int pos = GetReverseUnicodePosition(GetCurrentPos());
|
const unsigned int pos = GetReverseUnicodePosition(GetCurrentPos());
|
||||||
wxString text = GetText();
|
wxString text = GetText();
|
||||||
|
|
||||||
// Find the start of current tag
|
// Find the start and end of current tag
|
||||||
wxChar curChar = 0;
|
wxChar curChar = 0;
|
||||||
|
wxChar prevChar = 0;
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
int inDepth = 0;
|
int inDepth = 0;
|
||||||
int tagStart = -1;
|
int tagStart = -1;
|
||||||
int tagEnd = -1;
|
int tagEnd = -1;
|
||||||
for (unsigned int i=0;i<text.Length();i++) {
|
for (unsigned int i=0;i<text.Length()+1;i++) {
|
||||||
// Get character
|
// Get character
|
||||||
curChar = text[i];
|
if (i<text.Length()) curChar = text[i];
|
||||||
|
else curChar = 0;
|
||||||
|
|
||||||
// Change depth
|
// Change depth
|
||||||
if (curChar == _T('{')) {
|
if (curChar == _T('{')) {
|
||||||
|
@ -347,8 +400,8 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
}
|
}
|
||||||
if (curChar == _T('}')) {
|
if (curChar == _T('}')) {
|
||||||
depth--;
|
depth--;
|
||||||
if (i > pos && depth == 0) {
|
if (i >= pos && depth == 0) {
|
||||||
tagEnd = i=1;
|
tagEnd = i-1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -371,18 +424,21 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
|
|
||||||
// Not inside parenthesis
|
// Not inside parenthesis
|
||||||
if (inDepth == 0) {
|
if (inDepth == 0) {
|
||||||
if (curChar == _T('\\')) {
|
if (prevChar == _T('\\')) {
|
||||||
// Found start
|
// Found start
|
||||||
if (i <= pos) tagStart = i;
|
if (i <= pos) tagStart = i;
|
||||||
|
|
||||||
// Found end
|
// Found end
|
||||||
else {
|
else {
|
||||||
tagEnd = i-1;
|
tagEnd = i-2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Previous character
|
||||||
|
prevChar = curChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate length
|
// Calculate length
|
||||||
|
@ -391,14 +447,15 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
else len = text.Length() - tagStart;
|
else len = text.Length() - tagStart;
|
||||||
|
|
||||||
// No tag available
|
// 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();
|
CallTipCancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Current tag
|
// Current tag
|
||||||
wxString tag = text.Mid(tagStart,len);
|
wxString tag = text.Mid(tagStart,len);
|
||||||
unsigned int posInTag = pos - tagStart;
|
|
||||||
|
|
||||||
// Metrics in tag
|
// Metrics in tag
|
||||||
int tagCommas = 0;
|
int tagCommas = 0;
|
||||||
|
@ -409,6 +466,7 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
wxString tagName = tag;
|
wxString tagName = tag;
|
||||||
for (unsigned int i=0;i<tag.Length();i++) {
|
for (unsigned int i=0;i<tag.Length();i++) {
|
||||||
wxChar curChar = tag[i];
|
wxChar curChar = tag[i];
|
||||||
|
bool isEnd = false;
|
||||||
|
|
||||||
// Commas
|
// Commas
|
||||||
if (curChar == _T(',')) {
|
if (curChar == _T(',')) {
|
||||||
|
@ -417,10 +475,15 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parenthesis
|
// Parenthesis
|
||||||
else if (curChar == _T('(') || curChar == _T(')')) {
|
else if (curChar == _T('(')) {
|
||||||
tagParenthesis++;
|
tagParenthesis++;
|
||||||
parN++;
|
parN++;
|
||||||
}
|
}
|
||||||
|
else if (curChar == _T(')')) {
|
||||||
|
tagParenthesis++;
|
||||||
|
parN++;
|
||||||
|
isEnd = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Tag name
|
// Tag name
|
||||||
if (parN == 1 && !gotName) {
|
if (parN == 1 && !gotName) {
|
||||||
|
@ -429,27 +492,55 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameter it's on
|
// Parameter it's on
|
||||||
if (i == posInTag) parPos = parN;
|
if (i == posInTag) {
|
||||||
|
parPos = parN;
|
||||||
|
if (curChar == _T(',') || curChar == _T('(') || curChar == _T(')')) {
|
||||||
|
parPos--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (isEnd) {
|
||||||
|
parN = 1000;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (parPos == -1) parPos = parN;
|
if (parPos == -1) parPos = parN;
|
||||||
|
|
||||||
// Tag name
|
// Tag name
|
||||||
tagName = tagName.Mid(1);
|
|
||||||
if (tagName.IsEmpty()) {
|
if (tagName.IsEmpty()) {
|
||||||
CallTipCancel();
|
CallTipCancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prototypes
|
|
||||||
wxArrayString proto;
|
|
||||||
proto.Add(_T("move(x1,y1,x2,y2)"));
|
|
||||||
proto.Add(_T("move(x1,y1,x2,y2,t1,t2)"));
|
|
||||||
|
|
||||||
// Find matching prototype
|
// Find matching prototype
|
||||||
wxString useProto;
|
wxString useProto;
|
||||||
|
wxString cleanProto;
|
||||||
|
wxString protoName;
|
||||||
|
bool semiProto = false;
|
||||||
for (unsigned int i=0;i<proto.Count();i++) {
|
for (unsigned int i=0;i<proto.Count();i++) {
|
||||||
if (proto[i].Left(tagName.Length()) == tagName) {
|
// 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
|
||||||
if (proto[i].Freq(_T(',')) >= tagCommas) {
|
if (proto[i].Freq(_T(',')) >= tagCommas) {
|
||||||
|
// Found
|
||||||
useProto = proto[i];
|
useProto = proto[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -462,19 +553,24 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parameter number for tags without "(),"
|
||||||
|
if (semiProto && parPos == 0 && posInTag >= protoName.Length()) parPos = 1;
|
||||||
|
|
||||||
// Highlight start/end
|
// Highlight start/end
|
||||||
int highStart = useProto.Length();
|
int highStart = useProto.Length();
|
||||||
int highEnd = -1;
|
int highEnd = -1;
|
||||||
parN = 0;
|
parN = 0;
|
||||||
|
int delta = 0;
|
||||||
for (unsigned int i=0;i<useProto.Length();i++) {
|
for (unsigned int i=0;i<useProto.Length();i++) {
|
||||||
wxChar curChar = useProto[i];
|
wxChar curChar = useProto[i];
|
||||||
if (i == 0 || curChar == _T(',') || curChar == _T('(') || curChar == _T(')')) {
|
if (i == 0 || curChar == _T(',') || curChar == _T(';') || curChar == _T('(') || curChar == _T(')')) {
|
||||||
if (parN == parPos) highStart = i+1;
|
if (curChar == _T(';')) delta++;
|
||||||
|
if (parN == parPos) highStart = i+1-delta;
|
||||||
else if (parN == parPos+1) highEnd = i;
|
else if (parN == parPos+1) highEnd = i;
|
||||||
parN++;
|
parN++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (highStart == 1) highStart = 0;
|
if (highStart <= 1) highStart = 0;
|
||||||
if (highEnd == -1) highEnd = useProto.Length();
|
if (highEnd == -1) highEnd = useProto.Length();
|
||||||
|
|
||||||
// Calltip is over
|
// Calltip is over
|
||||||
|
@ -484,7 +580,7 @@ void SubsTextEditCtrl::UpdateCallTip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show calltip
|
// Show calltip
|
||||||
CallTipShow(pos,useProto);
|
CallTipShow(pos,cleanProto);
|
||||||
CallTipSetHighlight(highStart,highEnd);
|
CallTipSetHighlight(highStart,highEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,8 @@ private:
|
||||||
wxArrayString thesSugs;
|
wxArrayString thesSugs;
|
||||||
int currentWordPos;
|
int currentWordPos;
|
||||||
|
|
||||||
|
wxArrayString proto;
|
||||||
|
|
||||||
void OnMouseEvent(wxMouseEvent &event);
|
void OnMouseEvent(wxMouseEvent &event);
|
||||||
|
|
||||||
wxString GetWordAtPosition(int pos);
|
wxString GetWordAtPosition(int pos);
|
||||||
|
|
Loading…
Reference in New Issue