public static BookmarkModel CreateTestData(BookmarkProfile profile, string rootLabel = "Bookmarks") { BookmarkModel root = new BookmarkModel(profile, BookmarkModel.BookmarkEntryType.Root, rootLabel); BookmarkModel sub = new BookmarkModel(profile, BookmarkModel.BookmarkEntryType.Directory, rootLabel + "/Sub"); BookmarkModel sub2 = new BookmarkModel(profile, BookmarkModel.BookmarkEntryType.Directory, rootLabel + "/Sub2"); root.SubModels.Add(sub); root.SubModels.Add(sub2); sub.SubModels.Add(new BookmarkModel(profile, BookmarkModel.BookmarkEntryType.Link, rootLabel + "/Sub/Link")); return root; }
public override async Task <IList <IEntryModel> > ListAsync(IEntryModel entry, CancellationToken ct, Func <IEntryModel, bool> filter = null, bool refresh = false) { BookmarkModel bm = entry as BookmarkModel; filter = filter ?? (em => true); if (bm != null) { return(bm.SubModels.Where(sub => filter(sub)).Cast <IEntryModel>().ToList()); } throw new NotImplementedException(); }
public static void Test() { BookmarkProfile profile = new BookmarkProfile(); BookmarkModel root = CreateTestData(profile); XmlSerializer serializer = new XmlSerializer(typeof(BookmarkModel)); MemoryStream ms = new MemoryStream(); serializer.Serialize(ms, root); ms.Seek(0, SeekOrigin.Begin); BookmarkModel root1 = serializer.Deserialize(ms) as BookmarkModel; Debug.WriteLine(root1); }
private void add(BookmarkModel source, BookmarkModel target) { var addedModel = (source.Type == BookmarkModel.BookmarkEntryType.Link) ? target.AddLink(source.Label, source.LinkPath) : target.AddFolder(source.Label); if (source.Type == BookmarkModel.BookmarkEntryType.Directory) { foreach (var sub in source.SubModels) { add(sub, addedModel); } } }
public async Task LoadSettingsAsync() { var settingsFile = await _store.ParseAsync(_fileName); if (settingsFile != null) { XmlSerializer serializer = new XmlSerializer(typeof(BookmarkModel)); using (var stream = await _store.DiskIO.OpenStreamAsync(settingsFile, FileAccess.Read, CancellationToken.None)) { BookmarkModel bm = serializer.Deserialize(stream) as BookmarkModel; bm.Profile = this; _rootModel = bm; } await RefreshAllBookmarksAsync(); } }
private BookmarkModel lookup(BookmarkModel lookupEntryModel, string[] pathSplits, int idx) { if (lookupEntryModel == null) { return(null); } if (idx >= pathSplits.Length) { return(lookupEntryModel); } return (lookup(lookupEntryModel.SubModels.FirstOrDefault(sub => sub.Name.Equals(pathSplits[idx])), pathSplits, idx + 1)); }
public override void OnDragCompleted(IEnumerable <IDraggable> draggables, DragDropEffectsEx effect) { if (effect == DragDropEffectsEx.Move) { foreach (var b in draggables.Where(d => d is BookmarkModel).Cast <BookmarkModel>()) { BookmarkModel parentModel = b.Parent as BookmarkModel; if (parentModel != null) { parentModel.Remove(b.Label); } (parentModel.Profile as BookmarkProfile).RaiseEntryChanged( new EntryChangedEvent(ChangeType.Deleted, b.FullPath)); } } }
public override DragDropEffectsEx Drop(IEnumerable <IDraggable> draggables, DragDropEffectsEx allowedEffects) { foreach (var e in draggables.Where(d => d is IEntryModel).Cast <IEntryModel>()) { BookmarkModel be = e as BookmarkModel; if (be != null) { add(be, _dropTarget as BookmarkModel); } else { _dropTarget.AddLink(e.Label, e.FullPath); } } return(allowedEffects); }
public BookmarkModel AddFolder(string label) { var nameGenerator = FileNameGenerator.Rename(label); while (SubModels.Any(bm => bm.Label == label)) { label = nameGenerator.Generate(); } var retVal = new BookmarkModel(Profile as BookmarkProfile, BookmarkEntryType.Directory, FullPath + "/" + label) { Name = label }; SubModels.Add(retVal); (Profile as BookmarkProfile).RaiseEntryChanged(new EntryChangedEvent(ChangeType.Created, retVal.FullPath)); return(retVal); }
public BookmarkProfile(IEventAggregator events = null) : base(events) { ProfileName = "Bookmarks"; HierarchyComparer = new PathHierarchyComparer <BookmarkModel>(StringComparison.CurrentCultureIgnoreCase, '/'); MetadataProvider = new BasicMetadataProvider(); Path = PathHelper.Web; _rootLabel = "Bookmarks"; _rootModel = new BookmarkModel(this, BookmarkModel.BookmarkEntryType.Root, _rootLabel); //BookmarkSerializeTest.CreateTestData(this, rootLabel); //new BookmarkModel(BookmarkModel.BookmarkEntryType.Root, rootLabel); //CommandProviders.Add(new BookmarkCommandProvider(this)); DeleteCommand = ScriptCommands.ForEach("{DeleteEntries}", "{CurrentEntry}", ScriptCommands.ExecuteMethod("{CurrentEntry.Parent}", "Remove", new object[] { "{CurrentEntry.Label}" })); CreateFolderCommand = ScriptCommands.ExecuteFunc("{BaseFolder}", "AddFolder", new object[] { "{FolderName}" }, "{CreatedFolder}"); PathPatterns = new string[] { _rootLabel + ".*" }; DragDrop = new BookmarkDragDropHandler(); AllBookmarks = new List <BookmarkModel>(); }
public override IEnumerable <IModelIconExtractor <IEntryModel> > GetIconExtractSequence(IEntryModel entry) { BookmarkModel bm = entry as BookmarkModel; switch (bm.Type) { case BookmarkModel.BookmarkEntryType.Link: return(new List <IModelIconExtractor <IEntryModel> >() { new LoadFromLinkPath(_profiles) }); case BookmarkModel.BookmarkEntryType.Root: return(new List <IModelIconExtractor <IEntryModel> >() { new LoadFromAssembly(typeof(BookmarkProfile).GetTypeInfo().Assembly, "FileExplorer.Themes.Resources.bookmark.ico") }); default: return(base.GetIconExtractSequence(entry)); } }
public BookmarkDropHelper(BookmarkModel dropTarget) { IsDroppable = true; _dropTarget = dropTarget; }