private void Colorize(ScintillaEditForm document) { string content = document.GetContent() as String; string tags = GetAspNetTagsAsString(content); document.Editor.Lexing.Keywords[0] = defaultTags + tags; document.Editor.Lexing.Colorize(); }
public LookupList GetLookupList(ScintillaEditForm document) { string content = document.GetContent() as string; if (content == null) { return(null); } if (!IsRubyCodeSection(content, document.Editor.CurrentPos)) { return(GetXhtmlLookupList(document)); } else { return(null); } }
private bool IsInsideRule(ScintillaEditForm document) { string content = document.GetContent() as string; content = content.Substring(0, document.Editor.CurrentPos); int open = content.LastIndexOf("{"); int close = content.LastIndexOf("}"); if (open == -1 && close == -1) { return(false); } if (open != -1 && close == -1) { return(true); } return(close < open); }
public LookupList GetXhtmlLookupList(ScintillaEditForm document) { string text = document.GetContent() as string; if (String.IsNullOrEmpty(text)) { return(null); } text = text.Substring(0, document.Editor.CurrentPos); // XHTML of HTML5? bool isHTML5 = IsHTML5(text); // Split the current line into opening-tag delimited segments string[] split = text.Split('<'); // If no split we have no opening tag if (split.Length == 1) { return(null); } // Current tag is start of last split segment string target = split[split.Length - 1]; // If we have a closed tag we are in content, not a tag if (target.IndexOf('>') != -1) { return(null); } // If no spaces in target text must be tag name (or part of) if (target.IndexOf(' ') == -1) { /* * Tag lookup. */ List <LookupListItem> tagList = GetTagList(isHTML5); List <String> insertionTemplates = new List <String>(); // Full tag is either complete or just the closing tag (index = 0) if (target.StartsWith("/")) { target = target.TrimStart('/'); insertionTemplates.Add(_closingTag); } else { insertionTemplates.Add(_fullTag); } // Add the template for closed tags (index = 1) insertionTemplates.Add(_emptyTag); // Add the server-side script template (index = 2) insertionTemplates.Add(scriptTag); return(new LookupList(target, tagList, insertionTemplates)); } else { /* * Target consists of tag name followed by one or more attributes. * Attributes are quote delimited and may have spaces between the * attribute name and the value string. The values may be singular * or multiple separated by semicolons or spaces. * * <tag a="b" c="d;e" foo = " bar baz| * * For the lookup the attribute and current values will be foo * and baz (or blank if there is a space or ';' after baz). */ // Split into tag and trailing content string[] split2 = target.Split(); string tagName = split2[0]; string tagContent = target.Substring(tagName.Length).TrimStart(); if (InAttributeValue(target)) { /* * Attribute value lookup. */ // Get the attribute name string[] split3 = tagContent.Split('='); string attrName = String.Empty; if (split.Length > 1) { string[] split4 = split3[split3.Length - 2].Trim().Split(); attrName = split4[split4.Length - 1].Trim(); } // Get the lookup lead text string valText = split3[split3.Length - 1]; int i = valText.Length - 1; // Allow for multiple values if (tagContent[i] != ';' && tagContent[i] != ' ') { string[] split4 = tagContent.Split(new Char[] { ' ', ';', '"' }); valText = split4[split4.Length - 1]; } List <LookupListItem> valList = GetAttributeValueList(tagName, attrName, isHTML5); if (valList == null) { return(null); } else { return(new LookupList(valText, valList)); } } else { /* * Attribute lookup. */ // Get the attribute name or partial name string[] split3 = tagContent.Split(); string attrName = split3[split3.Length - 1]; List <LookupListItem> attrList = GetAttributeList(tagName, isHTML5); if (attrList == null) { return(null); } string template = String.Format("{0}=\"{1}\"", QuickSharp.CodeAssist.Constants. INSERTION_TEMPLATE_TEXT_PLACEHOLDER, QuickSharp.CodeAssist.Constants. INSERTION_TEMPLATE_CPOS_PLACEHOLDER); return(new LookupList(attrName, attrList, template)); } } }
public virtual LookupList GetLookupList(ScintillaEditForm document) { /* * Read controls, assemblies and namespaces from the web.config. */ ReadWebConfig(); /* * Refresh the master namespace lists. */ UpdateLists(); /* * Colorize the ASP.NET tags. This just looks for * strings that look like tags, there is no attempt * to recognize them as valid types so no Code Assist * functionality is required. */ Colorize(document); /* * Prepare the search content and target for * the code assist lookup. Get the full source * and the source up to the caret position. */ string text = document.GetContent() as string; /* * Save all the content. Unlike the C# code * provider we are also interested in content after * the caret. (This is because of a shortcut in the * code provider where we treat the current scope as * only existing before the caret. We can mostly get * away with it in normal code but not here.) */ _fullSource = text; /* * Now we have the source see if there are any extra * assemblies declared in the page. */ AddDeclaredAssemblies(text); /* * Call the appropriate lookup provider. */ int currentPos = document.Editor.CurrentPos; /* * Because scriptlets and directives have similar syntax, * directive check must come before the scriptlet test. */ if (IsCodeSection(text, currentPos)) // <script runat="server"> { return(GetCodeSectionLookupList(document, text)); } else if (IsDirectiveSection(text, currentPos)) // <%@ { return(GetDirectiveSectionLookupList(text, currentPos)); } else if (IsScriptletSection(text, currentPos)) // <% or <%= { return(GetCodeSectionLookupList(document, text)); } else // In a tag { text = text.Substring(0, currentPos); /* * Look for a dollar expression (e.g. "<%$ AppSettings:MyVal " ) */ Regex re = new Regex(@"<%\$\s*(\w*)(:)?(\w*)(\s*)$"); Match match = re.Match(text); if (match.Success) { return(GetDollarExpressionLookupList(match)); } /* * Look for tags or tag attributes. */ AspNetTag tag = GetAspNetTag(text); if (tag != null) { if (tag.WantAttributes) { return(GetTagAttributesLookupList(tag)); } else { return(GetTagLookupList(tag)); } } else { return(xhtmlProvider.GetXhtmlLookupList(document)); } } }
private LookupList GetList(ScintillaEditForm document) { if (activeDatabase == null) { return(null); } Colorize(document); string source = document.GetContent() as string; if (source == null) { return(null); } /* * Mark the current positon and cleanup. */ source = source.Insert(document.Editor.CurrentPos, "¬¬¬"); source = Cleanup(source); int pos = source.IndexOf("¬¬¬"); if (pos == -1) { return(null); } string src1 = source.Substring(0, pos); string src2 = source.Substring(pos + 3); /* * Get the current statement; before and after the cursor. */ string[] split1 = src1.Split(';'); src1 = split1[split1.Length - 1]; string[] split2 = src2.Split(';'); src2 = split2[0]; string firstToken = GetFirstToken(src1); if (!IsSQLStatement(firstToken)) { return(null); } string secondToken = GetSecondToken(src1); string activeKeyword = GetActiveKeyword(src1); switch (firstToken) { case "select": switch (activeKeyword) { case "select": return(GetEntityList(src1, src2, true, true, true, true)); case "from": case "join": return(GetEntityList(src1, src2, true, true, false, true)); case "where": case "on": case "order_by": case "group_by": case "having": return(GetEntityList(src1, src2, true, true, true, true)); default: return(null); } case "insert": switch (activeKeyword) { case "into": return(GetEntityList(src1, src2, true, true, false, false)); default: return(null); } case "update": switch (activeKeyword) { case "update": return(GetEntityList(src1, src2, true, true, false, false)); case "set": return(GetEntityList(src1, src2, false, false, true, false)); case "where": return(GetEntityList(src1, src2, false, false, true, false)); default: return(null); } case "delete": switch (activeKeyword) { case "from": return(GetEntityList(src1, src2, true, true, false, false)); case "where": return(GetEntityList(src1, src2, false, false, true, false)); default: return(null); } case "create": switch (activeKeyword) { case "table": case "view": return(GetEntityList(src1, src2, true, false, false, false)); } if (secondToken == "view") { switch (activeKeyword) { case "select": return(GetEntityList(src1, src2, true, true, true, true)); case "from": case "join": return(GetEntityList(src1, src2, true, true, false, true)); case "where": case "on": case "order_by": case "group_by": case "having": return(GetEntityList(src1, src2, true, true, true, true)); default: return(null); } } return(null); case "alter": case "drop": switch (activeKeyword) { case "table": case "view": return(GetEntityList(src1, src2, true, true, false, false)); default: return(null); } case "use": return(GetEntityList(src1, src2, true, false, false, false)); default: return(null); } }
public virtual LookupList GetLookupList(ScintillaEditForm document) { UpdateLists(); if ((settingsManager.ColorizeTypes || settingsManager.ColorizeVariables) && settingsManager.ColorizeOnLookup) { ColourizeVariablesAndTypes(document); } /* * Prepare the search content and target for * the code assist lookup. */ Line line = document.Editor.Lines.Current; string text = line.Text.Substring(0, line.SelectionStartPosition - line.StartPosition); int lineStartPos = GetLineStartPosition(text); text = text.TrimStart(); /* * Check for embedded option or empty comment. */ if (text.StartsWith("//")) { if (text.Length > 2 && "$?&".IndexOf(text[2]) != -1) { return(EmbeddedOptionHelper.GetEmbbededOptionFileList(text)); } else { return(null); } } /* * Get the full source and the source up to the * caret position. */ string fullSource = document.GetContent() as string; int currentPos = document.Editor.CurrentPos; string preSource = fullSource.Substring(0, currentPos); /* * Restrict the fullSource to the current class definition. */ fullSource = GetFullSource(fullSource, ref currentPos); if (fullSource == String.Empty) { return(null); } if (currentPos > fullSource.Length) { return(null); } /* * Detect if we are before the first class declaration. * If not we can stop the lookup as soon as we've done * the 'using' search as this is the only lookup type * valid before a class definition. This means 'using' * declarations have to appear before the class defs * but I think that's good practice anyway. */ Regex re = new Regex(@"(?s)class\s+.+\{"); bool beforeClass = re.Match(preSource).Success; LookupContext context = new LookupContext( fullSource, preSource, text, lineStartPos, currentPos, beforeClass); return(GetCSharpLookupList(context)); }
private void ColourizeVariablesAndTypes(ScintillaEditForm document) { string source = CSharpFormattingTools. RemoveUnwantedText(document.GetContent() as string); source = CSharpFormattingTools. RemoveUnwantedBracketText(source); List <string> namespaces = GetNamespaceList(source); if (settingsManager.ColorizeTypes) { /* * Lexer WORD2 - types */ List <string> assemblies = new List <string>(); foreach (string ns in namespaces) { List <string> names = referenceManager.GetNamespaceAssemblies(ns); foreach (string name in names) { if (!assemblies.Contains(name)) { assemblies.Add(name); } } } assemblies.AddRange(workspaceAssemblyList); document.Editor.Lexing.Keywords[1] = CodeAssistTools.GetNamespaceTypesAsString( namespaces, assemblies); } if (settingsManager.ColorizeVariables) { /* * Lexer GLOBALCLASS - variables */ DeclaredVariables declaredVariables = new DeclaredVariables( source, namespaces, false, DeclarationContext.All); InheritedVariablesBase inheritedVariables = new InheritedVariablesCode( source, DeclarationContext.All, workspaceAssemblyList, fullNamespaceList, rootNamespaceList, configNamespaceList); StringBuilder sb = new StringBuilder(); foreach (Variable v in declaredVariables.Items) { sb.Append(v.Name); sb.Append(" "); } foreach (Variable v in inheritedVariables.Items) { sb.Append(v.Name); sb.Append(" "); } document.Editor.Lexing.Keywords[3] = sb.ToString(); } document.Editor.Lexing.Colorize(); }
private LookupList GetList(ScintillaEditForm document) { if (activeDatabase == null) { return(null); } Colorize(document); string source = document.GetContent() as string; if (source == null) { return(null); } /* * Mark the current positon and cleanup. */ source = source.Insert(document.Editor.CurrentPos, "¬¬¬"); source = Cleanup(source); int pos = source.IndexOf("¬¬¬"); if (pos == -1) { return(null); } string src1 = source.Substring(0, pos); string src2 = source.Substring(pos + 3); /* * Get the current statement; before and after the cursor. */ string[] split1 = src1.Split(';'); src1 = split1[split1.Length - 1]; string[] split2 = src2.Split(';'); src2 = split2[0]; string firstToken = GetFirstToken(src1); if (!IsSQLStatement(firstToken)) { return(null); } string secondToken = GetSecondToken(src1); string activeKeyword = GetActiveKeyword(src1); /* * Although the 'main' database is a schema it is the only one that can appear * in the lookup so we might as well not display it. * The design of the SQL Code Assist system means that it won't work with * attached databases. If we attach a database we need to refresh the connection * to get the new schema but this causes the attached database to be detached * again so we can never see attached databases in the code assist lookups. */ switch (firstToken) { case "select": switch (activeKeyword) { case "select": return(GetEntityList(src1, src2, false, true, true, true)); case "from": case "join": return(GetEntityList(src1, src2, false, true, false, true)); case "where": case "on": case "order_by": case "group_by": case "having": return(GetEntityList(src1, src2, false, true, true, true)); default: return(null); } case "insert": switch (activeKeyword) { case "into": return(GetEntityList(src1, src2, false, true, false, false)); default: return(null); } case "update": switch (activeKeyword) { case "update": return(GetEntityList(src1, src2, false, true, false, false)); case "set": return(GetEntityList(src1, src2, false, false, true, false)); case "where": return(GetEntityList(src1, src2, false, false, true, false)); default: return(null); } case "delete": switch (activeKeyword) { case "from": return(GetEntityList(src1, src2, false, true, false, false)); case "where": return(GetEntityList(src1, src2, false, false, true, false)); default: return(null); } case "create": switch (activeKeyword) { case "table": case "view": return(GetEntityList(src1, src2, false, false, false, false)); } if (secondToken == "view") { switch (activeKeyword) { case "select": return(GetEntityList(src1, src2, false, true, true, true)); case "from": case "join": return(GetEntityList(src1, src2, false, true, false, true)); case "where": case "on": case "order_by": case "group_by": case "having": return(GetEntityList(src1, src2, false, true, true, true)); default: return(null); } } return(null); case "alter": case "drop": switch (activeKeyword) { case "table": case "view": return(GetEntityList(src1, src2, false, true, false, false)); default: return(null); } default: return(null); } }
private void MatchButton_Click(object sender, EventArgs e) { _regexComboBox.BackColor = Color.Empty; string regex = _regexComboBox.Text.Trim(); if (String.IsNullOrEmpty(regex)) { _regexComboBox.BackColor = Color.Yellow; return; } MainForm mainForm = ApplicationManager. GetInstance().MainForm; ScintillaEditForm document = mainForm.ActiveDocument as ScintillaEditForm; if (document == null) { return; } string target = document.GetContent() as string; if (String.IsNullOrEmpty(target)) { return; } _treeView.Nodes.Clear(); Regex re = null; try { re = new Regex(regex); MatchCollection mc = re.Matches(target); string rootText = String.Format("{0} {1}", mc.Count, (mc.Count == 1) ? Resources.ResultMatch : Resources.ResultMatches ); if (mc.Count > 0) { rootText += String.Format(" ({0} {1})", mc[0].Groups.Count, (mc[0].Groups.Count == 1) ? Resources.ResultGroup : Resources.ResultGroups ); } TreeNode rootNode = new TreeNode(rootText); rootNode.ImageKey = Constants.IMAGE_KEY_SEARCH; rootNode.SelectedImageKey = Constants.IMAGE_KEY_SEARCH; _treeView.Nodes.Add(rootNode); foreach (Match m in mc) { string matchText = String.Format("{0} {1}: [{2}]", Resources.ResultTextLine, LineFromPosition(document.Lines, m.Index), m.Value); TreeNode matchNode = new TreeNode(matchText); matchNode.ImageKey = Constants.IMAGE_KEY_MATCH; matchNode.SelectedImageKey = Constants.IMAGE_KEY_MATCH; int groupCount = 0; foreach (Group g in m.Groups) { string s = String.Format("{0,2:00} ({1}): [{2}]", groupCount, re.GroupNameFromNumber(groupCount), g.Value); TreeNode n = new TreeNode(s); n.ImageKey = Constants.IMAGE_KEY_GROUP; n.SelectedImageKey = Constants.IMAGE_KEY_GROUP; matchNode.Nodes.Add(n); groupCount++; } rootNode.Nodes.Add(matchNode); } rootNode.Expand(); AddItemToHistory(regex); UpdateComboBoxList(); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.RegexErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }