コード例 #1
0
        // When a key is pressed, and before the key is processed by the editor, this method will be invoked.
        // Return true if the key press should be processed by the editor.
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            if (!IsActiveExtension())
            {
                return(base.KeyPress(descriptor));
            }
            bool res;

            if (CurrentCompletionContext != null)
            {
                if (CompletionWindowManager.PreProcessKeyEvent(descriptor))
                {
                    CompletionWindowManager.PostProcessKeyEvent(descriptor);
                    autoHideCompletionWindow = true;
                    // in named parameter case leave the parameter window open.
                    autoHideParameterWindow = descriptor.KeyChar != ':';
                    if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible)
                    {
                        ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
                    }

                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, descriptor))
                {
                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            //			int oldPos = Editor.CursorPosition;
            //			int oldLen = Editor.TextLength;
            char deleteOrBackspaceTriggerChar = '\0';

            if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset);
            }
            if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset - 1);
            }

            res = base.KeyPress(descriptor);
            if (Editor.EditMode == EditMode.TextLink && Editor.TextLinkPurpose == TextLinkPurpose.Rename)
            {
                return(res);
            }
            if (descriptor.KeyChar == (char)16 || descriptor.KeyChar == (char)17)
            {
                return(res);
            }

            CompletionWindowManager.PostProcessKeyEvent(descriptor);

            var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt
                             | ModifierKeys.Command;

            // Handle parameter completion
            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
            }

            if ((descriptor.ModifierKeys & ignoreMods) != 0)
            {
                return(res);
            }

            // don't complete on block selection
            if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
            {
                return(res);
            }
            // Handle code completion
            if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                completionTokenSrc.Cancel();
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;
                completionTokenSrc       = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo(CompletionTriggerReason.CharTyped, descriptor.KeyChar), token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;
                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);
                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    if (result.TriggerWordStart >= 0)
                                    {
                                        CurrentCompletionContext.TriggerOffset = result.TriggerWordStart;
                                    }
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                } catch (AggregateException) {
                }
            }

            if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                if (!char.IsLetterOrDigit(deleteOrBackspaceTriggerChar) && deleteOrBackspaceTriggerChar != '_')
                {
                    return(res);
                }
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;

                int cpos, wlen;
                if (!GetCompletionCommandOffset(out cpos, out wlen))
                {
                    cpos = Editor.CaretOffset;
                    wlen = 0;
                }

                CurrentCompletionContext.TriggerOffset     = cpos;
                CurrentCompletionContext.TriggerWordLength = wlen;

                completionTokenSrc.Cancel();
                completionTokenSrc = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleCodeCompletionAsync(CurrentCompletionContext, new CompletionTriggerInfo(CompletionTriggerReason.BackspaceOrDeleteCommand, deleteOrBackspaceTriggerChar), token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;

                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    if (result.TriggerWordStart >= 0)
                                    {
                                        CurrentCompletionContext.TriggerOffset = result.TriggerWordStart;
                                    }
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                                else
                                {
                                    CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                    CurrentCompletionContext = null;
                } catch (AggregateException) {
                    CurrentCompletionContext = null;
                }
            }

            if (CompletionWidget != null)
            {
                CodeCompletionContext ctx  = CompletionWidget.CurrentCodeCompletionContext;
                var newparameterHintingSrc = new CancellationTokenSource();
                var token = newparameterHintingSrc.Token;
                try {
                    var task = HandleParameterCompletionAsync(ctx, descriptor.KeyChar, token);
                    if (task != null)
                    {
                        parameterHintingSrc.Cancel();
                        parameterHintingSrc = newparameterHintingSrc;
                        parameterHingtingCursorPositionChanged = false;
                        task.ContinueWith(t => {
                            if (!token.IsCancellationRequested && t.Result != null)
                            {
                                ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, t.Result);
                                if (parameterHingtingCursorPositionChanged)
                                {
                                    ParameterInformationWindowManager.UpdateCursorPosition(this, CompletionWidget);
                                }
                            }
                        }, token, TaskContinuationOptions.None, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        //Key was typed that was filtered out, no heavy processing will be performed(task==null)
                        //but we still want to update ParameterInfo window to avoid displaying it outside method call
                        parameterHingtingCursorPositionChanged = true;
                    }
                } catch (TaskCanceledException) {
                } catch (AggregateException) {
                }
            }
            return(res);
        }
        // When a key is pressed, and before the key is processed by the editor, this method will be invoked.
        // Return true if the key press should be processed by the editor.
        public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
        {
            bool res;

            if (currentCompletionContext != null)
            {
                if (CompletionWindowManager.PreProcessKeyEvent(key, keyChar, modifier))
                {
                    CompletionWindowManager.PostProcessKeyEvent(key, keyChar, modifier);
                    autoHideCompletionWindow = true;
                    return(false);
                }
                autoHideCompletionWindow = false;
            }

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, key, modifier))
                {
                    return(false);
                }
                autoHideCompletionWindow = false;
            }

            //			int oldPos = Editor.CursorPosition;
            //			int oldLen = Editor.TextLength;

            res = base.KeyPress(key, keyChar, modifier);

            CompletionWindowManager.PostProcessKeyEvent(key, keyChar, modifier);

            var ignoreMods = Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask
                             | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.SuperMask;

            // Handle parameter completion
            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, key, modifier);
            }

            if ((modifier & ignoreMods) != 0)
            {
                return(res);
            }

            // don't complete on block selection
            if (!EnableCodeCompletion || Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block)
            {
                return(res);
            }

            // Handle code completion

            if (keyChar != '\0' && CompletionWidget != null && currentCompletionContext == null)
            {
                currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;
                int triggerWordLength = currentCompletionContext.TriggerWordLength;
                ICompletionDataList completionList = HandleCodeCompletion(currentCompletionContext, keyChar,
                                                                          ref triggerWordLength);

                if (triggerWordLength > 0 && (triggerWordLength < Editor.Caret.Offset ||
                                              (triggerWordLength == 1 && Editor.Caret.Offset == 1)))
                {
                    currentCompletionContext
                        = CompletionWidget.CreateCodeCompletionContext(Editor.Caret.Offset - triggerWordLength);
                    currentCompletionContext.TriggerWordLength = triggerWordLength;
                }
                if (completionList != null)
                {
                    if (!CompletionWindowManager.ShowWindow(this, keyChar, completionList, CompletionWidget, currentCompletionContext))
                    {
                        currentCompletionContext = null;
                    }
                }
                else
                {
                    currentCompletionContext = null;
                }
            }

            if (EnableParameterInsight && CompletionWidget != null)
            {
                CodeCompletionContext  ctx           = CompletionWidget.CurrentCodeCompletionContext;
                IParameterDataProvider paramProvider = HandleParameterCompletion(ctx, keyChar);
                if (paramProvider != null)
                {
                    ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, paramProvider);
                }
            }

            autoHideCompletionWindow = true;

            return(res);
        }
