Inheritance: Treefrog.Utility.Symbol
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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;
                }
            }
        }
Ejemplo n.º 5
0
 public void RegisterToggle(CommandKey key, Func <object, bool> performCheck, Action <object> perform)
 {
     _handlers[key] = new StatefulCommandHandler()
     {
         CanPerform = performCheck ?? DefaultStatefulCheck,
         Perform    = perform,
     };
 }
Ejemplo n.º 6
0
 public void Register(CommandKey key, Func <object, bool> performCheck, Action <object> perform)
 {
     _handlers[key] = new CommandHandler()
     {
         CanPerform = performCheck,
         Perform    = perform,
     };
 }
Ejemplo n.º 7
0
        protected bool CanHandleGroup(CommandKey key)
        {
            if (!CanHandle(key))
            {
                return(false);
            }

            return(CanHandleGroup(_handlers[key].Group));
        }
Ejemplo 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;
        }
Ejemplo 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);
         }
     }
 }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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));
        }
Ejemplo n.º 15
0
 public CommandMenuTag(CommandKey key, object param)
 {
     _key = key;
     _param = param;
 }
Ejemplo n.º 16
0
 public void Perform(CommandKey key)
 {
     Perform(key, null);
 }
Ejemplo 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);
     }
 }
Ejemplo n.º 18
0
 private void PerformCommand(CommandKey key)
 {
     if (_commandManager.CanPerform(key))
         _commandManager.Perform(key);
 }
Ejemplo n.º 19
0
 private bool CanPerformCommand(CommandKey key)
 {
     return _commandManager != null && _commandManager.CanPerform(key);
 }
Ejemplo n.º 20
0
        private bool CanPerformCommand(CommandKey key)
        {
            if (_editor.CurrentLevel == null || _editor.CurrentLevel.CommandManager == null)
                return false;

            return _editor.CurrentLevel.CommandManager.CanPerform(key);
        }
Ejemplo n.º 21
0
 public CommandMenuEntry(CommandKey key)
 {
     Key = key;
 }
Ejemplo 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);
            }
        }
Ejemplo n.º 23
0
 public void RegisterToggle(CommandToggleGroup group, CommandKey key, Func <bool> performCheck, Action perform)
 {
     RegisterToggle(group, key, (obj) => { return(performCheck()); }, (obj) => { perform(); });
 }
Ejemplo n.º 24
0
 public void Unregister(CommandKey key)
 {
     _handlers.Remove(key);
 }
Ejemplo n.º 25
0
 public void Invalidate(CommandKey key)
 {
     OnCommandInvalidated(new CommandSubscriberEventArgs(key));
 }
Ejemplo n.º 26
0
 public virtual bool CanHandle(CommandKey key)
 {
     return(_handlers.ContainsKey(key));
 }
Ejemplo n.º 27
0
 public bool CanPerform(CommandKey key)
 {
     return(CanPerform(key, null));
 }
Ejemplo n.º 28
0
 public CommandRecord Lookup(CommandKey key)
 {
     CommandRecord inst;
     if (_registry.TryGetValue(key, out inst))
         return inst;
     else
         return null;
 }
Ejemplo 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);
        }
Ejemplo n.º 30
0
 public void Register(CommandKey key, Func <bool> performCheck, Action perform)
 {
     Register(key, (obj) => { return(performCheck()); }, (obj) => { perform(); });
 }
Ejemplo n.º 31
0
 public CommandMenuEntry(CommandKey key, object param)
     : this(key)
 {
     Param = param;
 }
Ejemplo n.º 32
0
 public void RegisterToggle(CommandToggleGroup group, CommandKey key)
 {
     RegisterToggle(group, key, null as Func <object, bool>, null as Action <object>);
 }
Ejemplo n.º 33
0
        private void PerformCommand(CommandKey key)
        {
            if (_editor.CurrentLevel == null || _editor.CurrentLevel.CommandManager == null)
                return;

            _editor.CurrentLevel.CommandManager.Perform(key);
        }
Ejemplo 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);
        }
Ejemplo n.º 35
0
 private void Invalidate(CommandKey key)
 {
     if (_commandMap.ContainsKey(key)) {
         ToolStripButton item = _commandMap[key];
         item.Enabled = CanPerformCommand(key);
         item.Checked = IsCommandSelected(key);
     }
 }
Ejemplo n.º 36
0
 private void Invalidate(CommandKey key)
 {
     ToolStripButton button;
     if (_commandButtonMap.TryGetValue(key, out button)) {
         button.Enabled = CanPerformCommand(key);
         button.Checked = IsCommandSelected(key);
     }
 }
Ejemplo n.º 37
0
 private bool CanPerformCommand(CommandKey key, object param)
 {
     return _commandManager != null && _commandManager.CanPerform(key, param);
 }
Ejemplo n.º 38
0
 public CommandRecord(CommandKey key)
 {
     Key = key;
 }
Ejemplo n.º 39
0
 private bool IsCommandSelected(CommandKey key)
 {
     return _commandManager != null && _commandManager.IsSelected(key);
 }
Ejemplo n.º 40
0
 public CommandMenuTag(CommandKey key)
     : this(key, null)
 {
 }
Ejemplo n.º 41
0
 private void PerformCommand(CommandKey key, object param)
 {
     if (CanPerformCommand(key, param))
         _commandManager.Perform(key, param);
 }
Ejemplo n.º 42
0
 public CommandSubscriberEventArgs(CommandKey key)
 {
     CommandKey = key;
 }