Example #1
0
        public override void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
        {
            var document = IdeApp.Workbench.ActiveDocument;
            var editor   = document?.Editor;

            if (editor == null || Provider == null)
            {
                base.InsertCompletionText(window, ref ka, descriptor);
                return;
            }
            var completionChange = Provider.GetChangeAsync(doc, CompletionItem, null, default(CancellationToken)).WaitAndGetResult(default(CancellationToken));

            var currentBuffer = editor.GetPlatformTextBuffer();
            var textChange    = completionChange.TextChange;

            var triggerSnapshotSpan = new SnapshotSpan(triggerSnapshot, new Span(textChange.Span.Start, textChange.Span.Length));
            var mappedSpan          = triggerSnapshotSpan.TranslateTo(currentBuffer.CurrentSnapshot, SpanTrackingMode.EdgeInclusive);

            using (var undo = editor.OpenUndoGroup()) {
                editor.ReplaceText(mappedSpan.Start, mappedSpan.Length, completionChange.TextChange.NewText);

                if (completionChange.NewPosition.HasValue)
                {
                    editor.CaretOffset = completionChange.NewPosition.Value;
                }

                if (CompletionItem.Rules.FormatOnCommit)
                {
                    var endOffset = mappedSpan.Start.Position + completionChange.TextChange.NewText.Length;
                    Format(editor, document, mappedSpan.Start, endOffset);
                }
            }
        }
        public static string GetCurrentWord(CompletionListWindow window)
        {
            int partialWordLength = window.PartialWord != null ? window.PartialWord.Length : 0;
            int replaceLength     = window.CodeCompletionContext.TriggerWordLength + partialWordLength - window.InitialWordLength;

            return(window.CompletionWidget.GetText(window.CodeCompletionContext.TriggerOffset, window.CodeCompletionContext.TriggerOffset + replaceLength));
        }
//			static int num = 0;
//			int id;
            public OpacityTimer(CompletionListWindow window)
            {
//				id = num++;
                this.window = window;
                Opacity     = 0.0;
                window.declarationviewwindow.Opacity = Opacity;
            }
Example #4
0
        public virtual Task <KeyActions> InsertCompletionText(CompletionListWindow window, KeyActions ka, KeyDescriptor descriptor)
        {
            var currentWord = GetCurrentWord(window, descriptor);

            window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, currentWord, CompletionText);
            return(Task.FromResult(ka));
        }
        public CompletionListWindowGtk(CompletionListWindow facade, WindowType type = WindowType.Popup) : base(type)
        {
            this.facade = facade;

            if (IdeApp.Workbench != null)
            {
                this.TransientFor = IdeApp.Workbench.RootWindow;
            }
            TypeHint       = Gdk.WindowTypeHint.Combo;
            SizeAllocated += new SizeAllocatedHandler(ListSizeChanged);
            Events         = Gdk.EventMask.PropertyChangeMask;
            WindowTransparencyDecorator.Attach(this);
            DataProvider = facade;
            HideDeclarationView();
            VisibilityNotifyEvent += (object sender, VisibilityNotifyEventArgs e) => {
                if (!Visible)
                {
                    HideDeclarationView();
                }
            };
            List.ListScrolled += (object sender, EventArgs e) => {
                HideDeclarationView();
                UpdateDeclarationView();
            };
            List.WordsFiltered += delegate {
                HideDeclarationView();
                UpdateDeclarationView();
            };
            List.VisibilityNotifyEvent += (object sender, VisibilityNotifyEventArgs e) => {
                if (!List.Visible)
                {
                    HideDeclarationView();
                }
            };
        }
Example #6
0
        // ext may be null, but then parameter completion don't work
        internal static void PrepareShowWindow(CompletionTextEditorExtension ext, char firstChar, ICompletionWidget completionWidget, CodeCompletionContext completionContext)
        {
            isShowing = true;

            if (wnd == null)
            {
                wnd = new CompletionListWindow();
                wnd.WordCompleted += HandleWndWordCompleted;
            }
            if (ext != null)
            {
                var widget = ext.Editor.GetNativeWidget <Gtk.Widget> ();
                wnd.TransientFor = widget?.Parent?.Toplevel as Gtk.Window;
            }
            else
            {
                var widget = completionWidget as Gtk.Widget;
                if (widget != null)
                {
                    var window = widget.Toplevel as Gtk.Window;
                    if (window != null)
                    {
                        wnd.TransientFor = window;
                    }
                }
            }
            wnd.Extension = ext;

            wnd.InitializeListWindow(completionWidget, completionContext);
        }
