예제 #1
0
        static ITextBuffer GetParseableFileContentInternal(string fileName)
        {
            //ITextBuffer res = project.GetParseableFileContent(fileName);
            //if (res != null)
            //	return res;

            OpenedFile file = FileService.GetOpenedFile(fileName);

            if (file != null)
            {
                IFileDocumentProvider p = file.CurrentView as IFileDocumentProvider;
                if (p != null)
                {
                    IDocument document = p.GetDocumentForFile(file);
                    if (document != null)
                    {
                        return(document.CreateSnapshot());
                    }
                }

                using (Stream s = file.OpenRead()) {
                    // load file
                    return(new StringTextBuffer(ICSharpCode.AvalonEdit.Utils.FileReader.ReadFileContent(s, DefaultFileEncoding)));
                }
            }

            // load file
            return(new StringTextBuffer(ICSharpCode.AvalonEdit.Utils.FileReader.ReadFileContent(fileName, DefaultFileEncoding)));
        }
예제 #2
0
        /// <summary>
        /// Gets the content of the file using encoding auto-detection (or DefaultFileEncoding, if that fails).
        /// If the file is already open, gets the text in the opened view content.
        /// </summary>
        public static string GetParseableFileContent(string fileName)
        {
            IViewContent viewContent = FileService.GetOpenFile(fileName);
            IEditable    editable    = viewContent as IEditable;

            if (editable != null)
            {
                return(editable.Text);
            }
            //string res = project.GetParseableFileContent(fileName);
            //if (res != null)
            //	return res;

            OpenedFile file = FileService.GetOpenedFile(fileName);

            if (file != null)
            {
                IFileDocumentProvider p = file.CurrentView as IFileDocumentProvider;
                if (p != null)
                {
                    IDocument document = p.GetDocumentForFile(file);
                    if (document != null)
                    {
                        return(document.TextContent);
                    }
                }

                using (Stream s = file.OpenRead()) {
                    // load file
                    Encoding encoding = DefaultFileEncoding;
                    return(ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(s, ref encoding));
                }
            }

            // load file
            return(ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(fileName, DefaultFileEncoding));
        }