Пример #1
0
		public MDSubMenuItem (CommandManager manager, CommandEntrySet ces, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null)
		{
			this.ces = ces;

			this.Submenu = new MDMenu (manager, ces, commandSource, initialCommandTarget);
			this.Title = this.Submenu.Title;
		}
Пример #2
0
		public TitleMenuItem (MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null)
		{
			this.manager = manager;
			this.initialCommandTarget = initialCommandTarget;
			this.commandSource = commandSource;
			this.commandArrayInfo = commandArrayInfo;

			this.menu = menu;
			menuEntry = entry;
			menuEntrySet = entry as CommandEntrySet;
			menuLinkEntry = entry as LinkCommandEntry;

			if (commandArrayInfo != null) {
				Header = commandArrayInfo.Text;

				var commandArrayInfoSet = commandArrayInfo as CommandInfoSet;
				if (commandArrayInfoSet != null) {
					foreach (var item in commandArrayInfoSet.CommandInfos) {
						if (item.IsArraySeparator)
							Items.Add (new Separator { UseLayoutRounding = true, });
						else
							Items.Add (new TitleMenuItem (manager, entry, item, commandSource, initialCommandTarget, menu));
					}
				}
			}

			if (menuEntrySet != null) {
				Header = menuEntrySet.Name;

				foreach (CommandEntry item in menuEntrySet) {
					if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator) {
						Items.Add (new Separator { UseLayoutRounding = true, });
					} else
						Items.Add (new TitleMenuItem (manager, item, menu: menu));
				}
			} else if (menuLinkEntry != null) {
				Header = menuLinkEntry.Text;
				Click += OnMenuLinkClicked;
			} else if (entry != null) {
				actionCommand = manager.GetCommand (menuEntry.CommandId) as ActionCommand;
				if (actionCommand == null)
					return;

				IsCheckable = actionCommand.ActionType == ActionType.Check;

				// FIXME: Use proper keybinding text.
				if (actionCommand.KeyBinding != null)
					InputGestureText = actionCommand.KeyBinding.ToString ();
				
				if (!actionCommand.Icon.IsNull)
					Icon = new Image { Source = actionCommand.Icon.GetImageSource (Xwt.IconSize.Small) };
				Click += OnMenuClicked;
			}

			Height = SystemParameters.CaptionHeight;
			UseLayoutRounding = true;
		}
Пример #3
0
		public MDMenu (CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget)
		{
			this.WeakDelegate = this;

			AutoEnablesItems = false;

			Title = (ces.Name ?? "").Replace ("_", "");

			foreach (CommandEntry ce in ces) {
				if (ce.CommandId == Command.Separator) {
					AddItem (NSMenuItem.SeparatorItem);
					if (!string.IsNullOrEmpty (ce.OverrideLabel))
						AddItem (new MDMenuHeaderItem (ce.OverrideLabel));
					continue;
				}

				if (string.Equals (ce.CommandId as string, servicesID, StringComparison.Ordinal)) {
					AddItem (new MDServicesMenuItem ());
					continue;
				}

				var subset = ce as CommandEntrySet;
				if (subset != null) {
					AddItem (new MDSubMenuItem (manager, subset, commandSource, initialCommandTarget));
					continue;
				}

				var lce = ce as LinkCommandEntry;
				if (lce != null) {
					AddItem (new MDLinkMenuItem (lce));
					continue;
				}

				Command cmd = manager.GetCommand (ce.CommandId);
				if (cmd == null) {
					LoggingService.LogError ("MacMenu: '{0}' maps to null command", ce.CommandId);
					continue;
				}

				if (cmd is CustomCommand) {
					LoggingService.LogWarning ("MacMenu: '{0}' is unsupported custom-rendered command' '", ce.CommandId);
					continue;
				}

				var acmd = cmd as ActionCommand;
				if (acmd == null) {
					LoggingService.LogWarning ("MacMenu: '{0}' has unknown command type '{1}'", cmd.GetType (), ce.CommandId);
					continue;
				}

				AddItem (new MDMenuItem (manager, ce, acmd, commandSource, initialCommandTarget));
			}
		}
