Example #1
0
        public void StartBind()
        {
            //== Prepare Keystroke
            Keystroke CtrlIns = new Keystroke(Keys.Insert, Keys.Control);
            Keystroke CtrlDel = new Keystroke(Keys.Delete, Keys.Control);
            Keystroke F2      = new Keystroke(Keys.F2, Keys.None);
            Keystroke F5      = new Keystroke(Keys.F5, Keys.None);
            Keystroke Enter   = new Keystroke(Keys.Enter, Keys.None);
            //Keystroke Esc = new Keystroke(Keys.Escape, Keys.None);

            //== Prepare action.
            ActionEvent actionAddNewRow = new ActionEvent();

            actionAddNewRow.Action += actionAddNewRow_Action;

            ActionEvent actionRemoveRow = new ActionEvent();

            actionRemoveRow.Action += actionRemoveRow_Action;

            ActionEvent actionF5 = new ActionEvent();

            actionF5.Action += actionF5_Action;

            //ActionEvent actionEsc = new ActionEvent();
            //actionEsc.Action += actionEsc_Action;


            //== Start bind keystroke and action.
            InputMap im  = m_owner.GetInputMap(InputMapMode.WhenFocused);
            InputMap imx = m_owner.GetInputMap(InputMapMode.WhenAncestorOfFocused);

            ActionMap am = m_owner.GetActionMap();

            im.Put(CtrlIns, eAction.AddRow.ToString());
            im.Put(CtrlDel, eAction.RemoveRow.ToString());
            im.Put(F2, SpreadActions.StopEditing);
            im.Put(F5, "F5");
            im.Put(Enter, SpreadActions.StartEditing);

            //imx.Put(Esc, "Esc");

            am.Put(eAction.AddRow.ToString(), actionAddNewRow);
            am.Put(eAction.RemoveRow.ToString(), actionRemoveRow);
            am.Put("F5", actionF5);
            //am.Put("Esc", actionEsc);


            m_bBind = true;
        }
Example #2
0
 public ColorfulLabel(string s) : base(s)
 {
     InputMap.Put(new KeyStroke('c', false, false, false), "color");
     ActionMap.Put("color", (o, args) =>
     {
         var rng    = new Random();
         var values = Enum.GetValues(typeof(ConsoleColor));
         Foreground = (ConsoleColor?)values.GetValue(rng.Next(values.Length));
         Print(args.Graphics);
     });
 }
Example #3
0
        public FileOptionsPanel(ImmutableList <File> f, AbstractHierarchicalDictionary <KeyStroke, string> inputMap)
        {
            TextComponent fileName;

            Strategy = new BorderStrategy();

            var topParent = new Parent(new LineStrategy {
                Orientation = Orientation.Vertical
            });

            AddComponent(topParent, BorderStrategy.Top);
            fileName = new TextComponent(f == null ? "Current directory options" :
                                         f.Count == 1 ? f[0].GetFileName() : f.Count + " files...")
            {
                HAlign = HorizontalAlignment.Centered
            };
            topParent.AddComponent(fileName);
            topParent.AddComponent(new Separator());

            var table = new TableComponent <FileOption>
            {
                Data = new ObservableCollection <FileOption>(f == null
                    ? FileOption.OptionsForCurrentDirectory
                                                             .Where(opt => opt.CanActionBeApplied?.Invoke(null, null) ?? true).ToList()
                    : FileOption.Options
                                                             .Where(opt => opt.CanActionBeApplied(f, null)).ToList()),
                ShowHeader = false
            };

            table.AddColumn(new IndicatorColumnType <FileOption>());
            table.AddColumn(new BasicColumnType <FileOption>("", option => option.Title)
            {
                GrowPriority = 1
            });
            table.AddColumn(
                new BasicColumnType <FileOption>("", option => SearchForShortcut(option.ActionName, inputMap))
            {
                HAlign = HorizontalAlignment.Right
            });
            table.ActionOnListElement += (sender, args) => { RemovalCallback(args.Item.ActionName, args.Graphics); };
            AddComponent(table, BorderStrategy.Center);

            var btn = new Button("Back");

            btn.ActionOnComponent += (sender, args) => RemovalCallback?.Invoke(null, args.Graphics);
            AddComponent(btn, BorderStrategy.Bottom);

            ActionMap.Put(StandardActionNames.CancelAction, (o, args) => RemovalCallback?.Invoke(null, args.Graphics));
        }