public ContextMenuProvider(MenuService menuService, FrameworkElement elem, Guid guid, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, Guid? ctxMenuGuid) {
			this.menuService = menuService;
			element = elem;
			this.guid = guid;
			this.provider = provider;
			this.initCtxMenu = initCtxMenu;
			this.ctxMenuGuid = ctxMenuGuid ?? new Guid(MenuConstants.CTX_MENU_GUID);
			elem.ContextMenu = new ContextMenu();
			elem.ContextMenuOpening += FrameworkElement_ContextMenuOpening;
		}
Exemple #2
0
 public ContextMenuProvider(MenuService menuService, FrameworkElement elem, Guid guid, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, Guid?ctxMenuGuid)
 {
     this.menuService         = menuService;
     element                  = elem;
     this.guid                = guid;
     this.provider            = provider;
     this.initCtxMenu         = initCtxMenu;
     this.ctxMenuGuid         = ctxMenuGuid ?? new Guid(MenuConstants.CTX_MENU_GUID);
     elem.ContextMenu         = new ContextMenu();
     elem.ContextMenuOpening += FrameworkElement_ContextMenuOpening;
 }
 public ContextMenuCreator(MenuManager menuManager, FrameworkElement elem, Guid guid, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, Guid? ctxMenuGuid)
 {
     this.menuManager = menuManager;
     this.element = elem;
     this.guid = guid;
     this.creator = creator;
     this.initCtxMenu = initCtxMenu;
     this.ctxMenuGuid = ctxMenuGuid ?? new Guid(MenuConstants.CTX_MENU_GUID);
     elem.ContextMenu = new ContextMenu();
     elem.ContextMenuOpening += FrameworkElement_ContextMenuOpening;
 }
Exemple #4
0
 public ContextMenuCreator(MenuManager menuManager, FrameworkElement elem, Guid guid, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, Guid?ctxMenuGuid)
 {
     this.menuManager         = menuManager;
     this.element             = elem;
     this.guid                = guid;
     this.creator             = creator;
     this.initCtxMenu         = initCtxMenu;
     this.ctxMenuGuid         = ctxMenuGuid ?? new Guid(MenuConstants.CTX_MENU_GUID);
     elem.ContextMenu         = new ContextMenu();
     elem.ContextMenuOpening += FrameworkElement_ContextMenuOpening;
 }
Exemple #5
0
 public IContextMenuProvider InitializeContextMenu(FrameworkElement elem, string guid, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, string ctxMenuGuid) => InitializeContextMenu(elem, new Guid(guid), provider, initCtxMenu, ctxMenuGuid == null ? (Guid?)null : new Guid(ctxMenuGuid));
Exemple #6
0
 public IContextMenuProvider InitializeContextMenu(FrameworkElement elem, Guid guid, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, Guid?ctxMenuGuid)
 {
     Debug.Assert(guid != Guid.Empty);
     return(new ContextMenuProvider(this, elem, guid, provider, initCtxMenu, ctxMenuGuid));
 }
