Пример #1
0
        public void Remove()
        {
            var 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());
            AssertHelper.SequenceEqual(new[] { "Doc3", "Doc2" }, recentFileList.RecentFiles.Select(f => f.Path));
            recentFileList.Remove(recentFileList.RecentFiles.First());
            AssertHelper.SequenceEqual(new[] { "Doc2" }, recentFileList.RecentFiles.Select(f => f.Path));
            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));
        }
Пример #2
0
        private IDocument OpenCore(string fileName, FileType fileType = null)
        {
            // Check if document is already opened
            var document = Documents.SingleOrDefault(d => d.FileName == fileName);

            if (document == null)
            {
                IDocumentType documentType;
                if (fileType != null)
                {
                    documentType = GetDocumentType(fileType);
                }
                else
                {
                    documentType = documentTypes.FirstOrDefault(dt => dt.FileExtension == Path.GetExtension(fileName));
                    if (documentType == null)
                    {
                        Trace.TraceError(string.Format(CultureInfo.InvariantCulture,
                                                       "The extension of the file '{0}' is not supported.", fileName));
                        messageService.ShowError(shellService.ShellView,
                                                 string.Format(CultureInfo.CurrentCulture, Resources.FileExtensionNotSupported, fileName));
                        return(null);
                    }
                }

                try
                {
                    document = documentType.Open(fileName);
                }
                catch (Exception e)
                {
                    Trace.TraceError(e.ToString());
                    messageService.ShowError(shellService.ShellView,
                                             string.Format(CultureInfo.CurrentCulture, Resources.CannotOpenFile, fileName));
                    if (e is FileNotFoundException)
                    {
                        var recentFile = recentFileList.RecentFiles.FirstOrDefault(x => x.Path == fileName);
                        if (recentFile != null)
                        {
                            recentFileList.Remove(recentFile);
                        }
                    }
                    return(null);
                }

                fileService.AddDocument(document);
                recentFileList.AddFile(document.FileName);
            }
            ActiveDocument = document;
            return(document);
        }
Пример #3
0
    public void AddRecentFile(string path)
    {
        if (RecentFileList.Contains(path) == false)
        {
            if (RecentFileList.Count == this.MaxRecentFiles)
            {
                RecentFileList.RemoveAt(RecentFileList.Count - 1);
            }
            RecentFileList.Insert(0, path);
        }
        else
        {
            if (RecentFileList.Count == this.MaxRecentFiles)
            {
                RecentFileList.RemoveAt(RecentFileList.Count - 1);
            }

            RecentFileList.Remove(path);
            RecentFileList.Insert(0, path);
        }
        this.Save();
    }