/// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        ///	<param name="commandManager">The CommandManager to use.</param>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition of the commands to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(CommandManager commandManager, Control parentWindow, Point position, int alternateXPosition, CommandContextMenuDefinition commandContextMenuDefinition)
        {
            //	If the command context menu definition was null, or contained no Command identifiers, we're done.
            Debug.Assert(commandContextMenuDefinition != null, "Cannot show a CommandContextMenu without a CommandContextMenuDefinition");
            if (commandContextMenuDefinition == null || commandContextMenuDefinition.Entries.Count == 0)
                return null;

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command context menu definition.
            CommandContextMenu commandContextMenu = new CommandContextMenu(commandManager, commandContextMenuDefinition);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return command;
        }
        /// <summary>
        /// Builds the menu items of this CommandContextMenu from the specified CommandContextMenuDefinition.
        /// </summary>
        /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition.</param>
        private void BuildMenuItems(CommandManager commandManager, CommandContextMenuDefinition commandContextMenuDefinition)
        {
            //	Raise the BeforeShowMenu event in the CommandContextMenuDefinition, allowing
            //	interested parties to manage commands.
            commandContextMenuDefinition.RaiseBeforeShowMenu();

            //	Build the menu items.
            if (commandContextMenuDefinition.Entries.Count != 0)
            {
                MenuItems.AddRange(MenuBuilder.CreateMenuItems(commandManager, commandContextMenuDefinition));
            }
        }
예제 #3
0
        internal static PushpinContextCommand ShowPushpinContextMenu(Control parent, Point location, CommandManager commandManager)
        {
            Command command;
            using (CommandLoader commandLoader = new CommandLoader(commandManager, PushpinContextMenuIds))
            {
                CommandContextMenuDefinition ccmd = new CommandContextMenuDefinition();
                ccmd.CommandBar = false;
                ccmd.Entries.Add(CommandId.MapEditPushpin, false, false);
                ccmd.Entries.Add(CommandId.MapDeletePushpin, false, false);

                command = CommandContextMenu.ShowModal(
                    commandManager, parent, location, ccmd);
            }

            if (command != null)
                return (PushpinContextCommand)_pushpinCommandIds[Enum.Parse(typeof(CommandId), command.Identifier)];
            else
                return PushpinContextCommand.None;
        }
예제 #4
0
        internal static MapContextCommand ShowMapContextMenu(Control parent, Point location, MapContextCommand[] hideCommands, CommandManager commandManager)
        {
            Command returnCommand;
            using (CommandLoader commandLoader = new CommandLoader(commandManager, FilterMapContextMenuCommands(hideCommands)))
            {
                CommandContextMenuDefinition ccmd = new CommandContextMenuDefinition();
                ccmd.CommandBar = false;
                ccmd.Entries.Add(CommandId.MapAddPushpin, false, true);
                ccmd.Entries.Add(CommandId.MapZoomStreetLevel, false, false);
                ccmd.Entries.Add(CommandId.MapZoomCityLevel, false, false);
                ccmd.Entries.Add(CommandId.MapZoomRegionLevel, false, false);
                ccmd.Entries.Add(CommandId.MapCenterMap, false, false);

                returnCommand = CommandContextMenu.ShowModal(
                    commandManager, parent, location, ccmd);
            }

            if (returnCommand != null)
                return (MapContextCommand)_mapCommandIds[Enum.Parse(typeof(CommandId), returnCommand.Identifier)];
            else
                return MapContextCommand.None;
        }
        private CommandContextMenuDefinition MergeContextMenuDefinitions(CommandContextMenuDefinition menu1, CommandContextMenuDefinition menu2)
        {
            // menu to return
            CommandContextMenuDefinition mergedMenu = new CommandContextMenuDefinition();

            // first menu (ensure a trailing separator)
            mergedMenu.Entries.AddRange(menu1.Entries);
            mergedMenu.Entries[mergedMenu.Entries.Count - 1].SeparatorAfter = true;

            // second menu
            mergedMenu.Entries.AddRange(menu2.Entries);

            // return the merged menu
            return mergedMenu;
        }
        private void InitializeCommands()
        {
            commandContextManager = new CommandContextManager(_decoratorsManager.CommandManager);
            commandContextManager.BeginUpdate();

            commandAddMenu = new Command(CommandId.AddDecorator);
            _decoratorsManager.CommandManager.Add(commandAddMenu);
            addCommandContextMenuDefinition = new CommandContextMenuDefinition(components);
            if (_decoratorsManager != null)
            {
                for (int i = 0; i < _decoratorsManager.ImageDecoratorGroups.Length; i++)
                {
                    ImageDecoratorGroup imageDecoratorGroup = _decoratorsManager.ImageDecoratorGroups[i];

                    foreach (ImageDecorator imageDecorator in imageDecoratorGroup.ImageDecorators)
                    {
                        if (!imageDecorator.IsHidden) //don't show hidden decorators in the command list
                        {
                            Command ImageDecoratorApplyCommand = imageDecorator.Command;
                            MenuDefinitionEntryCommand imageDecoratorMenuEntry = new MenuDefinitionEntryCommand(components);
                            imageDecoratorMenuEntry.CommandIdentifier = ImageDecoratorApplyCommand.Identifier;
                            addCommandContextMenuDefinition.Entries.Add(imageDecoratorMenuEntry);

                            ImageDecoratorApplyCommand.Execute += new EventHandler(imageDecoratorApplyCommand_Execute);
                            ImageDecoratorApplyCommand.Tag = imageDecorator.Id;
                        }
                    }
                }
            }

            commandImageRemove = new Command(CommandId.RemoveDecorator);
            commandImageRemove.Execute += new EventHandler(commandRemoveMenu_Execute);
            commandContextManager.AddCommand(commandImageRemove, CommandContext.Normal);

            _decoratorsManager.CommandManager.SuppressEvents = true;
            try
            {
                commandContextManager.EndUpdate();
            }
            finally
            {
                _decoratorsManager.CommandManager.SuppressEvents = true;
            }
        }
