Exemple #1
0
        private Point GetCursorLocation(ScintillaEditForm document)
        {
            if (document == null)
            {
                return(Point.Empty);
            }

            Line line = document.Editor.Lines.Current;

            int borderWidth =
                (_mainForm.Width - _mainForm.ClientSize.Width) / 2;

            int titlebarHeight = _mainForm.Height -
                                 _mainForm.ClientSize.Height - (2 * borderWidth);

            Point p = new Point(
                _mainForm.Location.X +
                document.Location.X +
                document.Editor.Location.X +
                document.Editor.PointXFromPosition(line.SelectionStartPosition),
                _mainForm.Location.Y +
                titlebarHeight +
                _mainForm.MainMenu.Height +
                _mainForm.ClientWindow.Location.Y +
                document.Location.Y +
                document.Editor.Location.Y +
                document.Editor.PointYFromPosition(line.SelectionStartPosition));

            return(p);
        }
Exemple #2
0
        private void UI_HELP_MENU_CONTEXT_HELP_Click(object sender, EventArgs e)
        {
            if (!File.Exists(_settingsManager.DexplorePath))
            {
                return;
            }

            string keyword = String.Empty;

            if (_mainForm.ActiveDocument != null)
            {
                ScintillaEditForm ef =
                    _mainForm.ActiveDocument as ScintillaEditForm;

                if (ef != null)
                {
                    string currentword =
                        ef.Editor.GetWordFromPosition(ef.Editor.CurrentPos);

                    if (!String.IsNullOrEmpty(currentword))
                    {
                        keyword = " /LaunchFKeywordTopic " + currentword;
                    }
                }
            }

            FileTools.LaunchApplication(false,
                                        _settingsManager.DexplorePath,
                                        _settingsManager.DexploreArgs + keyword);
        }
        public virtual void DocumentActivated(ScintillaEditForm document)
        {
            if ((settingsManager.ColorizeTypes ||
                 settingsManager.ColorizeVariables) &&
                settingsManager.ColorizeOnActivate)
            {
                UpdateLists();

                Control parent = document.Parent;

                /*
                 * Use the wait cursor to make document
                 * switching look a bit snappier.
                 */

                try
                {
                    if (parent != null)
                    {
                        parent.Cursor = Cursors.WaitCursor;
                    }

                    ColourizeVariablesAndTypes(document);
                }
                finally
                {
                    if (parent != null)
                    {
                        parent.Cursor = Cursors.Default;
                    }
                }
            }
        }
Exemple #4
0
 public void DocumentActivated(ScintillaEditForm document)
 {
     if (_activeProvider != null)
     {
         _activeProvider.ColorizeDocument(document);
     }
 }
Exemple #5
0
        private void FindInFilesForm_Shown(object sender, System.EventArgs e)
        {
            _replaceTextComboBox.SelectionLength = 0;
            _fileSpecComboBox.SelectionLength    = 0;

            /*
             * If we have an editor see if we have any selected text.
             */

            ScintillaEditForm sci = GetActiveEditor();

            if (sci != null)
            {
                /*
                 * May be multiline so we split at first newline
                 * after normalizing for Windows/Mac/Unix differences.
                 */

                string text = sci.Editor.Selection.Text;
                text = text.Replace("\n", "\r");
                int i = text.IndexOf("\r");
                if (i != -1)
                {
                    text = text.Substring(0, i);
                }

                _findTextComboBox.Text = text;
                _findTextComboBox.Focus();
                _findTextComboBox.SelectAll();
            }
        }
