public void OnCobolFileChanged(object sender, CobolFileChangedEvent fileEvent) { if (fileEvent.Type == CobolFileChangeType.FileChanged) { textDocument.LoadChars(cobolFile.ReadChars()); } else { throw new InvalidOperationException("File change type " + fileEvent.Type + " is not supported in this configuration"); } }
/// <summary> /// Loads the content of a source file in the editor /// </summary> public TypeCobolEditor(CobolFile sourceFile) { TextView textView = TextArea.TextView; // Default text style FontFamily = new FontFamily("Consolas"); FontSize = 13; // Show line numbers ShowLineNumbers = true; // Activate search box SearchPanel.Install(this); // Plug in TypeCobol syntax highlighting syntaxHighlighter = new SyntaxHighlighter(); textView.LineTransformers.Add(syntaxHighlighter); // Plug in TypeCobol error marker errorMarker = new ErrorMarker(this); textView.BackgroundRenderers.Add(errorMarker); textView.LineTransformers.Add(errorMarker); // Tooltip management tooltipManager = new TooltipManager(this, errorMarker); textView.MouseHover += tooltipManager.MouseHover; textView.MouseHoverStopped += tooltipManager.MouseHoverStopped; textView.VisualLinesChanged += tooltipManager.VisualLinesChanged; // Initial load of the cobol file if necessary if (sourceFile != null) { Document = new ICSharpCode.AvalonEdit.Document.TextDocument(sourceFile.ReadChars()); } // Wrap the AvalonEdit.Document in a ITextDocument interface textDocument = new AvalonEditTextDocument(Document, IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), ColumnsLayout.CobolReferenceFormat); }
/// <summary> /// Common internal implementation for all constructors above /// </summary> private FileCompiler(string libraryName, string fileName, CobolFile loadedCobolFile, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, ITextDocument textDocument, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile, [CanBeNull] MultilineScanState scanState, CompilationProject compilationProject, List <RemarksDirective.TextNameVariation> copyTextNameVariations) { var chrono = new Stopwatch(); chrono.Start(); // 1.a Find the Cobol source file CobolFile sourceFile = null; CompilationProject = compilationProject; if (fileName != null) { if (sourceFileProvider.TryGetFile(libraryName, fileName, out sourceFile)) { CobolFile = sourceFile; } else { var message = string.IsNullOrEmpty(libraryName) ? string.Format("Cobol source file not found: {0}", fileName) : string.Format("Cobol source file not found: {0} in {1}", fileName, libraryName); throw new Exception(message); } } // 1.b Register a Cobol source file which was already loaded else if (loadedCobolFile != null) { CobolFile = loadedCobolFile; } chrono.Stop(); SourceFileSearchTime = (int)chrono.ElapsedMilliseconds; chrono.Reset(); // 2.a Load it in a new text document in memory chrono.Start(); if (textDocument == null) { TextDocument = new ReadOnlyTextDocument(sourceFile?.Name, sourceFile?.Encoding, columnsLayout, sourceFile?.ReadChars()); } // 2.b Load it in an existing text document in memory else if (sourceFile != null) { TextDocument = textDocument; textDocument.LoadChars(sourceFile.ReadChars()); } // 2.c Use a pre-existing text document // - not yet associated with a Cobol source file // - with a Cobol source file already loaded else if (sourceFile == null || loadedCobolFile != null) { TextDocument = textDocument; } chrono.Stop(); SourceFileLoadTime = (int)chrono.ElapsedMilliseconds; chrono.Reset(); // 3. Prepare the data structures used by the different steps of the compiler if (isCopyFile) { CompilationResultsForCopy = new CompilationDocument(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, scanState, copyTextNameVariations); CompilationResultsForCopy.CustomSymbols = customSymbols; } else { CompilationResultsForProgram = new CompilationUnit(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, copyTextNameVariations); CompilationResultsForProgram.CustomSymbols = customSymbols; } CompilerOptions = compilerOptions; }
/// <summary> /// Common internal implementation for all 4 constructors above /// </summary> private FileCompiler(string libraryName, string fileName, CobolFile loadedCobolFile, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, ITextDocument textDocument, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile, [CanBeNull] MultilineScanState scanState, CompilationProject compilationProject, List <RemarksDirective.TextNameVariation> copyTextNameVariations) { // 1.a Find the Cobol source file CobolFile sourceFile = null; CompilationProject = compilationProject; if (fileName != null) { if (sourceFileProvider.TryGetFile(libraryName, fileName, out sourceFile)) { CobolFile = sourceFile; } else { if (isCopyFile) { compilationProject.MissingCopys.Add(fileName); } throw new Exception(string.Format("Could not find a Cobol source file named {0} in {1}", fileName, libraryName)); } } // 1.b Register a Cobol source file which was already loaded else if (loadedCobolFile != null) { CobolFile = loadedCobolFile; } // 2.a Load it in a new text document in memory if (textDocument == null) { TextDocument = new ReadOnlyTextDocument(sourceFile.Name, sourceFile.Encoding, columnsLayout, sourceFile.ReadChars()); } // 2.b Load it in an existing text document in memory else if (sourceFile != null) { TextDocument = textDocument; textDocument.LoadChars(sourceFile.ReadChars()); } // 2.c Use a pre-existing text document // - not yet associated with a Cobol source file // - with a Cobol source file already loaded else if (sourceFile == null || loadedCobolFile != null) { TextDocument = textDocument; } // 3. Prepare the data structures used by the different steps of the compiler if (isCopyFile) { CompilationResultsForCopy = new CompilationDocument(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, scanState, copyTextNameVariations); CompilationResultsForCopy.CustomSymbols = customSymbols; } else { CompilationResultsForProgram = new CompilationUnit(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, copyTextNameVariations); CompilationResultsForProgram.CustomSymbols = customSymbols; } CompilerOptions = compilerOptions; }