Example #1
0
 public MenuItemRepository(IUnitOfWork<MenuItemContext> uow, ICurrentUser currentUser)
 {
     _context = uow.Context;
     this._dbSet = _context.Set<MenuItem>();
     _uow = uow;
     this._currentUser = currentUser;
 }
Example #2
0
        public override string GetText(MenuItemContext context)
        {
            var harborApp = context.GetDependency<IHarborAppRepository>().GetApp();
            if (string.IsNullOrEmpty(harborApp.GoogleAnalyticsAccount))
            {
                return "Google Analytics (not configured)";
            }

            return "Google Analytics " + harborApp.GoogleAnalyticsAccount;
        }
Example #3
0
 public override bool HasPermission(MenuItemContext context)
 {
     return context.User.HasPermission(UserFeature.SystemSettings);
 }
Example #4
0
 public override bool HasPermission(MenuItemContext context)
 {
     return context.User.HasPermission(UserFeature.Files);
 }
Example #5
0
 public override string GetText(MenuItemContext context)
 {
     var harborApp = context.GetDependency<IHarborAppRepository>().GetApp();
     return "About version " + harborApp.Version;
 }
Example #6
0
        void InitializeMainSubMenu(MenuItem menuItem, MenuMD md, IInputElement commandTarget)
        {
            Reinitialize(menuItem);

            List<MenuItemGroupMD> groups;
            var guid = new Guid(md.Metadata.Guid);
            bool b = guidToGroups.TryGetValue(guid, out groups);
            Debug.Assert(b);
            if (b) {
                var ctx = new MenuItemContext(guid, true, new GuidObject(guid, null), null);
                var firstMenuItem = menuItem.Items.Count == 1 ? menuItem.Items[0] as MenuItem : null;
                var allItems = CreateMenuItems(ctx, groups, commandTarget, firstMenuItem, false);
                foreach (var i in allItems) {
                    if (firstMenuItem != i)
                        menuItem.Items.Add(i);
                }
            }
        }
Example #7
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;
        }
Example #8
0
		void InitializeSubMenu(MenuItem menuItem, MenuItemContext ctx, Guid ownerMenuGuid, IInputElement commandTarget, bool isCtxMenu) {
			Reinitialize(menuItem);

			List<MenuItemGroupMD> groups;
			bool b = guidToGroups.TryGetValue(ownerMenuGuid, out groups);
			Debug.Assert(b);
			if (b) {
				BindBackgroundBrush(menuItem, isCtxMenu);
				var firstMenuItem = menuItem.Items.Count == 1 ? menuItem.Items[0] as MenuItem : null;
				var allItems = CreateMenuItems(ctx, groups, commandTarget, firstMenuItem, isCtxMenu);
				foreach (var i in allItems) {
					if (firstMenuItem != i)
						menuItem.Items.Add(i);
				}
			}
		}
Example #9
0
		MenuItem Create(IMenuItem item, IMenuItemMetadata metadata, MenuItemContext ctx, IInputElement commandTarget, MenuItem menuItem, bool isCtxMenu) {
			if (menuItem == null)
				menuItem = new MenuItem();
			menuItem.CommandTarget = commandTarget;

			string header = ResourceHelper.GetString(item, metadata.Header);
			string inputGestureText = ResourceHelper.GetString(item, metadata.InputGestureText);
			ImageReference? iconImgRef = ImageReferenceHelper.GetImageReference(item, metadata.Icon);

			header = item.GetHeader(ctx) ?? header;
			inputGestureText = item.GetInputGestureText(ctx) ?? inputGestureText;
			iconImgRef = item.GetIcon(ctx) ?? iconImgRef;
			menuItem.IsChecked = item.IsChecked(ctx);

			menuItem.Header = header;
			menuItem.InputGestureText = inputGestureText;

			var cmdHolder = item as ICommandHolder;
			bool lastIsEnabledCallValue = false;
			if (iconImgRef != null) {
				if (cmdHolder == null)
					lastIsEnabledCallValue = item.IsEnabled(ctx);
				else {
					var routedCommand = cmdHolder.Command as RoutedCommand;
					lastIsEnabledCallValue = commandTarget == null || routedCommand == null || routedCommand.CanExecute(ctx, commandTarget);
				}
				Add16x16Image(menuItem, iconImgRef.Value, lastIsEnabledCallValue);
			}

			if (metadata.Guid != null) {
				var itemGuid = Guid.Parse(metadata.Guid);
				List<MenuItemGroupMD> list;
				if (guidToGroups.TryGetValue(itemGuid, out list)) {
					menuItem.Items.Add(new MenuItem());
					menuItem.SubmenuOpened += (s, e) => {
						if (e.Source == menuItem)
							InitializeSubMenu(menuItem, ctx, itemGuid, commandTarget, isCtxMenu);
					};
					menuItem.SubmenuClosed += (s, e) => {
						if (e.Source == menuItem) {
							menuItem.Items.Clear();
							menuItem.Items.Add(new MenuItem());
						}
					};
				}
			}

			menuItem.Command = cmdHolder != null ? cmdHolder.Command : new RelayCommand(a => {
				Debug.Assert(!ctx.IsDisposed);
				if (!ctx.IsDisposed) {
					item.Execute(ctx);
					ctx.Dispose();
				}
			}, a => {
				if (ctx.IsDisposed)
					return false;
				bool b = item.IsEnabled(ctx);
				if (lastIsEnabledCallValue != b && iconImgRef != null)
					Add16x16Image(menuItem, iconImgRef.Value, lastIsEnabledCallValue = b);
				return b;
			});

			return menuItem;
		}
Example #10
0
		List<object> CreateMenuItems(MenuItemContext ctx, List<MenuItemGroupMD> groups, IInputElement commandTarget, MenuItem firstMenuItem, bool isCtxMenu) {
			var allItems = new List<object>();

			var items = new List<MenuItemMD>();
			bool needSeparator = false;
			foreach (var group in groups) {
				items.Clear();
				foreach (var item in group.Items) {
					if (item.MenuItem.IsVisible(ctx))
						items.Add(item);
				}
				if (items.Count == 0)
					continue;
				if (needSeparator)
					allItems.Add(new Separator());
				needSeparator = true;

				foreach (var item in items) {
					var itemProvider = item.MenuItem as IMenuItemProvider;
					if (itemProvider != null) {
						foreach (var createdItem in itemProvider.Create(ctx)) {
							var menuItem = Create(createdItem.MenuItem, createdItem.Metadata, ctx, commandTarget, firstMenuItem, isCtxMenu);
							firstMenuItem = null;
							allItems.Add(menuItem);
						}
					}
					else {
						var menuItem = Create(item.MenuItem, item.Metadata, ctx, commandTarget, firstMenuItem, isCtxMenu);
						firstMenuItem = null;
						allItems.Add(menuItem);
					}
				}
			}

			return allItems;
		}
Example #11
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;
		}
Example #12
0
 public MenuItemRepository1(MenuItemUnitOfWork uow)
 {
     _context = uow.Context;
 }
Example #13
0
 public virtual bool HasPermission(MenuItemContext context)
 {
     return true;
 }
Example #14
0
 public virtual string GetText(MenuItemContext context)
 {
     return Text;
 }