This class encapsulates the logic for a recent file list.
This class can be used in a Settings file to store and load the recent file list as user settings. In Visual Studio you might need to enter the full class name "System.Waf.Applications.RecentFileList" in the "Select a type" dialog.
Inheritance: IXmlSerializable
コード例 #1
0
ファイル: FileController.cs プロジェクト: jbe2277/waf
        public FileController(IMessageService messageService, IFileDialogService fileDialogService, IShellService shellService,
            FileService fileService, ExportFactory<SaveChangesViewModel> saveChangesViewModelFactory)
        {
            this.messageService = messageService;
            this.fileDialogService = fileDialogService;
            this.shellService = shellService;
            this.fileService = fileService;
            this.saveChangesViewModelFactory = saveChangesViewModelFactory;
            this.documentTypes = new List<IDocumentType>();
            this.newCommand = new DelegateCommand(NewCommand);
            this.openCommand = new DelegateCommand(OpenCommand);
            this.closeCommand = new DelegateCommand(CloseCommand, CanCloseCommand);
            this.saveCommand = new DelegateCommand(SaveCommand, CanSaveCommand);
            this.saveAsCommand = new DelegateCommand(SaveAsCommand, CanSaveAsCommand);
            
            this.fileService.NewCommand = newCommand;
            this.fileService.OpenCommand = openCommand;
            this.fileService.CloseCommand = closeCommand;
            this.fileService.SaveCommand = saveCommand;
            this.fileService.SaveAsCommand = saveAsCommand;

            this.recentFileList = Settings.Default.RecentFileList ?? new RecentFileList();
            this.fileService.RecentFileList = recentFileList;

            PropertyChangedEventManager.AddHandler(fileService, FileServicePropertyChanged, "");
        }
コード例 #2
0
        public FileController(CompositionContainer container, IMessageService messageService, IFileDialogService fileDialogService, 
            IShellService shellService, FileService fileService)
        {
            this.container = container;
            this.messageService = messageService;
            this.fileDialogService = fileDialogService;
            this.shellService = shellService;
            this.fileService = fileService;
            this.documentTypes = new List<IDocumentType>();
            this.newCommand = new DelegateCommand(NewCommand);
            this.openCommand = new DelegateCommand(OpenCommand);
            this.closeCommand = new DelegateCommand(CloseCommand, CanCloseCommand);
            this.saveCommand = new DelegateCommand(SaveCommand, CanSaveCommand);
            this.saveAsCommand = new DelegateCommand(SaveAsCommand, CanSaveAsCommand);

            this.fileService.NewCommand = newCommand;
            this.fileService.OpenCommand = openCommand;
            this.fileService.CloseCommand = closeCommand;
            this.fileService.SaveCommand = saveCommand;
            this.fileService.SaveAsCommand = saveAsCommand;

            this.recentFileList = Settings.Default.RecentFileList;
            if (this.recentFileList == null) { this.recentFileList = new RecentFileList(); }
            this.fileService.RecentFileList = recentFileList;

            AddWeakEventListener(fileService, FileServicePropertyChanged);
        }
コード例 #3
0
        public void RecentFileList()
        {
            FileService fileService = Container.GetExportedValue<FileService>();

            RecentFileList recentFileList = new RecentFileList();
            AssertHelper.PropertyChangedEvent(fileService, x => x.RecentFileList, () => fileService.RecentFileList = recentFileList);
            Assert.AreEqual(recentFileList, fileService.RecentFileList);
        }
コード例 #4
0
ファイル: RecentFileListTest.cs プロジェクト: jbe2277/waf
        public void SetMaxFilesNumber()
        {
            RecentFileList recentFileList = new RecentFileList();
            recentFileList.AddFile("Doc4");
            recentFileList.AddFile("Doc3");
            recentFileList.AddFile("Doc2");
            recentFileList.AddFile("Doc1");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new [] { "Doc1", "Doc2", "Doc3", "Doc4" }));
            
            // Set a lower number than items are in the list => expect that the list is truncated.
            recentFileList.MaxFilesNumber = 3;
            Assert.AreEqual(3, recentFileList.MaxFilesNumber);
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2", "Doc3" }));

            AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.MaxFilesNumber = -3);
        }
コード例 #5
0
ファイル: RecentFileListTest.cs プロジェクト: jbe2277/waf
        public void AddFilesAndPinThem()
        {
            RecentFileList recentFileList = new RecentFileList();
            recentFileList.MaxFilesNumber = 3;

            // Add files to an empty list
            recentFileList.AddFile("Doc3");
            recentFileList.AddFile("Doc2");
            recentFileList.AddFile("Doc1");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2", "Doc3" }));

            // Pin first file
            recentFileList.RecentFiles.First(r => r.Path == "Doc3").IsPinned = true;
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc1", "Doc2" }));

            // Add a file to a full list
            recentFileList.AddFile("Doc4");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc4", "Doc1" }));

            // Add a file that already exists in the list
            recentFileList.AddFile("Doc1");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc1", "Doc4" }));

            // Pin all files
            recentFileList.RecentFiles.First(r => r.Path == "Doc4").IsPinned = true;
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc4", "Doc3", "Doc1" }));
            recentFileList.RecentFiles.First(r => r.Path == "Doc1").IsPinned = true;
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc4", "Doc3" }));

            // Add a file to a full pinned list
            recentFileList.AddFile("Doc5");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc4", "Doc3" }));

            // Add a file that already exists in the list
            recentFileList.AddFile("Doc4");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc4", "Doc1", "Doc3" }));

            // Unpin files
            recentFileList.RecentFiles.First(r => r.Path == "Doc4").IsPinned = false;
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc3", "Doc4" }));
            recentFileList.RecentFiles.First(r => r.Path == "Doc1").IsPinned = false;
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc1", "Doc4" }));
        }