Пример #4
0
		public MDMenuItem (CommandManager manager, CommandEntry ce, ActionCommand command, CommandSource commandSource, object initialCommandTarget)
		{
			this.ce = ce;
			this.manager = manager;
			this.initialCommandTarget = initialCommandTarget;
			this.commandSource = commandSource;

			isArrayItem = command.CommandArray;

			Target = this;
			Action = ActionSel;
		}
Пример #5
0
 /// <summary>
 /// Contructor
 /// </summary>
 public frmMain()
 {
     InitializeComponent();
     selectedOperation = CommandSource.workWithFolders;
     _commandParams = new CommandParameters();
     _executorParams = new ExecutorParameters();
     _executorParams.Source = selectedOperation;
     _commands = new CommandsCollection();
     _formats.Add("По умолчанию");
     _formats.Add("Unicode");
     _formats.Add("Big Endian Unicode");
     _formats.Add("ASCII");
     _formats.Add("UTF32");
     _formats.Add("UTF7");
     _formats.Add("UTF8");
 }
Пример #6
0
		/// <summary>
		/// Dispatches a command.
		/// </summary>
		/// <returns>
		/// True if a handler for the command was found
		/// </returns>
		/// <param name='commandId'>
		/// Identifier of the command
		/// </param>
		/// <param name='dataItem'>
		/// Data item for the command. It must be one of the data items obtained by calling GetCommandInfo.
		/// </param>
		/// <param name='source'>
		/// What is causing the command to be dispatched
		/// </param>
		public bool DispatchCommand (object commandId, object dataItem, CommandSource source)
		{
			return DispatchCommand (commandId, dataItem, null, source);
		}
        private async Task CommandHandler(DiscordClient client, MessageCreateEventArgs e)
        {
            var source = new CommandSource
            {
                Channel = e.Channel.Name,
                Message = e.Message.Content,
                User    = e.Author.Username
            };

            if (Array.Exists(BotUsers, element => element.ToLowerInvariant() == source.User.ToLowerInvariant()))
            {
                return;
            }

            try
            {
                foreach (var command in BotCommands)
                {
                    if (command.IsActivated(source))
                    {
                        if (command is IResponseMessage messageText)
                        {
                            await e.Channel.SendMessageAsync(messageText.GetMessageEvent(source));
                        }

                        if (command is IResponseImage messageImage)
                        {
                            var embed = new DiscordEmbedBuilder
                            {
                                ImageUrl = messageImage.GetImageEvent(source)
                            };
                            await e.Channel.SendMessageAsync("", false, embed);
                        }

                        if (command is IResponseVideo messageVideo)
                        {
                            var embed = new DiscordEmbedBuilder
                            {
                                Url = messageVideo.GetVideoEvent(source)
                            };
                            await e.Channel.SendMessageAsync("", false, embed);
                        }

                        if (command is IResponseAudio messageAudio)
                        {
                            var embed = new DiscordEmbedBuilder
                            {
                                Url = messageAudio.GetAudioEvent(source)
                            };
                            await e.Channel.SendMessageAsync("", false, embed);
                        }

                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);

                await e.Channel.SendMessageAsync(ex.Message);
            }
        }
Пример #8
0
 string ToggleAnnouncementMode(CommandSource source)
 {
     AnnouncementMode = AnnouncementMode == AnnouncementMode.Daily ? AnnouncementMode.Hourly : AnnouncementMode.Daily;
     return("Dogs will now change " + AnnouncementMode.ToString().ToLower() + ".");
 }
Пример #9
0
 string Post(CommandSource source)
 {
     CommandListener.FireCommand(DOTD);
     return(string.Empty);
 }
Пример #10
0
 string Unmute(CommandSource source)
 {
     Muted = false;
     return(string.Empty);
 }
Пример #11
0
		public MDMenu (CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget) : this (manager, ces, commandSource, initialCommandTarget, null)
		{
		}
Пример #12
0
        public MDMenuItem(CommandManager manager, CommandEntry ce, ActionCommand command, CommandSource commandSource, object initialCommandTarget)
        {
            this.ce      = ce;
            this.manager = manager;
            this.initialCommandTarget = initialCommandTarget;
            this.commandSource        = commandSource;

            isArrayItem = command.CommandArray;

            Target = this;
            Action = ActionSel;
        }
Пример #13
0
 public void ExecuteCommand(object cmd, object dataItem = null, CommandSource source = CommandSource.Unknown)
 {
     session.ExecuteCommand(cmd, dataItem, source);
 }
Пример #14
0
 static int Main_Simplest(string[] args)
 => CommandSource.Run <CliRoot>(args);
 /// <summary>
 /// Constructor
 /// </summary>
 public ExecutorParameters()
 {
     _source = CommandSource.workWithFolders;
     _format = Encoding.Default;
 }
Пример #16
0
 static int Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     return(CommandSource.Create(nameof(Format)).Run(args));
 }
