Exemple #1
0
        internal static ContextMenu FolderContextMenu(FolderNode folder)
        {
            ContextMenuCommands commands = folder.ParentList.BaseType == BaseType.DocumentLibrary
                ? libraryCommands : listCommands;

            return(new ContextMenu()
            {
                List = new ObservableList <ContextMenuCommand>(folder.IsRootFolder ? commands.List : commands.Folder),
                Execute = delegate(IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    switch (command.EditMode)
                    {
                    case EditMode.Refresh:
                        if (!folder.IsRootFolder)
                        {
                            folder.Refresh();
                        }
                        else
                        {
                            ((ListNode)folder.ParentList).Refresh();
                        }
                        break;

                    case EditMode.Edit:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, ListItem = folder.Item, TargetList = folder.ParentList
                        });
                        break;

                    case EditMode.AddItem:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, TargetFolder = folder, TargetList = folder.ParentList
                        });
                        break;

                    case EditMode.Upload:
                        Uploader.Upload(folder);
                        break;

                    case EditMode.AddFolder:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode, TargetFolder = folder, TargetList = folder.ParentList
                        });
                        break;

                    default:
                        if (folder.IsRootFolder)
                        {
                            throw new NotImplementedException("List deletion is not implemented yet.");
                        }

                        DeleteFolder(folder);
                        break;
                    }
                },
                Renderer = delegate(IMenuItem menuItem, IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    switch (command.EditMode)
                    {
                    case EditMode.AddFolder:
                    case EditMode.AddItem:
                        menuItem.Enabled = folder.IsRootFolder || (folder.Item.EffectiveBasePermissions & BasePermissions.AddListItems) == BasePermissions.AddListItems;
                        break;

                    case EditMode.Delete:
                        menuItem.Enabled = folder.IsRootFolder || (folder.Item.EffectiveBasePermissions & BasePermissions.DeleteListItems) == BasePermissions.DeleteListItems;
                        break;

                    case EditMode.Edit:
                        menuItem.Enabled = !folder.IsRootFolder || BasePermissions.EditListItems == (BasePermissions.EditListItems & folder.Item.EffectiveBasePermissions);
                        break;

                    case EditMode.Refresh:
                        menuItem.Enabled = true;
                        break;
                    }


                    menuItem.Text = command.Name;
                    menuItem.ImageClass = command.Image + "Icon";
                    menuItem.SeparatorBefore = (command.EditMode == EditMode.Refresh || command.EditMode == EditMode.Delete || command.EditMode == EditMode.AddItem);
                }
            });
        }