Exemple #6
0
        private void UI_EDIT_MENU_CODE_ASSIST_Click(
            object sender, EventArgs e)
        {
            ScintillaEditForm document =
                _mainForm.ActiveDocument as ScintillaEditForm;

            Invoke(document);
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        private bool ReplaceInFile(string filePath, string findText, string replaceText)
        {
            /*
             * Check if the file contains the search term.
             */

            string fullPath = Path.GetFullPath(filePath);

            string fileText = GetFileText(fullPath);

            if (fileText.IndexOf(findText) == -1)
            {
                return(false);
            }

            /*
             * Load the file into an editor and replace all matches
             * with the new text (don't update the MRU list).
             */

            _mainForm.LoadDocumentIntoWindow(fullPath, false);

            ScintillaEditForm document =
                _mainForm.ActiveDocument as ScintillaEditForm;

            if (document == null)
            {
                return(false);
            }

            document.Editor.Markers.DeleteAll(
                QuickSharp.Editor.Constants.BOOKMARK_MARKER);

            document.Editor.UndoRedo.BeginUndoAction();

            foreach (Line line in document.Lines)
            {
                if (line.Text.IndexOf(findText) != -1)
                {
                    string s = line.Text.Replace(findText, replaceText);
                    line.AddMarker(QuickSharp.Editor.Constants.BOOKMARK_MARKER);

                    /*
                     * Line needs to be trimmed of any EOL characters to prevent
                     * extra blank lines being inserted.
                     */

                    line.Text = s.TrimEnd(new Char[] { '\n', '\r' });
                }
            }

            document.Editor.UndoRedo.EndUndoAction();

            return(true);
        }
Exemple #9
0
 public LookupList GetLookupList(ScintillaEditForm document)
 {
     if (_activeProvider != null)
     {
         return(_activeProvider.GetLookupList(document));
     }
     else
     {
         return(null);
     }
 }
Exemple #10
0
        private LookupList GetCodeSectionLookupList(
            ScintillaEditForm document, string fullSource)
        {
            /*
             * Get the token at the cursor position for the lookup target.
             */

            Line line = document.Editor.Lines.Current;

            string text = line.Text.Substring(0,
                                              line.SelectionStartPosition -
                                              line.StartPosition);

            int lineStartPos = GetLineStartPosition(text);

            text = text.TrimStart();

            /*
             * Get the code content from the page. This will be all the
             * code between script tags and all the code in scriptlet
             * tags (amalgamated into a single dummy method).
             */

            // Mark the current location.
            fullSource = fullSource.Insert(
                document.Editor.CurrentPos, "!##!");

            // Get the code content from the page.
            string scriptSource    = GetInlineCode(fullSource);
            string scriptletSource = GetScriptletCode(fullSource);

            fullSource = scriptSource + "\r\n" + scriptletSource;

            string preSource = fullSource;

            int currentPos = preSource.IndexOf("!##!");

            if (currentPos == -1)
            {
                return(null);
            }

            preSource  = preSource.Substring(0, currentPos);
            fullSource = fullSource.Replace("!##!", String.Empty);

            LookupContext context = new LookupContext(
                fullSource, preSource, text,
                lineStartPos, currentPos, true);

            return(GetCSharpLookupList(context));
        }
Exemple #11
0
        protected void Colorize(ScintillaEditForm document)
        {
            if (activeDatabase != null)
            {
                document.Editor.Lexing.Keywords[0] =
                    activeDatabase.GetKeywords();
                document.Editor.Lexing.Keywords[1] =
                    activeDatabase.GetDataTypes();
                document.Editor.Lexing.Keywords[5] =
                    activeDatabase.GetFunctions();

                document.Editor.Lexing.Keywords[4] =
                    activeDatabase.GetEntityNames();

                document.Editor.Lexing.Colorize();
            }
        }
Exemple #12
0
        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);
            }
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        private void UpdateHelpMenuStatus()
        {
            _helpMenuHelpContents.Enabled =
                File.Exists(_settingsManager.DexplorePath);

            _helpMenuContextHelp.Enabled = false;
            if (_mainForm.ActiveDocument == null)
            {
                return;
            }

            ScintillaEditForm ef = _mainForm.ActiveDocument as ScintillaEditForm;

            if (ef == null)
            {
                return;
            }

            _helpMenuContextHelp.Enabled =
                File.Exists(_settingsManager.DexplorePath);
        }
Exemple #15
0
        private string GetFileText(string path)
        {
            /*
             * Check the file isn't already open.
             */

            foreach (QuickSharp.Core.Document document in
                     _mainForm.ClientWindow.Documents)
            {
                ScintillaEditForm editor =
                    document as ScintillaEditForm;

                if (editor != null && FileTools.MatchPaths(path, editor.FilePath))
                {
                    return(editor.Editor.Text);
                }
            }

            /*
             * Read the content from the disk.
             */

            return(FileTools.ReadFile(path));
        }
Exemple #16
0
        /// <summary>
        /// Get the list of lookup items for the current document.
        /// </summary>
        /// <param name="document">The current document.</param>
        /// <returns>A list of lookup items.</returns>
        public LookupList GetLookupList(ScintillaEditForm document)
        {
            if (document == null)
            {
                return(null);
            }

            DocumentType documentType = new DocumentType(document.FileName);

            if (documentType == null ||
                String.IsNullOrEmpty(documentType.ToString()))
            {
                return(null);
            }

            ICodeAssistProvider provider = GetProvider(documentType);

            if (provider == null)
            {
                return(null);
            }

            return(provider.GetLookupList(document));
        }
