protected override bool ProcessTextAreaKey(Keys keyData)
        {
            if (!Visible)
            {
                return(false);
            }

            switch (keyData)
            {
            case Keys.Back:
                --endOffset;
                if (endOffset < startOffset)
                {
                    Close();
                }
                return(false);

            case Keys.Delete:
                if (control.ActiveTextAreaControl.Caret.Offset <= endOffset)
                {
                    --endOffset;
                }
                if (endOffset < startOffset)
                {
                    Close();
                }
                return(false);

            case Keys.Home:
                codeCompletionListView.SelectIndex(0);
                return(true);

            case Keys.End:
                codeCompletionListView.SelectIndex(completionData.Length - 1);
                return(true);

            case Keys.PageDown:
                codeCompletionListView.PageDown();
                return(true);

            case Keys.PageUp:
                codeCompletionListView.PageUp();
                return(true);

            case Keys.Down:
                codeCompletionListView.SelectNextItem();
                return(true);

            case Keys.Up:
                codeCompletionListView.SelectPrevItem();
                return(true);

            case Keys.Tab:
            case Keys.Return:
                InsertSelectedItem();
                return(true);
            }
            return(base.ProcessTextAreaKey(keyData));
        }
Exemple #2
0
        protected override bool ProcessTextAreaKey(Keys keyData)
        {
            if (!Visible)
            {
                return(false);
            }

            var result = false;

            switch (keyData)
            {
            case Keys.Home:
                codeCompletionListView.SelectIndex(0);
                result = true; break;

            case Keys.End:
                codeCompletionListView.SelectIndex(completionData.Length - 1);
                result = true; break;

            case Keys.PageDown:
                codeCompletionListView.PageDown();
                result = true; break;

            case Keys.PageUp:
                codeCompletionListView.PageUp();
                result = true; break;

            case Keys.Down:
                codeCompletionListView.SelectNextItem();
                result = true; break;

            case Keys.Up:
                codeCompletionListView.SelectPrevItem();
                result = true; break;

            case Keys.Tab:
                InsertSelectedItem('\t');
                result = true; break;

            case Keys.Return:
                InsertSelectedItem('\n');
                result = true; break;
            }

            if (result)
            {
                return(true);
            }
            else
            {
                return(base.ProcessTextAreaKey(keyData));
            }
        }
        AutoCompleteWindow(ICompletionDataProvider completionDataProvider, Form parentForm, TextEditorControl control, string fileName, bool showDeclarationWindow)
            : base(parentForm, control)
        {
            this.showDeclarationWindow = showDeclarationWindow;

            workingScreen = Screen.GetWorkingArea(Location);
            startOffset   = control.ActiveTextAreaControl.Caret.Offset + 1;
            endOffset     = startOffset;
            if (completionDataProvider.PreSelection != null)
            {
                startOffset -= completionDataProvider.PreSelection.Length + 1;
                endOffset--;
            }

            codeCompletionListView                      = new CodeCompletionListView(completionData);
            codeCompletionListView.ImageList            = completionDataProvider.ImageList;
            codeCompletionListView.Dock                 = DockStyle.Fill;
            codeCompletionListView.SelectedItemChanged += new EventHandler(CodeCompletionListViewSelectedItemChanged);
            codeCompletionListView.DoubleClick         += new EventHandler(CodeCompletionListViewDoubleClick);
            codeCompletionListView.Click               += new EventHandler(CodeCompletionListViewClick);
            Controls.Add(codeCompletionListView);

            if (completionData.Length > 10)
            {
                vScrollBar.Dock        = DockStyle.Right;
                vScrollBar.Minimum     = 0;
                vScrollBar.Maximum     = completionData.Length - 8;
                vScrollBar.SmallChange = 1;
                vScrollBar.LargeChange = 3;
                codeCompletionListView.FirstItemChanged += new EventHandler(CodeCompletionListViewFirstItemChanged);
                Controls.Add(vScrollBar);
            }

            this.drawingSize = GetListViewSize();
            SetLocation();

            declarationViewWindow = new DeclarationViewWindow(parentForm);
            SetDeclarationViewLocation();
            declarationViewWindow.ShowDeclarationViewWindow();
            control.Focus();
            CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);

            if (completionDataProvider.DefaultIndex >= 0)
            {
                codeCompletionListView.SelectIndex(completionDataProvider.DefaultIndex);
            }

            if (completionDataProvider.PreSelection != null)
            {
                CaretOffsetChanged(this, EventArgs.Empty);
            }

            vScrollBar.Scroll += new ScrollEventHandler(DoScroll);
        }
