示例#1
0
        private void CreateChildren(TagBuilder li, List <MenuItem> items, MenuItem?current, int level, string id, bool isCurrent)
        {
            var ihasSub = false;
            var menu    = new TagBuilder("div");

            menu.GenerateId(id, ".");
            menu.AddCssClass($"menu-{level}");
            if (Align == AlignMode.Vertical)
            {
                if (isCurrent)
                {
                    menu.AddCssClass("show");
                }
                menu.AddCssClass("collapse");
            }
            var ul = new TagBuilder("ul");

            menu.InnerHtml.AppendHtml(ul);
            foreach (var it in items.OrderByDescending(x => x.Priority))
            {
                var children = it.Where(IsAuthorized).ToList();
                var item     = CreateMenuItem(it, current, children, it.Any());
                if (item != null)
                {
                    ihasSub = true;
                    ul.InnerHtml.AppendHtml(item);
                }
            }
            if (ihasSub)
            {
                li.InnerHtml.AppendHtml(menu);
            }
        }
示例#2
0
 /// <inheritdoc/>
 protected override void OnHoverChanged(MenuItem?oldItem, MenuItem?newItem)
 {
     if (IsActivated && newItem != null)
     {
         SelectedItem = newItem;
     }
 }
示例#3
0
    protected override ActionResult <MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
    {
        MenuItemCollection menu = _menuItemCollectionFactory.Create();

        if (id == Constants.System.RootString)
        {
            // root actions
            menu.Items.Add <ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
            menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            return(menu);
        }

        IEntitySlim?cte =
            _entityService.Get(int.Parse(id, CultureInfo.InvariantCulture), UmbracoObjectTypes.DocumentType);

        //only refresh & create if it's a content type
        if (cte != null)
        {
            IContentType?ct         = _contentTypeService.Get(cte.Id);
            MenuItem?    createItem =
                menu.Items.Add <ActionCreateBlueprintFromContent>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);
            createItem?.NavigateToRoute("/settings/contentBlueprints/edit/-1?create=true&doctype=" + ct?.Alias);

            menu.Items.Add(new RefreshNode(LocalizedTextService, true));

            return(menu);
        }

        menu.Items.Add <ActionDelete>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);

        return(menu);
    }
示例#4
0
 public MenuItem(string label, string preview, MenuItem?parent = null, Action?onSelectedCallback = null)
 {
     Label              = label;
     Preview            = preview;
     Parent             = parent;
     Width              = label.Length;
     OnSelectedCallback = onSelectedCallback;
 }
示例#5
0
 /// <summary>
 /// 根据当前路径设置菜单激活状态
 /// </summary>
 /// <param name="item"></param>
 private void CascadingSetActive(MenuItem?item)
 {
     // 重新设置菜单激活状态
     if (item != null)
     {
         MenuItem.CascadingCancelActive(Items);
         MenuItem.CascadingSetActive(item);
     }
 }
示例#6
0
        private IEnumerable <MenuItem> LoadNavigators(MenuItem?current)
        {
            while (current != null && current.Level >= 0)
            {
                yield return(current);

                current = current.Parent;
            }
        }
        /// <summary>
        /// Weist dem <see cref="RecentFilesMenu"/> das <see cref="MenuItem"/> zu, als dessen Submenü das
        /// <see cref="RecentFilesMenu"/> angezeigt wird. Diese Methode muss vor allen anderen aufgerufen werden!
        /// </summary>
        /// <param name="miRecentFiles">Das <see cref="MenuItem"/>, als dessen Submenü das
        /// <see cref="RecentFilesMenu"/> angezeigt wird.</param>
        /// <exception cref="ArgumentNullException"><paramref name="miRecentFiles"/> ist <c>null</c>.</exception>
        public void Initialize(MenuItem miRecentFiles)
        {
            if (miRecentFiles is null)
            {
                throw new ArgumentNullException(nameof(miRecentFiles));
            }

            _miRecentFiles         = miRecentFiles;
            _miRecentFiles.Loaded += miRecentFiles_Loaded;
        }