コード例 #3
0
        // When a key is pressed, and before the key is processed by the editor, this method will be invoked.
        // Return true if the key press should be processed by the editor.
        public override bool KeyPress(Gdk.Key key, char keyChar, Gdk.ModifierType modifier)
        {
            bool res;

            KeyActions ka = KeyActions.None;

            if (currentCompletionContext != null)
            {
                if (CompletionWindowManager.PreProcessKeyEvent(key, keyChar, modifier, out ka))
                {
                    CompletionWindowManager.PostProcessKeyEvent(ka, key, keyChar, modifier);
                    autoHideCompletionWindow = true;
                    return(false);
                }
                autoHideCompletionWindow = false;
            }

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(CompletionWidget, key, modifier))
                {
                    return(false);
                }
                autoHideCompletionWindow = false;
            }

//			int oldPos = Editor.CursorPosition;
//			int oldLen = Editor.TextLength;

            res = base.KeyPress(key, keyChar, modifier);

            CompletionWindowManager.PostProcessKeyEvent(ka, key, keyChar, modifier);

            var ignoreMods = Gdk.ModifierType.ControlMask | Gdk.ModifierType.MetaMask
                             | Gdk.ModifierType.Mod1Mask | Gdk.ModifierType.SuperMask;

            // Handle parameter completion
            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                ParameterInformationWindowManager.PostProcessKeyEvent(CompletionWidget, key, modifier);
            }

            if ((modifier & ignoreMods) != 0)
            {
                return(res);
            }

            /*
             * if (Document.TextEditorData == null || Document.TextEditorData.IsSomethingSelected && Document.TextEditorData.SelectionMode != Mono.TextEditor.SelectionMode.Block) {
             *      int posChange = Editor.CursorPosition - oldPos;
             *      if (currentCompletionContext != null && (Math.Abs (posChange) > 1 || (Editor.TextLength - oldLen) != posChange)) {
             *              currentCompletionContext = null;
             *              CompletionWindowManager.HideWindow ();
             *              ParameterInformationWindowManager.HideWindow ();
             *              return res;
             *      }
             * }*/

            // don't complete on block selection
            if (!enableCodeCompletion || Document.Editor.SelectionMode == Mono.TextEditor.SelectionMode.Block)
            {
                return(res);
            }

            // Handle code completion

            if (keyChar != '\0' && CompletionWidget != null && currentCompletionContext == null)
            {
                currentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;

                int triggerWordLength = currentCompletionContext.TriggerWordLength;
                ICompletionDataList completionList = HandleCodeCompletion(currentCompletionContext, keyChar,
                                                                          ref triggerWordLength);

                if (triggerWordLength > 0 && (triggerWordLength < Editor.Caret.Offset ||
                                              (triggerWordLength == 1 && Editor.Caret.Offset == 1)))
                {
                    currentCompletionContext
                        = CompletionWidget.CreateCodeCompletionContext(Editor.Caret.Offset - triggerWordLength);
                    currentCompletionContext.TriggerWordLength = triggerWordLength;
                }

                if (completionList != null)
                {
                    if (!CompletionWindowManager.ShowWindow(keyChar, completionList, CompletionWidget,
                                                            currentCompletionContext, OnCompletionWindowClosed))
                    {
                        currentCompletionContext = null;
                    }
                }
                else
                {
                    currentCompletionContext = null;
                }
            }

            if (enableParameterInsight && CompletionWidget != null)
            {
                CodeCompletionContext  ctx           = CompletionWidget.CurrentCodeCompletionContext;
                IParameterDataProvider paramProvider = HandleParameterCompletion(ctx, keyChar);
                if (paramProvider != null)
                {
                    ParameterInformationWindowManager.ShowWindow(CompletionWidget, ctx, paramProvider);
                }
            }

            autoHideCompletionWindow = true;

            return(res);
        }