Пример #17
0
 public virtual CommandResult Execute(CommandSource source)
 {
     return(new CommandResult());
 }
Пример #18
0
        public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null)
        {
            this.manager = manager;
            this.initialCommandTarget = initialCommandTarget;
            this.commandSource        = commandSource;
            this.commandArrayInfo     = commandArrayInfo;

            this.menu     = menu;
            menuEntry     = entry;
            menuEntrySet  = entry as CommandEntrySet;
            menuLinkEntry = entry as LinkCommandEntry;

            if (commandArrayInfo != null)
            {
                Header = commandArrayInfo.Text;

                var commandArrayInfoSet = commandArrayInfo as CommandInfoSet;
                if (commandArrayInfoSet != null)
                {
                    foreach (var item in commandArrayInfoSet.CommandInfos)
                    {
                        if (item.IsArraySeparator)
                        {
                            Items.Add(new Separator {
                                UseLayoutRounding = true,
                            });
                        }
                        else
                        {
                            Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget, menu));
                        }
                    }
                }
            }

            if (menuEntrySet != null)
            {
                Header = menuEntrySet.Name;

                foreach (CommandEntry item in menuEntrySet)
                {
                    if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator)
                    {
                        Items.Add(new Separator {
                            UseLayoutRounding = true,
                        });
                    }
                    else
                    {
                        Items.Add(new TitleMenuItem(manager, item, menu: menu));
                    }
                }
            }
            else if (menuLinkEntry != null)
            {
                Header = menuLinkEntry.Text;
                Click += OnMenuLinkClicked;
            }
            else if (entry != null)
            {
                actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand;
                if (actionCommand == null)
                {
                    return;
                }

                IsCheckable = actionCommand.ActionType == ActionType.Check;

                // FIXME: Use proper keybinding text.
                if (actionCommand.KeyBinding != null)
                {
                    InputGestureText = actionCommand.KeyBinding.ToString();
                }

                if (!actionCommand.Icon.IsNull)
                {
                    Icon = new Image {
                        Source = actionCommand.Icon.GetImageSource(Xwt.IconSize.Small)
                    }
                }
                ;
                Click += OnMenuClicked;
            }

            Height            = SystemParameters.CaptionHeight;
            UseLayoutRounding = true;
        }

        Menu menu;

        /// <summary>
        /// Updates a command entry. Should only be called from a toplevel node.
        /// This will update all the menu's children.
        /// </summary>
        void Update()
        {
            hasCommand = false;
            if (menuLinkEntry != null)
            {
                return;
            }

            if (menuEntrySet != null || commandArrayInfo is CommandInfoSet)
            {
                for (int i = 0; i < Items.Count; ++i)
                {
                    var titleMenuItem = Items[i] as TitleMenuItem;

                    if (titleMenuItem != null)
                    {
                        titleMenuItem.Update();
                        continue;
                    }

                    // If we have a separator, don't draw another one if the previous visible item is a separator.
                    var separatorMenuItem = Items [i] as Separator;
                    separatorMenuItem.Visibility = Visibility.Collapsed;
                    for (int j = i - 1; j >= 0; --j)
                    {
                        var iterMenuItem = Items [j] as Control;

                        if (iterMenuItem is Separator)
                        {
                            break;
                        }

                        if (iterMenuItem.Visibility != Visibility.Visible)
                        {
                            continue;
                        }

                        separatorMenuItem.Visibility = Visibility.Visible;
                        break;
                    }
                }
                if (menuEntrySet != null && menuEntrySet.AutoHide)
                {
                    Visibility = Items.Cast <Control> ().Any(item => item.Visibility == Visibility.Visible) ? Visibility.Visible : Visibility.Collapsed;
                }
                return;
            }

            var info = manager.GetCommandInfo(menuEntry.CommandId, new CommandTargetRoute(initialCommandTarget));

            if (actionCommand != null)
            {
                if (!string.IsNullOrEmpty(info.Description) && (string)ToolTip != info.Description)
                {
                    ToolTip = info.Description;
                }

                if (actionCommand.CommandArray && commandArrayInfo == null)
                {
                    Visibility = Visibility.Collapsed;

                    var parent = (TitleMenuItem)Parent;

                    int count       = 1;
                    int indexOfThis = parent.Items.IndexOf(this);
                    foreach (var child in info.ArrayInfo)
                    {
                        Control toAdd;
                        if (child.IsArraySeparator)
                        {
                            toAdd = new Separator();
                        }
                        else
                        {
                            toAdd = new TitleMenuItem(manager, menuEntry, child, menu: menu);
                        }

                        toRemoveFromParent.Add(toAdd);
                        parent.Items.Insert(indexOfThis + (count++), toAdd);
                    }
                    return;
                }
            }

            SetInfo(commandArrayInfo != null ? commandArrayInfo : info);
        }

        bool hasCommand = false;
        void SetInfo(CommandInfo info)
        {
            hasCommand = true;
            Header     = info.Text;
            Icon       = new Image {
                Source = info.Icon.GetImageSource(Xwt.IconSize.Small)
            };
            IsEnabled  = info.Enabled;
            Visibility = info.Visible && (menuEntry.DisabledVisible || IsEnabled) ?
                         Visibility.Visible : Visibility.Collapsed;
            IsChecked = info.Checked || info.CheckedInconsistent;
            ToolTip   = info.Description;
        }

        /// <summary>
        /// Clears a command entry's saved data. Should only be called from a toplevel node.
        /// This will update all the menu's children.
        /// </summary>
        IEnumerable <Control> Clear()
        {
            if (menuLinkEntry != null)
            {
                return(Enumerable.Empty <TitleMenuItem> ());
            }

            if (menuEntrySet != null)
            {
                var toRemove = Enumerable.Empty <Control> ();
                foreach (var item in Items)
                {
                    var titleMenuItem = item as TitleMenuItem;
                    if (titleMenuItem == null)
                    {
                        continue;
                    }

                    toRemove = toRemove.Concat(titleMenuItem.Clear());
                }

                foreach (var item in toRemove)
                {
                    Items.Remove(item);
                }

                return(Enumerable.Empty <TitleMenuItem> ());
            }

            var ret = toRemoveFromParent;

            toRemoveFromParent = new List <Control> ();
            return(ret);
        }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandMessageParser"/> class.
 /// </summary>
 /// <param name="messageBinder">The binder.</param>
 /// <param name="commandSource">The location that the parser will use to get the command.</param>
 public CommandMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, CommandSource commandSource)
     : base(conventionManager, messageBinder)
 {
     this.commandSource = commandSource;
 }
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandMessageParser"/> class.
 /// </summary>
 /// <param name="messageBinder">The message binder.</param>
 /// <param name="commandSource">The location that the parser will use to get the command.</param>
 public CommandMessageParser(IMessageBinder messageBinder, CommandSource commandSource)
     : this(messageBinder, UpdateSourceTrigger.PropertyChanged, commandSource)
 {
 }