Exemple #4
0
        CodeCompletionWindow(ICompletionDataProvider completionDataProvider, ICompletionData[] completionData, Form parentForm, TextEditorControl control, bool showDeclarationWindow, bool fixedListViewWidth, int startOffset, int endOffset)
            : base(parentForm, control)
        {
            dataProvider               = completionDataProvider;
            this.completionData        = completionData;
            document                   = control.Document;
            this.showDeclarationWindow = showDeclarationWindow;
            this.fixedListViewWidth    = fixedListViewWidth;

            workingScreen    = Screen.GetWorkingArea(Location);
            this.startOffset = startOffset;
            if (startOffset == -1)
            {
                this.startOffset = control.ActiveTextAreaControl.Caret.Offset + 1;
            }
            this.endOffset = endOffset;
            if (this.endOffset == -1)
            {
                this.endOffset = startOffset;
            }
            if (completionDataProvider.PreSelection != null)
            {
                this.startOffset -= completionDataProvider.PreSelection.Length + 1;
                this.endOffset--;
            }

            codeCompletionListView                      = new CodeCompletionListView(completionData);
            codeCompletionListView.ImageList            = completionDataProvider.ImageList;
            codeCompletionListView.Dock                 = DockStyle.Fill;
            codeCompletionListView.SelectedItemChanged += CodeCompletionListViewSelectedItemChanged;
            codeCompletionListView.DoubleClick         += CodeCompletionListViewDoubleClick;
            codeCompletionListView.Click               += CodeCompletionListViewClick;
            Controls.Add(codeCompletionListView);

            if (completionData.Length > MaxListLength)
            {
                vScrollBar.Dock        = DockStyle.Right;
                vScrollBar.Minimum     = 0;
                vScrollBar.Maximum     = completionData.Length - 1;
                vScrollBar.SmallChange = 1;
                vScrollBar.LargeChange = MaxListLength;
                codeCompletionListView.FirstItemChanged += CodeCompletionListViewFirstItemChanged;
                Controls.Add(vScrollBar);
            }

            drawingSize = GetListViewSize();
            SetLocation();

            if (declarationViewWindow == null)
            {
                declarationViewWindow = new DeclarationViewWindow(parentForm);
            }
            SetDeclarationViewLocation();
            declarationViewWindow.ShowDeclarationViewWindow();
            declarationViewWindow.MouseMove += ControlMouseMove;
            control.Focus();
            CodeCompletionListViewSelectedItemChanged(this, EventArgs.Empty);

            if (completionDataProvider.DefaultIndex >= 0)
            {
                codeCompletionListView.SelectIndex(completionDataProvider.DefaultIndex);
            }

            if (completionDataProvider.PreSelection != null)
            {
                CaretOffsetChanged(this, EventArgs.Empty);
            }

            vScrollBar.ValueChanged           += VScrollBarValueChanged;
            document.DocumentAboutToBeChanged += DocumentAboutToBeChanged;
            document.DocumentChanged          += DocumentDocumentChanged;
        }
Exemple #5
0
        protected void RefreshList(ICompletionData[] completionData)
        {
            StartOffset = control.ActiveTextAreaControl.Caret.Offset + 1;
            EndOffset   = StartOffset;
            if (CompletionDataProvider.PreSelection != null)
            {
                StartOffset -= CompletionDataProvider.PreSelection.Length + 1;
                EndOffset--;
            }

            SuspendLayout();

            string previouslySelected = null;

            if (ListView != null)
            {
                if (ListView.SelectedCompletionData != null)
                {
                    previouslySelected = ListView.SelectedCompletionData.Text;
                }
                Controls.Remove(ListView);
                ListView.Dispose();
            }

            _currentCompletionData = completionData;
            ListView                      = new CodeCompletionListView(completionData);
            ListView.ImageList            = CompletionDataProvider.ImageList;
            ListView.Dock                 = DockStyle.Fill;
            ListView.SelectedItemChanged += (s, e) => UpdateDeclarationView();
            //ListView.DoubleClick += (s, e) => InsertSelectedItem('\0');
            //ListView.MouseDown += (s, e) => control.ActiveTextAreaControl.TextArea.Focus(); // Makes click impossible
            //ListView.GotFocus += (s, e) => control.ActiveTextAreaControl.TextArea.Focus(); // Interfers with scrollbar
            ListView.MouseUp += (s, e) => InsertSelectedItem('\0');
            Controls.Add(ListView);

            if (completionData.Length > MaxListLength)
            {
                _scrollBar.Maximum         = completionData.Length - 1;
                _scrollBar.Value           = 0;
                ListView.FirstItemChanged += (s, e) =>
                {
                    if (_inScrollUpdate)
                    {
                        return;
                    }
                    _inScrollUpdate  = true;
                    _scrollBar.Value = Math.Min(_scrollBar.Maximum, ListView.FirstItem);
                    _inScrollUpdate  = false;
                };
                _scrollBar.Visible = true;
            }
            else
            {
                _scrollBar.Visible = false;
            }
            drawingSize = GetListViewSize(completionData.Length);
            Width       = drawingSize.Width;
            Height      = drawingSize.Height;
            ResumeLayout();

            //control.Focus();
            UpdateDeclarationView();
            var selectIndex = previouslySelected == null ? -1 : Array.FindIndex(completionData, d => d.Text == previouslySelected);

            if (selectIndex >= 0)
            {
                ListView.SelectIndex(selectIndex);
            }
            else if (CompletionDataProvider.DefaultIndex >= 0)
            {
                ListView.SelectIndex(CompletionDataProvider.DefaultIndex);
            }

            if (CompletionDataProvider.PreSelection != null)
            {
                // Need to sort the array after passing it to listview, as its contructor forces a different sorting
                Array.Sort(completionData, (a, b) =>
                {
                    var ax = a.Text.StartsWith(CompletionDataProvider.PreSelection, StringComparison.InvariantCultureIgnoreCase);
                    var bx = b.Text.StartsWith(CompletionDataProvider.PreSelection, StringComparison.InvariantCultureIgnoreCase);
                    return(ax == bx ? 0 : (ax ? -1 : 1));
                });
                CaretOffsetChanged(this, EventArgs.Empty);
            }
        }