static private void CompleteTemplate(string Context) { // get indentation ScintillaControl Sci = ASContext.CurSciControl; if (Sci == null) { return; } int position = Sci.CurrentPos; int line = Sci.LineFromPosition(position); int indent = Sci.LineIndentPosition(line) - Sci.PositionFromLine(line); string tab = Sci.GetLine(line).Substring(0, indent); // get EOL int eolMode = Sci.EOLMode; string newline = LineEndDetector.GetNewLineMarker(eolMode); CommentBlockStyle cbs = PluginBase.Settings.CommentBlockStyle; string star = cbs == CommentBlockStyle.Indented ? " *" : "*"; string parInd = cbs == CommentBlockStyle.Indented ? "\t" : " "; if (!PluginBase.MainForm.Settings.UseTabs) { parInd = " "; } // empty box if (Context == null) { Sci.ReplaceSel(newline + tab + star + " " + newline + tab + star + "/"); position += newline.Length + tab.Length + 1 + star.Length; Sci.SetSel(position, position); } // method details else { string box = newline + tab + star + " "; Match mFun = re_splitFunction.Match(Context); if (mFun.Success && !re_property.IsMatch(mFun.Groups["fname"].Value)) { // parameters MemberList list = ParseMethodParameters(mFun.Groups["params"].Value); foreach (MemberModel param in list) { box += newline + tab + star + " @param" + parInd + param.Name; } // return type Match mType = re_variableType.Match(mFun.Groups["type"].Value); if (mType.Success && !mType.Groups["type"].Value.Equals("void", StringComparison.OrdinalIgnoreCase)) { box += newline + tab + star + " @return"; //+mType.Groups["type"].Value; } } box += newline + tab + star + "/"; Sci.ReplaceSel(box); position += newline.Length + tab.Length + 1 + star.Length; Sci.SetSel(position, position); } }
/// <summary> /// Gets the correct coding style line break chars /// </summary> public static String ProcessCodeStyleLineBreaks(String text) { String CSLB = "$(CSLB)"; Int32 nextIndex = text.IndexOfOrdinal(CSLB); if (nextIndex < 0) { return(text); } CodingStyle cs = PluginBase.Settings.CodingStyle; if (cs == CodingStyle.BracesOnLine) { return(text.Replace(CSLB, "")); } Int32 eolMode = (Int32)Globals.Settings.EOLMode; String lineBreak = LineEndDetector.GetNewLineMarker(eolMode); String result = ""; Int32 currentIndex = 0; while (nextIndex >= 0) { result += text.Substring(currentIndex, nextIndex - currentIndex) + lineBreak + GetLineIndentation(text, nextIndex); currentIndex = nextIndex + CSLB.Length; nextIndex = text.IndexOfOrdinal(CSLB, currentIndex); } return(result + text.Substring(currentIndex)); }
/// <summary> /// Inserts the imports to the current document /// </summary> private void InsertImports(List <MemberModel> imports, String searchInText, ScintillaControl sci, Int32 indent) { String eol = LineEndDetector.GetNewLineMarker(sci.EOLMode); Int32 line = imports[0].LineFrom - DeletedImportsCompensation; imports.Sort(new CaseSensitiveImportComparer()); sci.GotoLine(line); Int32 curLine = 0; List <String> uniques = this.GetUniqueImports(imports, searchInText, sci.FileName); // correct position compensation for private imports DeletedImportsCompensation = imports.Count - uniques.Count; String prevPackage = null; for (Int32 i = 0; i < uniques.Count; i++) { string importStringToInsert = "import " + uniques[i] + ";" + eol; if (this.SeparatePackages) { string currentPackage = importStringToInsert.Substring(0, importStringToInsert.LastIndexOf('.')); if (prevPackage != null && prevPackage != currentPackage) { sci.NewLine(); sci.GotoLine(++curLine); sci.SetLineIndentation(sci.LineFromPosition(sci.CurrentPos) - 1, indent); DeletedImportsCompensation--; } prevPackage = currentPackage; } curLine = sci.LineFromPosition(sci.CurrentPos); sci.InsertText(sci.CurrentPos, importStringToInsert); sci.SetLineIndentation(curLine, indent); sci.GotoLine(++curLine); } }
protected virtual void GenerateDocumentation(string context) { // get indentation var sci = ASContext.CurSciControl; if (sci == null) { return; } var position = sci.CurrentPos; var line = sci.LineFromPosition(position); var indent = sci.LineIndentPosition(line) - sci.PositionFromLine(line); var tab = sci.GetLine(line).Substring(0, indent); var newline = LineEndDetector.GetNewLineMarker(sci.EOLMode); var cbs = PluginBase.Settings.CommentBlockStyle; var star = cbs == CommentBlockStyle.Indented ? " *" : "*"; var parInd = cbs == CommentBlockStyle.Indented ? "\t" : " "; if (!PluginBase.MainForm.Settings.UseTabs) { parInd = " "; } // empty box if (context == null) { sci.ReplaceSel(newline + tab + star + " " + newline + tab + star + "/"); position += newline.Length + tab.Length + 1 + star.Length; sci.SetSel(position, position); } // method details else { var box = newline + tab + star + " "; var mFun = re_splitFunction.Match(context); if (mFun.Success && !re_property.IsMatch(mFun.Groups["fname"].Value)) { // parameters var list = ParseMethodParameters(mFun.Groups["params"].Value); foreach (var param in list) { box += newline + tab + star + " @param" + parInd + param.Name; } // return type var mType = re_variableType.Match(mFun.Groups["type"].Value); if (mType.Success && !mType.Groups["type"].Value.Equals("void", StringComparison.OrdinalIgnoreCase)) { box += newline + tab + star + " @return"; //+mType.Groups["type"].Value; } } box += newline + tab + star + "/"; sci.ReplaceSel(box); position += newline.Length + tab.Length + 1 + star.Length; sci.SetSel(position, position); } }
/// <summary> /// Inserts the specified snippet to the document /// </summary> public static Int32 InsertSnippetText(ScintillaControl sci, Int32 currentPosition, String snippet) { sci.BeginUndoAction(); try { Int32 newIndent; String text = snippet; if (sci.SelTextSize > 0) { currentPosition -= sci.MBSafeTextLength(sci.SelText); } Int32 line = sci.LineFromPosition(currentPosition); Int32 indent = sci.GetLineIndentation(line); sci.ReplaceSel(""); Int32 lineMarker = LineEndDetector.DetectNewLineMarker(text, sci.EOLMode); String newline = LineEndDetector.GetNewLineMarker(lineMarker); if (newline != "\n") { text = text.Replace(newline, "\n"); } newline = LineEndDetector.GetNewLineMarker((Int32)PluginBase.MainForm.Settings.EOLMode); text = PluginBase.MainForm.ProcessArgString(text).Replace(newline, "\n"); newline = LineEndDetector.GetNewLineMarker(sci.EOLMode); String[] splitted = text.Trim().Split('\n'); for (Int32 j = 0; j < splitted.Length; j++) { if (j != splitted.Length - 1) { sci.InsertText(sci.CurrentPos, splitted[j] + newline); } else { sci.InsertText(sci.CurrentPos, splitted[j]); } sci.CurrentPos += sci.MBSafeTextLength(splitted[j]) + newline.Length; if (j > 0) { line = sci.LineFromPosition(sci.CurrentPos - newline.Length); newIndent = sci.GetLineIndentation(line) + indent; sci.SetLineIndentation(line, newIndent); } } Int32 length = sci.CurrentPos - currentPosition - newline.Length; Int32 delta = PostProcessSnippets(sci, currentPosition); return(length + delta); } finally { sci.EndUndoAction(); } }
/// <summary> /// Writes the snippet to the specified file /// </summary> private void WriteFile(String name, String content) { StreamWriter file; // Restore previous eol mode content = content.Replace("\r\n", LineEndDetector.GetNewLineMarker(this.eolMode)); String path = Path.Combine(this.SnippetDir, this.currentSyntax); path = Path.Combine(path, name + ".fds"); file = File.CreateText(path); file.Write(content); file.Close(); this.UpdateSnippetList(name); }
public static MemberModel GetTemplateBlockMember(ScintillaNet.ScintillaControl Sci, string blockTmpl) { blockTmpl = blockTmpl.Replace("\n", LineEndDetector.GetNewLineMarker(Sci.EOLMode)); int lineNum = 0; while (lineNum < Sci.LineCount) { string line = Sci.GetLine(lineNum); int funcBlockIndex = line.IndexOf(blockTmpl); if (funcBlockIndex != -1) { MemberModel latest = new MemberModel(); latest.LineFrom = lineNum; latest.LineTo = lineNum; return(latest); } lineNum++; } return(null); }
/// <summary> /// Saves a backup file to the recovery directory /// </summary> public static void SaveTemporaryFile(String file, String text, Encoding encoding) { try { String name = ConvertToFileName(file) + ".bak"; String recoveryDir = FileNameHelper.RecoveryDir; if (!Directory.Exists(recoveryDir)) { Directory.CreateDirectory(recoveryDir); } String path = Path.Combine(recoveryDir, name); // Create full file path Int32 lineEndMode = LineEndDetector.DetectNewLineMarker(text, (Int32)Globals.Settings.EOLMode); String lineEndMarker = LineEndDetector.GetNewLineMarker(lineEndMode); text = file + lineEndMarker + lineEndMarker + text; FileHelper.WriteFile(path, text, encoding); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
/// <summary> /// Shows the activated snippet's contents /// </summary> private void SnippetListViewSelectedIndexChanged(Object sender, EventArgs e) { if (this.snippetListView.SelectedItems.Count == 0) { return; } if (this.saveButton.Enabled) { this.PromptToSaveSnippet(); } String name = this.snippetListView.SelectedItems[0].Text; String path = Path.Combine(this.SnippetDir, this.currentSyntax); path = Path.Combine(path, name + ".fds"); String content = File.ReadAllText(path); // Convert eols to windows and save current eol mode this.eolMode = LineEndDetector.DetectNewLineMarker(content, 0); content = content.Replace(LineEndDetector.GetNewLineMarker(this.eolMode), "\r\n"); this.snippetNameTextBox.Text = name; this.contentsTextBox.Text = content; this.saveButton.Enabled = false; }
/// <summary> /// Handles the incoming character /// </summary> public static void OnChar(ScintillaControl sci, Int32 value) { if (cType == XMLType.Invalid || (sci.ConfigurationLanguage != "xml" && sci.ConfigurationLanguage != "html")) { return; } XMLContextTag ctag; Int32 position = sci.CurrentPos; if (sci.BaseStyleAt(position) == 6 && value != '"') { return; // in XML attribute } Char c = ' '; DataEvent de; switch (value) { case 10: // Shift+Enter to insert <BR/> Int32 line = sci.LineFromPosition(position); if (Control.ModifierKeys == Keys.Shift) { ctag = GetXMLContextTag(sci, position); if (ctag.Tag == null || ctag.Tag.EndsWith('>')) { int start = sci.PositionFromLine(line) - ((sci.EOLMode == 0)? 2:1); sci.SetSel(start, position); sci.ReplaceSel((PluginSettings.UpperCaseHtmlTags) ? "<BR/>" : "<br/>"); sci.SetSel(start + 5, start + 5); return; } } if (PluginSettings.SmartIndenter) { // There is no standard for XML formatting, although most IDEs have similarities. We are mostly going with Visual Studio style with slight differences. // Get last non-empty line. String text = ""; Int32 line2 = line - 1; while (line2 >= 0 && text.Length == 0) { text = sci.GetLine(line2).TrimEnd(); line2--; } if ((text.EndsWith('>') && !text.EndsWithOrdinal("?>") && !text.EndsWithOrdinal("%>")) || text.EndsWithOrdinal("<!--") || text.EndsWithOrdinal("<![CDATA[")) { // Get the previous tag. do { position--; c = (Char)sci.CharAt(position); }while (position > 0 && c != '>'); ctag = GetXMLContextTag(sci, c == '>' ? position + 1 : position); // Line indentation. Int32 indent = sci.GetLineIndentation(line2 + 1); String checkStart = null; bool subIndent = true; if (text.EndsWithOrdinal("<!--")) { checkStart = "-->"; subIndent = false; } else if (text.EndsWithOrdinal("<![CDATA[")) { checkStart = "]]>"; subIndent = false; } else if (ctag.Closed || ctag.Closing) { //Closed tag. Look for the nearest open and not closed tag for proper indentation subIndent = false; if (ctag.Name != null) { var tmpTags = new Stack <XMLContextTag>(); var tmpTag = ctag; if (!tmpTag.Closed) { tmpTags.Push(tmpTag); } while (tmpTag.Position != 0) { tmpTag = GetXMLContextTag(sci, tmpTag.Position); if (tmpTag.Tag != null && tmpTag.Name != null) { if (tmpTag.Closed) { continue; } else if (tmpTag.Closing) { tmpTags.Push(tmpTag); } else { if (tmpTags.Count > 0 && tmpTags.Peek().Name == tmpTag.Name) { tmpTags.Pop(); } else { break; } } } } if (tmpTags.Count > 0) { indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTags.Pop().Position)); } else if (tmpTag.Name != null) { subIndent = true; checkStart = "</" + tmpTag.Name; indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTag.Position)); } else { indent = sci.GetLineIndentation(sci.LineFromPosition(tmpTag.Position)); } } } else if (ctag.Name != null) { // Indentation. Some IDEs use the tag position, VS uses the tag start line indentation. indent = sci.GetLineIndentation(sci.LineFromPosition(ctag.Position)); checkStart = "</" + ctag.Name; if (ctag.Name.ToLower() == "script" || ctag.Name.ToLower() == "style") { subIndent = false; } } try { sci.BeginUndoAction(); if (checkStart != null) { text = sci.GetLine(line).TrimStart(); if (text.StartsWithOrdinal(checkStart)) { sci.SetLineIndentation(line, indent); sci.InsertText(sci.PositionFromLine(line), LineEndDetector.GetNewLineMarker(sci.EOLMode)); } } // Indent the code if (subIndent) { indent += sci.Indent; } sci.SetLineIndentation(line, indent); position = sci.LineIndentPosition(line); sci.SetSel(position, position); } finally { sci.EndUndoAction(); } return; } else if (!text.EndsWith('>')) { ctag = GetXMLContextTag(sci, sci.CurrentPos); if (ctag.Tag == null || ctag.Name == null) { return; } // We're inside a tag. Visual Studio indents with regards to the first line, other IDEs indent using the indentation of the last line with text. int indent; string tag = (ctag.Tag.IndexOf('\r') > 0 || ctag.Tag.IndexOf('\n') > 0) ? ctag.Tag.Substring(0, ctag.Tag.IndexOfAny(new[] { '\r', '\n' })).TrimEnd() : ctag.Tag.TrimEnd(); if (tag.EndsWith('\"')) { int i; int l = tag.Length; for (i = ctag.Name.Length + 1; i < l; i++) { if (!char.IsWhiteSpace(tag[i])) { break; } } indent = sci.Column(ctag.Position) + sci.MBSafePosition(i); } else { indent = sci.GetLineIndentation(sci.LineFromPosition(ctag.Position)) + sci.Indent; } sci.SetLineIndentation(line, indent); position = sci.LineIndentPosition(line); sci.SetSel(position, position); return; } } break; case '<': case '/': if (value == '/') { if ((position < 2) || ((Char)sci.CharAt(position - 2) != '<')) { return; } ctag = new XMLContextTag(); ctag.Position = position - 2; ctag.Closing = true; } else { ctag = GetXMLContextTag(sci, position); if (ctag.Tag != null) { return; } } // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.Element", ctag); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } // New tag if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known) { List <ICompletionListItem> items = new List <ICompletionListItem>(); String previous = null; foreach (string ns in namespaces) { items.Add(new NamespaceItem(ns)); } foreach (HTMLTag tag in knownTags) { if (tag.Name != previous && (tag.NS == "" || tag.NS == defaultNS)) { items.Add(new HtmlTagItem(tag.Name, tag.Tag)); previous = tag.Name; } } items.Sort(new ListItemComparer()); CompletionList.Show(items, true); } return; case ':': ctag = GetXMLContextTag(sci, position); if (ctag.NameSpace == null || position - ctag.Position > ctag.Name.Length + 2) { return; } // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.Namespace", ctag); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } // Show namespace's tags if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known) { List <ICompletionListItem> items = new List <ICompletionListItem>(); String previous = null; foreach (HTMLTag tag in knownTags) { if (tag.Name != previous && tag.NS == ctag.NameSpace) { items.Add(new HtmlTagItem(tag.Name, tag.Name)); previous = tag.Name; } } CompletionList.Show(items, true); } return; case '>': if (PluginSettings.CloseTags) { ctag = GetXMLContextTag(sci, position); if (ctag.Name != null && !ctag.Closed) { // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.CloseElement", ctag); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } if (ctag.Closing) { return; } Boolean isLeaf = false; if (cType == XMLType.Known) { foreach (HTMLTag tag in knownTags) { if (String.Compare(tag.Tag, ctag.Name, true) == 0) { isLeaf = tag.IsLeaf; break; } } } if (isLeaf) { sci.SetSel(position - 1, position); sci.ReplaceSel("/>"); sci.SetSel(position + 1, position + 1); } else { String closeTag = "</" + ctag.Name + ">"; sci.ReplaceSel(closeTag); sci.SetSel(position, position); } } } return; case ' ': c = (char)sci.CharAt(position); if (c > 32 && c != '/' && c != '>' && c != '<') { return; } ctag = GetXMLContextTag(sci, position); if (ctag.Tag != null) { if (InQuotes(ctag.Tag) || ctag.Tag.LastIndexOf('"') < ctag.Tag.LastIndexOf('=')) { return; } // Allow another plugin to handle this Object[] obj = new Object[] { ctag, "" }; de = new DataEvent(EventType.Command, "XMLCompletion.Attribute", obj); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known) { foreach (HTMLTag tag in knownTags) { if (String.Compare(tag.Tag, ctag.Name, true) == 0) { List <ICompletionListItem> items = new List <ICompletionListItem>(); String previous = null; foreach (String attr in tag.Attributes) { if (attr != previous) { items.Add(new HtmlAttributeItem(attr)); previous = attr; } } CompletionList.Show(items, true); return; } } } } /*else * { * if (Control.ModifierKeys == Keys.Shift) * { * sci.SetSel(position - 1, position); * sci.ReplaceSel(" "); * } * }*/ return; case '=': if (PluginSettings.InsertQuotes) { ctag = GetXMLContextTag(sci, position); position = sci.CurrentPos - 2; if (ctag.Tag != null && !String.IsNullOrEmpty(ctag.Name) && Char.IsLetter(ctag.Name[0]) && !InQuotes(ctag.Tag) && (GetWordLeft(sci, ref position).Length > 0)) { position = sci.CurrentPos; c = (Char)sci.CharAt(position); if (c > 32 && c != '>') { sci.ReplaceSel("\"\" "); } else { sci.ReplaceSel("\"\""); } sci.SetSel(position + 1, position + 1); justInsertedQuotesAt = position + 1; // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.AttributeValue", new Object[] { ctag, string.Empty }); EventManager.DispatchEvent(PluginBase.MainForm, de); } } return; case '"': ctag = GetXMLContextTag(sci, position); if (position > 1 && ctag.Tag != null && !ctag.Tag.StartsWithOrdinal("<!")) { // TODO Colorize text change to highlight what's been done if (justInsertedQuotesAt == position - 1) { justInsertedQuotesAt = -1; c = (Char)sci.CharAt(position - 2); if (c == '"' && (Char)sci.CharAt(position - 2) == '"') { sci.SetSel(position - 2, position); sci.ReplaceSel("\""); } // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.AttributeValue", new Object[] { ctag, string.Empty }); EventManager.DispatchEvent(PluginBase.MainForm, de); } else { c = (Char)sci.CharAt(position - 1); if (c == '"' && (Char)sci.CharAt(position) == '"') { sci.SetSel(position - 1, position + 1); sci.ReplaceSel("\""); } } } break; case '?': case '%': if (PluginSettings.CloseTags && position > 1) { ctag = GetXMLContextTag(sci, position - 2); if (ctag.Tag == null || ctag.Tag.EndsWith('>')) { if ((Char)sci.CharAt(position - 2) == '<') { sci.ReplaceSel((Char)value + ">"); sci.SetSel(position, position); } } } break; case '!': if (PluginSettings.CloseTags && position > 1) { ctag = GetXMLContextTag(sci, position - 2); if (ctag.Tag == null || ctag.Tag.EndsWith('>')) { if ((Char)sci.CharAt(position - 2) == '<') { CompletionList.Show(xmlBlocks, true); } } } break; } }
private string ProcessFileTemplate(string args) { Int32 eolMode = (Int32)MainForm.Settings.EOLMode; String lineBreak = LineEndDetector.GetNewLineMarker(eolMode); ClassModel cmodel; List <String> imports = new List <string>(); string extends = ""; string implements = ""; string access = ""; string inheritedMethods = ""; string paramString = ""; string superConstructor = ""; int index; // resolve imports if (lastFileOptions.interfaces != null && lastFileOptions.interfaces.Count > 0) { bool isHaxe2 = PluginBase.CurrentSDK != null && PluginBase.CurrentSDK.Name.ToLower().Contains("haxe 2"); implements = " implements "; string[] _implements; index = 0; foreach (string item in lastFileOptions.interfaces) { if (item.Split('.').Length > 1) { imports.Add(item); } _implements = item.Split('.'); implements += (index > 0 ? (isHaxe2 ? ", implements " : ", ") : "") + _implements[_implements.Length - 1]; if (lastFileOptions.createInheritedMethods) { processOnSwitch = lastFileFromTemplate; // let ASCompletion generate the implementations when file is opened } index++; } } if (lastFileOptions.superClass != "") { String super = lastFileOptions.superClass; if (lastFileOptions.superClass.Split('.').Length > 1) { imports.Add(super); } string[] _extends = super.Split('.'); extends = " extends " + _extends[_extends.Length - 1]; processContext = ASContext.GetLanguageContext(lastFileOptions.Language); if (lastFileOptions.createConstructor && processContext != null && constructorArgs == null) { cmodel = processContext.GetModel(super.LastIndexOf('.') < 0 ? "" : super.Substring(0, super.LastIndexOf('.')), _extends[_extends.Length - 1], ""); if (!cmodel.IsVoid()) { foreach (MemberModel member in cmodel.Members) { if (member.Name == cmodel.Constructor) { paramString = member.ParametersString(); AddImports(imports, member, cmodel); superConstructor = "super("; index = 0; if (member.Parameters != null) { foreach (MemberModel param in member.Parameters) { if (param.Name.StartsWith(".")) { break; } superConstructor += (index > 0 ? ", " : "") + param.Name; index++; } } superConstructor += ");\n" + (lastFileOptions.Language == "as3" ? "\t\t\t" : "\t\t"); break; } } } } processContext = null; } if (constructorArgs != null) { paramString = constructorArgs; foreach (String type in constructorArgTypes) { if (!imports.Contains(type)) { imports.Add(type); } } } if (lastFileOptions.Language == "as3") { access = lastFileOptions.isPublic ? "public " : "internal "; access += lastFileOptions.isDynamic ? "dynamic " : ""; access += lastFileOptions.isFinal ? "final " : ""; } else if (lastFileOptions.Language == "haxe") { access = lastFileOptions.isPublic ? "public " : "private "; access += lastFileOptions.isDynamic ? "dynamic " : ""; } else { access = lastFileOptions.isDynamic ? "dynamic " : ""; } string importsSrc = ""; string prevImport = null; imports.Sort(); foreach (string import in imports) { if (prevImport != import) { prevImport = import; if (import.LastIndexOf('.') == -1) { continue; } if (import.Substring(0, import.LastIndexOf('.')) == lastFileOptions.Package) { continue; } importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + "import " + import + ";" + lineBreak; } } if (importsSrc.Length > 0) { importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + lineBreak; } args = args.Replace("$(Import)", importsSrc); args = args.Replace("$(Extends)", extends); args = args.Replace("$(Implements)", implements); args = args.Replace("$(Access)", access); args = args.Replace("$(InheritedMethods)", inheritedMethods); args = args.Replace("$(ConstructorArguments)", paramString); args = args.Replace("$(Super)", superConstructor); return(args); }
public void DuplicateIncrease() { if (!PluginBase.MainForm.CurrentDocument.IsEditable) { return; } ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; sci.BeginUndoAction(); int pos = sci.CurrentPos; int line = sci.LineFromPosition(pos); int start = sci.PositionFromLine(line); if (IsMultilineSelection(sci)) { sci.SetSel(start, sci.SelectionEnd); } // sci.GetLine est bugge sur la derniere ligne dans la beta 7 string text = ""; if (line < sci.LineCount - 1) { text = sci.GetLine(line); if (sci.EOLMode == 0) { text = text.Substring(0, text.Length - 1); } } else { text = sci.GetCurLine(sci.LineLength(line)); } //TraceManager.Add(":" + text + ":"); int ss = sci.SelectionStart - start; int se = sci.SelectionEnd - start; int dec = 0; //TraceManager.Add("ss:" + ss + ", se:"+se); MatchCollection matches = RegIncNum.Matches(text); String[] arr = RegIncNum.Split(text); string s = ""; int mi; int ml; string mv; bool test1; bool test2; string prv; string nxt; string prvmv; string nxtmv; // for (int i = 0; i < arr.Length; i++) { s += arr[i]; // if (i < arr.Length - 1) { mi = matches[i].Index; ml = matches[i].Length; mv = matches[i].Value; //TraceManager.Add(i + ":" + arr[i]); // la selection inclue mi ? test1 = (mi >= ss && mi < se); // le debut de la selection se trouve-t-il entre mi et mi+ml ? test2 = (ss >= mi && ss < (mi + ml)); // TraceManager.Add("ss:" + ss + ", index:" + mi + ", end:" + (mi + ml) + ", test1:" + test1 + ", test2:"+test2); if (test1 || test2) { s += mv; } else { prv = arr[i]; nxt = arr[i + 1]; if (i == 0) { prvmv = ""; } else { prvmv = matches[i - 1].Value; } if (i == matches.Count - 1) { nxtmv = ""; } else { nxtmv = matches[i + 1].Value; } if (prv.EndsWith(".")) { s += mv; } else if (mv == "9" && prv.EndsWith("scale") && nxt.StartsWith("Grid")) { s += mv; // scale9Grid } else if (mv == "2" && prv.EndsWith("LN")) { s += mv; // LN2 } else if (mv == "10" && prv.EndsWith("LN")) { s += mv; // LN10 } else if (mv == "2" && prv.EndsWith("LOG") && nxt.StartsWith("E")) { s += mv; // LOG2E } else if (mv == "10" && prv.EndsWith("LOG") && nxt.StartsWith("E")) { s += mv; // LOG10E } else if (mv == "2" && prv.EndsWith("SQRT")) { s += mv; // SQRT2 } else if (mv == "1" && prv.EndsWith("SQRT") && nxt == "_" && nxtmv == "2") { s += mv; // SQRT1_2 } else if (mv == "2" && prv == "_" && prvmv == "1") { s += mv; // SQRT1_2 } else if (mv == "3" && prv.EndsWith("id")) { s += mv; // id3 } else if (mv == "3" && prv.EndsWith("ID") && nxt.StartsWith("Info")) { s += mv; // ID3Info } else if (mv == "1" && prv.EndsWith("AVM") && nxt.StartsWith("Movie")) { s += mv; // AVM1Movie } else if (mv == "3" && prv.EndsWith("AS")) { s += mv; // AVM1Movie } else if (prv.EndsWith("FLASH")) { s += mv; // FLASH1 ... FLASH9 } else if (mv == "2" && prv.EndsWith("ACTIONSCRIPT")) { s += mv; // ACTIONSCRIPT2 } else if (mv == "3" && prv.EndsWith("ACTIONSCRIPT")) { s += mv; // ACTIONSCRIPT3 } else if (mv == "32" && prv.EndsWith("getPixel")) { s += mv; // getPixel32 } else if (mv == "32" && prv.EndsWith("setPixel")) { s += mv; // setPixel32 } else { string inc = (Convert.ToInt32(mv) + 1).ToString(); if (inc.Length > mv.Length && mi < ss) { dec++; } s += inc; } } } } sci.InsertText(sci.LineEndPosition(line), LineEndDetector.GetNewLineMarker(sci.EOLMode) + s); int sel = sci.PositionFromLine(line + 1) + dec; sci.SetSel(sel + ss, sel + se); sci.EndUndoAction(); }
/// <summary> /// Handles the incoming character /// </summary> public static void OnChar(ScintillaControl sci, Int32 value) { if (cType == XMLType.Invalid || (sci.ConfigurationLanguage != "xml" && sci.ConfigurationLanguage != "html")) { return; } XMLContextTag ctag; Int32 position = sci.CurrentPos; if (sci.BaseStyleAt(position) == 6 && value != '"') { return; // in XML attribute } Char c = ' '; DataEvent de; switch (value) { case 10: // Shift+Enter to insert <BR/> Int32 line = sci.LineFromPosition(position); if (Control.ModifierKeys == Keys.Shift) { ctag = GetXMLContextTag(sci, position); if (ctag.Tag == null || ctag.Tag.EndsWith(">")) { int start = sci.PositionFromLine(line) - ((sci.EOLMode == 0)? 2:1); sci.SetSel(start, position); sci.ReplaceSel((PluginSettings.UpperCaseHtmlTags) ? "<BR/>" : "<br/>"); sci.SetSel(start + 5, start + 5); return; } } if (PluginSettings.SmartIndenter) { // Get last non-empty line String text = ""; Int32 line2 = line - 1; while (line2 >= 0 && text.Length == 0) { text = sci.GetLine(line2).TrimEnd(); line2--; } if ((text.EndsWith(">") && !text.EndsWith("?>") && !text.EndsWith("%>") && !closingTag.IsMatch(text)) || text.EndsWith("<!--") || text.EndsWith("<![CDATA[")) { // Get the previous tag do { position--; c = (Char)sci.CharAt(position); }while (position > 0 && c != '>'); ctag = GetXMLContextTag(sci, c == '>' ? position + 1 : position); if ((Char)sci.CharAt(position - 1) == '/') { return; } // Insert blank line if we pressed Enter between a tag & it's closing tag Int32 indent = sci.GetLineIndentation(line2 + 1); String checkStart = null; bool subIndent = true; if (text.EndsWith("<!--")) { checkStart = "-->"; subIndent = false; } else if (text.EndsWith("<![CDATA[")) { checkStart = "]]>"; subIndent = false; } else if (ctag.Closed) { subIndent = false; } else if (ctag.Name != null) { checkStart = "</" + ctag.Name; if (ctag.Name.ToLower() == "script" || ctag.Name.ToLower() == "style") { subIndent = false; } if (ctag.Tag.IndexOf('\r') > 0 || ctag.Tag.IndexOf('\n') > 0) { subIndent = false; } } if (checkStart != null) { text = sci.GetLine(line).TrimStart(); if (text.StartsWith(checkStart)) { sci.SetLineIndentation(line, indent); sci.InsertText(sci.PositionFromLine(line), LineEndDetector.GetNewLineMarker(sci.EOLMode)); } } // Indent the code if (subIndent) { indent += sci.Indent; } sci.SetLineIndentation(line, indent); position = sci.LineIndentPosition(line); sci.SetSel(position, position); return; } } break; case '<': case '/': if (value == '/') { if ((position < 2) || ((Char)sci.CharAt(position - 2) != '<')) { return; } ctag = new XMLContextTag(); ctag.Closing = true; } else { ctag = GetXMLContextTag(sci, position); if (ctag.Tag != null) { return; } } // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.Element", ctag); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } // New tag if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known) { List <ICompletionListItem> items = new List <ICompletionListItem>(); String previous = null; foreach (string ns in namespaces) { items.Add(new NamespaceItem(ns)); } foreach (HTMLTag tag in knownTags) { if (tag.Name != previous && (tag.NS == "" || tag.NS == defaultNS)) { items.Add(new HtmlTagItem(tag.Name, tag.Tag)); previous = tag.Name; } } items.Sort(new ListItemComparer()); CompletionList.Show(items, true); } return; case ':': ctag = GetXMLContextTag(sci, position); if (ctag.NameSpace == null || position - ctag.Position > ctag.Name.Length + 2) { return; } // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.Namespace", ctag); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } // Show namespace's tags if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known) { List <ICompletionListItem> items = new List <ICompletionListItem>(); String previous = null; foreach (HTMLTag tag in knownTags) { if (tag.Name != previous && tag.NS == ctag.NameSpace) { items.Add(new HtmlTagItem(tag.Name, tag.Name)); previous = tag.Name; } } CompletionList.Show(items, true); } return; case '>': if (PluginSettings.CloseTags) { ctag = GetXMLContextTag(sci, position); if (ctag.Name != null && !ctag.Closed) { // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.CloseElement", ctag); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } if (ctag.Closing) { return; } Boolean isLeaf = false; if (cType == XMLType.Known) { foreach (HTMLTag tag in knownTags) { if (String.Compare(tag.Tag, ctag.Name, true) == 0) { isLeaf = tag.IsLeaf; break; } } } if (isLeaf) { sci.SetSel(position - 1, position); sci.ReplaceSel("/>"); sci.SetSel(position + 1, position + 1); } else { String closeTag = "</" + ctag.Name + ">"; sci.ReplaceSel(closeTag); sci.SetSel(position, position); } } } return; case ' ': c = (char)sci.CharAt(position); if (c > 32 && c != '/' && c != '>' && c != '<') { return; } ctag = GetXMLContextTag(sci, position); if (ctag.Tag != null) { if (InQuotes(ctag.Tag) || ctag.Tag.LastIndexOf('"') < ctag.Tag.LastIndexOf('=')) { return; } // Allow another plugin to handle this Object[] obj = new Object[] { ctag, "" }; de = new DataEvent(EventType.Command, "XMLCompletion.Attribute", obj); EventManager.DispatchEvent(PluginBase.MainForm, de); if (de.Handled) { return; } if (PluginSettings.EnableXMLCompletion && cType == XMLType.Known) { foreach (HTMLTag tag in knownTags) { if (String.Compare(tag.Tag, ctag.Name, true) == 0) { List <ICompletionListItem> items = new List <ICompletionListItem>(); String previous = null; foreach (String attr in tag.Attributes) { if (attr != previous) { items.Add(new HtmlAttributeItem(attr)); previous = attr; } } CompletionList.Show(items, true); return; } } } } /*else * { * if (Control.ModifierKeys == Keys.Shift) * { * sci.SetSel(position - 1, position); * sci.ReplaceSel(" "); * } * }*/ return; case '=': if (PluginSettings.InsertQuotes) { ctag = GetXMLContextTag(sci, position); position = sci.CurrentPos - 2; if (ctag.Tag != null && !String.IsNullOrEmpty(ctag.Name) && Char.IsLetter(ctag.Name[0]) && !InQuotes(ctag.Tag) && (GetWordLeft(sci, ref position).Length > 0)) { position = sci.CurrentPos; c = (Char)sci.CharAt(position); if (c > 32 && c != '>') { sci.ReplaceSel("\"\" "); } else { sci.ReplaceSel("\"\""); } sci.SetSel(position + 1, position + 1); justInsertedQuotesAt = position + 1; // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.AttributeValue", new Object[] { ctag, string.Empty }); EventManager.DispatchEvent(PluginBase.MainForm, de); } } return; case '"': ctag = GetXMLContextTag(sci, position); if (position > 1 && ctag.Tag != null && !ctag.Tag.StartsWith("<!")) { // TODO Colorize text change to highlight what's been done if (justInsertedQuotesAt == position - 1) { justInsertedQuotesAt = -1; c = (Char)sci.CharAt(position - 2); if (c == '"' && (Char)sci.CharAt(position - 2) == '"') { sci.SetSel(position - 2, position); sci.ReplaceSel("\""); } // Allow another plugin to handle this de = new DataEvent(EventType.Command, "XMLCompletion.AttributeValue", new Object[] { ctag, string.Empty }); EventManager.DispatchEvent(PluginBase.MainForm, de); } else { c = (Char)sci.CharAt(position - 1); if (c == '"' && (Char)sci.CharAt(position) == '"') { sci.SetSel(position - 1, position + 1); sci.ReplaceSel("\""); } } } break; case '?': case '%': if (PluginSettings.CloseTags && position > 1) { ctag = GetXMLContextTag(sci, position - 2); if (ctag.Tag == null || ctag.Tag.EndsWith(">")) { if ((Char)sci.CharAt(position - 2) == '<') { sci.ReplaceSel((Char)value + ">"); sci.SetSel(position, position); } } } break; case '!': if (PluginSettings.CloseTags && position > 1) { ctag = GetXMLContextTag(sci, position - 2); if (ctag.Tag == null || ctag.Tag.EndsWith(">")) { if ((Char)sci.CharAt(position - 2) == '<') { CompletionList.Show(xmlBlocks, true); } } } break; } }
public PositionInfos(ScintillaControl sci, Int32 position, String argString) { // Variables String[] vars = argString.Split('¤'); this.ArgCurWord = vars[0]; this.ArgPackageName = vars[1]; this.ArgClassName = vars[2]; this.ArgClassType = vars[3]; this.ArgMemberName = vars[4]; this.ArgMemberType = vars[5]; // Selection Int32 ss = sci.SelectionStart; Int32 se = sci.SelectionEnd; if (se != ss) { this.SelectionStart = ss; this.SelectionEnd = se; this.HasSelection = true; if (sci.LineFromPosition(ss) != sci.LineFromPosition(se)) { this.SelectionIsMultiline = true; } else { SelectedText = sci.SelText; } } // Current this.CurrentPosition = position; this.CurrentCharCode = sci.CharAt(position); this.CurrentIsWhiteChar = (HelpTools.IsWhiteChar(this.CurrentCharCode)); this.CurrentIsDotChar = (this.CurrentCharCode == 46); this.CurrentIsActionScriptChar = HelpTools.IsActionScriptChar(this.CurrentCharCode); this.CurrentIsWordChar = HelpTools.IsWordChar((byte)this.CurrentCharCode); Int32 s = sci.StyleAt(position); this.CurrentIsInsideComment = (s == 1 || s == 2 || s == 3 || s == 17); // Next Int32 np = sci.PositionAfter(position); if (np != position) { this.NextPosition = np; } else { this.CaretIsAtEndOfDocument = true; } // Word this.CodePage = sci.CodePage; // (UTF-8|Big Endian|Little Endian : 65001) (8 Bits|UTF-7 : 0) if (this.CurrentIsInsideComment == false && this.SelectionIsMultiline == false) { Int32 wsp = sci.WordStartPosition(position, true); // Attention (WordEndPosition n'est pas estimé comme par defaut) Int32 wep = sci.PositionBefore(sci.WordEndPosition(position, true)); if (this.CodePage != 65001) { wsp = HelpTools.GetWordStartPositionByWordChar(sci, position); // Attention (WordEndPosition n'est pas estimé comme par defaut) wep = sci.PositionBefore(HelpTools.GetWordEndPositionByWordChar(sci, position)); } this.WordStartPosition = wsp; this.WordEndPosition = wep; if (this.CodePage == 65001) { this.WordFromPosition = this.ArgCurWord; } else { this.WordFromPosition = HelpTools.GetText(sci, wsp, sci.PositionAfter(wep)); } if (position > wep) { this.CaretIsAfterLastLetter = true; } } // Previous if (this.CurrentPosition > 0) { this.PreviousPosition = sci.PositionBefore(position); this.PreviousCharCode = sci.CharAt(this.PreviousPosition); this.PreviousIsWhiteChar = HelpTools.IsWhiteChar(this.PreviousCharCode); this.PreviousIsDotChar = (this.PreviousCharCode == 46); this.PreviousIsActionScriptChar = HelpTools.IsActionScriptChar(this.PreviousCharCode); } // Line this.CurrentLineIdx = sci.LineFromPosition(position); if (this.CurrentPosition > 0) { this.PreviousLineIdx = sci.LineFromPosition(this.PreviousPosition); } this.LineIdxMax = sci.LineCount - 1; this.LineStartPosition = HelpTools.LineStartPosition(sci, this.CurrentLineIdx); this.LineEndPosition = sci.LineEndPosition(this.CurrentLineIdx); this.NewLineMarker = LineEndDetector.GetNewLineMarker(sci.EOLMode); // Previous / Next if (this.WordStartPosition != -1) { this.PreviousNonWhiteCharPosition = HelpTools.PreviousNonWhiteCharPosition(sci, this.WordStartPosition); this.PreviousWordIsFunction = (sci.GetWordFromPosition(this.PreviousNonWhiteCharPosition) == "function"); this.NextNonWhiteCharPosition = HelpTools.NextNonWhiteCharPosition(sci, this.WordEndPosition); } // Function if (this.PreviousWordIsFunction) { Int32 nobp = HelpTools.NextCharPosition(sci, position, "("); Int32 ncbp = HelpTools.NextCharPosition(sci, position, ")"); Int32 nlbp = HelpTools.NextCharPosition(sci, position, "{"); if ((nobp < ncbp) && (ncbp < nlbp)) { this.NextOpenBracketPosition = nobp; this.NextCloseBracketPosition = ncbp; this.NextLeftBracePosition = nlbp; } // Arguments String args = HelpTools.GetText(sci, sci.PositionAfter(this.NextOpenBracketPosition), this.NextCloseBracketPosition).Trim(); if (args.Length > 0) { this.HasArguments = true; this.Arguments = HelpTools.ExtractArguments(sci, args); } } }
public static void ApplySciSettings(ScintillaControl sci, Boolean hardUpdate) { try { ISettings settings = PluginBase.Settings; sci.CaretPeriod = settings.CaretPeriod; sci.CaretWidth = settings.CaretWidth; sci.EOLMode = LineEndDetector.DetectNewLineMarker(sci.Text, (Int32)settings.EOLMode); sci.IsBraceMatching = settings.BraceMatchingEnabled; sci.UseHighlightGuides = !settings.HighlightGuide; sci.Indent = settings.IndentSize; sci.SmartIndentType = settings.SmartIndentType; sci.IsBackSpaceUnIndents = settings.BackSpaceUnIndents; sci.IsCaretLineVisible = settings.CaretLineVisible; sci.IsIndentationGuides = settings.ViewIndentationGuides; sci.IndentView = settings.IndentView; sci.IsTabIndents = settings.TabIndents; sci.IsUseTabs = settings.UseTabs; sci.IsViewEOL = settings.ViewEOL; sci.ScrollWidth = Math.Max(settings.ScrollWidth, 1); sci.ScrollWidthTracking = settings.ScrollWidth == 0 || settings.ScrollWidth == 3000; sci.TabWidth = settings.TabWidth; sci.ViewWS = Convert.ToInt32(settings.ViewWhitespace); sci.WrapMode = Convert.ToInt32(settings.WrapText); sci.SetProperty("fold", Convert.ToInt32(settings.UseFolding).ToString()); sci.SetProperty("fold.comment", Convert.ToInt32(settings.FoldComment).ToString()); sci.SetProperty("fold.compact", Convert.ToInt32(settings.FoldCompact).ToString()); sci.SetProperty("fold.preprocessor", Convert.ToInt32(settings.FoldPreprocessor).ToString()); sci.SetProperty("fold.at.else", Convert.ToInt32(settings.FoldAtElse).ToString()); sci.SetProperty("fold.html", Convert.ToInt32(settings.FoldHtml).ToString()); sci.SetProperty("lexer.cpp.track.preprocessor", "0"); sci.SetVirtualSpaceOptions((Int32)settings.VirtualSpaceMode); sci.SetFoldFlags((Int32)settings.FoldFlags); /** * Set if themes should colorize the first margin */ Language language = SciConfig.GetLanguage(sci.ConfigurationLanguage); if (language != null && language.editorstyle != null) { Boolean colorizeMarkerBack = language.editorstyle.ColorizeMarkerBack; if (colorizeMarkerBack) { sci.SetMarginTypeN(BookmarksMargin, (Int32)MarginType.Fore); } else { sci.SetMarginTypeN(BookmarksMargin, (Int32)MarginType.Symbol); } } /** * Set correct line number margin width */ Boolean viewLineNumbers = settings.ViewLineNumbers; if (viewLineNumbers) { sci.SetMarginWidthN(LineMargin, ScaleArea(sci, 36)); } else { sci.SetMarginWidthN(LineMargin, 0); } /** * Set correct bookmark margin width */ Boolean viewBookmarks = settings.ViewBookmarks; if (viewBookmarks) { sci.SetMarginWidthN(BookmarksMargin, ScaleArea(sci, 14)); } else { sci.SetMarginWidthN(BookmarksMargin, 0); } /** * Set correct folding margin width */ Boolean useFolding = settings.UseFolding; if (!useFolding && !viewBookmarks && !viewLineNumbers) { sci.SetMarginWidthN(FoldingMargin, 0); } else if (useFolding) { sci.SetMarginWidthN(FoldingMargin, ScaleArea(sci, 15)); } else { sci.SetMarginWidthN(FoldingMargin, ScaleArea(sci, 2)); } sci.SetMarginWidthN(1, 0); //Inheritance Margin (see ASCompletion.PluginMain.Margin) /** * Adjust caret policy based on settings */ if (settings.KeepCaretCentered) { sci.SetXCaretPolicy((Int32)(CaretPolicy.Jumps | CaretPolicy.Even), 30); sci.SetYCaretPolicy((Int32)(CaretPolicy.Jumps | CaretPolicy.Even), 2); } else // Match edge... { sci.SetXCaretPolicy((Int32)CaretPolicy.Even, 0); sci.SetYCaretPolicy((Int32)CaretPolicy.Even, 0); } sci.SetVisiblePolicy((Int32)(CaretPolicy.Strict | CaretPolicy.Even), 0); /** * Set scroll range (if false, over-scroll mode is enabled) */ sci.EndAtLastLine = settings.EndAtLastLine ? 1 : 0; /** * Adjust the print margin */ sci.EdgeColumn = settings.PrintMarginColumn; if (sci.EdgeColumn > 0) { sci.EdgeMode = 1; } else { sci.EdgeMode = 0; } /** * Add missing ignored keys */ foreach (Keys keys in ShortcutManager.AllShortcuts) { if (keys != Keys.None && !sci.ContainsIgnoredKeys(keys)) { sci.AddIgnoredKeys(keys); } } if (hardUpdate) { String lang = sci.ConfigurationLanguage; sci.ConfigurationLanguage = lang; } sci.Colourise(0, -1); sci.Refresh(); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
public void DuplicateSwitch() { if (!PluginBase.MainForm.CurrentDocument.IsEditable) { return; } ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl; sci.BeginUndoAction(); int pos = sci.CurrentPos; int line = sci.LineFromPosition(pos); int start = sci.PositionFromLine(line); if (IsMultilineSelection(sci)) { sci.SetSel(start, sci.SelectionEnd); } int ss = sci.SelectionStart - start; int se = sci.SelectionEnd - start; // sci.GetLine est bugge sur la derniere ligne dans la beta 7 string text = ""; if (line < sci.LineCount - 1) { text = sci.GetLine(line); if (sci.EOLMode == 0) { text = text.Substring(0, text.Length - 1); } } else { text = sci.GetCurLine(sci.LineLength(line)); } // 0.3 string s = ""; if (text.IndexOf("addEventListener") > -1 || text.IndexOf("removeEventListener") > -1) { // SWITCH EVENTS InitializeEvents(); ParseEvents test = new ParseEvents(eventsKeys, eventsValues, text); //TraceManager.Add("test.name:" + test.name); //TraceManager.Add("test.callback:" + test.callback); //TraceManager.Add("test.switchName:" + test.switchName); //TraceManager.Add("test.switchCallback:" + test.switchCallback); String[] arr = RegexEvents.Split(text); for (int i = 0; i < arr.Length; i++) { if (arr[i] == test.name) { s += test.switchName; } else { s += arr[i]; } } s = Regex.Replace(s, test.callback, test.switchCallback); } else { // SWITCH PROPERTIES InitializeProperties(); List <String> props = settingObject.PropertiesList; String[] arr = RegexProperties.Split(text); for (int i = 0; i < arr.Length; i++) { s += SwitchValue(propertiesKeys, propertiesValues, arr[i]); } } //TraceManager.Add("s:" + s); sci.InsertText(sci.LineEndPosition(line), LineEndDetector.GetNewLineMarker(sci.EOLMode) + s); int nxt = line + 1; int ss2 = sci.PositionFromLine(nxt) + ss; if (sci.LineFromPosition(ss2) != nxt) { ss2 = sci.LineEndPosition(nxt); } int se2 = sci.PositionFromLine(nxt) + se; if (sci.LineFromPosition(se2) != nxt) { se2 = sci.LineEndPosition(nxt); } sci.SetSel(ss2, se2); sci.EndUndoAction(); }
private string ProcessFileTemplate(string args) { Int32 eolMode = (Int32)MainForm.Settings.EOLMode; String lineBreak = LineEndDetector.GetNewLineMarker(eolMode); List <String> imports = new List <string>(); string extends = ""; string implements = ""; string access = ""; string inheritedMethods = ""; string paramString = ""; string superConstructor = ""; string classMetadata = ""; int index; // resolve imports if (lastFileOptions.interfaces != null && lastFileOptions.interfaces.Count > 0) { string implementContinuation; implements = " implements "; index = 0; if (lastFileOptions.Language == "haxe") { bool isHaxe2 = PluginBase.CurrentSDK != null && PluginBase.CurrentSDK.Name.ToLower().Contains("haxe 2"); implementContinuation = isHaxe2 ? ", implements " : " implements "; } else { implementContinuation = ", "; } foreach (string item in lastFileOptions.interfaces) { if (item.Contains('.')) { imports.Add(item); } implements += (index > 0 ? implementContinuation : "") + item.Split('.').Last(); if (lastFileOptions.createInheritedMethods) { processOnSwitch = lastFileFromTemplate; // let ASCompletion generate the implementations when file is opened } index++; } } if (lastFileOptions.superClass != "") { var superClassFullName = lastFileOptions.superClass; if (superClassFullName.Contains(".")) { imports.Add(superClassFullName); } var superClassShortName = superClassFullName.Split('.').Last(); var fileName = Path.GetFileNameWithoutExtension(lastFileFromTemplate); extends = fileName == superClassShortName ? $" extends {superClassFullName}" : $" extends {superClassShortName}"; processContext = ASContext.GetLanguageContext(lastFileOptions.Language); if (lastFileOptions.createConstructor && processContext != null && constructorArgs == null) { var lastDotIndex = superClassFullName.LastIndexOf('.'); var cmodel = processContext.GetModel(lastDotIndex < 0 ? "" : superClassFullName.Substring(0, lastDotIndex), superClassShortName, ""); if (!cmodel.IsVoid()) { if ((cmodel.Flags & FlagType.TypeDef) != 0) { var tmp = cmodel; while (!tmp.IsVoid()) { if (!string.IsNullOrEmpty(tmp.Constructor)) { cmodel = tmp; break; } tmp.ResolveExtends(); tmp = tmp.Extends; } } foreach (MemberModel member in cmodel.Members) { if (member.Name == cmodel.Constructor) { paramString = member.ParametersString(); AddImports(imports, member, cmodel); superConstructor = "super("; index = 0; if (member.Parameters != null) { foreach (MemberModel param in member.Parameters) { if (param.Name.StartsWith('.')) { break; } var pname = TemplateUtils.GetParamName(param); superConstructor += (index > 0 ? ", " : "") + pname; index++; } } superConstructor += ");\n" + (lastFileOptions.Language == "as3" ? "\t\t\t" : "\t\t"); break; } } } } processContext = null; } if (constructorArgs != null) { paramString = constructorArgs; foreach (String type in constructorArgTypes) { if (!imports.Contains(type)) { imports.Add(type); } } } if (lastFileOptions.Language == "as3") { access = lastFileOptions.isPublic ? "public " : "internal "; access += lastFileOptions.isDynamic ? "dynamic " : ""; access += lastFileOptions.isFinal ? "final " : ""; } else if (lastFileOptions.Language == "haxe") { access = lastFileOptions.isPublic ? "public " : "private "; access += lastFileOptions.isDynamic ? "dynamic " : ""; if (lastFileOptions.isFinal) { classMetadata += "@:final\n"; } } else { access = lastFileOptions.isDynamic ? "dynamic " : ""; } string importsSrc = ""; string prevImport = null; imports.Sort(); foreach (string import in imports) { if (prevImport != import) { prevImport = import; if (import.LastIndexOf('.') == -1) { continue; } if (import.Substring(0, import.LastIndexOf('.')) == lastFileOptions.Package) { continue; } importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + "import " + import + ";" + lineBreak; } } if (importsSrc.Length > 0) { importsSrc += (lastFileOptions.Language == "as3" ? "\t" : "") + lineBreak; } args = args.Replace("$(Import)", importsSrc); args = args.Replace("$(Extends)", extends); args = args.Replace("$(Implements)", implements); args = args.Replace("$(Access)", access); args = args.Replace("$(InheritedMethods)", inheritedMethods); args = args.Replace("$(ConstructorArguments)", paramString); args = args.Replace("$(Super)", superConstructor); args = args.Replace("$(ClassMetadata)", classMetadata); return(args); }
public string GetDefaultEOLMarker() { return(LineEndDetector.GetNewLineMarker((Int32)mainForm.Settings.EOLMode)); }
/// <summary> /// Add closing brace to a code block. /// If enabled, move the starting brace to a new line. /// </summary> /// <param name="Sci"></param> /// <param name="txt"></param> /// <param name="line"></param> public static void AutoCloseBrace(ScintillaControl Sci, int line) { // find matching brace int bracePos = Sci.LineEndPosition(line - 1) - 1; while ((bracePos > 0) && (Sci.CharAt(bracePos) != '{')) { bracePos--; } if (bracePos == 0 || Sci.BaseStyleAt(bracePos) != 5) { return; } int match = Sci.SafeBraceMatch(bracePos); int start = line; int indent = Sci.GetLineIndentation(start - 1); if (match > 0) { int endIndent = Sci.GetLineIndentation(Sci.LineFromPosition(match)); if (endIndent + Sci.TabWidth > indent) { return; } } // find where to include the closing brace int startIndent = indent; int count = Sci.LineCount; int lastLine = line; int position; string txt = Sci.GetLine(line).Trim(); line++; int eolMode = Sci.EOLMode; string NL = LineEndDetector.GetNewLineMarker(eolMode); if (txt.Length > 0 && ")]};,".IndexOf(txt[0]) >= 0) { Sci.BeginUndoAction(); try { position = Sci.CurrentPos; Sci.InsertText(position, NL + "}"); Sci.SetLineIndentation(line, startIndent); } finally { Sci.EndUndoAction(); } return; } else { while (line < count - 1) { txt = Sci.GetLine(line).TrimEnd(); if (txt.Length != 0) { indent = Sci.GetLineIndentation(line); if (indent <= startIndent) { break; } lastLine = line; } else { break; } line++; } } if (line >= count - 1) { lastLine = start; } // insert closing brace Sci.BeginUndoAction(); try { position = Sci.LineEndPosition(lastLine); Sci.InsertText(position, NL + "}"); Sci.SetLineIndentation(lastLine + 1, startIndent); } finally { Sci.EndUndoAction(); } }
public static void ApplySciSettings(ScintillaControl sci, Boolean hardUpdate) { try { sci.CaretPeriod = Globals.Settings.CaretPeriod; sci.CaretWidth = Globals.Settings.CaretWidth; sci.EOLMode = LineEndDetector.DetectNewLineMarker(sci.Text, (Int32)Globals.Settings.EOLMode); sci.IsBraceMatching = Globals.Settings.BraceMatchingEnabled; sci.UseHighlightGuides = !Globals.Settings.HighlightGuide; sci.Indent = Globals.Settings.IndentSize; sci.SmartIndentType = Globals.Settings.SmartIndentType; sci.IsBackSpaceUnIndents = Globals.Settings.BackSpaceUnIndents; sci.IsCaretLineVisible = Globals.Settings.CaretLineVisible; sci.IsIndentationGuides = Globals.Settings.ViewIndentationGuides; sci.IndentView = Globals.Settings.IndentView; sci.IsTabIndents = Globals.Settings.TabIndents; sci.IsUseTabs = Globals.Settings.UseTabs; sci.IsViewEOL = Globals.Settings.ViewEOL; sci.ScrollWidth = Globals.Settings.ScrollWidth; sci.TabWidth = Globals.Settings.TabWidth; sci.ViewWS = Convert.ToInt32(Globals.Settings.ViewWhitespace); sci.WrapMode = Convert.ToInt32(Globals.Settings.WrapText); sci.SetProperty("fold", Convert.ToInt32(Globals.Settings.UseFolding).ToString()); sci.SetProperty("fold.comment", Convert.ToInt32(Globals.Settings.FoldComment).ToString()); sci.SetProperty("fold.compact", Convert.ToInt32(Globals.Settings.FoldCompact).ToString()); sci.SetProperty("fold.preprocessor", Convert.ToInt32(Globals.Settings.FoldPreprocessor).ToString()); sci.SetProperty("fold.at.else", Convert.ToInt32(Globals.Settings.FoldAtElse).ToString()); sci.SetProperty("fold.html", Convert.ToInt32(Globals.Settings.FoldHtml).ToString()); sci.SetProperty("lexer.cpp.track.preprocessor", "0"); sci.SetVirtualSpaceOptions((Int32)Globals.Settings.VirtualSpaceMode); sci.SetFoldFlags((Int32)Globals.Settings.FoldFlags); /** * Set correct line number margin width */ Boolean viewLineNumbers = Globals.Settings.ViewLineNumbers; if (viewLineNumbers) { sci.SetMarginWidthN(1, ScaleHelper.Scale(31)); } else { sci.SetMarginWidthN(1, 0); } /** * Set correct bookmark margin width */ Boolean viewBookmarks = Globals.Settings.ViewBookmarks; if (viewBookmarks) { sci.SetMarginWidthN(0, ScaleHelper.Scale(14)); } else { sci.SetMarginWidthN(0, 0); } /** * Set correct folding margin width */ Boolean useFolding = Globals.Settings.UseFolding; if (!useFolding && !viewBookmarks && !viewLineNumbers) { sci.SetMarginWidthN(2, 0); } else if (useFolding) { sci.SetMarginWidthN(2, ScaleHelper.Scale(15)); } else { sci.SetMarginWidthN(2, ScaleHelper.Scale(2)); } /** * Adjust the print margin */ sci.EdgeColumn = Globals.Settings.PrintMarginColumn; if (sci.EdgeColumn > 0) { sci.EdgeMode = 1; } else { sci.EdgeMode = 0; } /** * Add missing ignored keys */ foreach (Keys keys in ShortcutManager.AllShortcuts) { if (keys != Keys.None && !sci.ContainsIgnoredKeys(keys)) { sci.AddIgnoredKeys(keys); } } if (hardUpdate) { String lang = sci.ConfigurationLanguage; sci.ConfigurationLanguage = lang; } sci.Colourise(0, -1); sci.Refresh(); } catch (Exception ex) { ErrorManager.ShowError(ex); } }
protected override void GenerateDocumentation(string context) { var sci = ASContext.CurSciControl; if (sci == null) { return; } var position = sci.CurrentPos; var line = sci.LineFromPosition(position); var indent = sci.LineIndentPosition(line) - sci.PositionFromLine(line); var tab = sci.GetLine(line).Substring(0, indent); var newline = LineEndDetector.GetNewLineMarker(sci.EOLMode); var cbs = PluginBase.Settings.CommentBlockStyle; var headerStar = cbs == CommentBlockStyle.Indented ? " *" : "*"; string bodyStar; var enableLeadingAsterisks = ((HaXeSettings)ASContext.Context.Settings).EnableLeadingAsterisks; if (enableLeadingAsterisks) { bodyStar = headerStar; } else { bodyStar = cbs == CommentBlockStyle.Indented ? " " : " "; } var parInd = cbs == CommentBlockStyle.Indented ? "\t" : " "; if (!PluginBase.MainForm.Settings.UseTabs) { parInd = " "; } // empty box if (context == null) { sci.ReplaceSel(newline + tab + headerStar + " " + newline + tab + headerStar + "/"); position += newline.Length + tab.Length + 1 + headerStar.Length; sci.SetSel(position, position); } // method details else { var box = newline + tab + bodyStar + " "; var mFun = re_splitFunction.Match(context); if (mFun.Success && !re_property.IsMatch(mFun.Groups["fname"].Value)) { // parameters var list = ParseMethodParameters(mFun.Groups["params"].Value); box = list.Aggregate(box, (current, param) => current + (newline + tab + bodyStar + " @param" + parInd + param.Name)); // return type var mType = re_variableType.Match(mFun.Groups["type"].Value); if (mType.Success && !mType.Groups["type"].Value.Equals("void", StringComparison.OrdinalIgnoreCase)) { box += newline + tab + bodyStar + " @return"; } } if (enableLeadingAsterisks) { box += newline + tab + headerStar + "/"; } else { box += newline + tab + "**" + "/"; } sci.ReplaceSel(box); position += newline.Length + tab.Length + 1 + headerStar.Length; sci.SetSel(position, position); } }