Пример #21
0
 public void ExecuteCommand(object cmd, object dataItem = null, CommandSource source = CommandSource.Unknown)
 {
     Gtk.Application.Invoke(delegate {
         AutoTestService.CommandManager.DispatchCommand(cmd, dataItem, null, source);
     });
 }
Пример #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandMessageParser"/> class.
 /// </summary>
 /// <param name="messageBinder">The binder.</param>
 /// <param name="defaultTrigger">The default trigger.</param>
 /// <param name="commandSource">The location that the parser will use to get the command.</param>
 public CommandMessageParser(IMessageBinder messageBinder, UpdateSourceTrigger defaultTrigger, CommandSource commandSource)
     : base(messageBinder, defaultTrigger)
 {
     _commandSource = commandSource;
 }
Пример #23
0
        public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null)
        {
            this.manager = manager;
            this.initialCommandTarget = initialCommandTarget;
            this.commandSource        = commandSource;
            this.commandArrayInfo     = commandArrayInfo;

            this.menu     = menu;
            menuEntry     = entry;
            menuEntrySet  = entry as CommandEntrySet;
            menuLinkEntry = entry as LinkCommandEntry;

            if (commandArrayInfo != null)
            {
                Header = commandArrayInfo.Text;

                var commandArrayInfoSet = commandArrayInfo as CommandInfoSet;
                if (commandArrayInfoSet != null)
                {
                    foreach (var item in commandArrayInfoSet.CommandInfos)
                    {
                        if (item.IsArraySeparator)
                        {
                            Items.Add(new Separator {
                                UseLayoutRounding = true,
                            });
                        }
                        else
                        {
                            Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget, menu));
                        }
                    }
                }
            }

            if (menuEntrySet != null)
            {
                Header = menuEntrySet.Name;

                foreach (CommandEntry item in menuEntrySet)
                {
                    if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator)
                    {
                        Items.Add(new Separator {
                            UseLayoutRounding = true,
                        });
                    }
                    else
                    {
                        Items.Add(new TitleMenuItem(manager, item, menu: menu));
                    }
                }
            }
            else if (menuLinkEntry != null)
            {
                Header = menuLinkEntry.Text;
                Click += OnMenuLinkClicked;
            }
            else if (entry != null)
            {
                actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand;
                if (actionCommand == null)
                {
                    return;
                }

                IsCheckable = actionCommand.ActionType == ActionType.Check;

                // FIXME: Use proper keybinding text.
                if (actionCommand.KeyBinding != null)
                {
                    InputGestureText = actionCommand.KeyBinding.ToString();
                }

                try {
                    if (!actionCommand.Icon.IsNull)
                    {
                        Icon = new ImageBox(actionCommand.Icon.GetStockIcon().WithSize(Xwt.IconSize.Small));
                    }
                } catch (Exception ex) {
                    MonoDevelop.Core.LoggingService.LogError("Failed loading menu icon: " + actionCommand.Icon, ex);
                }
                Click += OnMenuClicked;
            }

            Height            = SystemParameters.CaptionHeight;
            UseLayoutRounding = true;
        }
		void OnCommandActivating (object commandId, CommandInfo commandInfo, object target, CommandSource source)
		{
			if (CommandActivating != null)
				CommandActivating (this, new CommandActivationEventArgs (commandId, commandInfo, target, source));
		}
