Beispiel #1
0
        public void Execute(IActionContext context)
        {
            IResourceList resources         = context.SelectedResources;
            IResource     folder            = BookmarkService.GetBookmarksRoot();
            IResource     selected          = folder;
            string        url               = context.CurrentUrl;
            bool          isWeblinkSelected = false;

            if (resources.Count > 0)
            {
                selected = resources[0];
            }
            else
            {
                if (FavoritesPlugin._favoritesTreePane.SelectedNode != null)
                {
                    selected = FavoritesPlugin._favoritesTreePane.SelectedNode;
                }
            }
            if (selected.Type == "Folder")
            {
                folder = selected;
            }
            else if (selected.Type == "Weblink")
            {
                folder            = BookmarkService.GetParent(selected);
                isWeblinkSelected = url != null && selected.GetPropText(FavoritesPlugin._propURL) == url;
            }
            else
            {
                selected = selected.GetLinkProp("Source");
                if (selected != null && selected.Type == "Weblink")
                {
                    folder            = BookmarkService.GetParent(selected);
                    isWeblinkSelected = url != null && selected.GetPropText(FavoritesPlugin._propURL) == url;
                }
            }

            using (AddFavoriteForm frm = new AddFavoriteForm(folder))
            {
                if (!isWeblinkSelected || Core.TabManager.CurrentTabId != "Web")
                {
                    if (url != null)
                    {
                        frm.SetURL(url);
                    }
                    if (context.CurrentPageTitle != null)
                    {
                        frm._nameBox.Text = context.CurrentPageTitle;
                    }
                }
                frm.ShowDialog(Core.MainWindow);
            }
        }
Beispiel #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);
 }
Beispiel #3
0
        private void _okButton_Click(object sender, System.EventArgs e)
        {
            HashSet updatesResources = new HashSet();

            for (int i = 0; i < content.Count; ++i)
            {
                IResource webLink = content[i];
                if (webLink.Type != "Weblink" && webLink.Type != "Folder")
                {
                    webLink = webLink.GetLinkProp("Source");
                }
                updatesResources.Add(webLink);
            }

            for (int i = 0; i < content.Count; ++i)
            {
                IResource webLink = content[i];
                if (webLink.Type != "Weblink" && webLink.Type != "Folder")
                {
                    webLink = webLink.GetLinkProp("Source");
                }
                IResource parent = BookmarkService.GetParent(webLink);
                while (parent != null)
                {
                    if (content.IndexOf(parent) >= 0)
                    {
                        updatesResources.Remove(webLink);
                        break;
                    }
                    parent = BookmarkService.GetParent(parent);
                }
            }

            int updateFreq = (_updateCheckBox.Checked) ? ((int)_hoursBox.Value * 60 * 60) : 0;
            int unitIndex  = _unitBox.SelectedIndex;

            if (unitIndex > 0)
            {
                updateFreq *= 24;
                if (unitIndex > 1)
                {
                    updateFreq *= 7;
                }
            }

            foreach (HashSet.Entry E in updatesResources)
            {
                new ResourceProxy((IResource)E.Key).SetPropAsync(FavoritesPlugin._propUpdateFreq, updateFreq);
            }

            Close();
        }
Beispiel #4
0
 public void Execute(IActionContext context)
 {
     if (context.SelectedResources.Count == 0)
     {
         _parentFolder = BookmarkService.GetBookmarksRoot();
     }
     else
     {
         _parentFolder = context.SelectedResources[0];
         if (_parentFolder.Type == "Weblink")
         {
             _parentFolder = BookmarkService.GetParent(_parentFolder);
         }
     }
     Core.ResourceAP.QueueJob(JobPriority.Immediate, new MethodInvoker(NewFolder));
 }
Beispiel #5
0
        /**
         * Gets full name of IE folder or favorite
         */
        public string GetResourceFullname(IResource res)
        {
            Guard.NullArgument(res, "res");
            IResource parent = res;
            IResource ieRoot = _bookmarkservice.GetProfileRoot(this);

            if (ieRoot != null)
            {
                Stack parents = new Stack();
                for ( ; ;)
                {
                    if (parent == ieRoot)
                    {
                        string fullName = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
                        while (parents.Count > 0)
                        {
                            res      = (IResource)parents.Pop();
                            fullName = IOTools.Combine(fullName, res.DisplayName);
                        }
                        if (fullName.IndexOfAny(InvalidNameChars) >= 0)
                        {
                            foreach (char invalidChar in Path.InvalidPathChars)
                            {
                                fullName = fullName.Replace(invalidChar, '-');
                            }
                        }
                        fullName = fullName.Replace("https://", null);
                        fullName = fullName.Replace("http://", null);
                        fullName = fullName.Replace("ftp://", null);
                        fullName = fullName.Replace("file://", null);
                        fullName = fullName.Replace("://", null);
                        if (res.Type != "Folder")
                        {
                            fullName += ".url";
                        }
                        return(fullName);
                    }
                    if ((parent = BookmarkService.GetParent(parent)) == null)
                    {
                        break;
                    }
                    parents.Push(res);
                    res = parent;
                }
            }
            return(string.Empty);
        }
Beispiel #6
0
        public void Rename(IResource res, string newName)
        {
            BookmarkChange change = new BookmarkChange();

            change.type  = 0;
            change.id    = res.Id;
            change.rdfid = res.GetPropText(FavoritesPlugin._propBookmarkId);
            IResource parent = BookmarkService.GetParent(res);

            if (parent != null)
            {
                change.parent    = GetFolderBookmarkId(parent);
                change.parent_id = parent.Id;
            }
            change.name = newName;
            change.url  = res.GetPropText(FavoritesPlugin._propURL);
            LogBookmarkChange(change);
        }
Beispiel #7
0
        public void ResourcesDropped(IResource targetResource, IResourceList droppedResources)
        {
            IBookmarkProfile targetProfile = _bookmarkService.GetOwnerProfile(targetResource);

            foreach (IResource dropRes in droppedResources)
            {
                IResource        oldParent     = BookmarkService.GetParent(dropRes);
                IBookmarkProfile sourceProfile = _bookmarkService.GetOwnerProfile(dropRes);
                if (sourceProfile == targetProfile)
                {
                    if (targetProfile != null)
                    {
                        targetProfile.Move(dropRes, targetResource, oldParent);
                    }
                    new ResourceProxy(dropRes).SetProp(_propParent, targetResource);
                }
                else
                {
                    if (sourceProfile != null)
                    {
                        sourceProfile.Delete(dropRes);
                    }
                    new ResourceProxy(dropRes).SetProp(_propParent, targetResource);
                    if (targetProfile != null)
                    {
                        targetProfile.Create(dropRes);
                    }
                }
                // the resource may have been moved from a parent which belonged to a workspace
                // to the top level (#5066)
                if (dropRes.Type == "Weblink")
                {
                    Core.WorkspaceManager.AddToActiveWorkspace(dropRes);
                }
                else
                {
                    Core.WorkspaceManager.AddToActiveWorkspaceRecursive(dropRes);
                }
            }
        }