Inheritance: Treefrog.Utility.Symbol
Esempio n. 1
0
        protected virtual void StatefulPerform(CommandKey key, object param)
        {
            CommandHandler handler;

            if (!_handlers.TryGetValue(key, out handler))
            {
                return;
            }

            StatefulCommandHandler stateHandler = handler as StatefulCommandHandler;

            if (stateHandler == null)
            {
                return;
            }

            stateHandler.Selected = !stateHandler.Selected;

            if (stateHandler.Perform != null)
            {
                stateHandler.Perform(param);
            }

            Invalidate(key);
        }
Esempio n. 2
0
        public virtual bool IsSelected(CommandKey key)
        {
            CommandHandler handler;

            if (!_handlers.TryGetValue(key, out handler))
            {
                return(false);
            }

            StatefulCommandHandler stateHandler = handler as StatefulCommandHandler;

            if (stateHandler != null)
            {
                return(stateHandler.Selected);
            }

            CommandGroup group;

            if (!_toggleGroups.TryGetValue(handler.Group, out group))
            {
                return(false);
            }

            return(group.Selected == key);
        }
Esempio n. 3
0
        protected virtual void GroupPerform(CommandKey key, object param)
        {
            CommandHandler handler;

            if (!_handlers.TryGetValue(key, out handler))
            {
                return;
            }

            CommandGroup group;

            if (!_toggleGroups.TryGetValue(handler.Group, out group))
            {
                return;
            }

            if (group.Selected == key)
            {
                return;
            }

            group.Selected = key;

            if (group.Handler.Perform != null)
            {
                group.Handler.Perform(param);
            }

            if (handler.Perform != null)
            {
                handler.Perform(param);
            }

            InvalidateGroup(handler.Group);
        }
Esempio n. 4
0
        public override void Perform(CommandKey key, object param)
        {
            if (base.CanHandle(key))
            {
                base.Perform(key, param);
                return;
            }

            foreach (ICommandSubscriber subscriber in _forwardManagers)
            {
                if (subscriber == null || subscriber.CommandManager == null)
                {
                    continue;
                }
                if (!subscriber.CommandManager.CanPerform(key, param))
                {
                    continue;
                }

                subscriber.CommandManager.Perform(key, param);
                if (!IsMulticast)
                {
                    break;
                }
            }
        }
Esempio n. 5
0
 public void RegisterToggle(CommandKey key, Func <object, bool> performCheck, Action <object> perform)
 {
     _handlers[key] = new StatefulCommandHandler()
     {
         CanPerform = performCheck ?? DefaultStatefulCheck,
         Perform    = perform,
     };
 }
Esempio n. 6
0
 public void Register(CommandKey key, Func <object, bool> performCheck, Action <object> perform)
 {
     _handlers[key] = new CommandHandler()
     {
         CanPerform = performCheck,
         Perform    = perform,
     };
 }
Esempio n. 7
0
        protected bool CanHandleGroup(CommandKey key)
        {
            if (!CanHandle(key))
            {
                return(false);
            }

            return(CanHandleGroup(_handlers[key].Group));
        }
Esempio n. 8
0
        public void RegisterToggle(CommandToggleGroup group, CommandKey key, Func <object, bool> performCheck, Action <object> perform)
        {
            if (!_toggleGroups[group].Members.Contains(key))
            {
                _toggleGroups[group].Members.Add(key);
            }

            Register(key, performCheck, perform);

            _handlers[key].Group = group;
        }
Esempio n. 9
0
 public virtual void Perform(CommandKey key, object param)
 {
     if (CanHandleGroup(key))
     {
         GroupPerform(key, param);
     }
     else if (CanHandle(key))
     {
         if (_handlers[key] is StatefulCommandHandler)
         {
             StatefulPerform(key, param);
         }
         else if (_handlers[key].Perform != null)
         {
             _handlers[key].Perform(param);
         }
     }
 }
