コード例 #1
0
 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;
 }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
                }
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 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>();
 }
コード例 #11
0
        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));
            }
        }
コード例 #12
0
 public BookmarkDropHelper(BookmarkModel dropTarget)
 {
     IsDroppable = true;
     _dropTarget = dropTarget;
 }