/// <summary> /// Populate a context menu appropriate for a non-dockable workspace provided page. /// </summary> /// <param name="page">Reference to page.</param> /// <param name="kcm">Reference to context menu.</param> /// <returns>True if the context menu should be displayed; otherwise false.</returns> public virtual bool ShowPageContextMenuRequest(KryptonPage page, KryptonContextMenu kcm) { // Cannot action a null reference if (page == null) throw new ArgumentNullException("page"); if (kcm == null) throw new ArgumentNullException("kcm"); // By default there is nothing to display bool retDisplay = false; // If the page is not located in the hierarchy then there are no options we can provide DockingLocation location = FindPageLocation(page); if (location != DockingLocation.None) { // Reset the context menu with an items collection KryptonContextMenuItems options = new KryptonContextMenuItems(); kcm.Items.Clear(); kcm.Items.Add(options); // Can only make floating if we can find a floating element to target the action against if (FindDockingFloating(page.UniqueName) != null) { // Add an option for floating the page KryptonContextMenuItem floatingItem = new KryptonContextMenuItem(Strings.TextFloat); floatingItem.Tag = page.UniqueName; floatingItem.Click += new EventHandler(OnDropDownFloatingClicked); floatingItem.Enabled = ((location != DockingLocation.Floating) && (page.AreFlagsSet(KryptonPageFlags.DockingAllowFloating))); options.Items.Add(floatingItem); retDisplay = true; } // Can only make docked if we can find a docked edge to target the action against if (FindDockingEdgeDocked(page.UniqueName) != null) { // Add an option for docked the page KryptonContextMenuItem dockedItem = new KryptonContextMenuItem(Strings.TextDock); dockedItem.Tag = page.UniqueName; dockedItem.Click += new EventHandler(OnDropDownDockedClicked); dockedItem.Enabled = ((location != DockingLocation.Docked) && (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))); options.Items.Add(dockedItem); retDisplay = true; } // Can only make tabbed document if we can find a workspace to target the action against if (FindDockingWorkspace(page.UniqueName) != null) { // Add an option for docked the page KryptonContextMenuItem workspaceItem = new KryptonContextMenuItem(Strings.TextTabbedDocument); workspaceItem.Tag = page.UniqueName; workspaceItem.Click += new EventHandler(OnDropDownWorkspaceClicked); workspaceItem.Enabled = ((location != DockingLocation.Workspace) && (page.AreFlagsSet(KryptonPageFlags.DockingAllowWorkspace))); options.Items.Add(workspaceItem); retDisplay = true; } else { // No workspace so look for a navigator instead if (FindDockingNavigator(page.UniqueName) != null) { // Add an option for docked the page KryptonContextMenuItem workspaceItem = new KryptonContextMenuItem(Strings.TextTabbedDocument); workspaceItem.Tag = page.UniqueName; workspaceItem.Click += new EventHandler(OnDropDownNavigatorClicked); workspaceItem.Enabled = ((location != DockingLocation.Navigator) && (page.AreFlagsSet(KryptonPageFlags.DockingAllowNavigator))); options.Items.Add(workspaceItem); retDisplay = true; } } // Can only make auto hidden if we can find a auto hidden edge to target the action against if (FindDockingEdgeAutoHidden(page.UniqueName) != null) { // Add an option for docked the page KryptonContextMenuItem autoHiddenItem = new KryptonContextMenuItem(Strings.TextAutoHide); autoHiddenItem.Tag = page.UniqueName; autoHiddenItem.Click += new EventHandler(OnDropDownAutoHiddenClicked); autoHiddenItem.Enabled = ((location != DockingLocation.AutoHidden) && (page.AreFlagsSet(KryptonPageFlags.DockingAllowAutoHidden))); options.Items.Add(autoHiddenItem); retDisplay = true; } // Can only add the close menu option if we are allowed to close the page if (page.AreFlagsSet(KryptonPageFlags.DockingAllowClose)) { // Add an option for closing the page KryptonContextMenuItem closeItem = new KryptonContextMenuItem(Strings.TextClose); closeItem.Tag = page.UniqueName; closeItem.Click += new EventHandler(OnDropDownCloseClicked); options.Items.Add(closeItem); retDisplay = true; } } // Let events customize the context menu ContextPageEventArgs args = new ContextPageEventArgs(page, kcm, !retDisplay); OnShowPageContextMenu(args); return !args.Cancel; }
/// <summary> /// Raises the ShowWorkspacePageContextMenu event. /// </summary> /// <param name="e">An ContextPageEventArgs containing the event args.</param> protected virtual void OnShowWorkspacePageContextMenu(ContextPageEventArgs e) { if (ShowWorkspacePageContextMenu != null) ShowWorkspacePageContextMenu(this, e); }
private void kryptonDockingManager_ShowWorkspacePageContextMenu(object sender, ContextPageEventArgs e) { // Create a set of custom menu items KryptonContextMenuItems customItems = new KryptonContextMenuItems(); KryptonContextMenuSeparator customSeparator = new KryptonContextMenuSeparator(); KryptonContextMenuItem customItem1 = new KryptonContextMenuItem("Custom Item 3", new EventHandler(OnCustomMenuItem)); KryptonContextMenuItem customItem2 = new KryptonContextMenuItem("Custom Item 4", new EventHandler(OnCustomMenuItem)); customItem1.Tag = e.Page; customItem2.Tag = e.Page; customItems.Items.AddRange(new KryptonContextMenuItemBase[] { customSeparator, customItem1, customItem2 }); // Add set of custom items into the provided menu e.KryptonContextMenu.Items.Add(customItems); }