Esempio n. 10
0
        public virtual bool CanPerform(CommandKey key, object param)
        {
            if (!CanHandle(key))
            {
                return(false);
            }

            if (GroupCanPerform(key, param))
            {
                return(true);
            }

            if (_handlers[key].CanPerform != null && _handlers[key].CanPerform(param))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 11
0
        public override bool CanPerform(CommandKey key, object param)
        {
            if (base.CanHandle(key))
            {
                return(base.CanPerform(key, param));
            }

            foreach (ICommandSubscriber subscriber in _forwardManagers)
            {
                if (subscriber == null || subscriber.CommandManager == null)
                {
                    continue;
                }
                if (subscriber.CommandManager.CanPerform(key, param))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 12
0
        public override bool IsSelected(CommandKey key)
        {
            if (base.CanHandle(key))
            {
                return(base.IsSelected(key));
            }

            foreach (ICommandSubscriber subscriber in _forwardManagers)
            {
                if (subscriber == null || subscriber.CommandManager == null)
                {
                    continue;
                }
                if (subscriber.CommandManager.IsSelected(key))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 13
0
        public override CommandKey SelectedCommand(CommandToggleGroup group)
        {
            if (base.CanHandleGroup(group))
            {
                return(base.SelectedCommand(group));
            }

            foreach (ICommandSubscriber subscriber in _forwardManagers)
            {
                if (subscriber == null || subscriber.CommandManager == null)
                {
                    continue;
                }
                CommandKey selected = subscriber.CommandManager.SelectedCommand(group);
                if (selected != CommandKey.Unknown)
                {
                    return(selected);
                }
            }

            return(CommandKey.Unknown);
        }
Esempio n. 14
0
        protected virtual bool GroupCanPerform(CommandKey key, object param)
        {
            CommandHandler handler;

            if (!_handlers.TryGetValue(key, out handler))
            {
                return(false);
            }

            CommandGroup group;

            if (!_toggleGroups.TryGetValue(handler.Group, out group))
            {
                return(false);
            }

            if (group.Handler.CanPerform == null)
            {
                return(false);
            }

            return(group.Handler.CanPerform(param));
        }
Esempio n. 15
0
 public CommandMenuTag(CommandKey key, object param)
 {
     _key = key;
     _param = param;
 }
Esempio n. 16
0
 public void Perform(CommandKey key)
 {
     Perform(key, null);
 }
Esempio n. 17
0
 private void Invalidate(CommandKey key)
 {
     if (_buttonMap.ContainsKey(key)) {
         ToolStripButton item = _buttonMap[key];
         item.Enabled = CanPerformCommand(key, TagValueFromItem(item));
         item.Checked = IsCommandSelected(key);
     }
     if (_menuMap.ContainsKey(key)) {
         ToolStripMenuItem item = _menuMap[key];
         item.Enabled = CanPerformCommand(key, TagValueFromItem(item));
         item.Checked = IsCommandSelected(key);
     }
 }
Esempio n. 18
0
 private void PerformCommand(CommandKey key)
 {
     if (_commandManager.CanPerform(key))
         _commandManager.Perform(key);
 }
Esempio n. 19
0
 private bool CanPerformCommand(CommandKey key)
 {
     return _commandManager != null && _commandManager.CanPerform(key);
 }
        private bool CanPerformCommand(CommandKey key)
        {
            if (_editor.CurrentLevel == null || _editor.CurrentLevel.CommandManager == null)
                return false;

            return _editor.CurrentLevel.CommandManager.CanPerform(key);
        }
Esempio n. 21
0
 public CommandMenuEntry(CommandKey key)
 {
     Key = key;
 }
Esempio n. 22
0
        private void MapMenuItem(CommandKey key, ToolStripMenuItem item)
        {
            if (key != CommandKey.Unknown && item != null) {
                _menuMap.Add(key, item);
                item.Click += BoundMenuClickHandler;

                Invalidate(key);
            }
        }
Esempio n. 23
0
 public void RegisterToggle(CommandToggleGroup group, CommandKey key, Func <bool> performCheck, Action perform)
 {
     RegisterToggle(group, key, (obj) => { return(performCheck()); }, (obj) => { perform(); });
 }
Esempio n. 24
0
 public void Unregister(CommandKey key)
 {
     _handlers.Remove(key);
 }
Esempio n. 25
0
 public void Invalidate(CommandKey key)
 {
     OnCommandInvalidated(new CommandSubscriberEventArgs(key));
 }
Esempio n. 26
0
 public virtual bool CanHandle(CommandKey key)
 {
     return(_handlers.ContainsKey(key));
 }
Esempio n. 27
0
 public bool CanPerform(CommandKey key)
 {
     return(CanPerform(key, null));
 }
Esempio n. 28
0
 public CommandRecord Lookup(CommandKey key)
 {
     CommandRecord inst;
     if (_registry.TryGetValue(key, out inst))
         return inst;
     else
         return null;
 }
Esempio n. 29
0
        private static void Register(CommandKey key, string displayName, Image resource = null, Keys shortcut = Keys.None, string description = null, string shortcutDisplay = null)
        {
            CommandRecord record = new CommandRecord(key) {
                DisplayName = displayName,
                Description = description,
                Shortcut = shortcut,
                ShortcutDisplay = shortcutDisplay,
            };

            if (resource != null)
                record.Image = resource;

            _default.Register(record);
        }
Esempio n. 30
0
 public void Register(CommandKey key, Func <bool> performCheck, Action perform)
 {
     Register(key, (obj) => { return(performCheck()); }, (obj) => { perform(); });
 }
Esempio n. 31
0
 public CommandMenuEntry(CommandKey key, object param)
     : this(key)
 {
     Param = param;
 }
Esempio n. 32
0
 public void RegisterToggle(CommandToggleGroup group, CommandKey key)
 {
     RegisterToggle(group, key, null as Func <object, bool>, null as Action <object>);
 }
        private void PerformCommand(CommandKey key)
        {
            if (_editor.CurrentLevel == null || _editor.CurrentLevel.CommandManager == null)
                return;

            _editor.CurrentLevel.CommandManager.Perform(key);
        }
Esempio n. 34
0
        private static void Register(CommandKey key, string displayName, string resource = null, Keys shortcut = Keys.None, string description = null, string shortcutDisplay = null)
        {
            CommandRecord record = new CommandRecord(key) {
                DisplayName = displayName,
                Description = description,
                Shortcut = shortcut,
                ShortcutDisplay = shortcutDisplay,
            };

            if (resource != null)
                record.Image = Image.FromStream(_assembly.GetManifestResourceStream(resource));

            _default.Register(record);
        }
Esempio n. 35
0
 private void Invalidate(CommandKey key)
 {
     if (_commandMap.ContainsKey(key)) {
         ToolStripButton item = _commandMap[key];
         item.Enabled = CanPerformCommand(key);
         item.Checked = IsCommandSelected(key);
     }
 }
Esempio n. 36
0
 private void Invalidate(CommandKey key)
 {
     ToolStripButton button;
     if (_commandButtonMap.TryGetValue(key, out button)) {
         button.Enabled = CanPerformCommand(key);
         button.Checked = IsCommandSelected(key);
     }
 }
Esempio n. 37
0
 private bool CanPerformCommand(CommandKey key, object param)
 {
     return _commandManager != null && _commandManager.CanPerform(key, param);
 }
Esempio n. 38
0
 public CommandRecord(CommandKey key)
 {
     Key = key;
 }
Esempio n. 39
0
 private bool IsCommandSelected(CommandKey key)
 {
     return _commandManager != null && _commandManager.IsSelected(key);
 }
Esempio n. 40
0
 public CommandMenuTag(CommandKey key)
     : this(key, null)
 {
 }
Esempio n. 41
0
 private void PerformCommand(CommandKey key, object param)
 {
     if (CanPerformCommand(key, param))
         _commandManager.Perform(key, param);
 }
Esempio n. 42
0
 public CommandSubscriberEventArgs(CommandKey key)
 {
     CommandKey = key;
 }