Пример #25
0
		public CommandActivationEventArgs (object commandId, CommandInfo commandInfo, object dataItem, object target, CommandSource source, TimeSpan executionTime = default(TimeSpan))
		{
			this.CommandId = commandId;
			this.CommandInfo = commandInfo;
			this.Target = target;
			this.Source = source;
			this.DataItem = dataItem;
			this.ExecutionTime = executionTime;
		}			
Пример #26
0
		bool DefaultDispatchCommand (ActionCommand cmd, CommandInfo info, object dataItem, object target, CommandSource source)
		{
			DefaultUpdateCommandInfo (cmd, info);
			
			if (cmd.CommandArray) {
				//if (info.ArrayInfo.FindCommandInfo (dataItem) == null)
				//	return false;
			}
			else if (!info.Enabled || !info.Visible)
				return false;
			
			if (cmd.DefaultHandler == null) {
				if (cmd.DefaultHandlerType == null)
					return false;
				cmd.DefaultHandler = (CommandHandler) Activator.CreateInstance (cmd.DefaultHandlerType);
			}
			OnCommandActivating (cmd.Id, info, dataItem, target, source);
			cmd.DefaultHandler.InternalRun (dataItem);
			OnCommandActivated (cmd.Id, info, dataItem, target, source);
			return true;
		}
Пример #27
0
 string Mute(CommandSource source)
 {
     Muted = true;
     return(string.Empty);
 }
Пример #28
0
		public CommandActivationEventArgs (object commandId, CommandInfo commandInfo, object dataItem, object target, CommandSource source)
		{
			this.CommandId = commandId;
			this.CommandInfo = commandInfo;
			this.Target = target;
			this.Source = source;
			this.DataItem = dataItem;
		}			
