Ejemplo n.º 1
0
        public void Execute(IActionContext context)
        {
            IResourceList resources = context.SelectedResources;

            if (resources.Count > 1)
            {
                if (MessageBox.Show(Core.MainWindow,
                                    "Are you sure you want to delete selected weblinks and/or folders?", "Delete Bookmarks",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }
            for (int i = 0; i < resources.Count; ++i)
            {
                IResource res = context.SelectedResources[i];
                if (res.Type != "Folder" && res.Type != "Weblink")
                {
                    res = res.GetLinkProp("Source");
                }
                if (res != null && (res.Type == "Folder" || res.Type == "Weblink"))
                {
                    if (resources.Count == 1)
                    {
                        if (res.Type != "Folder" || res.DisplayName != "New Folder")
                        {
                            if (MessageBox.Show(Core.MainWindow,
                                                "Are you sure you want to delete '" + res.DisplayName + "'?", "Delete Bookmark",
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            {
                                return;
                            }
                        }
                    }
                    IBookmarkService bookmarkService =
                        (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));
                    IBookmarkProfile profile = bookmarkService.GetOwnerProfile(res);
                    string           error   = null;
                    if (profile != null && profile.CanDelete(res, out error))
                    {
                        profile.Delete(res);
                    }
                    if (res.Type == "Folder")
                    {
                        bookmarkService.DeleteFolder(res);
                    }
                    else
                    {
                        bookmarkService.DeleteBookmark(res);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public bool CanDropResources(IResource targetResource, IResourceList dragResources)
 {
     if (dragResources.Count > 0)
     {
         if (targetResource != _bookmarkService.BookmarksRoot)
         {
             if (targetResource.Type != "Folder")
             {
                 return(false);
             }
             IBookmarkProfile targetProfile = _bookmarkService.GetOwnerProfile(targetResource);
             foreach (IResource dragRes in dragResources)
             {
                 string           error;
                 IBookmarkProfile sourceProfile = _bookmarkService.GetOwnerProfile(dragRes);
                 if (sourceProfile == targetProfile)
                 {
                     if (targetProfile != null && !targetProfile.CanMove(dragRes, targetResource, out error))
                     {
                         return(false);
                     }
                 }
                 else
                 {
                     if (sourceProfile != null && !sourceProfile.CanDelete(dragRes, out error))
                     {
                         return(false);
                     }
                     if (targetProfile != null && !targetProfile.CanCreate(dragRes, out error))
                     {
                         return(false);
                     }
                 }
             }
             IResource temp = targetResource;
             do
             {
                 if (dragResources.IndexOf(temp) >= 0)
                 {
                     return(false);
                 }
                 temp = BookmarkService.GetParent(temp);
             } while(temp != null);
         }
         string[] types = dragResources.GetAllTypes();
         if (types.Length < 3)
         {
             return((types[0] == "Weblink" || types[0] == "Folder") &&
                    (types.Length == 1 || types[1] == "Weblink" || types[1] == "Folder"));
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        /**
         * returns action flags for group of weblinks or folders (IAction.Update methods)
         */
        public static void IActionUpdateWeblinksOrFolders(
            IActionContext context, ref ActionPresentation presentation, ActionType type)
        {
            if (context.SelectedResources == null || context.SelectedResources.Count == 0)
            {
                presentation.Visible = false;
            }
            else
            {
                IBookmarkService service =
                    (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));
                for (int i = 0; i < context.SelectedResources.Count; ++i)
                {
                    IResource res = context.SelectedResources[i];
                    if (res.Type != "Folder" && res.Type != "Weblink")
                    {
                        res = res.GetLinkProp("Source");
                        if (res == null || (res.Type != "Weblink" && res.Type != "Folder"))
                        {
                            presentation.Visible = false;
                            return;
                        }
                    }
                    IBookmarkProfile profile = service.GetOwnerProfile(res);
                    string           error   = null;
                    if (profile != null)
                    {
                        switch (type)
                        {
                        case ActionType.Create:
                        {
                            if (!profile.CanCreate(null, out error))
                            {
                                presentation.Visible = false;
                            }
                            break;
                        }

                        case ActionType.Update:
                        {
                            if (!profile.CanRename(res, out error))
                            {
                                presentation.Visible = false;
                            }
                            break;
                        }

                        case ActionType.Delete:
                        {
                            if (!profile.CanDelete(res, out error))
                            {
                                presentation.Visible = false;
                            }
                            break;
                        }

                        case ActionType.Edit:
                        {
                            break;
                        }
                        }
                        if (!presentation.Visible && error != null && error.Length > 0)
                        {
                            presentation.ToolTip = error;
                        }
                    }
                }
            }
        }