示例#1
0
        public void EditStatusItem(StatusItem statusItem)
        {
            if (statusItem == null)
            {
                Enabled = false;
                CleanEditStatusItem();
                return;
            }
            else
            {
                Enabled = true;
            }
            _statusItem     = statusItem;
            _txtTitle.Text  = statusItem?.Title ?? "";
            _txtAction.Text = statusItem != null && statusItem.Action != null?GetTargetAction(statusItem.Action) : ustring.Empty;

            _txtShortcut.Text = ShortcutHelper.GetShortcutTag(statusItem.Shortcut, StatusBar.ShortcutDelimiter) ?? "";
        }
示例#2
0
        public DynamicStatusBarDetails(ustring title) : base(title)
        {
            var _lblTitle = new Label("Title:")
            {
                Y = 1
            };

            Add(_lblTitle);

            _txtTitle = new TextField()
            {
                X     = Pos.Right(_lblTitle) + 4,
                Y     = Pos.Top(_lblTitle),
                Width = Dim.Fill()
            };
            Add(_txtTitle);

            var _lblAction = new Label("Action:")
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_lblTitle) + 1
            };

            Add(_lblAction);

            _txtAction = new TextView()
            {
                ColorScheme = Colors.Dialog,
                X           = Pos.Left(_txtTitle),
                Y           = Pos.Top(_lblAction),
                Width       = Dim.Fill(),
                Height      = 5
            };
            Add(_txtAction);

            var _lblShortcut = new Label("Shortcut:")
            {
                X = Pos.Left(_lblTitle),
                Y = Pos.Bottom(_txtAction) + 1
            };

            Add(_lblShortcut);

            _txtShortcut = new TextField()
            {
                X        = Pos.X(_txtAction),
                Y        = Pos.Y(_lblShortcut),
                Width    = Dim.Fill(),
                ReadOnly = true
            };
            _txtShortcut.KeyDown += (e) => {
                if (!ProcessKey(e.KeyEvent))
                {
                    return;
                }

                var k = ShortcutHelper.GetModifiersKey(e.KeyEvent);
                if (CheckShortcut(k, true))
                {
                    e.Handled = true;
                }
            };

            bool ProcessKey(KeyEvent ev)
            {
                switch (ev.Key)
                {
                case Key.CursorUp:
                case Key.CursorDown:
                case Key.Tab:
                case Key.BackTab:
                    return(false);
                }

                return(true);
            }

            bool CheckShortcut(Key k, bool pre)
            {
                var m = _statusItem != null ? _statusItem : new StatusItem(k, "", null);

                if (pre && !ShortcutHelper.PreShortcutValidation(k))
                {
                    _txtShortcut.Text = "";
                    return(false);
                }
                if (!pre)
                {
                    if (!ShortcutHelper.PostShortcutValidation(ShortcutHelper.GetShortcutFromTag(
                                                                   _txtShortcut.Text, StatusBar.ShortcutDelimiter)))
                    {
                        _txtShortcut.Text = "";
                        return(false);
                    }
                    return(true);
                }
                _txtShortcut.Text = ShortcutHelper.GetShortcutTag(k, StatusBar.ShortcutDelimiter);

                return(true);
            }

            _txtShortcut.KeyUp += (e) => {
                var k = ShortcutHelper.GetModifiersKey(e.KeyEvent);
                if (CheckShortcut(k, false))
                {
                    e.Handled = true;
                }
            };
            Add(_txtShortcut);

            var _btnShortcut = new Button("Clear Shortcut")
            {
                X = Pos.X(_lblShortcut),
                Y = Pos.Bottom(_txtShortcut) + 1
            };

            _btnShortcut.Clicked += () => {
                _txtShortcut.Text = "";
            };
            Add(_btnShortcut);
        }