void CopyData(TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document(); monoDocument = new Document(); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange(data); copiedDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset(segment.Offset); var spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert(copiedDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert(monoDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert(copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert(monoDocument.Length, "\r"); } } line = data.Document.GetLine(selection.MinLine); spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public static string GenerateHtml (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options) { var htmlText = new StringBuilder (); htmlText.AppendLine (@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"); htmlText.AppendLine ("<HTML>"); htmlText.AppendLine ("<HEAD>"); htmlText.AppendLine ("<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=utf-8\">"); htmlText.AppendLine ("<META NAME=\"GENERATOR\" CONTENT=\"Mono Text Editor\">"); htmlText.AppendLine ("</HEAD>"); htmlText.AppendLine ("<BODY>"); var selection = new TextSegment (0, doc.TextLength); int startLineNumber = doc.OffsetToLineNumber (selection.Offset); int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset); htmlText.AppendLine ("<FONT face = '" + options.Font.Family + "'>"); bool first = true; if (mode is SyntaxMode) { SyntaxModeService.StartUpdate (doc, (SyntaxMode)mode, selection.Offset, selection.EndOffset); SyntaxModeService.WaitUpdate (doc); } foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) { if (!first) { htmlText.AppendLine ("<BR>"); } else { first = false; } if (mode == null) { AppendHtmlText (htmlText, doc, options, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset)); continue; } int curSpaces = 0; foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) { int start = System.Math.Max (selection.Offset, chunk.Offset); int end = System.Math.Min (chunk.EndOffset, selection.EndOffset); var chunkStyle = style.GetChunkStyle (chunk); if (start < end) { htmlText.Append ("<SPAN style='"); if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal) htmlText.Append ("font-weight:" + ((int)chunkStyle.FontWeight) + ";"); if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal) htmlText.Append ("font-style:" + chunkStyle.FontStyle.ToString ().ToLower () + ";"); htmlText.Append ("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString () + ";"); htmlText.Append ("'>"); AppendHtmlText (htmlText, doc, options, start, end); htmlText.Append ("</SPAN>"); } } } htmlText.AppendLine ("</FONT>"); htmlText.AppendLine ("</BODY></HTML>"); if (Platform.IsWindows) return GenerateCFHtml (htmlText.ToString ()); return htmlText.ToString (); }
void Init(IViewContent view) { this.view = view; editable = view.GetService <IEditable>(); textEditor = view.GetService <ITextEditor>(); textEditorOptions = textEditor.Options; }
static void AppendHtmlText (StringBuilder htmlText, TextDocument doc, ITextEditorOptions options, int start, int end) { for (int i = start; i < end; i++) { char ch = doc.GetCharAt (i); switch (ch) { case ' ': htmlText.Append (" "); break; case '\t': for (int i2 = 0; i2 < options.TabSize; i2++) htmlText.Append (" "); break; case '<': htmlText.Append ("<"); break; case '>': htmlText.Append (">"); break; case '&': htmlText.Append ("&"); break; case '"': htmlText.Append ("""); break; default: htmlText.Append (ch); break; } } }
public CustomEditorOptions(ITextEditorOptions initializeFrom) { if (initializeFrom == null) { throw new ArgumentNullException(nameof(initializeFrom)); } WordFindStrategy = initializeFrom.WordFindStrategy; TabsToSpaces = initializeFrom.TabsToSpaces; IndentationSize = initializeFrom.IndentationSize; TabSize = initializeFrom.TabSize; ShowIconMargin = initializeFrom.ShowIconMargin; ShowLineNumberMargin = initializeFrom.ShowLineNumberMargin; ShowFoldMargin = initializeFrom.ShowFoldMargin; HighlightCaretLine = initializeFrom.HighlightCaretLine; RulerColumn = initializeFrom.RulerColumn; ShowRuler = initializeFrom.ShowRuler; IndentStyle = initializeFrom.IndentStyle; OverrideDocumentEolMarker = initializeFrom.OverrideDocumentEolMarker; EnableSyntaxHighlighting = initializeFrom.EnableSyntaxHighlighting; RemoveTrailingWhitespaces = initializeFrom.RemoveTrailingWhitespaces; WrapLines = initializeFrom.WrapLines; FontName = initializeFrom.FontName; GutterFontName = initializeFrom.GutterFontName; EditorTheme = initializeFrom.EditorTheme; DefaultEolMarker = initializeFrom.DefaultEolMarker; GenerateFormattingUndoStep = initializeFrom.GenerateFormattingUndoStep; EnableSelectionWrappingKeys = initializeFrom.EnableSelectionWrappingKeys; ShowWhitespaces = initializeFrom.ShowWhitespaces; IncludeWhitespaces = initializeFrom.IncludeWhitespaces; SmartBackspace = initializeFrom.SmartBackspace; }
public CodeEditorAdapter(CodeEditor codeEditor, CodeEditorView textEditor) : base(textEditor) { if (codeEditor == null) throw new ArgumentNullException("codeEditor"); this.codeEditor = codeEditor; options = CodeEditorOptions.Instance; }
void Init(IViewContent view) { this.view = view; editable = view.GetService<IEditable>(); textEditor = view.GetService<ITextEditor>(); textEditorOptions = textEditor.Options; }
public TextEditorData(Document doc) { options = TextEditorOptions.DefaultOptions; Document = doc; this.SearchEngine = new BasicSearchEngine(); SelectionChanging += HandleSelectionChanging; }
public CodeEditorFormattingOptionsAdapter(TextEditorOptions originalAvalonEditOptions, ITextEditorOptions originalSDOptions, CSharpFormattingOptionsContainer container) { if (originalAvalonEditOptions == null) { throw new ArgumentNullException("originalAvalonEditOptions"); } if (originalSDOptions == null) { throw new ArgumentNullException("originalSDOptions"); } if (container == null) { throw new ArgumentNullException("container"); } this.originalAvalonEditOptions = originalAvalonEditOptions; this.avalonEditOptions = new TextEditorOptions(originalAvalonEditOptions); this.originalSDOptions = originalSDOptions; this.container = container; // Update overridden options once UpdateOverriddenProperties(); CSharpFormattingPolicies.Instance.FormattingPolicyUpdated += OnFormattingPolicyUpdated; this.originalAvalonEditOptions.PropertyChanged += OnOrigAvalonOptionsPropertyChanged; this.originalSDOptions.PropertyChanged += OnSDOptionsPropertyChanged; }
internal MonoTextEditor(TextDocument doc, ITextEditorOptions options, EditMode initialMode) { this.Direction = TextDirection.Ltr; uiThread = Thread.CurrentThread; GtkWorkarounds.FixContainerLeak(this); WidgetFlags |= WidgetFlags.NoWindow; LayoutCache = new LayoutCache(this); this.textArea = new TextArea(doc, options, initialMode); this.textArea.Initialize(this, doc, options, initialMode); this.textArea.EditorOptionsChanged += (sender, e) => OptionsChanged(sender, e); AddTopLevelWidget(textArea, 0, 0); ShowAll(); stage.ActorStep += OnActorStep; if (Platform.IsMac) { VScroll += delegate { for (int i = 1; i < containerChildren.Count; i++) { containerChildren[i].Child.QueueDraw(); } }; HScroll += delegate { for (int i = 1; i < containerChildren.Count; i++) { containerChildren[i].Child.QueueDraw(); } }; } }
public static IReadOnlyDictionary<AstNode, ISegment> WriteNode(StringWriter writer, AstNode node, CSharpFormattingOptions policy, ITextEditorOptions editorOptions) { var formatter = new SegmentTrackingOutputFormatter(writer); formatter.IndentationString = editorOptions.IndentationString; var visitor = new CSharpOutputVisitor(formatter, policy); node.AcceptVisitor(visitor); return formatter.Segments; }
public static ColorScheme GetColorStyle(this ITextEditorOptions options) { if (options == null) { throw new ArgumentNullException("options"); } return(SyntaxModeService.GetColorStyle(options.ColorScheme)); }
/// <summary> /// Gets the indentation string for a single indent. /// </summary> public static string GetIndentationString(this ITextEditorOptions options) { if (options == null) { throw new ArgumentNullException("options"); } return(options.TabsToSpaces ? new string (' ', options.IndentationSize) : "\t"); }
void Init(IViewContent view) { this.view = view; editable = view as IEditable; textEditorProvider = view as ITextEditorProvider; textEditor = textEditorProvider.TextEditor; textEditorOptions = textEditor.Options; }
public static EditorTheme GetEditorTheme(this ITextEditorOptions options) { if (options == null) { throw new ArgumentNullException("options"); } return(SyntaxHighlightingService.GetEditorTheme(options.EditorTheme)); }
void CopyData(TextEditorData data, Selection selection) { if (!selection.IsEmpty && data != null && data.Document != null) { this.docStyle = data.ColorStyle; this.options = data.Options; copyData = null; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange(data); copiedColoredChunks = ColoredSegment.GetChunks(data, segment); var pasteHandler = data.TextPasteHandler; if (pasteHandler != null) { try { copyData = pasteHandler.GetCopyData(segment); } catch (Exception e) { Console.WriteLine("Exception while getting copy data:" + e); } } break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); copiedColoredChunks = new List <List <ColoredSegment> >(); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedColoredChunks.Add(ColoredSegment.GetChunks(data, new TextSegment(curLine.Offset + col1, col2 - col1)).First()); } else { copiedColoredChunks.Add(new List <ColoredSegment>()); } } break; } } else { copiedColoredChunks = null; } }
public static void CorrectIndent(TextReader code, int startOffset, int endOffset, Action<int, int, string> documentReplace, DFormattingOptions options = null, ITextEditorOptions textStyle = null, bool formatLastLine = true) { textStyle = textStyle ?? TextEditorOptions.Default; var eng = new IndentEngine(options ?? DFormattingOptions.CreateDStandard(), textStyle.TabsToSpaces, textStyle.IndentSize, textStyle.KeepAlignmentSpaces); var replaceActions = new List<DFormattingVisitor.TextReplaceAction>(); int originalIndent = 0; bool hadLineBreak = true; int n = 0; for (int i = 0; i <= endOffset && (n = code.Read()) != -1; i++) { if(n == '\r' || n == '\n') { if (i >= startOffset && !eng.LineBeganInsideString) replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent)); hadLineBreak = true; originalIndent = 0; if (code.Peek() == '\n') { eng.Push((char)code.Read()); i++; } } else if(hadLineBreak) { if(n == ' ' || n== '\t') originalIndent++; else hadLineBreak = false; // If there's code left, format the last line of the selection either if (i == endOffset && formatLastLine) endOffset++; } eng.Push((char)n); } // Also indent the last line if we're at the EOF. if (code.Peek() == -1 || (formatLastLine && n != '\r' && n != '\n')) { if(!eng.LineBeganInsideString) replaceActions.Add(new DFormattingVisitor.TextReplaceAction(eng.Position - eng.LineOffset, originalIndent, eng.ThisLineIndent)); } // Perform replacements from the back of the document to the front - to ensure offset consistency for(int k = replaceActions.Count - 1; k>=0; k--) { var rep = replaceActions[k]; if(rep.RemovalLength > 0 || rep.NewText.Length != 0) documentReplace(rep.Offset, rep.RemovalLength, rep.NewText); } }
public TextEditorData(Document doc) { caret = new Caret(this); caret.PositionChanged += CaretPositionChanged; options = TextEditorOptions.DefaultOptions; Document = doc; this.SearchEngine = new BasicSearchEngine(); }
public CodeEditorAdapter(CodeEditor codeEditor, CodeEditorView textEditor) : base(textEditor) { if (codeEditor == null) { throw new ArgumentNullException("codeEditor"); } this.codeEditor = codeEditor; options = CodeEditorOptions.Instance; }
public TextEditor(TextDocument doc, ITextEditorOptions options, EditMode initialMode) { LayoutCache = new LayoutCache(this); this.textArea = new TextArea(doc, options, initialMode); this.textArea.Initialize(this, doc, options, initialMode); this.textArea.EditorOptionsChanged += (sender, e) => OptionsChanged(sender, e); AddTopLevelWidget(textArea, 0, 0); stage.ActorStep += OnActorStep; }
public static TextEditorOptions ToEditorOptions(this ITextEditorOptions options) { return(new TextEditorOptions { TabsToSpaces = options.ConvertTabsToSpaces, TabSize = options.IndentationSize, IndentSize = options.IndentationSize, ContinuationIndent = options.IndentationSize, LabelIndent = -options.IndentationSize, WrapLineLength = options.VerticalRulerColumn }); }
public void Dispose() { options = options.Kill(); DetachDocument(); if (caret != null) { caret.PositionChanged -= CaretPositionChanged; caret = null; } }
public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent, ITextEditorOptions textEditorOptions) { foreach (IViewContent existingView in viewContent.SecondaryViewContents) { if (existingView.GetType() == typeof(FormsDesignerViewContent)) { return new IViewContent[0]; } } IDesignerLoaderProvider loader = new RubyDesignerLoaderProvider(); IDesignerGenerator generator = new RubyDesignerGenerator(textEditorOptions); return new IViewContent[] { new FormsDesignerViewContent(viewContent, loader, generator) }; }
public static void Init () { if (inited) return; inited = true; var policy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<TextStylePolicy> ("text/plain"); instance = new DefaultSourceEditorOptions (policy); MonoDevelop.Projects.Policies.PolicyService.DefaultPolicies.PolicyChanged += instance.HandlePolicyChanged; PlainEditor = new PlainEditorOptions (); }
internal void AttachExtensions() { if (extensions != null) { foreach (var extension in extensions) { extension.Attach(this); } } // If we have any registered ITextEditorOptions service now, use it, otherwise global options options = this.GetService <ITextEditorOptions>() ?? CodeEditorOptions.Instance; }
public void ReportTimings(Mono.TextEditor.TextDocument document, ITextEditorOptions options) { if (count == 0) { // No timings recorded. return; } string extension = document.FileName.Extension; var metadata = GetTypingTimingMetadata(extension, options, document.Length, document.LineCount); MonoDevelop.SourceEditor.Counters.Typing.Inc(metadata); }
internal void DetachExtensions() { if (extensions != null) { // Detach extensions in reverse order for (int i = extensions.Count - 1; i >= 0; i--) { extensions[i].Detach(); } } // Switch to global options, if no specific options service is registered options = this.GetService <ITextEditorOptions>() ?? CodeEditorOptions.Instance; }
public static OptionSet Apply(OptionSet options, ITextEditorOptions policy) { var result = options; if (policy != null) { result = result.WithChangedOption(Microsoft.CodeAnalysis.Formatting.FormattingOptions.IndentationSize, LanguageNames.CSharp, policy.IndentationSize); result = result.WithChangedOption(Microsoft.CodeAnalysis.Formatting.FormattingOptions.NewLine, LanguageNames.CSharp, policy.DefaultEolMarker); result = result.WithChangedOption(Microsoft.CodeAnalysis.Formatting.FormattingOptions.SmartIndent, LanguageNames.CSharp, FormattingOptions.IndentStyle.Smart); result = result.WithChangedOption(Microsoft.CodeAnalysis.Formatting.FormattingOptions.TabSize, LanguageNames.CSharp, policy.TabSize); result = result.WithChangedOption(Microsoft.CodeAnalysis.Formatting.FormattingOptions.UseTabs, LanguageNames.CSharp, !policy.TabsToSpaces); } return(result); }
public TextEditorData(Document doc) { LineHeight = 16; caret = new Caret(this); caret.PositionChanged += CaretPositionChanged; options = TextEditorOptions.DefaultOptions; Document = doc; this.SearchEngine = new BasicSearchEngine(); this.heightTree = new HeightTree(this); this.heightTree.Rebuild(); }
public static void Init() { if (inited) { return; } inited = true; var policy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> ("text/plain"); instance = new DefaultSourceEditorOptions(policy); MonoDevelop.Projects.Policies.PolicyService.DefaultPolicies.PolicyChanged += instance.HandlePolicyChanged; PlainEditor = new PlainEditorOptions(); }
public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent, ITextEditorOptions textEditorOptions) { foreach (IViewContent existingView in viewContent.SecondaryViewContents) { if (existingView.GetType() == typeof(FormsDesignerViewContent)) { return(new IViewContent[0]); } } IDesignerLoaderProvider loader = new RubyDesignerLoaderProvider(); IDesignerGenerator generator = new RubyDesignerGenerator(textEditorOptions); return(new IViewContent[] { new FormsDesignerViewContent(viewContent, loader, generator) }); }
public DFormattingVisitor(DFormattingOptions policy, IDocumentAdapter document, DModule ast, ITextEditorOptions options = null) { if (policy == null) { throw new ArgumentNullException("policy"); } if (document == null) { throw new ArgumentNullException("document"); } this.ast = ast; this.policy = policy; this.document = document; this.options = options ?? TextEditorOptions.Default; curIndent = new FormattingIndentStack(this.options); }
public static string GenerateHtml (List<List<ColoredSegment>> chunks, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options, bool includeBoilerplate = true) { var htmlText = new StringBuilder (); if (includeBoilerplate) { htmlText.AppendLine (@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">"); htmlText.AppendLine ("<HTML>"); htmlText.AppendLine ("<HEAD>"); htmlText.AppendLine ("<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=utf-8\">"); htmlText.AppendLine ("<META NAME=\"GENERATOR\" CONTENT=\"Mono Text Editor\">"); htmlText.AppendLine ("</HEAD>"); htmlText.AppendLine ("<BODY>"); } htmlText.AppendLine ("<FONT face = '" + options.Font.Family + "'>"); bool first = true; foreach (var line in chunks) { if (!first) { htmlText.AppendLine ("<BR>"); } else { first = false; } foreach (var chunk in line) { var chunkStyle = style.GetChunkStyle (chunk.Style); htmlText.Append ("<SPAN style='"); if (chunkStyle.FontWeight != Xwt.Drawing.FontWeight.Normal) htmlText.Append ("font-weight:" + ((int)chunkStyle.FontWeight) + ";"); if (chunkStyle.FontStyle != Xwt.Drawing.FontStyle.Normal) htmlText.Append ("font-style:" + chunkStyle.FontStyle.ToString ().ToLower () + ";"); htmlText.Append ("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString () + ";"); htmlText.Append ("'>"); AppendHtmlText (htmlText, chunk.Text, options); htmlText.Append ("</SPAN>"); } } htmlText.AppendLine ("</FONT>"); if (includeBoilerplate) { htmlText.AppendLine ("</BODY></HTML>"); } if (Platform.IsWindows) return GenerateCFHtml (htmlText.ToString ()); return htmlText.ToString (); }
public CodeEditorFormattingOptionsAdapter(ITextEditorOptions globalOptions, CSharpFormattingOptionsContainer container) { if (globalOptions == null) { throw new ArgumentNullException("globalOptions"); } if (container == null) { throw new ArgumentNullException("container"); } this.globalOptions = globalOptions; this.globalCodeEditorOptions = globalOptions as ICodeEditorOptions; this.container = container; CSharpFormattingPolicies.Instance.FormattingPolicyUpdated += OnFormattingPolicyUpdated; globalOptions.PropertyChanged += OnGlobalOptionsPropertyChanged; }
public void Dispose() { options = options.Kill(); if (document != null) { document.LineChanged -= HandleDocLineChanged; document.BeginUndo -= OnBeginUndo; document.EndUndo -= OnEndUndo; document.Undone -= DocumentHandleUndone; document.Redone -= DocumentHandleRedone; // DOCUMENT MUST NOT BE DISPOSED !!! (Split View shares document) document = null; } caret = caret.Kill(x => x.PositionChanged -= CaretPositionChanged); SelectionChanging -= HandleSelectionChanging; }
public static string GenerateHtml (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options) { var htmlText = new StringBuilder (); htmlText.Append (@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN""><HTML><BODY>"); var selection = new TextSegment (0, doc.TextLength); int startLineNumber = doc.OffsetToLineNumber (selection.Offset); int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset); htmlText.Append ("<FONT face = '" + options.Font.Family + "'>"); bool first = true; foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) { if (!first) { htmlText.Append ("<BR/>"); } else { first = false; } if (mode == null) { AppendHtmlText (htmlText, doc, options, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset)); continue; } foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) { int start = System.Math.Max (selection.Offset, chunk.Offset); int end = System.Math.Min (chunk.EndOffset, selection.EndOffset); var chunkStyle = style.GetChunkStyle (chunk); if (start < end) { htmlText.Append ("<SPAN style = '"); if (chunkStyle.Bold) htmlText.Append ("font-weight:bold;"); if (chunkStyle.Italic) htmlText.Append ("font-style:italic;"); htmlText.Append ("color:" + ((HslColor)chunkStyle.Foreground).ToPangoString () + ";"); htmlText.Append ("' >"); AppendHtmlText (htmlText, doc, options, start, end); htmlText.Append ("</SPAN>"); } } } htmlText.Append ("</FONT>"); htmlText.Append ("</BODY></HTML>"); return htmlText.ToString (); }
public static string FormatCode(string code, DModule ast = null, IDocumentAdapter document = null, DFormattingOptions options = null, ITextEditorOptions textStyle = null) { options = options ?? DFormattingOptions.CreateDStandard(); textStyle = textStyle ?? TextEditorOptions.Default; ast = ast ?? DParser.ParseString(code) as DModule; var formattingVisitor = new DFormattingVisitor(options, document ?? new TextDocument{ Text = code }, ast, textStyle); formattingVisitor.WalkThroughAst(); var sb = new StringBuilder(code); formattingVisitor.ApplyChanges((int start, int length, string insertedText) => { sb.Remove(start,length); sb.Insert(start,insertedText); }); return sb.ToString(); }
static void AppendHtmlText(StringBuilder htmlText, TextDocument doc, ITextEditorOptions options, int start, int end) { for (int i = start; i < end; i++) { char ch = doc.GetCharAt(i); switch (ch) { case ' ': htmlText.Append(" "); break; case '\t': for (int i2 = 0; i2 < options.TabSize; i2++) { htmlText.Append(" "); } break; case '<': htmlText.Append("<"); break; case '>': htmlText.Append(">"); break; case '&': htmlText.Append("&"); break; case '"': htmlText.Append("""); break; default: htmlText.Append(ch); break; } } }
internal TypingTimingMetadata GetTypingTimingMetadata(string extension, ITextEditorOptions options, int lengthAtEnd, int lineCountAtEnd) { double totalMillis = totalTime.TotalMilliseconds; var average = totalMillis / count; var metadata = new TypingTimingMetadata { Average = average, First = firstTime.Value.TotalMilliseconds, Maximum = maxTime.TotalMilliseconds, Dropped = droppedEvents, PercentAnimation = totalTimeAnimationDrawing.TotalMilliseconds / totalMillis * 100, PercentDrawCaret = totalTimeCaretDrawing.TotalMilliseconds / totalMillis * 100, PercentDrawMargin = totalTimeMarginDrawing.TotalMilliseconds / totalMillis * 100, PercentExtensionKeypress = totalTimeExtensionKeyPress.TotalMilliseconds / totalMillis * 100, SessionKeypressCount = count, SessionLength = GetCurrentTime().TotalMilliseconds - openTime.TotalMilliseconds, LengthAtStart = lengthAtStart, LengthDelta = lengthAtEnd - lengthAtStart, LineCountAtStart = lineCountAtStart, LineCountDelta = lineCountAtEnd - lineCountAtStart, }; if (options != null) { metadata.FoldMarginShown = options.ShowFoldMargin; metadata.NumberMarginShown = options.ShowLineNumberMargin; metadata.ShowIconMargin = options.ShowIconMargin; metadata.ShowWhiteSpaces = options.ShowWhitespaces; metadata.IncludeWhitespaces = options.IncludeWhitespaces; } if (!string.IsNullOrEmpty(extension)) { metadata.Extension = extension; } bucketTimings.AddTo(metadata); return(metadata); }
static void AppendHtmlText(StringBuilder htmlText, string text, ITextEditorOptions options) { foreach (char ch in text) { switch (ch) { case ' ': htmlText.Append(" "); // NOTE:   doesn't work in all programs break; case '\t': for (int i2 = 0; i2 < options.TabSize; i2++) { htmlText.Append(" "); } break; case '<': htmlText.Append("<"); break; case '>': htmlText.Append(">"); break; case '&': htmlText.Append("&"); break; case '"': htmlText.Append("""); break; default: htmlText.Append(ch); break; } } }
public TextEditor(TextDocument doc, ITextEditorOptions options, EditMode initialMode) { //GtkWorkarounds.FixContainerLeak (this); //WidgetFlags |= WidgetFlags.NoWindow; this.textArea = new TextArea(doc, options, initialMode); this.textArea.Initialize(this, doc, options, initialMode); this.textArea.EditorOptionsChanged += (sender, e) => OptionsChanged(sender, e); PackStart(textArea, true, true); //AddTopLevelWidget (textArea, 0, 0); Show(); /*if (Platform.IsMac) { * VScroll += delegate { * for (int i = 1; i < containerChildren.Count; i++) { * containerChildren[i].Child.QueueDraw (); * } * }; * HScroll += delegate { * for (int i = 1; i < containerChildren.Count; i++) { * containerChildren[i].Child.QueueDraw (); * } * }; * }*/ }
public CustomEditorOptions (ITextEditorOptions initializeFrom) { if (initializeFrom == null) throw new ArgumentNullException (nameof (initializeFrom)); WordFindStrategy = initializeFrom.WordFindStrategy; TabsToSpaces = initializeFrom.TabsToSpaces; IndentationSize = initializeFrom.IndentationSize; TabSize = initializeFrom.TabSize; ShowIconMargin = initializeFrom.ShowIconMargin; ShowLineNumberMargin = initializeFrom.ShowLineNumberMargin; ShowFoldMargin = initializeFrom.ShowFoldMargin; HighlightCaretLine = initializeFrom.HighlightCaretLine; RulerColumn = initializeFrom.RulerColumn; ShowRuler = initializeFrom.ShowRuler; IndentStyle = initializeFrom.IndentStyle; OverrideDocumentEolMarker = initializeFrom.OverrideDocumentEolMarker; EnableSyntaxHighlighting = initializeFrom.EnableSyntaxHighlighting; RemoveTrailingWhitespaces = initializeFrom.RemoveTrailingWhitespaces; WrapLines = initializeFrom.WrapLines; FontName = initializeFrom.FontName; GutterFontName = initializeFrom.GutterFontName; ColorScheme = initializeFrom.ColorScheme; DefaultEolMarker = initializeFrom.DefaultEolMarker; GenerateFormattingUndoStep = initializeFrom.GenerateFormattingUndoStep; EnableSelectionWrappingKeys = initializeFrom.EnableSelectionWrappingKeys; ShowWhitespaces = initializeFrom.ShowWhitespaces; IncludeWhitespaces = initializeFrom.IncludeWhitespaces; SmartBackspace = initializeFrom.SmartBackspace; }
public CodeEditorFormattingOptionsAdapter(ITextEditorOptions globalOptions, CSharpFormattingOptionsContainer container) { if (globalOptions == null) throw new ArgumentNullException("globalOptions"); if (container == null) throw new ArgumentNullException("container"); this.globalOptions = globalOptions; this.globalCodeEditorOptions = globalOptions as ICodeEditorOptions; this.container = container; CSharpFormattingPolicies.Instance.FormattingPolicyUpdated += OnFormattingPolicyUpdated; globalOptions.PropertyChanged += OnGlobalOptionsPropertyChanged; }
public DerivedPythonDesignerGenerator(ITextEditorOptions textEditorOptions) : base(textEditorOptions) { }
void CopyData (TextEditorData data, Selection selection) { if (!selection.IsEmpty && data != null && data.Document != null) { this.docStyle = data.ColorStyle; this.options = data.Options; copyData = null; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange (data); copiedColoredChunks = ColoredSegment.GetChunks (data, segment); var pasteHandler = data.TextPasteHandler; if (pasteHandler != null) copyData = pasteHandler.GetCopyData (segment); break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); copiedColoredChunks = new List<List<ColoredSegment>> (); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedColoredChunks.Add (ColoredSegment.GetChunks (data, new TextSegment (curLine.Offset + col1, col2 - col1)).First ()); } else { copiedColoredChunks.Add (new List<ColoredSegment> ()); } } break; } } else { copiedColoredChunks = null; } }
public string GetMarkup (Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent) { return GetMarkup (doc, options, style, offset, length, removeIndent, true, true); }
public void Dispose () { if (IsDisposed) return; IsDisposed = true; options = options.Kill (); HeightTree.Dispose (); DetachDocument (); }
public TextEditorData (TextDocument doc) { LineHeight = 16; caret = new Caret (this); caret.PositionChanged += CaretPositionChanged; options = TextEditorOptions.DefaultOptions; document = doc; document.BeginUndo += OnBeginUndo; document.EndUndo += OnEndUndo; document.Undone += DocumentHandleUndone; document.Redone += DocumentHandleRedone; document.LineChanged += HandleDocLineChanged; document.TextReplaced += HandleTextReplaced; document.TextSet += HandleDocTextSet; document.Folded += HandleTextEditorDataDocumentFolded; document.FoldTreeUpdated += HandleFoldTreeUpdated; SearchEngine = new BasicSearchEngine (); HeightTree = new HeightTree (this); HeightTree.Rebuild (); }
public TextEditorData (Document doc) { caret = new Caret (this); caret.PositionChanged += CaretPositionChanged; options = TextEditorOptions.DefaultOptions; Document = doc; this.SearchEngine = new BasicSearchEngine (); SelectionChanging += HandleSelectionChanging; }
public void Dispose () { options = options.Kill (); if (document != null) { document.LineChanged -= HandleDocLineChanged; document.BeginUndo -= OnBeginUndo; document.EndUndo -= OnEndUndo; document.Undone -= DocumentHandleUndone; document.Redone -= DocumentHandleRedone; // DOCUMENT MUST NOT BE DISPOSED !!! (Split View shares document) document = null; } if (caret != null) { caret.PositionChanged -= CaretPositionChanged; caret = null; } SelectionChanging -= HandleSelectionChanging; }
public static TextEditorData Create(string content, ITextEditorOptions options = null) { var data = new TextEditorData (); data.Options.DefaultEolMarker = eolMarker; data.Options.IndentStyle = IndentStyle.Smart; if (options != null) data.Options = options; var sb = new StringBuilder (); int caretIndex = -1, selectionStart = -1, selectionEnd = -1; var foldSegments = new List<FoldSegment> (); var foldStack = new Stack<FoldSegment> (); for (int i = 0; i < content.Length; i++) { var ch = content [i]; switch (ch) { case '$': caretIndex = sb.Length; break; case '<': if (i + 1 < content.Length) { if (content [i + 1] == '-') { selectionStart = sb.Length; i++; break; } } goto default; case '-': if (i + 1 < content.Length) { var next = content [i + 1]; if (next == '>') { selectionEnd = sb.Length; i++; break; } if (next == '[') { var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None); segment.IsFolded = false; foldStack.Push (segment); i++; break; } } goto default; case '+': if (i + 1 < content.Length) { var next = content [i + 1]; if (next == '[') { var segment = new FoldSegment (data.Document, "...", sb.Length, 0, FoldingType.None); segment.IsFolded = true; foldStack.Push (segment); i++; break; } } goto default; case ']': if (foldStack.Count > 0) { FoldSegment segment = foldStack.Pop (); segment.Length = sb.Length - segment.Offset; foldSegments.Add (segment); break; } goto default; default: sb.Append (ch); break; } } data.Text = sb.ToString (); if (caretIndex >= 0) data.Caret.Offset = caretIndex; if (selectionStart >= 0) { if (caretIndex == selectionStart) { data.SetSelection (selectionEnd, selectionStart); } else { data.SetSelection (selectionStart, selectionEnd); if (caretIndex < 0) data.Caret.Offset = selectionEnd; } } if (foldSegments.Count > 0) data.Document.UpdateFoldSegments (foldSegments); return data; }
static string GenerateRtf (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options) { StringBuilder rtfText = new StringBuilder (); List<Gdk.Color> colorList = new List<Gdk.Color> (); var selection = new TextSegment (0, doc.TextLength); int startLineNumber = doc.OffsetToLineNumber (selection.Offset); int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset); bool isItalic = false; bool isBold = false; int curColor = -1; foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) { bool appendSpace = false; foreach (Chunk chunk in mode.GetChunks (style, line, line.Offset, line.Length)) { int start = System.Math.Max (selection.Offset, chunk.Offset); int end = System.Math.Min (chunk.EndOffset, selection.EndOffset); ChunkStyle chunkStyle = style.GetChunkStyle (chunk); if (start < end) { if (isBold != chunkStyle.Bold) { rtfText.Append (chunkStyle.Bold ? @"\b" : @"\b0"); isBold = chunkStyle.Bold; appendSpace = true; } if (isItalic != chunkStyle.Italic) { rtfText.Append (chunkStyle.Italic ? @"\i" : @"\i0"); isItalic = chunkStyle.Italic; appendSpace = true; } if (!colorList.Contains (chunkStyle.Color)) colorList.Add (chunkStyle.Color); int color = colorList.IndexOf (chunkStyle.Color); if (curColor != color) { curColor = color; rtfText.Append (@"\cf" + (curColor + 1)); appendSpace = true; } for (int i = start; i < end; i++) { char ch = doc.GetCharAt (i); switch (ch) { case '\\': rtfText.Append (@"\\"); break; case '{': rtfText.Append (@"\{"); break; case '}': rtfText.Append (@"\}"); break; case '\t': rtfText.Append (@"\tab"); appendSpace = true; break; default: if (appendSpace) { rtfText.Append (' '); appendSpace = false; } rtfText.Append (ch); break; } } } } rtfText.Append (@"\par"); rtfText.AppendLine (); } // color table StringBuilder colorTable = new StringBuilder (); colorTable.Append (@"{\colortbl ;"); for (int i = 0; i < colorList.Count; i++) { Gdk.Color color = colorList[i]; colorTable.Append (@"\red"); colorTable.Append (color.Red / 256); colorTable.Append (@"\green"); colorTable.Append (color.Green / 256); colorTable.Append (@"\blue"); colorTable.Append (color.Blue / 256); colorTable.Append (";"); } colorTable.Append ("}"); StringBuilder rtf = new StringBuilder(); rtf.Append (@"{\rtf1\ansi\deff0\adeflang1025"); // font table rtf.Append (@"{\fonttbl"); rtf.Append (@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}"); rtf.Append ("}"); rtf.Append (colorTable.ToString ()); rtf.Append (@"\viewkind4\uc1\pard"); rtf.Append (@"\f0"); try { string fontName = options.Font.ToString (); double fontSize = Double.Parse (fontName.Substring (fontName.LastIndexOf (' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2; rtf.Append (@"\fs"); rtf.Append (fontSize); } catch (Exception) {}; rtf.Append (@"\cf1"); rtf.Append (rtfText.ToString ()); rtf.Append("}"); // System.Console.WriteLine(rtf); return rtf.ToString (); }
public void Dispose () { options = options.Kill (); DetachDocument (); if (caret != null) { caret.PositionChanged -= CaretPositionChanged; caret = null; } }
public string GetMarkup (Document doc, ITextEditorOptions options, ColorSheme style, int offset, int length, bool removeIndent, bool useColors, bool replaceTabs) { int indentLength = GetIndentLength (doc, offset, length, false); int curOffset = offset; StringBuilder result = new StringBuilder (); while (curOffset < offset + length && curOffset < doc.Length) { LineSegment line = doc.GetLineByOffset (curOffset); int toOffset = System.Math.Min (line.Offset + line.EditableLength, offset + length); Stack<ChunkStyle> styleStack = new Stack<ChunkStyle> (); for (Chunk chunk = GetChunks (doc, style, line, curOffset, toOffset - curOffset); chunk != null; chunk = chunk.Next) { ChunkStyle chunkStyle = chunk.GetChunkStyle (style); bool setBold = chunkStyle.Bold && (styleStack.Count == 0 || !styleStack.Peek ().Bold) || !chunkStyle.Bold && (styleStack.Count == 0 || styleStack.Peek ().Bold); bool setItalic = chunkStyle.Italic && (styleStack.Count == 0 || !styleStack.Peek ().Italic) || !chunkStyle.Italic && (styleStack.Count == 0 || styleStack.Peek ().Italic); bool setUnderline = chunkStyle.Underline && (styleStack.Count == 0 || !styleStack.Peek ().Underline) || !chunkStyle.Underline && (styleStack.Count == 0 || styleStack.Peek ().Underline); bool setColor = styleStack.Count == 0 || TextViewMargin.GetPixel (styleStack.Peek ().Color) != TextViewMargin.GetPixel (chunkStyle.Color); if (setColor || setBold || setItalic || setUnderline) { if (styleStack.Count > 0) { result.Append("</span>"); styleStack.Pop (); } result.Append("<span"); if (useColors) { result.Append(" foreground=\""); result.Append(ColorToPangoMarkup (chunkStyle.Color)); result.Append("\""); } if (chunkStyle.Bold) result.Append(" weight=\"bold\""); if (chunkStyle.Italic) result.Append(" style=\"italic\""); if (chunkStyle.Underline) result.Append(" underline=\"single\""); result.Append(">"); styleStack.Push (chunkStyle); } for (int i = 0; i < chunk.Length && chunk.Offset + i < doc.Length; i++) { char ch = chunk.GetCharAt (doc, chunk.Offset + i); switch (ch) { case '&': result.Append ("&"); break; case '<': result.Append ("<"); break; case '>': result.Append (">"); break; case '\t': if (replaceTabs) { result.Append (new string (' ', options.TabSize)); } else { result.Append ('\t'); } break; default: result.Append (ch); break; } } } while (styleStack.Count > 0) { result.Append("</span>"); styleStack.Pop (); } curOffset = line.EndOffset; if (removeIndent) curOffset += indentLength; if (result.Length > 0 && curOffset < offset + length) result.AppendLine (); } return result.ToString (); }
public TextEditorData (Document doc) { LineHeight = 16; caret = new Caret (this); caret.PositionChanged += CaretPositionChanged; options = TextEditorOptions.DefaultOptions; Document = doc; this.SearchEngine = new BasicSearchEngine (); this.heightTree = new HeightTree (this); this.heightTree.Rebuild (); }
void CopyData (TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new TextDocument (); monoDocument = new TextDocument (); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = SyntaxModeService.GetSyntaxMode (monoDocument, data.MimeType); switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; var segment = selection.GetSelectionRange (data); var text = data.GetTextAt (segment); copiedDocument.Text = text; monoDocument.Text = text; var line = data.Document.GetLineByOffset (segment.Offset); var spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { DocumentLine curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol) - 1; int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol) - 1, curLine.Length); if (col1 < col2) { copiedDocument.Insert (copiedDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); monoDocument.Insert (monoDocument.TextLength, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. copiedDocument.Insert (copiedDocument.TextLength, Environment.NewLine); // \r in mono document stands for block selection line end. monoDocument.Insert (monoDocument.TextLength, "\r"); } } line = data.Document.GetLine (selection.MinLine); spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode as SyntaxMode, this.mode as SyntaxMode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public TextEditorFontSizeProperty(ITextEditorOptions textEditorOptions) : base("FontSize") { this.textEditorOptions = textEditorOptions; }
public static string GenerateRtf (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options) { var rtfText = new StringBuilder (); var colorList = new List<Cairo.Color> (); var selection = new TextSegment (0, doc.TextLength); int startLineNumber = doc.OffsetToLineNumber (selection.Offset); int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset); bool isItalic = false; bool isBold = false; int curColor = -1; foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) { bool appendSpace = false; if (mode == null) { AppendRtfText (rtfText, doc, System.Math.Max (selection.Offset, line.Offset), System.Math.Min (line.EndOffset, selection.EndOffset), ref appendSpace); continue; } foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) { int start = System.Math.Max (selection.Offset, chunk.Offset); int end = System.Math.Min (chunk.EndOffset, selection.EndOffset); var chunkStyle = style.GetChunkStyle (chunk); if (start < end) { if (isBold != (chunkStyle.FontWeight == Xwt.Drawing.FontWeight.Bold)) { isBold = chunkStyle.FontWeight == Xwt.Drawing.FontWeight.Bold; rtfText.Append (isBold ? @"\b" : @"\b0"); appendSpace = true; } if (isItalic != (chunkStyle.FontStyle == Xwt.Drawing.FontStyle.Italic)) { isItalic = chunkStyle.FontStyle == Xwt.Drawing.FontStyle.Italic; rtfText.Append (isItalic ? @"\i" : @"\i0"); appendSpace = true; } var foreground = style.GetForeground (chunkStyle); if (!colorList.Contains (foreground)) colorList.Add (foreground); int color = colorList.IndexOf (foreground); if (curColor != color) { curColor = color; rtfText.Append (@"\cf" + (curColor + 1)); appendSpace = true; } AppendRtfText (rtfText, doc, start, end, ref appendSpace); } } rtfText.Append (@"\par"); rtfText.AppendLine (); } var rtf = new StringBuilder(); rtf.Append (@"{\rtf1\ansi\deff0\adeflang1025"); // font table rtf.Append (@"{\fonttbl"); rtf.Append (@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}"); rtf.Append ("}"); rtf.Append (CreateColorTable (colorList)); rtf.Append (@"\viewkind4\uc1\pard"); rtf.Append (@"\f0"); try { string fontName = options.Font.ToString (); double fontSize = Double.Parse (fontName.Substring (fontName.LastIndexOf (' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2; rtf.Append (@"\fs"); rtf.Append (fontSize); } catch (Exception) {}; rtf.Append (@"\cf1"); rtf.Append (rtfText.ToString ()); rtf.Append("}"); return rtf.ToString (); }
public void Dispose () { if (IsDisposed) return; document.WaitForFoldUpdateFinished (); IsDisposed = true; options = options.Kill (); HeightTree.Dispose (); DetachDocument (); }