Example #7
0
        public static bool ShowWindow(char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext, System.Action closedDelegate)
        {
            try {
                if (wnd == null)
                {
                    wnd = new CompletionListWindow();
                    wnd.WordCompleted += HandleWndWordCompleted;
                }
                try {
                    if (!wnd.ShowListWindow(firstChar, list, completionWidget, completionContext, closedDelegate))
                    {
                        if (list is IDisposable)
                        {
                            ((IDisposable)list).Dispose();
                        }
                        DestroyWindow();
                        return(false);
                    }

                    if (ForceSuggestionMode)
                    {
                        wnd.AutoSelect = false;
                    }

                    OnWindowShown(EventArgs.Empty);
                    return(true);
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                    return(false);
                }
            } finally {
                ParameterInformationWindowManager.UpdateWindow(completionWidget);
            }
        }
        // ext may be null, but then parameter completion don't work
        public static bool ShowWindow(CompletionTextEditorExtension ext, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext)
        {
            try {
                if (ext != null)
                {
                    int inserted = ext.document.Editor.EnsureCaretIsNotVirtual();
                    if (inserted > 0)
                    {
                        completionContext.TriggerOffset = ext.document.Editor.Caret.Offset;
                    }
                }
                if (wnd == null)
                {
                    wnd = new CompletionListWindow();
                    wnd.WordCompleted += HandleWndWordCompleted;
                }
                if (ext != null)
                {
                    wnd.TransientFor = ext.document.Editor.Parent.Toplevel as Gtk.Window;
                }
                else
                {
                    var widget = completionWidget as Gtk.Widget;
                    if (widget != null)
                    {
                        var window = widget.Toplevel as Gtk.Window;
                        if (window != null)
                        {
                            wnd.TransientFor = window;
                        }
                    }
                }
                wnd.Extension = ext;
                try {
                    if (!wnd.ShowListWindow(firstChar, list, completionWidget, completionContext))
                    {
                        if (list is IDisposable)
                        {
                            ((IDisposable)list).Dispose();
                        }
                        HideWindow();
                        return(false);
                    }

                    if (ForceSuggestionMode)
                    {
                        wnd.AutoSelect = false;
                    }
                    wnd.Show();
                    DesktopService.RemoveWindowShadow(wnd);
                    OnWindowShown(EventArgs.Empty);
                    return(true);
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                    return(false);
                }
            } finally {
                ParameterInformationWindowManager.UpdateWindow(ext, completionWidget);
            }
        }
Example #9
0
 public virtual void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier)
 {
     if (CompletionText == GetCurrentWord(window))
     {
         return;
     }
     window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, GetCurrentWord(window), CompletionText);
 }
        internal static CompletionListWindow CreateAsDialog()
        {
            var w = new CompletionListWindow(Gtk.WindowType.Toplevel);

            w.window.TypeHint  = Gdk.WindowTypeHint.Dialog;
            w.window.Decorated = false;
            return(w);
        }
 public virtual void InsertCompletionText(CompletionListWindow window)
 {
     if (CompletionText == GetCurrentWord(window))
     {
         return;
     }
     window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, GetCurrentWord(window), CompletionText);
 }
Example #12
0
 static void DestroyWindow()
 {
     if (wnd != null)
     {
         wnd.Destroy();
         wnd = null;
     }
     OnWindowClosed(EventArgs.Empty);
 }
        public static string GetCurrentWord(CompletionListWindow window)
        {
            int partialWordLength = window.PartialWord != null ? window.PartialWord.Length : 0;
            int replaceLength     = window.CodeCompletionContext.TriggerWordLength + partialWordLength - window.InitialWordLength;
            int endOffset         = Math.Min(window.StartOffset + replaceLength, window.CompletionWidget.TextLength);
            var result            = window.CompletionWidget.GetText(window.StartOffset, endOffset);

            return(result);
        }
Example #14
0
 static void DestroyWindow()
 {
     if (wnd != null)
     {
         wnd.Destroy();
         ParameterInformationWindowManager.UpdateWindow(wnd.CompletionWidget);
         wnd = null;
     }
     OnWindowClosed(EventArgs.Empty);
 }
Example #15
0
 static void DestroyWindow()
 {
     if (wnd != null)
     {
         if (wnd.Visible)
         {
             wnd.HideWindow();
         }
         wnd.WordCompleted  -= HandleWndWordCompleted;
         wnd.VisibleChanged -= HandleWndVisibleChanged;
         wnd.Destroy();
         wnd = null;
     }
 }
Example #16
0
        public static string GetCurrentWord(CompletionListWindow window, MonoDevelop.Ide.Editor.Extension.KeyDescriptor descriptor)
        {
            int partialWordLength = window.PartialWord != null ? window.PartialWord.Length : 0;
            int replaceLength;

            if (descriptor.SpecialKey == SpecialKey.Return || descriptor.SpecialKey == SpecialKey.Tab)
            {
                replaceLength = window.CodeCompletionContext.TriggerWordLength + partialWordLength - window.InitialWordLength;
            }
            else
            {
                replaceLength = partialWordLength;
            }
            int endOffset = Math.Min(window.StartOffset + replaceLength, window.CompletionWidget.TextLength);
            var result    = window.CompletionWidget.GetText(window.StartOffset, endOffset);

            return(result);
        }
Example #17
0
        public virtual void InsertCompletionText(CompletionListWindow window, ref KeyActions ka, KeyDescriptor descriptor)
        {
            var currentWord = GetCurrentWord(window, descriptor);

            window.CompletionWidget.SetCompletionText(window.CodeCompletionContext, currentWord, CompletionText);
        }