Exemple #17
0
        private bool ReplaceInFileRE(string filePath, string replaceText, Regex regex)
        {
            /*
             * Must match against whole document as regex matches can
             * be multi-line; each match might span several lines so
             * we can't use a line by line approach.
             */

            string fullPath = Path.GetFullPath(filePath);
            string fileText = null;

            try
            {
                fileText = GetFileText(filePath);
            }
            catch
            {
                // just ignore dodgy files
                return(false);
            }

            MatchCollection matches = regex.Matches(fileText);

            if (matches.Count == 0)
            {
                return(false);
            }

            /*
             * Load the file into an editor and replace all matches
             * with the new text (don't update the MRU list).
             */

            _mainForm.LoadDocumentIntoWindow(fullPath, false);

            ScintillaEditForm document =
                _mainForm.ActiveDocument as ScintillaEditForm;

            if (document == null)
            {
                return(false);
            }

            document.Editor.Markers.DeleteAll(
                QuickSharp.Editor.Constants.BOOKMARK_MARKER);

            /*
             * Can't track the actual change locations using regex replace so we add a
             * sentinel string to mark the lines on which the changes occur. Then we
             * bookmark each line with a sentinel and remove it.
             * This is a bit hacky and would break if the sentinel actually appears
             * in the text but it's the only way to do multi-line replaces and still
             * preserve the bookmarks in the right places.
             */

            string sentinel = "{^£`^}";

            document.Editor.UndoRedo.BeginUndoAction();

            document.Editor.Text = regex.Replace(
                document.Editor.Text, sentinel + replaceText);

            foreach (Line line in document.Editor.Lines)
            {
                if (line.Text.IndexOf(sentinel) != -1)
                {
                    string s = line.Text.Replace(sentinel, String.Empty);
                    line.Text = s.TrimEnd(new Char[] { '\n', '\r' });

                    line.AddMarker(QuickSharp.Editor.Constants.BOOKMARK_MARKER);
                }
            }

            document.Editor.UndoRedo.EndUndoAction();

            return(true);
        }
Exemple #18
0
        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));
                }
            }
        }
Exemple #19
0
 public override LookupList GetLookupList(ScintillaEditForm document)
 {
     return(base.GetLookupList(document));
 }
Exemple #20
0
 public override void DocumentActivated(ScintillaEditForm document)
 {
     base.DocumentActivated(document);
 }
Exemple #21
0
        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));
                }
            }
        }
Exemple #22
0
        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);
            }
        }
Exemple #23
0
 public LookupList GetLookupList(ScintillaEditForm document)
 {
     return(GetCssLookupList(document));
 }
        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();
        }
