/// <summary> /// Fill auto list with symbols when a '.' appears. /// This is for access to the tables or to members of Vision objects. /// E.g: Render.Draw /// </summary> /// <param name="sciWordBeforeOperator">The word preceding the operator.</param> /// <param offset>The offset/number of characters in front of the operator /// (e.g. is 3 for manual invocation of 'Debug.Dra'). This is always 0 for automatic /// invocation at the position of the operator</param> /// <returns>A list of symbols for the current request (maybe null).</returns> private SymbolCollection HandleDotOperator(string sciWordBeforeOperator, int offset) { Scintilla SciControl = _currentDoc.ScintillaControl; CaretInfo caret = SciControl.Caret; SymbolCollection list = null; // access to a static function or enum constant if (SciControl.Lexing.Keywords[LUA_PATTERN_STATIC_CLASSES_IDX].Contains(sciWordBeforeOperator) || SciControl.Lexing.Keywords[LUA_PATTERN_MODULE_IDX].Contains(sciWordBeforeOperator)) { //drill down the hierarchy: Application.FileSystem.blah int iDepth = 1; string command = sciWordBeforeOperator; while (SciControl.CharAt(caret.Position - 1 - command.Length - iDepth - offset) == '.') { iDepth++; command = SciControl.GetWordFromPosition(caret.Position - 1 - command.Length - iDepth - offset) + "." + command; } list = ScriptManager.GetMembersForSymbol(command); //add static members (for modules) SymbolCollection additionals = ScriptManager.GetMembersFromMetaTable(sciWordBeforeOperator); if (list == null) { list = additionals; } else if (additionals != null) { foreach (SymbolInfo symbol in additionals) { list.Add(symbol); } } //remove unwanted duplicates of the vision module (inside other modules) if (sciWordBeforeOperator != "Vision" && additionals != null && list != null) { SymbolCollection unwanted = ScriptManager.GetMembersFromMetaTable("Vision"); foreach (SymbolInfo symbol in unwanted) { if (list.Contains(symbol)) { list.Remove(symbol); } } } } else if (SciControl.Lexing.Keywords[LUA_PATTERN_SPECIAL_VARS_IDX].Contains(sciWordBeforeOperator)) { list = ScriptManager.GetMembersFromMetaTable(sciWordBeforeOperator); } return(list); }
/// <summary> /// Fill auto list with symbols when a ':' appears. /// This is for "method" calls in Lua like self:DoSomething() /// </summary> /// <param name="sciWordBeforeOperator">The word preceding the operator.</param> /// <param offset>The offset/number of characters in front of the operator /// (e.g. is 6 for manual invocation of 'Debug:PrintL'). This is always 0 for automatic /// invocation at the position of the operator</param> /// <returns>A list of symbols for the current request (maybe null).</returns> private SymbolCollection HandleColonOperator(string sciWordBeforeOperator, int offset) { Scintilla SciControl = _currentDoc.ScintillaControl; CaretInfo caret = SciControl.Caret; SymbolCollection list = null; // access to a variable's members // for now, simply add every member function (note: no member variables) that were defined if (sciWordBeforeOperator == "self") { //note: we are not sure if 'self' is really a base entity list = ScriptManager.GetFunctionsForClass("VisBaseEntity_cl *"); if (list == null) { list = new SymbolCollection(); } //add the callbacks defined in the file (or which could be defined) foreach (String callback in SciControl.Lexing.Keywords[LUA_PATTERN_CALLBACKS_CLASSES_IDX].Split(' ')) { if (SciControl.Text.Contains(callback)) { list.Add(new SymbolInfo(callback, SymbolType.FUNCTION)); } else { list.Add(new SymbolInfo(callback, SymbolType.CONSTANT)); } } } else { //dig down like this: abc.efg.hij:blah() int iDepth = 1; string command = sciWordBeforeOperator; while (SciControl.CharAt(caret.Position - 1 - command.Length - iDepth - offset) == '.') { iDepth++; command = SciControl.GetWordFromPosition(caret.Position - 1 - command.Length - iDepth - offset) + "." + command; } list = ScriptManager.GetFunctionsFromGlobal(command); } if (list == null || list.Count == 0) { //add methods of 'self' list = ScriptManager.GetFunctionsFromMetaTables(); } return(list); }
/// <summary> /// Return the requiered indent for this line or -1 if the line is a multiline comment or string /// </summary> private int GetLineIndent(Line line) { int pos = line.StartPosition - 1; _scintilla.NativeInterface.Colourise(pos, pos + 1); // styles are used to determine indent so we must load them before proceeding int style = _scintilla.Styles.GetStyleAt(pos); if (style == 3 || style == 6 || style == 7 || style == 12 || style == 18 || line.Text.StartsWith("=begin")) { return(-1); } int indent = line.FoldLevel - 1024; string w1 = _scintilla.GetWordFromPosition(line.IndentPosition); string w2 = _scintilla.CharAt(line.IndentPosition).ToString(); if (_unindentWords.Contains(w1) || _unindentWords.Contains(w2)) { indent--; } return(indent); }
/// <summary> /// If Smart Indenting is enabled, this delegate will be added to the CharAdded multicast event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal void CheckSmartIndent(char ch) { char newline = (Scintilla.EndOfLine.Mode == EndOfLineMode.CR) ? '\r' : '\n'; switch (SmartIndentType) { case SmartIndent.None: return; case SmartIndent.Simple: if (ch == newline) { Line curLine = Scintilla.Lines.Current; curLine.Indentation = curLine.Previous.Indentation; Scintilla.CurrentPos = curLine.IndentPosition; } break; case SmartIndent.CPP: case SmartIndent.CPP2: if (ch == newline) { Line curLine = Scintilla.Lines.Current; Line tempLine = curLine; int previousIndent; string tempText; do { tempLine = tempLine.Previous; previousIndent = tempLine.Indentation; tempText = tempLine.Text.Trim(); if (tempText.Length == 0) { previousIndent = -1; } }while ((tempLine.Number > 1) && (previousIndent < 0)); if (tempText.EndsWith("{")) { int bracePos = Scintilla.CurrentPos - 1; while (bracePos > 0 && Scintilla.CharAt(bracePos) != '{') { bracePos--; } if (bracePos > 0 && Scintilla.Styles.GetStyleAt(bracePos) == 10) { previousIndent += TabWidth; } } curLine.Indentation = previousIndent; Scintilla.CurrentPos = curLine.IndentPosition; } else if (ch == '}') { int position = Scintilla.CurrentPos; Line curLine = Scintilla.Lines.Current; int previousIndent = curLine.Previous.Indentation; int match = Scintilla.SafeBraceMatch(position - 1); if (match != -1) { previousIndent = Scintilla.Lines.FromPosition(match).Indentation; curLine.Indentation = previousIndent; } } break; } }
/// <summary> /// Request for the autolist to be shown if possible /// </summary> /// <param name="manualOpen"></param> public override void RequestAutoList(bool manualOpen) { string sciWordBeforeOperator = ""; Scintilla SciControl = _currentDoc.ScintillaControl; CaretInfo caret = SciControl.Caret; //skip auto list if there is no carret if (caret == null) { return; } SymbolCollection list = null; char charBeforeCursor = (char)0; int offset = 0; if (caret.Position >= 1) { //avoid auto completion in comments, strings, etc... byte style = SciControl.Styles.GetStyleAt(caret.Position); for (int i = 0; i < LUA_AVOID_AUTO_COMPLETE_IN_STYLE_AREA.Length; i++) { if (style == LUA_AVOID_AUTO_COMPLETE_IN_STYLE_AREA[i]) { return; } } charBeforeCursor = SciControl.CharAt(caret.Position - 1); } if (charBeforeCursor != 0) { //get the word without the current character sciWordBeforeOperator = SciControl.GetWordFromPosition(caret.Position - 2); if (sciWordBeforeOperator != null) { // go back to last operator on manual open // e.g: Debug:PritLi ->-+ // ^--<--<--<-+ if (manualOpen) { char op = charBeforeCursor; //also stop if the start of the current line has been reached while (op != 0 && op != '.' && op != ':' && op != ' ' && op != '\n' && op != '\r' && op != '\t') { offset++; op = SciControl.CharAt(caret.Position - 2 - offset); } //grab the word before the operator string newWord = SciControl.GetWordFromPosition(caret.Position - 3 - offset); //use it if valid if (newWord != null) { sciWordBeforeOperator = newWord; charBeforeCursor = op; offset++; } } //handle the different operators switch (charBeforeCursor) { case '.': list = HandleDotOperator(sciWordBeforeOperator, offset); break; case ':': list = HandleColonOperator(sciWordBeforeOperator, offset); break; case ' ': list = HandleBlank(sciWordBeforeOperator); break; default: break; } } } // Ctrl-Space pressed and no '.' or ':' -> show global scope symbols, keywords and special variables if ((list == null || list.Count == 0) && manualOpen) { //showList = true; list = ScriptManager.GetGlobalSymbols(); sciWordBeforeOperator = SciControl.GetWordFromPosition(caret.Position - 1); string keywordString = SciControl.Lexing.Keywords[LUA_PATTERN_KEYWORDS_IDX]; string[] keywords = keywordString.Split(' '); // get keywords and special variables from the Lua.syn file foreach (string keyword in keywords) { list.Add(new SymbolInfo(keyword, SymbolType.KEYWORD)); } keywordString = SciControl.Lexing.Keywords[LUA_PATTERN_SPECIAL_VARS_IDX]; keywords = keywordString.Split(' '); foreach (string keyword in keywords) { if (!keyword.StartsWith("_")) { list.Add(new SymbolInfo(keyword, SymbolType.VARIABLE)); } } } if (list != null && list.Count > 0) { SciControl.AutoComplete.List.Clear(); if (!_imagesRegistered) { ImageList imageList = new ImageList(); imageList.Images.Add(Properties.Resources.lua_function); imageList.Images.Add(Properties.Resources.lua_table); imageList.Images.Add(Properties.Resources.lua_userdata); imageList.Images.Add(Properties.Resources.lua_local); imageList.Images.Add(Properties.Resources.lua_blank); SciControl.AutoComplete.RegisterImages(imageList, Color.Black); _imagesRegistered = true; } foreach (SymbolInfo symbol in list) { int icoNum = 4; switch (symbol._type) { case SymbolType.FUNCTION: icoNum = 0; break; case SymbolType.VARIABLE: icoNum = 1; break; case SymbolType.CLASS: icoNum = 2; break; case SymbolType.ENUM: icoNum = 3; break;//currently we do not use enums... default: break; } string name = symbol._name + "?" + icoNum; //avoid duplicates if (!SciControl.AutoComplete.List.Contains(name)) { SciControl.AutoComplete.List.Add(name); } } //insert a dummy if required (otherwise SciControl behaves strange) if (SciControl.AutoComplete.List.Count == 1) { SciControl.AutoComplete.List.Add("?4"); //insert a blank fake item SciControl.AutoComplete.SelectedIndex = 0; } else { SciControl.AutoComplete.List.Sort(); //highlight the best match in list if (offset > 0) { SciControl.AutoComplete.SelectedText = SciControl.GetWordFromPosition(caret.Position - 2); } else { SciControl.AutoComplete.SelectedIndex = 0; } } //show auto complete box SciControl.AutoComplete.AutoHide = false; SciControl.AutoComplete.Show(); } }
/// <summary> /// Pobierz dane /// </summary> public static void getAutocomplete(ref Scintilla _document, ref List <string[]> _Autocomplete) { if (_Autocomplete == null) { return; } int type; _document.SuspendLayout(); int carret; string word; //slowo przed kropka carret = _document.Caret.Position - 1; //odliczam kropke //46 krpopka if (carret > 0 && _document.CharAt(carret) == 46) //jezelie kropka { type = 2; } else { type = 1; } // jezeli kursor w polu szukaj wsrod nazw procedur,widokow,tabel //jezeli kropka : szukaj slowa przed kropka > i gdzie sie pojawia > i slowo za nim _document.AutoComplete.List.Clear(); switch (type) { case 1: string last = "#@$"; foreach (string[] f in _Autocomplete) { if (last != f[0]) { _document.AutoComplete.List.Add(f[0]); } last = f[0]; } break; case 2: if (carret <= 0) { return; } // int startPosition = NativeInterface.WordStartPosition(position, true); //int endPosition = NativeInterface.WordEndPosition(position, true); //return GetRange(startPosition, endPosition).Text; int test; int startword = _document.NativeInterface.WordStartPosition(carret, true); //tutaj mialem wlasna funkcje ale scintilla tez posiada wiec zobaczymy // int startword = crycore.STRING.getWordBeforePosition(carret,_document.Text); word = _document.Text.Substring(startword, carret - startword).ToLower(); //word = _document.GetWordFromPosition(carret - 1); word = crycore.STRING.getRealObjectName(word, ref _document); //szukaj wsyztskich alternatyw czyli tbldoc a zakladajac ze znaleziony ejst //string last = "#@$"; foreach (string[] f in _Autocomplete) { if (string.Compare(word, f[0].ToString(), true) == 0 && f[1] != "") //rowne tabeli { _document.AutoComplete.List.Add(f[1]); } // last = f[0]; } _document.AutoComplete.Show(); break; } _document.ResumeLayout(); }
private string ExportToHTML(Scintilla.ScintillaControl sc) { StringBuilder result = new StringBuilder(); result.Append("<span>"); int tabSize = 4; int styleCurrent = sc.StyleAt(0); result.Append(String.Format("<span class=\"S{0:d}\">", styleCurrent)); bool inStyleSpan = true; int lengthDoc = sc.Length; int column = 0; for (int i = 0; i < lengthDoc; ++i) { char ch = sc.CharAt(i); int style = sc.StyleAt(i); if (style != styleCurrent) { if (inStyleSpan) { result.Append("</span>"); inStyleSpan = false; } if (ch != '\r' && ch != '\n') { // No need of a span for the EOL result.Append(String.Format("<span class=\"S{0:d}\">", style)); inStyleSpan = true; styleCurrent = style; } } if (ch == ' ') { char prevCh = '\0'; if (column == 0) { // At start of line, must put a because regular space will be collapsed prevCh = ' '; } while (i < lengthDoc && sc.CharAt(i) == ' ') { if (prevCh != ' ') { result.Append(' '); } else { result.Append(" "); } prevCh = sc.CharAt(i); i++; column++; } i--; // the last incrementation will be done by the for loop } else if (ch == '\t') { int ts = tabSize - (column % tabSize); for (int itab = 0; itab < ts; itab++) { if (itab % 2 == 1) { result.Append(' '); } else { result.Append(" "); } } column += ts; } else if (ch == '\r' || ch == '\n') { if (inStyleSpan) { result.Append("</span>"); inStyleSpan = false; } if (ch == '\r' && sc.CharAt(i + 1) == '\n') { i++; // CR+LF line ending, skip the "extra" EOL char } column = 0; result.Append("<br />"); styleCurrent = sc.StyleAt(i + 1); result.Append('\n'); if (sc.CharAt(i + 1) != '\r' && sc.CharAt(i + 1) != '\n') { // We know it's the correct next style, // but no (empty) span for an empty line result.Append(String.Format("<span class=\"S{0:d}\">", styleCurrent)); inStyleSpan = true; } } else { switch (ch) { case '<': result.Append("<"); break; case '>': result.Append(">"); break; case '&': result.Append("&"); break; default: result.Append(ch); break; } column++; } } if(inStyleSpan) result.Append("</span>"); result.Append("</span>"); return result.ToString(); }