Exemplo n.º 1
0
        public void CopyBookmarks(int level, string sourcePath, string targetPath)
        {
            if (sourcePath.Equals(targetPath, StringComparison.InvariantCulture))
            {
                return;
            }

            if (targetPath.StartsWith(sourcePath, StringComparison.InvariantCulture))
            {
                return;
            }

            foreach (KeyValuePair <string, BookmarkFolder> kvp in BookmarkFolders
                     .Where(x => x.Key.StartsWith(sourcePath)).OrderBy(x => x.Key.Length).ToList())
            {
                string[] sourcePathParts    = kvp.Key.Split(new char[] { '/' }).Skip(level).ToArray();
                string   relativeSourcePath = string.Join("/", sourcePathParts);
                string   combinedTargetPath = string.IsNullOrEmpty(targetPath) ? relativeSourcePath : (targetPath + "/" + relativeSourcePath);

                RegisterPath(combinedTargetPath, kvp.Value.Text);
            }

            foreach (string key in Bookmarks
                     .Where(x => x.Key.StartsWith(sourcePath))
                     .Select(x => x.Key).ToList())
            {
                string combinedTargetPath = CombineBookmarkPath(level, key, targetPath);

                CopyBookmark(key, combinedTargetPath);
            }
        }
Exemplo n.º 2
0
        public void RemovePath(string path)
        {
            foreach (string key in Bookmarks
                     .Where(x => x.Key.Equals(path))
                     .Select(x => x.Key).ToList())
            {
                Bookmarks.Remove(key);
            }

            if (BookmarkFolders.ContainsKey(path))
            {
                BookmarkFolders.Remove(path);
            }

            foreach (string key in Bookmarks
                     .Where(x => x.Key.StartsWith(path + '/', StringComparison.OrdinalIgnoreCase))
                     .Select(x => x.Key).ToList())
            {
                Bookmarks.Remove(key);
            }

            foreach (string key in BookmarkFolders
                     .Where(x => x.Key.StartsWith(path + '/', StringComparison.OrdinalIgnoreCase))
                     .Select(x => x.Key).ToList())
            {
                BookmarkFolders.Remove(key);
            }
        }
Exemplo n.º 3
0
        public BookmarkFolder RegisterPath(string path, string customText)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            BookmarkFolder folder = null;

            string[] parts = path.Split(new char[] { '/' });

            for (int i = 0; i < parts.Length; ++i)
            {
                string        part = parts[i];
                StringBuilder sb   = new StringBuilder();

                for (int j = 0; j <= i; ++j)
                {
                    if (j != 0)
                    {
                        sb.Append('/');
                    }
                    sb.Append(parts[j]);
                }

                string subPath = sb.ToString();

                if (!BookmarkFolders.TryGetValue(subPath, out folder))
                {
                    folder = new BookmarkFolder()
                    {
                        Path = subPath, Text = customText ?? part
                    };

                    BookmarkFolderCancelEventArgs e = new BookmarkFolderCancelEventArgs(subPath, folder);

                    OnFolderAdding(e);

                    if (e.Cancel)
                    {
                        return(null);
                    }

                    BookmarkFolders.Add(subPath, folder);

                    OnFolderAdded(new BookmarkFolderChangeEventArgs(subPath, folder));
                }
            }

            return(folder);
        }