Exemple #25
0
        /// <summary>
        /// Invoke code assist on the current document.
        /// </summary>
        /// <param name="document">The current document.</param>
        public void Invoke(ScintillaEditForm document)
        {
            if (document == null)
            {
                return;
            }

            LookupList lookupList = null;

            try
            {
                _mainForm.Cursor = Cursors.WaitCursor;
                lookupList       = _codeAssistManager.GetLookupList(document);
            }
            catch
            {
                /*
                 * We want to ignore any exceptions that get this far
                 * for usability reasons. If the lookup fails we might
                 * as well just ignore it as there's nothing the user
                 * can do. We keep the command line option to allow
                 * debugging and testing.
                 */

                if (_applicationManager.HaveCommandLineSwitch(
                        Resources.SwitchDiagnostic))
                {
                    throw;
                }
            }
            finally
            {
                _mainForm.Cursor = Cursors.Default;
            }

            if (lookupList == null)
            {
                return;
            }

            if (lookupList.Items != null && lookupList.Items.Count > 0)
            {
                Point cursorLocation = GetCursorLocation(document);
                if (cursorLocation.IsEmpty)
                {
                    return;
                }

                /*
                 * Make sure the caret isn't too far out of bounds.
                 */

                if (cursorLocation.Y < _mainForm.Location.Y)
                {
                    return;
                }
                if (cursorLocation.Y > _mainForm.Location.Y + _mainForm.Height)
                {
                    return;
                }

                /*
                 * Move the lookup display point if the caret is
                 * close to the lower edge of the form.
                 */

                int threshold = GetWindowBottomEdge() -
                                Constants.LOOKUP_WINDOW_HEIGHT;
                if (cursorLocation.Y > threshold)
                {
                    cursorLocation.Y = threshold;
                }

                LookupForm lf;

                try
                {
                    _mainForm.Cursor = Cursors.WaitCursor;
                    lf = new LookupForm(cursorLocation, lookupList);
                }
                finally
                {
                    _mainForm.Cursor = Cursors.Default;
                }

                if (lf.ShowDialog() == DialogResult.OK)
                {
                    string selectedText  = lf.SelectedText;
                    string lookAheadText = lf.LookAheadText;

                    if (!String.IsNullOrEmpty(lookAheadText))
                    {
                        document.Editor.Caret.Position -=
                            lookAheadText.Length;
                        document.Editor.Selection.Start =
                            document.Editor.Caret.Position;
                        document.Editor.Selection.End =
                            document.Editor.Caret.Position + lookAheadText.Length;
                        document.Editor.Selection.Text = String.Empty;
                    }

                    if (lf.InsertionTemplate == null)
                    {
                        document.Editor.InsertText(selectedText);
                    }
                    else
                    {
                        string template = lf.InsertionTemplate;

                        string insertionText = template.Replace(
                            Constants.INSERTION_TEMPLATE_TEXT_PLACEHOLDER,
                            selectedText);

                        int cursorOffset = insertionText.IndexOf(
                            Constants.INSERTION_TEMPLATE_CPOS_PLACEHOLDER);

                        insertionText = insertionText.Replace(
                            Constants.INSERTION_TEMPLATE_CPOS_PLACEHOLDER,
                            String.Empty);

                        document.Editor.InsertText(insertionText);

                        /*
                         * If offset is -1 the caret stays at the
                         * end of the inserted text.
                         */

                        if (cursorOffset != -1)
                        {
                            document.Editor.Caret.Position -=
                                (insertionText.Length - cursorOffset);

                            document.Editor.Selection.Start   =
                                document.Editor.Selection.End =
                                    document.Editor.Caret.Position;
                        }
                    }
                }

                lf.Dispose();
            }
        }
Exemple #26
0
        /*
         * Note: this was moved to the ASP.NET provider to remove the
         * Xhtml module dependency in the C# provider. However, some
         * of the web-specific supporting code remains in the C# module.
         */

        #region Provider interface

        public virtual void DocumentActivated(ScintillaEditForm document)
        {
            Colorize(document);
        }
Exemple #27
0
 public void DocumentActivated(ScintillaEditForm document)
 {
 }
Exemple #28
0
 public void ColorizeDocument(ScintillaEditForm document)
 {
     Colorize(document);
 }
Exemple #29
0
        private LookupList GetCssLookupList(ScintillaEditForm document)
        {
            Line line = document.Editor.Lines.Current;

            string text = line.Text.Substring(0,
                                              line.SelectionStartPosition -
                                              line.StartPosition).TrimStart();

            if (!IsInsideRule(document))
            {
                return(null);
            }

            /*
             * Load the property list and get the property/value
             * text required for the lookup.
             */

            _cssProperties = GetCssProperties();

            Char[] separators = { '{', '}', ';' };

            string[] split = text.Split(separators);

            string lookahead = split[split.Length - 1];

            if (lookahead.IndexOf(":") != -1)
            {
                /*
                 * Looking for a CSS property value name.
                 */

                string[] split2 = lookahead.Split(':');

                string property = split2[0].Trim();

                // Get the property values

                if (!_cssProperties.ContainsKey(property))
                {
                    return(null);
                }

                List <LookupListItem> list =
                    GetPropertyValueList(_cssProperties[property]);

                // Get the last delimited segment of the lookahead

                lookahead = split2.Length > 1 ? split2[1] : String.Empty;

                string[] split3 = lookahead.Split(new Char[] { ' ', ',' });

                lookahead = split3[split3.Length - 1];

                return(new LookupList(lookahead, list));
            }
            else
            {
                /*
                 * Looking for a CSS property name.
                 */

                List <LookupListItem> list =
                    GetPropertyList(_cssProperties);

                string insertionTemplate = String.Format("{0}:",
                                                         QuickSharp.CodeAssist.Constants.
                                                         INSERTION_TEMPLATE_TEXT_PLACEHOLDER);

                return(new LookupList(lookahead, list, insertionTemplate));
            }
        }
        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));
        }