示例#8
0
        public ExtendedTextBox()
        {
            Disposables = new CompositeDisposable();

            _textPasted = new Subject <string>();

            CopyCommand = ReactiveCommand.CreateFromTask(CopyAsync);

            PasteCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    var pastedText = await PasteAsync();

                    _textPasted.OnNext(pastedText);
                }
                catch (Exception exception)
                {
                    _textPasted.OnError(exception);
                }
            });

            Observable
            .Merge(CopyCommand.ThrownExceptions)
            .Merge(PasteCommand.ThrownExceptions)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(ex => Logger.LogWarning(ex));

            this.GetObservable(IsReadOnlyProperty).Subscribe(isReadOnly =>
            {
                if (ContextMenu is null)
                {
                    return;
                }

                var items = ContextMenu.Items as Avalonia.Controls.Controls;

                if (isReadOnly)
                {
                    if (items.Contains(_pasteItem))
                    {
                        items.Remove(_pasteItem);
                        _pasteItem = null;
                    }
                }
                else
                {
                    if (!items.Contains(_pasteItem))
                    {
                        CreatePasteItem();
                        items.Add(_pasteItem);
                    }
                }
            });
        }
示例#9
0
        protected override void OnHoverChanged(MenuItem?oldItem, MenuItem?newItem)
        {
            if (newItem != null)
            {
                oldItem?.HideDropDown();

                Items.FirstOrDefault(i => i.IsDropDownOpened)?.HideDropDown();
            }

            newItem?.ShowDropDown();
        }
示例#10
0
 public static bool IsCurrent(this MenuItem?current, MenuItem item)
 {
     while (current != null && current.Level >= 0)
     {
         if (current.Name == item.Name)
         {
             return(true);
         }
         current = current.Parent;
     }
     return(false);
 }
示例#11
0
 /// <summary>
 /// 初始化类<see cref="MenuItem"/>。
 /// </summary>
 /// <param name="name">唯一名称,需要保证同一级下的名称唯一。</param>
 /// <param name="parent">父级菜单。</param>
 public MenuItem(string name, MenuItem?parent = null)
 {
     name   = name.ToLower();
     Parent = parent ?? new MenuItem();
     if (parent?.Name == null)
     {
         Name = name;
     }
     else
     {
         Name = $"{parent.Name}.{name}";
     }
     Level = Parent.Level + 1;
 }
    public async Task DeleteMenuItemsAsync(int id)
    {
        MenuItem?menuItem = await _menusContext.MenuItems.FindAsync(id);

        if (menuItem is null)
        {
            return;
        }

        _menusContext.Remove(menuItem);
        int records = await _menusContext.SaveChangesAsync();

        Console.WriteLine($"{records} deleted");
    }
        private void MenuItemClick(object sender, RoutedEventArgs e)
        {
            MenuItem?mi = sender as MenuItem;

            if (mi == null)
            {
                return;
            }
            MyShownObject?mso = mi.Tag as MyShownObject;

            if (mso == null)
            {
                return;
            }
            _mcv.CollectionToPrint.Remove(mso);
        }
示例#14
0
        public static T?FindClickedItem <T>(MenuItem?sender)
            where T : class
        {
            if (sender == null)
            {
                return(null);
            }

            var cm = sender.CommandParameter as ContextMenu;

            if (cm == null)
            {
                return(null);
            }

            return((cm.PlacementTarget as ListViewItem)?.Content as T);
        }
示例#15
0
        private static MenuItem?FindMenuItem(IEnumerable <MenuItem> menus, string url)
        {
            MenuItem?ret = null;

            foreach (var item in menus)
            {
                if (item.Items.Any())
                {
                    ret = FindMenuItem(item.Items, url);
                }
                else if (item.Url?.TrimStart('/').Equals(url, StringComparison.OrdinalIgnoreCase) ?? false)
                {
                    ret = item;
                }

                if (ret != null)
                {
                    break;
                }
            }
            return(ret);
        }