Exemple #7
0
        internal bool?ShowContextMenu(object evArgs, FrameworkElement ctxMenuElem, Guid topLevelMenuGuid, Guid ownerMenuGuid, GuidObject creatorObject, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, bool openedFromKeyboard)
        {
            InitializeMenuItemObjects();

            // There could be nested context menu handler calls, eg. first text editor followed by
            // the TabControl. We don't wan't the TabControl to disable the text editor's ctx menu.
            if (prevEventArgs.Target == evArgs)
            {
                return(null);
            }

            var ctx = new MenuItemContext(topLevelMenuGuid, openedFromKeyboard, creatorObject, provider?.GetGuidObjects(new GuidObjectsProviderArgs(creatorObject, openedFromKeyboard)));

            bool b = guidToGroups.TryGetValue(ownerMenuGuid, out var groups);

            if (!b)
            {
                return(false);
            }

            var menu = new ContextMenu();

            BindBackgroundBrush(menu, isCtxMenu: true);

            // The owner control could be zoomed (eg. text editor) but the context menu isn't, so make
            // sure we use 100% zoom here (same as the context menu).
            double defaultZoom = 1.0;

            DsImage.SetZoom(menu, defaultZoom);
            // Also make sure we use Display mode. Let MetroWindow handle it since it has some extra checks
            var window = Window.GetWindow(ctxMenuElem) as MetroWindow;

            window?.SetScaleTransform(menu, defaultZoom);

            var allItems = CreateMenuItems(ctx, groups, null, null, true);

            if (allItems.Count == 0)
            {
                return(false);
            }
            foreach (var i in allItems)
            {
                menu.Items.Add(i);
            }

            menu.Closed += (s, e) => {
                ctx.Dispose();
                ctxMenuElem.ContextMenu = new ContextMenu();
            };
            if (initCtxMenu != null)
            {
                initCtxMenu.Initialize(ctx, menu);
            }
            ctxMenuElem.ContextMenu = menu;
            prevEventArgs.Target    = evArgs;
            return(true);
        }
Exemple #8
0
        internal bool?ShowContextMenu(object evArgs, FrameworkElement ctxMenuElem, Guid topLevelMenuGuid, Guid ownerMenuGuid, GuidObject creatorObject, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, bool openedFromKeyboard)
        {
            InitializeMenuItemObjects();

            // There could be nested contex menu handler calls, eg. first text editor followed by
            // the TabControl. We don't wan't the TabControl to disable the text editor's ctx menu.
            if (prevEventArgs.Target == evArgs)
            {
                return(null);
            }

            var ctx = new MenuItemContext(topLevelMenuGuid, openedFromKeyboard, creatorObject, creator == null ? null : creator.GetGuidObjects(creatorObject, openedFromKeyboard));

            List <MenuItemGroupMD> groups;
            bool b = guidToGroups.TryGetValue(ownerMenuGuid, out groups);

            if (!b)
            {
                return(false);
            }

            var menu     = new ContextMenu();
            var allItems = CreateMenuItems(ctx, groups, null, null, true);

            if (allItems.Count == 0)
            {
                return(false);
            }
            foreach (var i in allItems)
            {
                menu.Items.Add(i);
            }

            menu.Opened += (s, e) => openedContextMenus.Add(menu);
            menu.Closed += (s, e) => {
                openedContextMenus.Remove(menu);
                ctxMenuElem.ContextMenu = new ContextMenu();
            };
            if (initCtxMenu != null)
            {
                initCtxMenu.Initialize(ctx, menu);
            }
            ctxMenuElem.ContextMenu = menu;
            prevEventArgs.Target    = evArgs;
            return(true);
        }
Exemple #9
0
 public IContextMenuCreator InitializeContextMenu(FrameworkElement elem, string guid, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, string ctxMenuGuid)
 {
     return(InitializeContextMenu(elem, new Guid(guid), creator, initCtxMenu, ctxMenuGuid == null ? (Guid?)null : new Guid(ctxMenuGuid)));
 }
Exemple #10
0
        internal bool? ShowContextMenu(object evArgs, FrameworkElement ctxMenuElem, Guid topLevelMenuGuid, Guid ownerMenuGuid, GuidObject creatorObject, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, bool openedFromKeyboard)
        {
            InitializeMenuItemObjects();

            // There could be nested contex menu handler calls, eg. first text editor followed by
            // the TabControl. We don't wan't the TabControl to disable the text editor's ctx menu.
            if (prevEventArgs.Target == evArgs)
                return null;

            var ctx = new MenuItemContext(topLevelMenuGuid, openedFromKeyboard, creatorObject, creator == null ? null : creator.GetGuidObjects(creatorObject, openedFromKeyboard));

            List<MenuItemGroupMD> groups;
            bool b = guidToGroups.TryGetValue(ownerMenuGuid, out groups);
            if (!b)
                return false;

            var menu = new ContextMenu();
            var allItems = CreateMenuItems(ctx, groups, null, null, true);
            if (allItems.Count == 0)
                return false;
            foreach (var i in allItems)
                menu.Items.Add(i);

            menu.Opened += (s, e) => openedContextMenus.Add(menu);
            menu.Closed += (s, e) => {
                openedContextMenus.Remove(menu);
                ctxMenuElem.ContextMenu = new ContextMenu();
            };
            if (initCtxMenu != null)
                initCtxMenu.Initialize(ctx, menu);
            ctxMenuElem.ContextMenu = menu;
            prevEventArgs.Target = evArgs;
            return true;
        }
