コード例 #1
0
ファイル: FileService.cs プロジェクト: pawels17/MUTDOD
        /// <summary>
        /// Opens a view content for the specified file
        /// or returns the existing view content for the file if it is already open.
        /// </summary>
        /// <param name="fileName">The name of the file to open.</param>
        /// <param name="switchToOpenedView">Specifies whether to switch to the view for the specified file.</param>
        /// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
        public IDocument OpenFile(string fileName, bool switchToOpenedDocument)
        {
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("File not found", fileName);
            }
            fileName = FileHelper.NormalizePath(fileName);
            loggingService.Value.Info("Open file " + fileName);

            OpenedFile file = GetOpenedFile(fileName);

            if (file == null)
            {
                file = GetOrCreateOpenedFile(fileName);
                file.TextSelectionChanged += TextSelectionChanged;
                DocumentFactory.CreateDocumentForFile(file);
            }

            if (file.Document != null)
            {
                LayoutManager.ShowDocument(file.Document, switchToOpenedDocument);
            }

            return(file.Document);
        }
コード例 #2
0
ファイル: FileService.cs プロジェクト: pawels17/MUTDOD
        public IDocument NewFile(string extension)
        {
            string defaultName;
            int    counter = 0;

            do
            {
                defaultName = "Untitled" + counter + (extension ?? string.Empty);
                counter++;
            }while (GetOpenedFile(defaultName) != null);

            OpenedFile file = CreateUntitledOpenedFile(extension, defaultName);

            file.TextSelectionChanged += TextSelectionChanged;
            DocumentFactory.CreateDocumentForFile(file);

            if (file.Document != null)
            {
                LayoutManager.ShowDocument(file.Document, true);
            }

            return(file.Document);
        }