Example #1
0
        internal static ContextMenu FolderItemsContextMenu(FolderItems folderItems, ListItem listItem, Action delete)
        {
            ContextMenuCommands commands = folderItems.ParentFolder.ParentList.BaseType == BaseType.DocumentLibrary
                ? libraryCommands : listCommands;

            ContextMenuCommand[] menuItems = commands.None;
            if (listItem != null)
            {
                menuItems = listItem.FileSystemObjectType == FileSystemObjectType.Folder ? commands.Folder : commands.Item;
            }

            return(new ContextMenu()
            {
                List = new ObservableList <ContextMenuCommand>(menuItems),
                Execute = delegate(IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    switch (command.EditMode)
                    {
                    case EditMode.Refresh:
                        folderItems.Refresh();
                        break;

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

                    case EditMode.Open:
                        HtmlWindow.Current.Open(listItem.AbsoluteUrl);
                        break;

                    case EditMode.Upload:
                        Uploader.Upload(folderItems.ParentFolder);
                        break;

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


                    case EditMode.Copy:
                        ListItemEditor.Show(new EditAction()
                        {
                            EditMode = command.EditMode,
                            ListItem = listItem,
                            TargetFolder = folderItems.ParentFolder,
                            TargetList = folderItems.ParentFolder.ParentList
                        });
                        break;

                    default:
                        delete();
                        break;
                    }
                },
                Renderer = delegate(IMenuItem menuItem, IHierarchyLevel menuLevel, long menuIndex)
                {
                    ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex];
                    menuItem.Text = command.Name;
                    menuItem.ImageClass = command.Image + "Icon";
                    menuItem.SeparatorBefore = (command.EditMode == EditMode.Refresh || command.EditMode == EditMode.Delete || command.EditMode == EditMode.Copy);
                    switch (command.EditMode)
                    {
                    case EditMode.AddFolder:
                        menuItem.Enabled = folderItems.ParentFolder.IsRootFolder ||
                                           (folderItems.ParentFolder.Item.EffectiveBasePermissions & BasePermissions.AddListItems)
                                           == BasePermissions.AddListItems;
                        break;

                    case EditMode.AddItem:
                    case EditMode.Copy:
                        menuItem.Enabled = folderItems.ParentFolder.ParentList.BaseType != BaseType.DocumentLibrary &&
                                           (folderItems.ParentFolder.IsRootFolder ||
                                            (folderItems.ParentFolder.Item.EffectiveBasePermissions & BasePermissions.AddListItems)
                                            == BasePermissions.AddListItems);
                        break;

                    case EditMode.Delete:
                        menuItem.Enabled = (listItem.EffectiveBasePermissions & BasePermissions.DeleteListItems) == BasePermissions.DeleteListItems;
                        break;

                    case EditMode.Edit:
                        menuItem.Enabled = BasePermissions.EditListItems == (BasePermissions.EditListItems & listItem.EffectiveBasePermissions);
                        break;

                    case EditMode.Refresh:
                        menuItem.Enabled = folderItems.CanRefresh;
                        break;
                    }
                }
            });
        }
Example #2
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);
                }
            });
        }