示例#16
0
    /// <summary>
    ///     Returns the menu structure for the node
    /// </summary>
    /// <param name="id"></param>
    /// <param name="queryStrings"></param>
    /// <returns></returns>
    protected override ActionResult <MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
    {
        MenuItemCollection menu = _menuItemCollectionFactory.Create();

        //Create the normal create action
        MenuItem?item = menu.Items.Add <ActionNew>(LocalizedTextService, opensDialog: true, useLegacyIcon: false);

        item?.NavigateToRoute(
            $"{queryStrings.GetRequiredValue<string>("application")}/templates/edit/{id}?create=true");

        if (id == Constants.System.RootString)
        {
            //refresh action
            menu.Items.Add(new RefreshNode(LocalizedTextService, separatorBefore: true));

            return(menu);
        }

        ITemplate?template = _fileService.GetTemplate(int.Parse(id, CultureInfo.InvariantCulture));

        if (template == null)
        {
            return(menu);
        }

        EntitySlim entity = FromTemplate(template);

        //don't allow delete if it has child layouts
        if (template.IsMasterTemplate == false)
        {
            //add delete option if it doesn't have children
            menu.Items.Add <ActionDelete>(LocalizedTextService, hasSeparator: true, opensDialog: true);
        }

        //add refresh
        menu.Items.Add(new RefreshNode(LocalizedTextService, separatorBefore: true));

        return(menu);
    }
示例#17
0
        private MenuItem?FindMenuItemByUrl(IEnumerable <MenuItem> items, string url)
        {
            MenuItem?ret = null;

            foreach (var item in items)
            {
                if (!string.IsNullOrEmpty(item.Url) && item.Url.Equals(url, StringComparison.OrdinalIgnoreCase))
                {
                    ret = item;
                    break;
                }
                if (item.Items.Any())
                {
                    ret = FindMenuItemByUrl(item.Items, url);
                    if (ret != null)
                    {
                        break;
                    }
                }
            }
            return(ret);
        }
示例#18
0
        /// <inheritdoc />
        public override void OnApplyTemplate()
        {
            if (this.showAbove is not null)
            {
                this.showAbove.Click -= this.OnShowAboveClick;
            }

            if (this.showBelow is not null)
            {
                this.showBelow.Click -= this.OnShowBelowClick;
            }

            this.showAbove = this.GetTemplateChild("PART_ShowAbove") as MenuItem;
            this.showBelow = this.GetTemplateChild("PART_ShowBelow") as MenuItem;

            if (this.showAbove is not null)
            {
                this.showAbove.Click += this.OnShowAboveClick;
            }

            if (this.showBelow is not null)
            {
                this.showBelow.Click += this.OnShowBelowClick;
            }

            if (this.MenuDownButton is not null)
            {
                foreach (var item in this.QuickAccessItems)
                {
                    this.MenuDownButton.Items.Remove(item);
                    item.InvalidateProperty(QuickAccessMenuItem.TargetProperty);
                }

                this.QuickAccessItems.AquireLogicalOwnership();
            }

            this.MenuDownButton = this.GetTemplateChild("PART_MenuDownButton") as DropDownButton;

            if (this.MenuDownButton is not null)
            {
                this.QuickAccessItems.ReleaseLogicalOwnership();

                for (var i = 0; i < this.QuickAccessItems.Count; i++)
                {
                    this.MenuDownButton.Items.Insert(i + 1, this.QuickAccessItems[i]);
                    this.QuickAccessItems[i].InvalidateProperty(QuickAccessMenuItem.TargetProperty);
                }
            }

            this.toolBarDownButton = this.GetTemplateChild("PART_ToolbarDownButton") as DropDownButton;

            // ToolBar panels
            this.toolBarPanel         = this.GetTemplateChild("PART_ToolBarPanel") as Panel;
            this.toolBarOverflowPanel = this.GetTemplateChild("PART_ToolBarOverflowPanel") as Panel;

            if (this.rootPanel is not null)
            {
                this.RemoveLogicalChild(this.rootPanel);
            }

            this.rootPanel = this.GetTemplateChild("PART_RootPanel") as Panel;

            if (this.rootPanel is not null)
            {
                this.AddLogicalChild(this.rootPanel);
            }

            // Clears cache
            this.cachedMenuDownButtonWidth     = 0;
            this.cachedOverflowDownButtonWidth = 0;
            this.cachedNonOverflowItemsCount   = this.GetNonOverflowItemsCount(this.ActualWidth);
            this.cachedConstraint = default;
        }
