/// <summary> /// Initializes a new instance of the <see cref="TextArea"/> class. /// </summary> /// <param name="motherTextEditorControl">The mother text editor control.</param> /// <param name="motherTextAreaControl">The mother text area control.</param> public TextArea(TextEditorControl motherTextEditorControl, TextAreaControl motherTextAreaControl) { _motherTextAreaControl = motherTextAreaControl; _motherTextEditorControl = motherTextEditorControl; _caret = new Caret(this); _selectionManager = new SelectionManager(Document, this); _textAreaClipboardHandler = new TextAreaClipboardHandler(this); ResizeRedraw = true; SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.Opaque, false); SetStyle(ControlStyles.ResizeRedraw, true); SetStyle(ControlStyles.Selectable, true); _lineNumberMargin = new LineNumberMargin(this); _foldMargin = new FoldMargin(this); _iconMargin = new IconMargin(this); _leftMargins.AddRange(new AbstractMargin[] { _iconMargin, _lineNumberMargin, _foldMargin }); _textView = new TextView(this); OptionsChanged(); new TextAreaMouseHandler(this).Attach(); new TextAreaDragDropHandler().Attach(this); _bracketHighlightingSchemes.Add(new BracketHighlightingScheme('{', '}')); _bracketHighlightingSchemes.Add(new BracketHighlightingScheme('(', ')')); _bracketHighlightingSchemes.Add(new BracketHighlightingScheme('[', ']')); _caret.PositionChanged += SearchMatchingBracket; Document.TextContentChanged += TextContentChanged; Document.FoldingManager.FoldingChanged += DocumentFoldingsChanged; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="TextEditorControl"/> class. /// </summary> public TextEditorControl() { GenerateDefaultActions(); HighlightingManager.Manager.SyntaxHighlightingReloaded += OnReloadHighlighting; SetStyle(ControlStyles.ContainerControl, true); _textAreaPanel.Dock = DockStyle.Fill; Document = (new DocumentFactory()).CreateDocument(); Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(); _primaryTextArea = new TextAreaControl(this); _activeTextAreaControl = _primaryTextArea; _primaryTextArea.TextArea.GotFocus += delegate { ActiveTextAreaControl = _primaryTextArea; }; _primaryTextArea.Dock = DockStyle.Fill; _textAreaPanel.Controls.Add(_primaryTextArea); InitializeTextAreaControl(_primaryTextArea); Controls.Add(_textAreaPanel); ResizeRedraw = true; Document.UpdateCommited += CommitUpdateRequested; OptionsChanged(); }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langword="false"/> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing) { // Clean up managed resources OnCompletionWindowClosed(this, EventArgs.Empty); OnInsightWindowClosed(this, EventArgs.Empty); if (_printDocument != null) { _printDocument.BeginPrint -= BeginPrint; _printDocument.PrintPage -= PrintPage; _printDocument = null; } Document.UndoStack.ClearAll(); Document.UpdateCommited -= CommitUpdateRequested; if (_textAreaPanel != null) { if (_secondaryTextArea != null) { _secondaryTextArea.Dispose(); _textAreaSplitter.Dispose(); _secondaryTextArea = null; _textAreaSplitter = null; } if (_primaryTextArea != null) { _primaryTextArea.Dispose(); } _textAreaPanel.Dispose(); _textAreaPanel = null; } HighlightingManager.Manager.SyntaxHighlightingReloaded -= OnReloadHighlighting; Document.HighlightingStrategy = null; Document.UndoStack.TextEditorControl = null; } base.Dispose(disposing); }
//-------------------------------------------------------------- #region Creation and Cleanup //-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="TextEditorControl"/> class. /// </summary> public TextEditorControl() { GenerateDefaultActions(); HighlightingManager.Manager.SyntaxHighlightingReloaded += OnReloadHighlighting; SetStyle(ControlStyles.ContainerControl, true); _textAreaPanel.Dock = DockStyle.Fill; Document = (new DocumentFactory()).CreateDocument(); Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy(); _primaryTextArea = new TextAreaControl(this); _activeTextAreaControl = _primaryTextArea; _primaryTextArea.TextArea.GotFocus += delegate { ActiveTextAreaControl = _primaryTextArea; }; _primaryTextArea.Dock = DockStyle.Fill; _textAreaPanel.Controls.Add(_primaryTextArea); InitializeTextAreaControl(_primaryTextArea); Controls.Add(_textAreaPanel); ResizeRedraw = true; Document.UpdateCommited += CommitUpdateRequested; OptionsChanged(); }
/// <summary> /// Releases the unmanaged resources used by the <see cref="Control"></see> and its child controls and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing) { if (!_disposed) { _disposed = true; if (_caret != null) { _caret.PositionChanged -= SearchMatchingBracket; _caret.Dispose(); } Document.TextContentChanged -= TextContentChanged; Document.FoldingManager.FoldingChanged -= DocumentFoldingsChanged; _motherTextAreaControl = null; _motherTextEditorControl = null; foreach (AbstractMargin margin in _leftMargins) { if (margin is IDisposable) (margin as IDisposable).Dispose(); } _textView.Dispose(); } } base.Dispose(disposing); }
/// <summary> /// Shows/hides a vertical split view of the document. /// </summary> public void ToggleSplitView() { if (_secondaryTextArea == null) { _secondaryTextArea = new TextAreaControl(this) { Dock = DockStyle.Bottom, Height = (Height / 2) }; _secondaryTextArea.TextArea.GotFocus += delegate { ActiveTextAreaControl = _secondaryTextArea; }; _textAreaSplitter = new Splitter { BorderStyle = BorderStyle.FixedSingle, Height = 8, Dock = DockStyle.Bottom }; _textAreaPanel.Controls.Add(_textAreaSplitter); _textAreaPanel.Controls.Add(_secondaryTextArea); InitializeTextAreaControl(_secondaryTextArea); _secondaryTextArea.OptionsChanged(); } else { ActiveTextAreaControl = _primaryTextArea; _textAreaPanel.Controls.Remove(_secondaryTextArea); _textAreaPanel.Controls.Remove(_textAreaSplitter); _secondaryTextArea.Dispose(); _textAreaSplitter.Dispose(); _secondaryTextArea = null; _textAreaSplitter = null; } }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- /// <summary> /// Initializes the text area control. /// </summary> /// <param name="newControl">The new control.</param> /// <remarks> /// <para> /// A <see cref="TextEditorControl"/> can contain multiple <see cref="TextAreaControl"/>s. /// E.g. for showing a split-view of the document. /// </para> /// <para> /// This method is called when a new <see cref="TextAreaControl"/> is created. /// </para> /// </remarks> protected void InitializeTextAreaControl(TextAreaControl newControl) { newControl.ContextMenuRequest += TextArea_ContextMenuRequest; newControl.MouseWheel += TextArea_MouseWheel; newControl.TextArea.KeyPress += TextArea_KeyPress; newControl.TextArea.DialogKeyPress += TextArea_DialogKeyPress; newControl.TextArea.ToolTipRequest += TextArea_ToolTipRequest; newControl.DoHandleMousewheel = false; }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing) { // Clean up managed resources OnCompletionWindowClosed(this, EventArgs.Empty); OnInsightWindowClosed(this, EventArgs.Empty); if (_printDocument != null) { _printDocument.BeginPrint -= BeginPrint; _printDocument.PrintPage -= PrintPage; _printDocument = null; } Document.UndoStack.ClearAll(); Document.UpdateCommited -= CommitUpdateRequested; if (_textAreaPanel != null) { if (_secondaryTextArea != null) { _secondaryTextArea.Dispose(); _textAreaSplitter.Dispose(); _secondaryTextArea = null; _textAreaSplitter = null; } if (_primaryTextArea != null) { _primaryTextArea.Dispose(); } _textAreaPanel.Dispose(); _textAreaPanel = null; } HighlightingManager.Manager.SyntaxHighlightingReloaded -= OnReloadHighlighting; Document.HighlightingStrategy = null; Document.UndoStack.TextEditorControl = null; } base.Dispose(disposing); }