Exemplo n.º 1
0
        public bool CompleteWord(ref KeyActions ka, KeyDescriptor descriptor)
        {
            if (SelectedItemIndex == -1 || completionDataList == null)
            {
                return(false);
            }
            var item = completionDataList [SelectedItemIndex];

            if (item == null)
            {
                return(false);
            }
            IsInCompletion = true;
            try {
                // first close the completion list, then insert the text.
                // this is required because that's the logical event chain, otherwise things could be messed up
                CloseCompletionList();

                /*			var cdItem = (CompletionData)item;
                 *                      cdItem.InsertCompletionText (this, ref ka, closeChar, keyChar, modifier);
                 *                      AddWordToHistory (PartialWord, cdItem.CompletionText);
                 *                      OnWordCompleted (new CodeCompletionContextEventArgs (CompletionWidget, CodeCompletionContext, cdItem.CompletionText));
                 */
                if (item.HasOverloads && declarationviewwindow != null && declarationviewwindow.CurrentOverload >= 0 && declarationviewwindow.CurrentOverload < item.OverloadedData.Count)
                {
                    item.OverloadedData[declarationviewwindow.CurrentOverload].InsertCompletionText(facade, ref ka, descriptor);
                }
                else
                {
                    item.InsertCompletionText(facade, ref ka, descriptor);
                }
                cache.CommitCompletionData(item);
                OnWordCompleted(new CodeCompletionContextEventArgs(CompletionWidget, CodeCompletionContext, item.DisplayText));
            } finally {
                IsInCompletion = false;
                CompletionWindowManager.HideWindow();
            }
            return(true);
        }
        public void PresentItems(ITrackingSpan triggerSpan, IList <CompletionItem> items, CompletionItem selectedItem, CompletionItem suggestionModeItem, bool suggestionMode, bool isSoftSelected, ImmutableArray <CompletionItemFilter> completionItemFilters, string filterText)
        {
            var result = new CompletionDataList();

            foreach (var item in items)
            {
                if (string.IsNullOrEmpty(item.DisplayText))
                {
                    continue;
                }
                result.Add(WrapItem(item));
            }
            if (suggestionMode)
            {
                result.AutoSelect = false;
            }
            if (filterText != null)
            {
                result.DefaultCompletionString = filterText;
            }
            if (suggestionModeItem != null)
            {
                result.DefaultCompletionString = suggestionModeItem.DisplayText;
                result.AutoSelect = false;
            }

            if (selectedItem != null)
            {
                result.DefaultCompletionString = selectedItem.DisplayText;
            }

            // TODO: isSoftSelected
            // TODO: completionItemFilters
            var editor = IdeApp.Workbench.ActiveDocument.Editor;
            var widget = IdeApp.Workbench.ActiveDocument.GetContent <ICompletionWidget> ();

            CompletionWindowManager.ShowWindow(null, (char)0, result, widget, widget.CreateCodeCompletionContext(editor.CaretOffset));
        }
Exemplo n.º 3
0
 protected override void DoubleClick()
 {
     CompleteWord();
     CompletionWindowManager.HideWindow();
 }
Exemplo n.º 4
0
        internal bool ShowListWindow(ICompletionDataList list, CodeCompletionContext completionContext)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            CodeCompletionContext = completionContext;
            CompletionDataList    = list;
            ResetState();

            mutableList             = completionDataList as IMutableCompletionDataList;
            PreviewCompletionString = completionDataList.CompletionSelectionMode == CompletionSelectionMode.OwnTextField;

            if (mutableList != null)
            {
                mutableList.Changing += OnCompletionDataChanging;
                mutableList.Changed  += OnCompletionDataChanged;

                if (mutableList.IsChanging)
                {
                    OnCompletionDataChanging(null, null);
                }
            }

            if (FillList())
            {
                AutoSelect                         = list.AutoSelect;
                AutoCompleteEmptyMatch             = list.AutoCompleteEmptyMatch;
                AutoCompleteEmptyMatchOnCurlyBrace = list.AutoCompleteEmptyMatchOnCurlyBrace;
                CloseOnSquareBrackets              = list.CloseOnSquareBrackets;
                // makes control-space in midle of words to work
                string text = CompletionWidget.GetCompletionText(CodeCompletionContext);
                DefaultCompletionString = completionDataList.DefaultCompletionString ?? "";
                if (text.Length == 0)
                {
                    initialWordLength = 0;
                    //completionWidget.SelectedLength;
                    StartOffset = completionContext.TriggerOffset;
                    UpdateWordSelection();
                    ResetSizes();
                    ShowAll();
                    UpdateWordSelection();
                    UpdateDeclarationView();
                    //if there is only one matching result we take it by default
                    if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging)
                    {
                        CompleteWord();
                        CompletionWindowManager.HideWindow();
                        return(false);
                    }
                    return(true);
                }

                initialWordLength   = CompletionWidget.SelectedLength > 0 ? 0 : text.Length;
                StartOffset         = CompletionWidget.CaretOffset - initialWordLength;
                HideWhenWordDeleted = initialWordLength != 0;
                ResetSizes();
                UpdateWordSelection();
                //if there is only one matching result we take it by default
                if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging)
                {
                    CompleteWord();
                    CompletionWindowManager.HideWindow();
                    return(false);
                }
                ShowAll();
                UpdateDeclarationView();
                return(true);
            }
            CompletionWindowManager.HideWindow();
            return(false);
        }