示例#19
0
 private void AddActionNode <TAction>(IUmbracoEntity item, MenuItemCollection menu, bool hasSeparator = false, bool opensDialog = false, bool useLegacyIcon = true)
     where TAction : IAction
 {
     MenuItem?menuItem = menu.Items.Add <TAction>(LocalizedTextService, hasSeparator, opensDialog, useLegacyIcon);
 }
示例#20
0
        private TagBuilder?CreateMenuItem(MenuItem item, MenuItem?current, List <MenuItem> items, bool hasSub)
        {
            var li = new TagBuilder("li");

            if (items?.Count > 0)
            {
                li.AddCssClass("nav-group");
            }
            else if (hasSub)
            {//包含子菜单,子菜单中没有一个有权限,则主菜单也没有权限
                return(null);
            }
            li.AddCssClass("nav-item");
            if (item.IsTitle)
            {//分组标题
                li.AddCssClass("nav-heading");
                li.InnerHtml.AppendHtml(item.LocalizedText);
                return(li);
            }
            var isCurrent = current.IsCurrent(item);
            var anchor    = new TagBuilder("a");

            if (isCurrent)
            {
                anchor.AddCssClass("active");
            }
            anchor.MergeAttribute("title", item.LocalizedText);
            anchor.AddCssClass($"nav-link");
            //图标
            if (!string.IsNullOrWhiteSpace(item.IconName))
            {
                anchor.InnerHtml.AppendHtml($"<i class=\"{item.IconName}\"></i>");
            }
            //文本
            var span = new TagBuilder("span");

            span.InnerHtml.Append(item.LocalizedText);
            anchor.InnerHtml.AppendHtml(span);
            if (!string.IsNullOrWhiteSpace(item.BadgeText))
            //badge
            {
                var badge = new TagBuilder("span");
                badge.AddCssClass("badge");
                badge.AddCssClass(item.BadgeClassName);
                badge.InnerHtml.Append(item.BadgeText);
                anchor.InnerHtml.AppendHtml(badge);
            }
            li.InnerHtml.AppendHtml(anchor);
            //子菜单
            if (items?.Count > 0)
            {
                var id = item.Name !.Replace('.', '_');
                anchor.AddCssClass("dropdown-indicator");
                if (Align == AlignMode.Vertical)
                {
                    if (isCurrent)
                    {
                        anchor.MergeAttribute("aria-expanded", "true");
                    }
                    else
                    {
                        anchor.AddCssClass("collapsed");
                    }
                    anchor.MergeAttribute("data-bs-toggle", "collapse");
                }
                anchor.MergeAttribute("href", "#" + id);
                CreateChildren(li, items, current, item.Level + 1, id, isCurrent);
            }
            else
            {
                var url = item.LinkUrl(_urlHelper !);
                anchor.MergeAttribute("href", url);
            }
            return(li);
        }