예제 #7
0
        private void InitializeContentSources()
        {
            // create commands for the content-sources (used by the dynamic command menu and sidebar)
            CommandManager.BeginUpdate();
            // first built in
            foreach (ContentSourceInfo contentSourceInfo in ContentSourceManager.BuiltInInsertableContentSources)
                CommandManager.Add(new ContentSourceCommand(this, contentSourceInfo, true));

            // then plug ins
            UpdateContentSourceCommands();

            CommandManager.EndUpdate();

            // subscribe to changes in the list of content sources
            ContentSourceManager.GlobalContentSourceListChanged += new EventHandler(ContentSourceManager_GlobalContentSourceListChanged);

            // create a dynamic command menu for the content sources
            string basePath = new Command(CommandId.InsertPictureFromFile).MainMenuPath.Split('/')[0];

            DynamicCommandMenuOptions options = new DynamicCommandMenuOptions(basePath, 500, Res.Get(StringId.DynamicCommandMenuMore), Res.Get(StringId.DynamicCommandMenuInsert));
            options.UseNumericMnemonics = false;
            options.MaxCommandsShownOnMenu = 20;
            options.SeparatorBegin = true;
            IDynamicCommandMenuContext context = ContentSourceManager.CreateDynamicCommandMenuContext(options, CommandManager, this);
            DynamicCommandMenu contentSourceList = new DynamicCommandMenu(context);

            CommandContextMenuDefinition insertMenuDefinition = new CommandContextMenuDefinition();
            insertMenuDefinition.CommandBar = true;
            insertMenuDefinition.Entries.Add(CommandId.InsertLink, false, false);
            insertMenuDefinition.Entries.Add(CommandId.InsertPictureFromFile, false, false);
            insertMenuDefinition.Entries.Add(WebImageContentSource.ID, false, false);
            insertMenuDefinition.Entries.Add(CommandId.InsertTable2, true, true);

            foreach (string commandId in contentSourceList.CommandIdentifiers)
                if (WebImageContentSource.ID != commandId)
                    insertMenuDefinition.Entries.Add(commandId, false, false);
        }
        /// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        ///	<param name="commandManager">The CommandManager to use.</param>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition of the commands to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(CommandManager commandManager, Control parentWindow, Point position, int alternateXPosition, CommandContextMenuDefinition commandContextMenuDefinition)
        {
            //	If the command context menu definition was null, or contained no Command identifiers, we're done.
            Debug.Assert(commandContextMenuDefinition != null, "Cannot show a CommandContextMenu without a CommandContextMenuDefinition");
            if (commandContextMenuDefinition == null || commandContextMenuDefinition.Entries.Count == 0)
            {
                return(null);
            }

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command context menu definition.
            CommandContextMenu commandContextMenu = new CommandContextMenu(commandManager, commandContextMenuDefinition);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return(command);
        }
 /// <summary>
 /// Shows a CommandContextMenu modally.
 /// </summary>
 ///	<param name="commandManager">The CommandManager to use.</param>
 /// <param name="parentWindow">The parent window.</param>
 /// <param name="position">The position to show the menu, in screen coordinates.</param>
 /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition of the commands to show in the menu.  These commands must be present in the CommandManager.</param>
 /// <returns>The command that was selected; or null if no command was selected.</returns>
 public static Command ShowModal(CommandManager commandManager, Control parentWindow, Point position, CommandContextMenuDefinition commandContextMenuDefinition)
 {
     return(ShowModal(commandManager, parentWindow, position, position.X, commandContextMenuDefinition));
 }
        /// <summary>
        /// Builds the menu items of this CommandContextMenu from the specified CommandContextMenuDefinition.
        /// </summary>
        /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition.</param>
        private void BuildMenuItems(CommandManager commandManager, CommandContextMenuDefinition commandContextMenuDefinition)
        {
            //	Raise the BeforeShowMenu event in the CommandContextMenuDefinition, allowing
            //	interested parties to manage commands.
            commandContextMenuDefinition.RaiseBeforeShowMenu();

            //	Build the menu items.
            if (commandContextMenuDefinition.Entries.Count != 0)
                MenuItems.AddRange(MenuBuilder.CreateMenuItems(commandManager, commandContextMenuDefinition));
        }