Exemple #11
0
 public IContextMenuCreator InitializeContextMenu(FrameworkElement elem, string guid, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, string ctxMenuGuid)
 {
     return InitializeContextMenu(elem, new Guid(guid), creator, initCtxMenu, ctxMenuGuid == null ? (Guid?)null : new Guid(ctxMenuGuid));
 }
Exemple #12
0
 public IContextMenuCreator InitializeContextMenu(FrameworkElement elem, Guid guid, IGuidObjectsCreator creator, IContextMenuInitializer initCtxMenu, Guid? ctxMenuGuid)
 {
     Debug.Assert(guid != Guid.Empty);
     return new ContextMenuCreator(this, elem, guid, creator, initCtxMenu, ctxMenuGuid);
 }
Exemple #13
0
		public IContextMenuProvider InitializeContextMenu(FrameworkElement elem, string guid, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, string ctxMenuGuid) => InitializeContextMenu(elem, new Guid(guid), provider, initCtxMenu, ctxMenuGuid == null ? (Guid?)null : new Guid(ctxMenuGuid));
Exemple #14
0
		internal bool? ShowContextMenu(object evArgs, FrameworkElement ctxMenuElem, Guid topLevelMenuGuid, Guid ownerMenuGuid, GuidObject creatorObject, IGuidObjectsProvider provider, IContextMenuInitializer initCtxMenu, bool openedFromKeyboard) {
			InitializeMenuItemObjects();

			// There could be nested contex menu handler calls, eg. first text editor followed by
			// the TabControl. We don't wan't the TabControl to disable the text editor's ctx menu.
			if (prevEventArgs.Target == evArgs)
				return null;

			var ctx = new MenuItemContext(topLevelMenuGuid, openedFromKeyboard, creatorObject, provider?.GetGuidObjects(new GuidObjectsProviderArgs(creatorObject, openedFromKeyboard)));

			List<MenuItemGroupMD> groups;
			bool b = guidToGroups.TryGetValue(ownerMenuGuid, out groups);
			if (!b)
				return false;

			var menu = new ContextMenu();
			BindBackgroundBrush(menu, isCtxMenu: true);

			// The owner control could be zoomed (eg. text editor) but the context menu isn't, so make
			// sure we use 100% zoom here (same as the context menu).
			double defaultZoom = 1.0;
			DsImage.SetZoom(menu, defaultZoom);
			// Also make sure we use Display mode. Let MetroWindow handle it since it has some extra checks
			var window = Window.GetWindow(ctxMenuElem) as MetroWindow;
			window?.SetScaleTransform(menu, defaultZoom);

			var allItems = CreateMenuItems(ctx, groups, null, null, true);
			if (allItems.Count == 0)
				return false;
			foreach (var i in allItems)
				menu.Items.Add(i);

			menu.Closed += (s, e) => {
				ctx.Dispose();
				ctxMenuElem.ContextMenu = new ContextMenu();
			};
			if (initCtxMenu != null)
				initCtxMenu.Initialize(ctx, menu);
			ctxMenuElem.ContextMenu = menu;
			prevEventArgs.Target = evArgs;
			return true;
		}