示例#21
0
        MenuItem Create(IMenuItem item, IMenuItemMetadata metadata, MenuItemContext ctx, IInputElement?commandTarget, MenuItem?menuItem, bool isCtxMenu)
        {
            Debug2.Assert(guidToGroups is not null);
            if (menuItem is null)
            {
                menuItem = new MenuItem();
            }
            menuItem.CommandTarget = commandTarget;

            var header           = ResourceHelper.GetStringOrNull(item, metadata.Header);
            var inputGestureText = ResourceHelper.GetStringOrNull(item, metadata.InputGestureText);
            var 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 is not null)
            {
                if (cmdHolder is null)
                {
                    lastIsEnabledCallValue = item.IsEnabled(ctx);
                }
                else
                {
                    var routedCommand = cmdHolder.Command as RoutedCommand;
                    lastIsEnabledCallValue = commandTarget is null || routedCommand is null || routedCommand.CanExecute(ctx, commandTarget);
                }
                Add16x16Image(menuItem, iconImgRef.Value, lastIsEnabledCallValue);
            }

            if (metadata.Guid is not null)
            {
                var itemGuid = Guid.Parse(metadata.Guid);
                if (guidToGroups.ContainsKey(itemGuid))
                {
                    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());
                        }
                    };
                }
            }

            ctx.OnDisposed += (_, __) => {
                // Buggy automation peers could hold a reference to us, so clear the captured variables (we can't clear the captured 'this')
                menuItem      = null;
                ctx           = null !;
                commandTarget = null;
                item          = null !;
                iconImgRef    = null;
            };

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

            return(menuItem);
        }
        public static List <KeyboardShortcut> LoadFromFile(string file, RoutedMethodRegistry?methodList)
        {
            if (!File.Exists(file))
            {
                throw new ArgumentException("The specified file does not exist. Keyboard shortcuts cannot be loaded.");
            }

            List <KeyboardShortcut> entries = new List <KeyboardShortcut>();

            XmlReader xr = XmlReader.Create(file);

            xr.MoveToContent();

            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.Element)
                {
                    //xr.ReadStartElement("ks");

                    string c = xr.GetAttribute("comb");
                    string k = xr.GetAttribute("keyid");
                    string m = xr.GetAttribute("methodid");

                    if (string.IsNullOrEmpty(c) || string.IsNullOrEmpty(k) || string.IsNullOrEmpty(m))
                    {
                        // skip item
                    }
                    else if (Enum.TryParse(c, out KeyboardCombination kc))
                    {
                        if (int.TryParse(k, out int kv))
                        {
                            RoutedEventHandler?reh = null;
                            MenuItem?          mi  = null;

                            if (methodList != null)
                            {
                                if (methodList.Contains(m))
                                {
                                    var v = methodList[m];
                                    reh = v.handler;
                                    mi  = v.menuItem;
                                }
                                else if (methodList.Contains("mnu" + m))
                                {
                                    m = "mnu" + m;

                                    var v = methodList[m];
                                    reh = v.handler;
                                    mi  = v.menuItem;
                                }
                                else if (methodList.Contains("btn" + m))
                                {
                                    m = "btn" + m;

                                    var v = methodList[m];
                                    reh = v.handler;
                                    mi  = v.menuItem;
                                }
                            }
                            KeyboardShortcut ke = new KeyboardShortcut(kc, (Key)kv, reh, m, mi);
                            entries.Add(ke);
                        }
                        else
                        {
                            if (Enum.TryParse(k, out Key kz))
                            {
                                RoutedEventHandler?reh = null;
                                MenuItem?          mi  = null;

                                if (methodList != null)
                                {
                                    if (methodList.Contains(m))
                                    {
                                        var v = methodList[m];
                                        reh = v.handler;
                                        mi  = v.menuItem;
                                    }
                                    else if (methodList.Contains("mnu" + m))
                                    {
                                        m = "mnu" + m;

                                        var v = methodList[m];
                                        reh = v.handler;
                                        mi  = v.menuItem;
                                    }
                                    else if (methodList.Contains("btn" + m))
                                    {
                                        m = "btn" + m;

                                        var v = methodList[m];
                                        reh = v.handler;
                                        mi  = v.menuItem;
                                    }
                                }
                                KeyboardShortcut ke = new KeyboardShortcut(kc, kz, reh, m, mi);
                                entries.Add(ke);
                            }
                        }
                    }

                    //xr.ReadEndElement();
                }
            }

            xr.Close();

            return(entries);
        }
示例#23
0
 public bool Equals(MenuItem?other)
 {
     return(other != null && DishId.Equals(other.DishId));
 }
示例#24
0
        public void RegisterKeyShortcut(KeyboardCombination combination, Key key, RoutedEventHandler method, string methodId, MenuItem?menuItem)
        {
            KeyboardShortcut kc = new KeyboardShortcut(combination, key, method, methodId, menuItem);

            RegisterKeyShortcut(kc);
        }
示例#25
0
 /// <summary>
 /// Raises the HoverChanged event.
 /// </summary>
 protected virtual void OnHoverChanged(MenuItem?oldItem, MenuItem?newItem)
 {
 }
示例#26
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)
                {
                    if (item.MenuItem is IMenuItemProvider itemProvider)
                    {
                        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);
        }