Пример #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandMessageParser"/> class.
 /// </summary>
 /// <param name="messageBinder">The binder.</param>
 /// <param name="commandSource">The location that the parser will use to get the command.</param>
 public CommandMessageParser(IMessageBinder messageBinder, CommandSource commandSource)
     : base(messageBinder)
 {
     _commandSource = commandSource;
 }
Пример #30
0
 string Sort(CommandSource source)
 {
     Data.Queue.Sort();
     return("Queue has been sorted.");
 }
Пример #31
0
		public void ExecuteCommand (object cmd, object dataItem = null, CommandSource source = CommandSource.Unknown)
		{
			Gtk.Application.Invoke (delegate {
				AutoTestService.CommandManager.DispatchCommand (cmd, dataItem, null, source);
			});
		}
Пример #32
0
 public MDMenu(CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget) : this(manager, ces, commandSource, initialCommandTarget, null)
 {
 }
Пример #33
0
		void OnCommandActivated (object commandId, CommandInfo commandInfo, object dataItem, object target, CommandSource source)
		{
			if (CommandActivated != null)
				CommandActivated (this, new CommandActivationEventArgs (commandId, commandInfo, dataItem, target, source));
		}
Пример #34
0
        public MDMenu(CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget, EventHandler closeHandler)
        {
            CloseHandler      = closeHandler;
            this.WeakDelegate = this;

            AutoEnablesItems = false;

            var label = ces.Name ?? "";

            Title = ContextMenuItem.SanitizeMnemonics(label);
            foreach (CommandEntry ce in ces)
            {
                if (ce.CommandId == Command.Separator)
                {
                    AddItem(NSMenuItem.SeparatorItem);
                    continue;
                }

                if (string.Equals(ce.CommandId as string, servicesID, StringComparison.Ordinal))
                {
                    AddItem(new MDServicesMenuItem());
                    continue;
                }

                var subset = ce as CommandEntrySet;
                if (subset != null)
                {
                    AddItem(new MDSubMenuItem(manager, subset, commandSource, initialCommandTarget));
                    continue;
                }

                var lce = ce as LinkCommandEntry;
                if (lce != null)
                {
                    AddItem(new MDLinkMenuItem(lce));
                    continue;
                }

                Command cmd = manager.GetCommand(ce.CommandId);
                if (cmd == null)
                {
                    LoggingService.LogError("MacMenu: '{0}' maps to null command", ce.CommandId);
                    continue;
                }

                if (cmd is CustomCommand)
                {
                    LoggingService.LogWarning("MacMenu: '{0}' is unsupported custom-rendered command' '", ce.CommandId);
                    continue;
                }

                var acmd = cmd as ActionCommand;
                if (acmd == null)
                {
                    LoggingService.LogWarning("MacMenu: '{0}' has unknown command type '{1}'", cmd.GetType(), ce.CommandId);
                    continue;
                }

                AddItem(new MDMenuItem(manager, ce, acmd, commandSource, initialCommandTarget));
            }
        }
Пример #35
0
		/// <summary>
		/// Dispatches a command.
		/// </summary>
		/// <returns>
		/// True if a handler for the command was found
		/// </returns>
		/// <param name='commandId'>
		/// Identifier of the command
		/// </param>
		/// <param name='source'>
		/// What is causing the command to be dispatched
		/// </param>
		public bool DispatchCommand (object commandId, CommandSource source)
		{
			return DispatchCommand (commandId, null, null, source);
		}
Пример #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandMessageParser"/> class.
 /// </summary>
 /// <param name="conventionManager">The convention mangager.</param>
 /// <param name="messageBinder">The message binder.</param>
 /// <param name="commandSource">The location that the parser will use to get the command.</param>
 public CommandMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, CommandSource commandSource)
     : this(conventionManager, messageBinder, UpdateSourceTrigger.PropertyChanged, commandSource)
 {
 }
