public LoadFile ( string fileName, Stream stream, bool autoLoadHighlighting, bool autodetectEncoding ) : void | ||
fileName | string | The name of the file to open. Used to find the correct highlighting strategy /// if autoLoadHighlighting is active, and sets the filename property to this value. |
stream | Stream | The stream to actually load the file content from. |
autoLoadHighlighting | bool | Automatically load the highlighting for the file |
autodetectEncoding | bool | Automatically detect file encoding and set Encoding property to the detected encoding. |
return | void |
public void LoadFile(string fileName, Stream stream, bool autoLoadHighlighting, bool autodetectEncoding)
{
if (stream == null)
throw new ArgumentNullException("stream");
BeginUpdate();
document.TextContent = String.Empty;
document.UndoStack.ClearAll();
document.BookmarkManager.Clear();
if (autoLoadHighlighting) {
try {
document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(fileName);
} catch (HighlightingDefinitionInvalidException ex) {
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
if (autodetectEncoding) {
Encoding encoding = this.Encoding;
Document.TextContent = Util.FileReader.ReadFileContent(stream, ref encoding);
this.Encoding = encoding;
} else {
using (StreamReader reader = new StreamReader(fileName, this.Encoding)) {
Document.TextContent = reader.ReadToEnd();
}
}
this.FileName = fileName;
Document.UpdateQueue.Clear();
EndUpdate();
OptionsChanged();
Refresh();
}
public void loadSourceCodeFileIntoTextEditor(String fileToLoad, TextEditorControlBase tecTargetTextEditor) { fileToLoad = tryToResolveFileLocation(fileToLoad, this); //this.okThreadSync(delegate //ExtensionMethods.invokeOnThread((Control)this, () => tecSourceCode.invokeOnThread( () => { try { partialFileViewMode = false; lbPartialFileView.Visible = false; tecSourceCode.Visible = true; long iCurrentFileSize = Files_WinForms.getFileSize(fileToLoad); if (iCurrentFileSize > (iMaxFileSize*1024)) { PublicDI.log.error("File to load is too big: max is {0}k, this file is {1}k : {2}", iMaxFileSize, iCurrentFileSize/1024, fileToLoad); loadPartialFileView(fileToLoad); } else { if (fileToLoad.extension(".h2")) { setPathToFileLoaded(fileToLoad); setDocumentContents(H2.load(fileToLoad).SourceCode, fileToLoad, false); setDocumentHighlightingStrategy("aa.cs"); } else { tecTargetTextEditor.LoadFile(fileToLoad); } if (fileToLoad.extension(".o2")) { var realFileTypeToload = Path.GetFileNameWithoutExtension(fileToLoad); tecSourceCode.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(realFileTypeToload); } lbSourceCode_UnsavedChanges.Visible = false; btSaveFile.Enabled = false; eFileOpen(fileToLoad); } } catch (Exception ex) { PublicDI.log.error("in loadSourceCodeFileIntoTextEditor: {0}", ex.Message); } return default(object); }); }