예제 #11
0
 public static MenuItem[] CreateMenuItems(CommandManager commandManager, CommandContextMenuDefinition commandContextMenuDefinition)
 {
     return CreateMenuItems(commandManager, commandContextMenuDefinition.CommandBar ? MenuType.CommandBarContext : MenuType.Context, commandContextMenuDefinition.Entries);
 }
예제 #12
0
 public static MenuItem[] CreateMenuItems(CommandManager commandManager, CommandContextMenuDefinition commandContextMenuDefinition)
 {
     return(CreateMenuItems(commandManager, commandContextMenuDefinition.CommandBar ? MenuType.CommandBarContext : MenuType.Context, commandContextMenuDefinition.Entries));
 }
 /// <summary>
 /// Shows a CommandContextMenu modally.
 /// </summary>
 ///	<param name="commandManager">The CommandManager to use.</param>
 /// <param name="parentWindow">The parent window.</param>
 /// <param name="position">The position to show the menu, in screen coordinates.</param>
 /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition of the commands to show in the menu.  These commands must be present in the CommandManager.</param>
 /// <returns>The command that was selected; or null if no command was selected.</returns>
 public static Command ShowModal(CommandManager commandManager, Control parentWindow, Point position, CommandContextMenuDefinition commandContextMenuDefinition)
 {
     return ShowModal(commandManager, parentWindow, position, position.X, commandContextMenuDefinition);
 }
