Exemple #1
0
        [GLib.ConnectBefore] // Otherwise this is handled internally, and we won't see it
        private void OnKeyPress(object sender, KeyPressEventArgs e)
        {
            char keyChar      = (char)Gdk.Keyval.ToUnicode(e.Event.KeyValue);
            bool controlSpace = IsControlSpace(e.Event);

            if (e.Event.Key == Gdk.Key.F3)
            {
                if (string.IsNullOrEmpty(_findForm.LookFor))
                {
                    _findForm.ShowFor(textEditor, false);
                }
                else
                {
                    _findForm.FindNext(true, (e.Event.State & Gdk.ModifierType.ShiftMask) == 0, string.Format("Search text «{0}» not found.", _findForm.LookFor));
                }
                e.RetVal = true;
            }
            else if (IntelliSenseChars.Contains(keyChar.ToString()) || controlSpace)
            {
                // If user one of the IntelliSenseChars, then display contextlist.
                string textBeforePeriod = GetWordBeforePosition(textEditor.Caret.Offset) + keyChar;

                // If the user entered a period, we need to take that into account when generating intellisense options.
                // To do this, we insert a period manually and stop the Gtk signal from propagating further.
                e.RetVal = true;
                if (keyChar == '.')
                {
                    textEditor.InsertAtCaret(keyChar.ToString());

                    // Process all events in the main loop, so that the period is inserted into the text editor.
                    while (GLib.MainContext.Iteration())
                    {
                        ;
                    }
                }
                NeedContextItemsArgs args = new NeedContextItemsArgs
                {
                    Coordinates  = GetPositionOfCursor(),
                    Code         = textEditor.Text,
                    Offset       = this.Offset,
                    ControlSpace = controlSpace,
                    LineNo       = textEditor.Caret.Line,
                    ColNo        = textEditor.Caret.Column - 1
                };

                ContextItemsNeeded?.Invoke(this, args);
            }
            else if (e.Event.Key == Gdk.Key.Key_0 && (e.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)
            {
                textEditor.Options.ZoomReset();
                e.RetVal = true;
            }
            else
            {
                e.RetVal = false;
            }
        }
Exemple #2
0
        [GLib.ConnectBefore] // Otherwise this is handled internally, and we won't see it
        private void OnKeyPress(object sender, KeyPressEventArgs e)
        {
            e.RetVal = false;
            char keyChar = (char)Gdk.Keyval.ToUnicode(e.Event.KeyValue);

            Gdk.ModifierType ctlModifier = !APSIM.Shared.Utilities.ProcessUtilities.CurrentOS.IsMac ? Gdk.ModifierType.ControlMask
                                           //Mac window manager already uses control-scroll, so use command
                                           //Command might be either meta or mod1, depending on GTK version
                : (Gdk.ModifierType.MetaMask | Gdk.ModifierType.Mod1Mask);

            bool   controlSpace      = IsControlSpace(e.Event);
            bool   controlShiftSpace = IsControlShiftSpace(e.Event);
            string textBeforePeriod  = GetWordBeforePosition(textEditor.Caret.Offset);
            double x; // unused, but needed as an out parameter.

            if (e.Event.Key == Gdk.Key.F3)
            {
                if (string.IsNullOrEmpty(findForm.LookFor))
                {
                    findForm.ShowFor(textEditor, false);
                }
                else
                {
                    findForm.FindNext(true, (e.Event.State & Gdk.ModifierType.ShiftMask) == 0, string.Format("Search text «{0}» not found.", findForm.LookFor));
                }
                e.RetVal = true;
            }
            // If the text before the period is not a number and the user pressed either one of the intellisense characters or control-space:
            else if (!double.TryParse(textBeforePeriod.Replace(".", ""), out x) && (IntelliSenseChars.Contains(keyChar.ToString()) || controlSpace || controlShiftSpace))
            {
                // If the user entered a period, we need to take that into account when generating intellisense options.
                // To do this, we insert a period manually and stop the Gtk signal from propagating further.
                e.RetVal = true;
                if (keyChar == '.')
                {
                    textEditor.InsertAtCaret(keyChar.ToString());

                    // Process all events in the main loop, so that the period is inserted into the text editor.
                    while (GLib.MainContext.Iteration())
                    {
                        ;
                    }
                }
                NeedContextItemsArgs args = new NeedContextItemsArgs
                {
                    Coordinates       = GetPositionOfCursor(),
                    Code              = textEditor.Text,
                    Offset            = this.Offset,
                    ControlSpace      = controlSpace,
                    ControlShiftSpace = controlShiftSpace,
                    LineNo            = textEditor.Caret.Line,
                    ColNo             = textEditor.Caret.Column - 1
                };

                ContextItemsNeeded?.Invoke(this, args);
            }
            else if ((e.Event.State & ctlModifier) != 0)
            {
                switch (e.Event.Key)
                {
                case Gdk.Key.Key_0: textEditor.Options.ZoomReset(); e.RetVal = true; break;

                case Gdk.Key.KP_Add:
                case Gdk.Key.plus: textEditor.Options.ZoomIn(); e.RetVal = true; break;

                case Gdk.Key.KP_Subtract:
                case Gdk.Key.minus: textEditor.Options.ZoomOut(); e.RetVal = true; break;
                }
            }
        }