コード例 #4
0
        // When a key is pressed, and before the key is processed by the editor, this method will be invoked.
        // Return true if the key press should be processed by the editor.
        public override bool KeyPress(KeyDescriptor descriptor)
        {
            bool res;

            if (CurrentCompletionContext != null)
            {
                if (CompletionWindowManager.PreProcessKeyEvent(descriptor))
                {
                    CompletionWindowManager.PostProcessKeyEvent(descriptor);
                    autoHideCompletionWindow = true;
                    // in named parameter case leave the parameter window open.
                    autoHideParameterWindow = descriptor.KeyChar != ':';
                    if (!autoHideParameterWindow && ParameterInformationWindowManager.IsWindowVisible)
                    {
                        ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
                    }

                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(this, CompletionWidget, descriptor))
                {
                    return(false);
                }
                autoHideCompletionWindow = autoHideParameterWindow = false;
            }

            //			int oldPos = Editor.CursorPosition;
            //			int oldLen = Editor.TextLength;
            char deleteOrBackspaceTriggerChar = '\0';

            if (descriptor.SpecialKey == SpecialKey.Delete && Editor.CaretOffset < Editor.Length)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset);
            }
            if (descriptor.SpecialKey == SpecialKey.BackSpace && Editor.CaretOffset > 0)
            {
                deleteOrBackspaceTriggerChar = Editor.GetCharAt(Editor.CaretOffset - 1);
            }

            res = base.KeyPress(descriptor);

            CompletionWindowManager.PostProcessKeyEvent(descriptor);

            var ignoreMods = ModifierKeys.Control | ModifierKeys.Alt
                             | ModifierKeys.Command;

            // Handle parameter completion
            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                ParameterInformationWindowManager.PostProcessKeyEvent(this, CompletionWidget, descriptor);
            }

            if ((descriptor.ModifierKeys & ignoreMods) != 0)
            {
                return(res);
            }

            // don't complete on block selection
            if (/*!EnableCodeCompletion ||*/ Editor.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block)
            {
                return(res);
            }
            // Handle code completion
            if (descriptor.KeyChar != '\0' && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;
                completionTokenSrc.Cancel();
                completionTokenSrc = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleCodeCompletionAsync(CurrentCompletionContext, descriptor.KeyChar, token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;

                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                    CurrentCompletionContext = null;
                } catch (AggregateException) {
                    CurrentCompletionContext = null;
                }
            }

            if ((descriptor.SpecialKey == SpecialKey.Delete || descriptor.SpecialKey == SpecialKey.BackSpace) && CompletionWidget != null && !CompletionWindowManager.IsVisible)
            {
                CurrentCompletionContext = CompletionWidget.CurrentCodeCompletionContext;

                int cpos, wlen;
                if (!GetCompletionCommandOffset(out cpos, out wlen))
                {
                    cpos = Editor.CaretOffset;
                    wlen = 0;
                }
                CurrentCompletionContext.TriggerOffset     = cpos;
                CurrentCompletionContext.TriggerWordLength = wlen;

                completionTokenSrc.Cancel();
                completionTokenSrc = new CancellationTokenSource();
                var caretOffset = Editor.CaretOffset;
                var token       = completionTokenSrc.Token;
                try {
                    var task = HandleBackspaceOrDeleteCodeCompletionAsync(CurrentCompletionContext, descriptor.SpecialKey, deleteOrBackspaceTriggerChar, token);
                    if (task != null)
                    {
                        // Show the completion window in two steps. The call to PrepareShowWindow creates the window but
                        // it doesn't show it. It is used only to process the keys while the completion data is being retrieved.
                        CompletionWindowManager.PrepareShowWindow(this, descriptor.KeyChar, CompletionWidget, CurrentCompletionContext);
                        EventHandler windowClosed = delegate(object o, EventArgs a) {
                            completionTokenSrc.Cancel();
                        };
                        CompletionWindowManager.WindowClosed += windowClosed;

                        task.ContinueWith(t => {
                            CompletionWindowManager.WindowClosed -= windowClosed;
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            var result = t.Result;
                            if (result != null)
                            {
                                int triggerWordLength = result.TriggerWordLength + (Editor.CaretOffset - caretOffset);

                                if (triggerWordLength > 0 && (triggerWordLength < Editor.CaretOffset ||
                                                              (triggerWordLength == 1 && Editor.CaretOffset == 1)))
                                {
                                    CurrentCompletionContext = CompletionWidget.CreateCodeCompletionContext(Editor.CaretOffset - triggerWordLength);
                                    CurrentCompletionContext.TriggerWordLength = triggerWordLength;
                                }
                                // Now show the window for real.
                                if (!CompletionWindowManager.ShowWindow(result, CurrentCompletionContext))
                                {
                                    CurrentCompletionContext = null;
                                }
                                else
                                {
                                    CompletionWindowManager.Wnd.StartOffset = CurrentCompletionContext.TriggerOffset;
                                    CompletionWindowManager.Wnd.EndOffset   = Editor.CaretOffset;
                                }
                            }
                            else
                            {
                                CompletionWindowManager.HideWindow();
                                CurrentCompletionContext = null;
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                    else
                    {
                        CurrentCompletionContext = null;
                    }
                } catch (TaskCanceledException) {
                    CurrentCompletionContext = null;
                } catch (AggregateException) {
                    CurrentCompletionContext = null;
                }
            }

            if (CompletionWidget != null)
            {
                CodeCompletionContext ctx = CompletionWidget.CurrentCodeCompletionContext;
                parameterHintingSrc.Cancel();
                parameterHintingSrc = new CancellationTokenSource();
                var token = parameterHintingSrc.Token;
                try {
                    var task = HandleParameterCompletionAsync(ctx, descriptor.KeyChar, token);
                    if (task != null)
                    {
                        task.ContinueWith(t => {
                            if (!token.IsCancellationRequested && t.Result != null)
                            {
                                ParameterInformationWindowManager.ShowWindow(this, CompletionWidget, ctx, t.Result);
                            }
                        }, Runtime.MainTaskScheduler);
                    }
                } catch (TaskCanceledException) {
                } catch (AggregateException) {
                }
            }

            /*			autoHideCompletionWindow = true;
             *                      autoHideParameterWindow = keyChar != ':';*/
            return(res);
        }
コード例 #5
0
ファイル: TextEdit.cs プロジェクト: anthrax3/ide-1
        protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
        {
            char charKey = (char)Gdk.Keyval.ToUnicode(evnt.KeyValue);

            if ((evnt.State == Gdk.ModifierType.ControlMask) && (charKey == 'v'))
            {
                PasteClipboard();
                return(true);
            }
            ;
            if ((evnt.State == Gdk.ModifierType.ControlMask) && (charKey == 'c'))
            {
                CopyClipboard();
                return(true);
            }
            ;

            KeyActions ka = KeyActions.None;

            //if (currentCompletionContext != null) {
            if (CompletionWindowManager.PreProcessKeyEvent(evnt.Key, (char)evnt.Key, evnt.State, out ka))
            {
                CompletionWindowManager.PostProcessKeyEvent(ka);

                if (evnt.Key == Gdk.Key.Up || evnt.Key == Gdk.Key.Down || evnt.Key == Gdk.Key.Return ||
                    evnt.Key == Gdk.Key.Left || evnt.Key == Gdk.Key.Right)                          //)
                {
                    return(true);
                }
            }
            //}

            if (ParameterInformationWindowManager.IsWindowVisible)
            {
                if (ParameterInformationWindowManager.ProcessKeyEvent(this, evnt.Key, evnt.State))
                {
                    return(false);
                }
            }

            if (CompletionWindowManager.IsTemplateModes)
            {
                return(true);
            }


            bool result = base.OnKeyPressEvent(evnt);

            if (!MainClass.Settings.SourceEditorSettings.AggressivelyTriggerCL)
            {
                return(result);
            }
            if (banCompletion)
            {
                return(result);
            }

            completionType = CompletionTyp.allType;

            if ((evnt.State != Gdk.ModifierType.None) && charKey != '(' && charKey != ')')
            {
                return(result);
            }

            int         offset      = this.Document.LocationToOffset(this.Caret.Location);
            int         lineNumber  = this.Document.OffsetToLineNumber(offset);
            LineSegment lineSegment = this.Document.GetLine(lineNumber);

            string lineText = this.Document.GetTextBetween(lineSegment.Offset, offset);


            int countBrackets1 = lineText.Count(c => c == '(');
            int countBrackets2 = lineText.Count(c => c == ')');

            if (countBrackets1 <= countBrackets2)
            {
                ParameterInformationWindowManager.HideWindow(this);
            }

            if (((charKey == '\0') || (char.IsPunctuation(charKey)) &&
                 (char.IsSymbol(charKey))
                 // ||( char.IsWhiteSpace(charKey) )
                 ) &&
                (charKey != '#') &&
                (charKey != '_') &&
                (charKey != '.'))
            {
                return(result);
            }


            int endOffset = offset;

            offset = FindPrevWordOffset(offset);

            if (offset > 0 || endOffset > 0 || offset < endOffset)
            {
                int    offset2      = FindPrevWordOffsetStartSpace(offset);
                string previousWord = this.Document.GetTextBetween(offset2, offset).Trim();

                int    offset3         = FindPrevWordOffsetWithoutDot(offset);
                string previousWordDot = this.Document.GetTextBetween(offset3, offset).Trim();

                //Console.WriteLine("previousWord-> {0}",previousWord);
                //Console.WriteLine("previousWord-> {0}",previousWordDot);

                /*int lineNumber= this.Document.OffsetToLineNumber(endOffset);
                 * LineSegment lineSegment = this.Document.GetLine(lineNumber);
                 *
                 * string lineText =this.Document.GetTextBetween(lineSegment.Offset,endOffset);
                 */

                if (!string.IsNullOrEmpty(lineText))                  // som za komentarom
                {
                    if (lineText.Contains("//"))
                    {
                        return(result);
                    }
                }

                string docText = this.Document.GetTextBetween(0, endOffset);

                int countCommentStart = CountExpresion("/*", docText);             //
                int countCommentEnd   = CountExpresion("*/", docText);             //
                //int countComment = CountExpresion(""",docText);

                int countSem = docText.Count(c => c == '"');

                if (charKey == '(')
                {
                    int    offsetB       = FindPrevWordOffsetWithoutBrackets(offset);
                    string previousWordB = this.Document.GetTextBetween(offsetB, offset - 1).Trim();
                    if ((charKey == '(') || (previousWordB.Trim().Contains('(')))
                    {
                        ParameterDataProvider pdp = new ParameterDataProvider(this, previousWordB.Trim());

                        /*IParameterDataProvider cp = null;
                         * CodeCompletionContext ctx = CreateCodeCompletionContext (cpos);
                         * cp = ParameterCompletionCommand (ctx);
                         */
                        ParameterInformationWindowManager.ShowWindow(this, pdp);

                        return(result);
                    }
                    return(result);
                }
                if (charKey == ')')
                {
                    ParameterInformationWindowManager.HideWindow(this);
                    return(result);
                }

                /*if(lineText.Trim().StartsWith("include")){
                 *      completionType = CompletionTyp.includeType;
                 *
                 *      Gtk.Action act = MainClass.MainWindow.EditorNotebook.EditorAction.GetAction("sourceeditor_insertautocomplete");
                 *      if (act!=null){
                 *              act.Activate();
                 *      }
                 *      return result;
                 * }*/

                // komentar alebo string "" /**/
                if ((countCommentStart > countCommentEnd) || (!ItEven(countSem)))
                {
                    return(result);
                }

                if ((charKey == '.') || (previousWordDot.Trim().Contains('.')))
                {
                    completionType = CompletionTyp.dotType;
                }

                if (previousWord.Trim() == "new")
                {
                    completionType = CompletionTyp.newType;
                }



                string word = this.Document.GetTextAt(offset, endOffset - offset).Trim();
                if ((!IsKeyvord(previousWord.Trim()) && IsIdentifier(word)) ||
                    (previousWord.Trim() == "new") ||
                    (charKey == '.'))
                {
                    Gtk.Action act = MainClass.MainWindow.EditorNotebook.EditorAction.GetAction("sourceeditor_insertautocomplete");
                    if (act != null)
                    {
                        act.Activate();
                    }
                }
            }

            return(result);
        }