예제 #14
0
        private void btnOptions_Click(object sender, System.EventArgs e)
        {
            CommandContextMenuDefinition menu = new CommandContextMenuDefinition();
            menu.Entries.Add(CommandId.RecentPost, false, false);
            menu.Entries.Add(CommandId.Glossary, false, false);

            Point screenPoint = PointToScreen(new Point(btnOptions.Left, btnOptions.Bottom));
            Point altScreenPoint = PointToScreen(new Point(btnOptions.Right, btnOptions.Bottom));
            LinkingCommand command = (LinkingCommand)CommandContextMenu.ShowModal(CommandManager, this, screenPoint, altScreenPoint.X, menu);

            if (command != null)
            {
                if (command.FindLink(textBoxLinkText.Text, this))
                {
                    textBoxAddress.Focus();
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the CommandContextMenu class.
 /// </summary>
 /// <param name="container"></param>
 private CommandContextMenu(CommandManager commandManager, CommandContextMenuDefinition commandContextMenuDefinition)
 {
     BuildMenuItems(commandManager, commandContextMenuDefinition);
 }
        private void InitializeCommands()
        {
            _htmlEditor.CommandManager.BeginUpdate();

            commandNewPost = _htmlEditor.CommandManager.Add(CommandId.NewPost, commandNewPost_Execute);
            commandNewPage = _htmlEditor.CommandManager.Add(CommandId.NewPage, commandNewPage_Execute);

            // new context menu definition
            _newPostContextMenuDefinition = new CommandContextMenuDefinition(this.components);
            _newPostContextMenuDefinition.Entries.Add(CommandId.NewPost, false, false);
            _newPostContextMenuDefinition.Entries.Add(CommandId.NewPage, false, false);
            commandNewPost.CommandBarButtonContextMenuDropDown = true;

            _htmlEditor.CommandManager.Add(CommandId.OpenDrafts, commandOpenDrafts_Execute);
            _htmlEditor.CommandManager.Add(CommandId.OpenRecentPosts, commandOpenRecentPosts_Execute);
            _htmlEditor.CommandManager.Add(CommandId.OpenPost, commandOpenPost_Execute);
            commandSavePost = _htmlEditor.CommandManager.Add(CommandId.SavePost, commandSavePost_Execute);
            commandDeleteDraft = _htmlEditor.CommandManager.Add(CommandId.DeleteDraft, commandDeleteDraft_Execute);
            _htmlEditor.CommandManager.Add(CommandId.PostAndPublish, commandPostAndPublish_Execute);
            commandPostAsDraft = _htmlEditor.CommandManager.Add(CommandId.PostAsDraft, commandPostAsDraft_Execute);
            commandPostAsDraftAndEditOnline = _htmlEditor.CommandManager.Add(CommandId.PostAsDraftAndEditOnline, commandPostAsDraftAndEditOnline_Execute);

            DraftPostItemsGalleryCommand draftGallery = new DraftPostItemsGalleryCommand(this as IBlogPostEditingSite,
                                                                                         CommandManager, false);
            draftGallery.Execute += commandOpenDrafts_Execute;
            DraftPostItemsGalleryCommand postGallery = new DraftPostItemsGalleryCommand(this as IBlogPostEditingSite,
                                                                                         CommandManager, true);
            postGallery.Execute += commandOpenRecentPosts_Execute;

            // publish command bar context menu
            _savePostContextMenuDefinition = new CommandContextMenuDefinition(this.components);
            _savePostContextMenuDefinition.CommandBar = true;
            _savePostContextMenuDefinition.Entries.Add(CommandId.SavePost, false, true);
            _savePostContextMenuDefinition.Entries.Add(CommandId.PostAsDraft, false, false);
            _savePostContextMenuDefinition.Entries.Add(CommandId.PostAsDraftAndEditOnline, false, false);
            commandSavePost.CommandBarButtonContextMenuDropDown = true;

            if (ApplicationDiagnostics.TestMode)
            {
                _htmlEditor.CommandManager.Add(CommandId.DiagnosticsConsole, new EventHandler(commandDiagnosticsConsole_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ShowBetaExpiredDialogs, new EventHandler(commandShowBetaExpiredDialogs_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ShowWebLayoutWarning, delegate { new WebLayoutViewWarningForm().ShowDialog(this); });
                _htmlEditor.CommandManager.Add(CommandId.ShowErrorDialog, new EventHandler(commandErrorDialog_Execute));
                _htmlEditor.CommandManager.Add(CommandId.BlogClientOptions, new EventHandler(commandBlogClientOptions_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ShowDisplayMessageTestForm, new EventHandler(commandShowDisplayMessageTestForm_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ShowSupportingFilesForm, new EventHandler(commandShowSupportingFilesForm_Execute));
                _htmlEditor.CommandManager.Add(CommandId.InsertLoremIpsum, new EventHandler(commandInsertLoremIpsum_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ValidateHtml, new EventHandler(commandValidateHtml_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ValidateXhtml, new EventHandler(commandValidateXhtml_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ValidateLocalizedResources, new EventHandler(commandValidateLocalizedResources_Execute));
                _htmlEditor.CommandManager.Add(CommandId.ShowAtomImageEndpointSelector, new EventHandler(commandShowAtomImageEndpointSelector_Execute));
                _htmlEditor.CommandManager.Add(CommandId.RaiseAssertion, delegate { Trace.Fail("You asked for it"); });
                _htmlEditor.CommandManager.Add(CommandId.ShowGoogleCaptcha, delegate { new GDataCaptchaForm().ShowDialog(this); });
                _htmlEditor.CommandManager.Add(CommandId.TerminateProcess, delegate { Process.GetCurrentProcess().Kill(); });
            }

            commandColorize = new Command(CommandId.Colorize);
            commandColorize.CommandBarButtonContextMenuHandler = new CommandBarButtonContextMenuHandler(new ColorizationContextHelper().Handler);
            _htmlEditor.CommandManager.Add(commandColorize);

            _htmlEditor.CommandManager.EndUpdate();

            // initialize the weblog menu commands
            _weblogCommandManager = new WeblogCommandManager(_editingManager, this);
            _weblogCommandManager.WeblogSelected += new WeblogHandler(_weblogMenuManager_WeblogSelected);
        }
 /// <summary>
 /// Initializes a new instance of the CommandContextMenu class.
 /// </summary>
 /// <param name="container"></param>
 private CommandContextMenu(CommandManager commandManager, CommandContextMenuDefinition commandContextMenuDefinition)
 {
     BuildMenuItems(commandManager, commandContextMenuDefinition);
 }