Esempio n. 1
0
        private void contextSaveBookmarks_Click(object sender, RoutedEventArgs e)
        {
            List<TagEntry> bookmarkedTags = _allTags.Entries.Where(t => t != null && t.IsBookmark).ToList();
            if (bookmarkedTags.Count == 0)
            {
                MetroMessageBox.Show("No Bookmarked Tags!",
                    "If you want to save the current bookmarks, it helps if you bookmark some tags first.");
                return;
            }

            // Save these bookmarks
            KeyValuePair<string, int> keypair = MetroTagBookmarkSaver.Show();

            if (keypair.Key == null || keypair.Value == -1)
                return;

            var bookmarkStorage = new BookmarkStorageFormat
            {
                StorageUsingTagNames = (keypair.Value == 1)
            };

            if (bookmarkStorage.StorageUsingTagNames)
            {
                bookmarkStorage.BookmarkedTagNames = bookmarkedTags.Select(t => new[]
                {
                    CharConstant.ToString(t.RawTag.Class.Magic),
                    t.TagFileName.ToLowerInvariant()
                }).ToList();
            }
            else
            {
                bookmarkStorage.BookmarkedDatumIndices = bookmarkedTags.Select(t => t.RawTag.Index.Value).ToList();
            }

            string jsonString = JsonConvert.SerializeObject(bookmarkStorage);

            if (File.Exists(keypair.Key))
                File.Delete(keypair.Key);

            File.WriteAllText(keypair.Key, jsonString);
        }
Esempio n. 2
0
        private void contextSaveBookmarks_Click(object sender, RoutedEventArgs e)
        {
            if (TagsBookmarked == null || TagsBookmarked.Count <= 0)
            {
                MetroMessageBox.Show("No Bookmarked Tags!",
                                     "If you want to save the current bookmarks, it helps if you bookmark some tags first.");
                return;
            }

            // Save these bookmarks
            var keypair = MetroTagBookmarkSaver.Show();

            if (keypair.Key == null || keypair.Value == -1)
                return;

            var bookmarkStorage = new BookmarkStorageFormat
                                      {
                                          StorageUsingTagNames = (keypair.Value == 1)
                                      };

            if (bookmarkStorage.StorageUsingTagNames)
            {
                bookmarkStorage.BookmarkedTagNames = new List<string[]>();
                foreach (var tagEntry in TagsBookmarked.SelectMany(tagClass => tagClass.Children))
                    bookmarkStorage.BookmarkedTagNames.Add(new[]
                                                               {
                                                                   tagEntry.ParentClass.TagClassMagic.ToLowerInvariant(),
                                                                   tagEntry.TagFileName.ToLowerInvariant()
                                                               });
            }
            else
            {
                bookmarkStorage.BookmarkedDatumIndices = new List<uint>();
                foreach (var tagEntry in TagsBookmarked.SelectMany(tagClass => tagClass.Children))
                    bookmarkStorage.BookmarkedDatumIndices.Add(tagEntry.RawTag.Index.Value);
            }

            var jsonString = JsonConvert.SerializeObject(bookmarkStorage);

            if (File.Exists(keypair.Key))
                File.Delete(keypair.Key);

            File.WriteAllText(keypair.Key, jsonString);
        }