Exemplo n.º 1
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;
		}
Exemplo n.º 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;
 }
Exemplo n.º 3
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));
Exemplo n.º 4
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));
 }
Exemplo n.º 5
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);
        }
 public GuidObjectsProvider(Func <GuidObjectsProviderArgs, IEnumerable <GuidObject> > createGuidObjects, IGuidObjectsProvider guidObjectsProvider)
 {
     this.createGuidObjects   = createGuidObjects;
     this.guidObjectsProvider = guidObjectsProvider;
 }
Exemplo n.º 7
0
        public static Func <GuidObjectsProviderArgs, IEnumerable <GuidObject> > Create(Func <GuidObjectsProviderArgs, IEnumerable <GuidObject> > createGuidObjects, IGuidObjectsProvider guidObjectsProvider)
        {
            var provider = new CommonGuidObjectsProvider(createGuidObjects, guidObjectsProvider);

            return(provider.GetGuidObjects);
        }
		public static Func<GuidObjectsProviderArgs, IEnumerable<GuidObject>> Create(Func<GuidObjectsProviderArgs, IEnumerable<GuidObject>> createGuidObjects, IGuidObjectsProvider guidObjectsProvider) {
			var provider = new CommonGuidObjectsProvider(createGuidObjects, guidObjectsProvider);
			return provider.GetGuidObjects;
		}
		CommonGuidObjectsProvider(Func<GuidObjectsProviderArgs, IEnumerable<GuidObject>> createGuidObjects, IGuidObjectsProvider guidObjectsProvider) {
			this.createGuidObjects = createGuidObjects;
			this.guidObjectsProvider = guidObjectsProvider;
		}
Exemplo n.º 10
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));
Exemplo n.º 11
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);
		}
Exemplo n.º 12
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;
		}
Exemplo n.º 13
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();
            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);
        }