Пример #37
0
		/// <summary>
		/// Dispatches a command.
		/// </summary>
		/// <returns>
		/// True if a handler for the command was found
		/// </returns>
		/// <param name='commandId'>
		/// Identifier of the command
		/// </param>
		/// <param name='dataItem'>
		/// Data item for the command. It must be one of the data items obtained by calling GetCommandInfo.
		/// </param>
		/// <param name='initialTarget'>
		/// Initial command route target. The command handler will start looking for command handlers in this object.
		/// </param>
		/// <param name='source'>
		/// What is causing the command to be dispatched
		/// </param>
		public bool DispatchCommand (object commandId, object dataItem, object initialTarget, CommandSource source)
		{
			RegisterUserInteraction ();
			
			if (guiLock > 0)
				return false;

			commandId = CommandManager.ToCommandId (commandId);
			
			List<HandlerCallback> handlers = new List<HandlerCallback> ();
			ActionCommand cmd = null;
			try {
				cmd = GetActionCommand (commandId);
				if (cmd == null)
					return false;

				CurrentCommand = cmd;
				CommandTargetRoute targetRoute = new CommandTargetRoute (initialTarget);
				object cmdTarget = GetFirstCommandTarget (targetRoute);
				CommandInfo info = new CommandInfo (cmd);

				while (cmdTarget != null)
				{
					HandlerTypeInfo typeInfo = GetTypeHandlerInfo (cmdTarget);
					
					bool bypass = false;
					
					CommandUpdaterInfo cui = typeInfo.GetCommandUpdater (commandId);
					if (cui != null) {
						if (cmd.CommandArray) {
							// Make sure that the option is still active
							info.ArrayInfo = new CommandArrayInfo (info);
							cui.Run (cmdTarget, info.ArrayInfo);
							if (!info.ArrayInfo.Bypass) {
								if (info.ArrayInfo.FindCommandInfo (dataItem) == null)
									return false;
							} else
								bypass = true;
						} else {
							info.Bypass = false;
							cui.Run (cmdTarget, info);
							bypass = info.Bypass;
							
							if (!bypass && (!info.Enabled || !info.Visible))
								return false;
						}
					}
					
					if (!bypass) {
						CommandHandlerInfo chi = typeInfo.GetCommandHandler (commandId);
						if (chi != null) {
							object localTarget = cmdTarget;
							if (cmd.CommandArray) {
								handlers.Add (delegate {
									OnCommandActivating (commandId, info, dataItem, localTarget, source);
									chi.Run (localTarget, cmd, dataItem);
									OnCommandActivated (commandId, info, dataItem, localTarget, source);
								});
							}
							else {
								handlers.Add (delegate {
									OnCommandActivating (commandId, info, dataItem, localTarget, source);
									chi.Run (localTarget, cmd);
									OnCommandActivated (commandId, info, dataItem, localTarget, source);
								});
							}
							handlerFoundInMulticast = true;
							cmdTarget = NextMulticastTarget (targetRoute);
							if (cmdTarget == null)
								break;
							else
								continue;
						}
					}
					cmdTarget = GetNextCommandTarget (targetRoute, cmdTarget);
				}

				if (handlers.Count > 0) {
					foreach (HandlerCallback c in handlers)
						c ();
					UpdateToolbars ();
					return true;
				}
	
				if (DefaultDispatchCommand (cmd, info, dataItem, cmdTarget, source)) {
					UpdateToolbars ();
					return true;
				}
			}
			catch (Exception ex) {
				string name = (cmd != null && cmd.Text != null && cmd.Text.Length > 0) ? cmd.Text : commandId.ToString ();
				name = name.Replace ("_","");
				ReportError (commandId, "Error while executing command: " + name, ex);
			}
			finally {
				CurrentCommand = null;
			}
			return false;
		}
Пример #38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandMessageParser"/> class.
 /// </summary>
 /// <param name="conventionManager">The convention manager.</param>
 /// <param name="messageBinder">The binder.</param>
 /// <param name="defaultTrigger">The default trigger.</param>
 /// <param name="commandSource">The location that the parser will use to get the command.</param>
 public CommandMessageParser(IConventionManager conventionManager, IMessageBinder messageBinder, UpdateSourceTrigger defaultTrigger, CommandSource commandSource)
     : base(conventionManager, messageBinder, defaultTrigger)
 {
     this.commandSource = commandSource;
 }