コード例 #6
0
ファイル: RecentFileListTest.cs プロジェクト: jbe2277/waf
        public void AddFiles()
        {
            RecentFileList recentFileList = new RecentFileList();
            recentFileList.MaxFilesNumber = 3;

            AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.AddFile(null));

            // Add files to an empty list
            recentFileList.AddFile("Doc3");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3" }));
            recentFileList.AddFile("Doc2");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2", "Doc3" }));
            recentFileList.AddFile("Doc1");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2", "Doc3" }));

            // Add a file to a full list
            recentFileList.AddFile("Doc4");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc4", "Doc1", "Doc2" }));

            // Add a file that already exists in the list
            recentFileList.AddFile("Doc2");
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2", "Doc4", "Doc1" }));
        }
コード例 #7
0
ファイル: RecentFileListTest.cs プロジェクト: jbe2277/waf
        public void Load()
        {
            RecentFileList recentFileList = new RecentFileList();
            recentFileList.MaxFilesNumber = 3;
            recentFileList.AddFile("Doc3");
            recentFileList.AddFile("Doc2");
            recentFileList.AddFile("Doc1");

            AssertHelper.ExpectedException<ArgumentNullException>(() => recentFileList.Load(null));

            // Load an empty recent file list
            recentFileList.Load(new RecentFile[] { });
            Assert.IsFalse(recentFileList.RecentFiles.Any());

            recentFileList.Load(new[] 
            {
                new RecentFile("NewDoc1") { IsPinned = true },
                new RecentFile("NewDoc2"),
                new RecentFile("NewDoc3"),
                new RecentFile("NewDoc4")
            });
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "NewDoc1", "NewDoc2", "NewDoc3" }));
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.IsPinned).SequenceEqual(new[] { true, false, false }));
        }
コード例 #8
0
ファイル: RecentFileListTest.cs プロジェクト: jbe2277/waf
        public void XmlSerializing()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(RecentFileList));

            // Serialize an empty list            
            MemoryStream stream1 = new MemoryStream();
            RecentFileList recentFileList1 = new RecentFileList();
            serializer.Serialize(stream1, recentFileList1);
            stream1.Position = 0;
            RecentFileList recentFileList2 = (RecentFileList)serializer.Deserialize(stream1);
            Assert.AreEqual(recentFileList1.RecentFiles.Count, recentFileList2.RecentFiles.Count);
            Assert.IsTrue(recentFileList1.RecentFiles.Select(f => f.Path).SequenceEqual(recentFileList2.RecentFiles.Select(f => f.Path)));

            // Serialize a list with items
            MemoryStream stream2 = new MemoryStream();
            recentFileList2.AddFile("Doc3");
            recentFileList2.AddFile("Doc2");
            recentFileList2.AddFile("Doc1");
            serializer.Serialize(stream2, recentFileList2);
            stream2.Position = 0;
            RecentFileList recentFileList3 = (RecentFileList)serializer.Deserialize(stream2);
            Assert.IsTrue(recentFileList2.RecentFiles.Select(f => f.Path).SequenceEqual(recentFileList3.RecentFiles.Select(f => f.Path)));

            // Set MaxFilesNumber to a lower number
            recentFileList3.MaxFilesNumber = 2;
            Assert.IsTrue(recentFileList3.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc1", "Doc2" }));

            // Check error handling of the serializable implementation
            IXmlSerializable serializable = recentFileList3;
            Assert.IsNull(serializable.GetSchema());
            AssertHelper.ExpectedException<ArgumentNullException>(() => serializable.ReadXml(null));
            AssertHelper.ExpectedException<ArgumentNullException>(() => serializable.WriteXml(null));
        }
コード例 #9
0
ファイル: RecentFileListTest.cs プロジェクト: jbe2277/waf
        public void Remove()
        {
            RecentFileList recentFileList = new RecentFileList();

            AssertHelper.ExpectedException<ArgumentNullException>(() => recentFileList.Remove(null));

            recentFileList.AddFile("Doc1");
            recentFileList.AddFile("Doc2");
            recentFileList.AddFile("Doc3");

            RecentFile lastAdded = recentFileList.RecentFiles.First();

            recentFileList.Remove(recentFileList.RecentFiles.Last());
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc3", "Doc2" }));
            recentFileList.Remove(recentFileList.RecentFiles.First());
            Assert.IsTrue(recentFileList.RecentFiles.Select(f => f.Path).SequenceEqual(new[] { "Doc2" }));
            recentFileList.Remove(recentFileList.RecentFiles.First());
            Assert.IsTrue(!recentFileList.RecentFiles.Any());

            // Try to delete a RecentFile object which was already deleted.
            AssertHelper.ExpectedException<ArgumentException>(() => recentFileList.Remove(lastAdded));
        }