Exemplo n.º 5
0
        public bool PreProcessKeyEvent(KeyDescriptor descriptor)
        {
            if (descriptor.SpecialKey == SpecialKey.Escape)
            {
                CompletionWindowManager.HideWindow();
                return(true);
            }

            KeyActions ka         = KeyActions.None;
            bool       keyHandled = false;

            if (CompletionDataList != null)
            {
                foreach (ICompletionKeyHandler handler in CompletionDataList.KeyHandler)
                {
                    if (handler.PreProcessKey(facade, descriptor, out ka))
                    {
                        keyHandled = true;
                        break;
                    }
                }
            }
            if (!keyHandled)
            {
                ka = PreProcessKey(descriptor);
            }
            if ((ka & KeyActions.Complete) != 0)
            {
                CompleteWord(ref ka, descriptor);
            }

            if ((ka & KeyActions.CloseWindow) != 0)
            {
                CompletionWindowManager.HideWindow();
                OnWindowClosed(EventArgs.Empty);
            }

            if ((ka & KeyActions.Ignore) != 0)
            {
                return(true);
            }
            if ((ka & KeyActions.Process) != 0)
            {
                if (descriptor.SpecialKey == SpecialKey.Left || descriptor.SpecialKey == SpecialKey.Right)
                {
                    // Close if there's a modifier active EXCEPT lock keys and Modifiers
                    // Makes an exception for Mod1Mask (usually alt), shift, control, meta and super
                    // This prevents the window from closing if the num/scroll/caps lock are active
                    // FIXME: modifier mappings depend on X server settings

//					if ((modifier & ~(Gdk.ModifierType.LockMask | (Gdk.ModifierType.ModifierMask & ~(Gdk.ModifierType.ShiftMask | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask | Gdk.ModifierType.SuperMask)))) != 0) {
                    // this version doesn't work for my system - seems that I've a modifier active
                    // that gdk doesn't know about. How about the 2nd version - should close on left/rigt + shift/mod1/control/meta/super
                    if ((descriptor.ModifierKeys & (ModifierKeys.Shift | ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Command)) != 0)
                    {
                        CompletionWindowManager.HideWindow();
                        OnWindowClosed(EventArgs.Empty);
                        return(false);
                    }

                    if (declarationviewwindow != null && declarationviewwindow.Multiple)
                    {
                        if (descriptor.SpecialKey == SpecialKey.Left)
                        {
                            declarationviewwindow.OverloadLeft();
                        }
                        else
                        {
                            declarationviewwindow.OverloadRight();
                        }
                    }
                    else
                    {
                        CompletionWindowManager.HideWindow();
                        OnWindowClosed(EventArgs.Empty);
                        return(false);
                    }
                    return(true);
                }
                if (completionDataList != null && completionDataList.CompletionSelectionMode == CompletionSelectionMode.OwnTextField)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        internal bool ShowListWindow(char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext, System.Action closedDelegate)
        {
            if (mutableList != null)
            {
                mutableList.Changing -= OnCompletionDataChanging;
                mutableList.Changed  -= OnCompletionDataChanged;
                HideFooter();
            }
            //initialWordLength = 0;
            this.completionDataList             = list;
            this.CompleteWithSpaceOrPunctuation = MonoDevelop.Core.PropertyService.Get("CompleteWithSpaceOrPunctuation", true);

            this.CodeCompletionContext = completionContext;
            this.closedDelegate        = closedDelegate;
            mutableList = completionDataList as IMutableCompletionDataList;
            List.PreviewCompletionString = completionDataList.CompletionSelectionMode == CompletionSelectionMode.OwnTextField;

            if (mutableList != null)
            {
                mutableList.Changing += OnCompletionDataChanging;
                mutableList.Changed  += OnCompletionDataChanged;

                if (mutableList.IsChanging)
                {
                    OnCompletionDataChanging(null, null);
                }
            }

            this.CompletionWidget = completionWidget;

            if (FillList())
            {
// not neccessarry, because list window is not reused anymore:
//				Reset (true);
                this.AutoSelect             = list.AutoSelect;
                this.AutoCompleteEmptyMatch = list.AutoCompleteEmptyMatch;
                // makes control-space in midle of words to work
                string text = completionWidget.GetCompletionText(completionContext);
                DefaultCompletionString = completionDataList.DefaultCompletionString ?? "";
                if (text.Length == 0)
                {
                    UpdateWordSelection();
                    initialWordLength = 0;                    //completionWidget.SelectedLength;
                    ResetSizes();
                    ShowAll();
                    UpdateWordSelection();
                    UpdateDeclarationView();

                    //if there is only one matching result we take it by default
                    if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging)
                    {
                        CompleteWord();
                        CompletionWindowManager.HideWindow();
                    }
                    return(true);
                }

                initialWordLength   = text.Length /*+ completionWidget.SelectedLength*/;
                PartialWord         = text;
                HideWhenWordDeleted = initialWordLength != 0;
                UpdateWordSelection();

                //if there is only one matching result we take it by default
                if (completionDataList.AutoCompleteUniqueMatch && IsUniqueMatch && !IsChanging)
                {
                    CompleteWord();
                    CompletionWindowManager.HideWindow();
                }
                else
                {
                    ResetSizes();
                    ShowAll();
                    UpdateDeclarationView();
                }
                return(true);
            }
            CompletionWindowManager.HideWindow();

            return(false);
        }
Exemplo n.º 7
0
        public bool PreProcessKeyEvent(Gdk.Key key, char keyChar, Gdk.ModifierType modifier, out KeyActions ka)
        {
            ka = KeyActions.None;
            bool keyHandled = false;

            foreach (ICompletionKeyHandler handler in CompletionDataList.KeyHandler)
            {
                if (handler.ProcessKey(this, key, keyChar, modifier, out ka))
                {
                    keyHandled = true;
                    break;
                }
            }

            if (!keyHandled)
            {
                ka = ProcessKey(key, keyChar, modifier);
            }

            if ((ka & KeyActions.Complete) != 0)
            {
                //bool completed =
                CompleteWord(ref ka, key, keyChar, modifier);
                //NOTE: this passes the enter keystroke through to the editor if the current item is an exact match
                //if (!completed) {
                //	CompletionWindowManager.HideWindow ();
                //	return false;
                //}
            }

            if ((ka & KeyActions.CloseWindow) != 0)
            {
                CompletionWindowManager.HideWindow();
            }

            if ((ka & KeyActions.Ignore) != 0)
            {
                return(true);
            }

            if ((ka & KeyActions.Process) != 0)
            {
                if (key == Gdk.Key.Left || key == Gdk.Key.Right)
                {
                    // Close if there's a modifier active EXCEPT lock keys and Modifiers
                    // Makes an exception for Mod1Mask (usually alt), shift, control, meta and super
                    // This prevents the window from closing if the num/scroll/caps lock are active
                    // FIXME: modifier mappings depend on X server settings

//					if ((modifier & ~(Gdk.ModifierType.LockMask | (Gdk.ModifierType.ModifierMask & ~(Gdk.ModifierType.ShiftMask | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask | Gdk.ModifierType.SuperMask)))) != 0) {
                    // this version doesn't work for my system - seems that I've a modifier active
                    // that gdk doesn't know about. How about the 2nd version - should close on left/rigt + shift/mod1/control/meta/super
                    if ((modifier & (Gdk.ModifierType.ShiftMask | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask | Gdk.ModifierType.SuperMask)) != 0)
                    {
                        CompletionWindowManager.HideWindow();
                        return(false);
                    }

                    if (declarationviewwindow.Multiple)
                    {
                        if (key == Gdk.Key.Left)
                        {
                            declarationviewwindow.OverloadLeft();
                        }
                        else
                        {
                            declarationviewwindow.OverloadRight();
                        }
                        UpdateDeclarationView();
                    }
                    else
                    {
                        CompletionWindowManager.HideWindow();
                        return(false);
                    }
                    return(true);
                }
                if (completionDataList != null && completionDataList.CompletionSelectionMode == CompletionSelectionMode.OwnTextField)
                {
                    return(true);
                }
            }
            return(false);
        }
 public void SelectNextPageItem()
 {
     CompletionWindowManager.PreProcessKeyEvent(Editor.Extension.KeyDescriptor.PageDown);
 }
 public void SelectPreviousPageItem()
 {
     CompletionWindowManager.PreProcessKeyEvent(Editor.Extension.KeyDescriptor.PageUp);
 }
Exemplo n.º 10
0
 public void Dismiss()
 {
     CompletionWindowManager.HideWindow();
 }