示例#1
0
        private void PopulateLookupList(LookupList lookupList)
        {
            _lookAheadText      = lookupList.LookAheadText;
            _insertionTemplates = lookupList.InsertionTemplates;

            _listView.SuspendLayout();

            foreach (LookupListItem item in lookupList.Items)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Tag         = item;
                lvi.Text        = " " + item.DisplayText;
                lvi.ImageKey    = item.Category;
                lvi.ToolTipText = item.ToolTipText;

                // Apply theme colors if available
                if (_themeFlags != null)
                {
                    if (_themeFlags.ViewAltBackColor != Color.Empty)
                    {
                        _listView.BackColor = _themeFlags.ViewAltBackColor;
                    }

                    if (_themeFlags.ViewAltForeColor != Color.Empty)
                    {
                        _listView.ForeColor = _themeFlags.ViewAltForeColor;
                    }
                }

                _listView.Items.Add(lvi);
            }

            _listView.ResumeLayout(true);

            if (!String.IsNullOrEmpty(lookupList.LookAheadText) &&
                (_listView.Items.Count > 0))
            {
                ListViewItem item = _listView.FindItemWithText(
                    " " + lookupList.LookAheadText, false, 0, true);

                if (item != null)
                {
                    item.Selected = true;
                    item.Focused  = true;
                    item.EnsureVisible();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Create the pop-up window.
        /// </summary>
        /// <param name="p">The location of the pop-up window.</param>
        /// <param name="list">The code assist information to be presented.</param>
        public LookupForm(Point p, LookupList list)
        {
            _themeFlags = ApplicationManager.GetInstance().
                          ClientProfile.ThemeFlags;

            InitializeComponent();

            _listView.MultiSelect      = false;
            _listView.Columns[0].Width = -1;

            this.StartPosition = FormStartPosition.Manual;
            this.Location      = p;

            PopulateLookupList(list);

            // Remember items start with " " (it looks better)
            _incrementalSearchText = " " + list.LookAheadText;

            // Allow client apps to modify the form.
            LookupFormProxy.GetInstance().UpdateFormControls(Controls);
        }
示例#3
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();
            }
        }