📄 texteditorcontrolbase.cs
字号:
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krger" email="mike@icsharpcode.net"/>
// <version value="$version"/>
// </file>
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.InteropServices;
using System.Xml;
using System.Text;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor.Actions;
namespace ICSharpCode.TextEditor
{
/// <summary>
/// This class is used for a basic text area control
/// </summary>
[ToolboxItem(false)]
public abstract class TextEditorControlBase : UserControl
{
string currentFileName = null;
int updateLevel = 0;
IDocument document;
/// <summary>
/// This hashtable contains all editor keys, where
/// the key is the key combination and the value the
/// action.
/// </summary>
protected Hashtable editactions = new Hashtable();
public ITextEditorProperties TextEditorProperties {
get {
return document.TextEditorProperties;
}
set {
document.TextEditorProperties = value;
OptionsChanged();
}
}
/// <value>
/// Current file's character encoding
/// </value>
public Encoding Encoding {
get {
return TextEditorProperties.Encoding;
}
set {
// if (encoding != null && value != null && !encoding.Equals(value) && !CharacterEncoding.IsUnicode(value)) {
// Byte[] bytes = encoding.GetBytes(Text);
// Text = new String(value.GetChars(bytes));
// }
TextEditorProperties.Encoding = value;
}
}
/// <value>
/// The current file name
/// </value>
[Browsable(false)]
[ReadOnly(true)]
public string FileName {
get {
return currentFileName;
}
set {
if (currentFileName != value) {
currentFileName = value;
OnFileNameChanged(EventArgs.Empty);
}
}
}
/// <value>
/// true, if the textarea is updating it's status, while
/// it updates it status no redraw operation occurs.
/// </value>
[Browsable(false)]
public bool IsUpdating {
get {
return updateLevel > 0;
}
}
/// <value>
/// The current document
/// </value>
[Browsable(false)]
public IDocument Document {
get {
return document;
}
set {
document = value;
document.UndoStack.TextEditorControl = this;
}
}
[Browsable(true)]
public override string Text {
get {
return Document.TextContent;
}
set {
Document.TextContent = value;
}
}
static Font ParseFont(string font)
{
string[] descr = font.Split(new char[]{',', '='});
return new Font(descr[1], Single.Parse(descr[3]));
}
/// <value>
/// If set to true the contents can't be altered.
/// </value>
[Browsable(false)]
[ReadOnly(true)]
public bool IsReadOnly {
get {
return Document.ReadOnly;
}
set {
Document.ReadOnly = value;
}
}
[Browsable(false)]
public bool IsInUpdate {
get {
return this.updateLevel > 0;
}
}
/// <value>
/// supposedly this is the way to do it according to .NET docs,
/// as opposed to setting the size in the constructor
/// </value>
protected override Size DefaultSize {
get {
return new Size(100, 100);
}
}
#region Document Properties
/// <value>
/// If true spaces are shown in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
[Description("If true spaces are shown in the textarea")]
public bool ShowSpaces {
get {
return document.TextEditorProperties.ShowSpaces;
}
set {
document.TextEditorProperties.ShowSpaces = value;
OptionsChanged();
}
}
/// <value>
/// If true antialiased fonts are used inside the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
[Description("If true antialiased fonts are used inside the textarea")]
public bool UseAntiAliasFont {
get {
return document.TextEditorProperties.UseAntiAliasedFont;
}
set {
document.TextEditorProperties.UseAntiAliasedFont = value;
OptionsChanged();
}
}
/// <value>
/// If true tabs are shown in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
[Description("If true tabs are shown in the textarea")]
public bool ShowTabs {
get {
return document.TextEditorProperties.ShowTabs;
}
set {
document.TextEditorProperties.ShowTabs = value;
OptionsChanged();
}
}
/// <value>
/// If true EOL markers are shown in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
[Description("If true EOL markers are shown in the textarea")]
public bool ShowEOLMarkers {
get {
return document.TextEditorProperties.ShowEOLMarker;
}
set {
document.TextEditorProperties.ShowEOLMarker = value;
OptionsChanged();
}
}
/// <value>
/// If true the horizontal ruler is shown in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
[Description("If true the horizontal ruler is shown in the textarea")]
public bool ShowHRuler {
get {
return document.TextEditorProperties.ShowHorizontalRuler;
}
set {
document.TextEditorProperties.ShowHorizontalRuler = value;
OptionsChanged();
}
}
/// <value>
/// If true the vertical ruler is shown in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(false)]
[Description("If true the vertical ruler is shown in the textarea")]
public bool ShowVRuler {
get {
return document.TextEditorProperties.ShowVerticalRuler;
}
set {
document.TextEditorProperties.ShowVerticalRuler = value;
OptionsChanged();
}
}
/// <value>
/// The row in which the vertical ruler is displayed
/// </value>
[Category("Appearance")]
[DefaultValue(80)]
[Description("The row in which the vertical ruler is displayed")]
public int VRulerRow {
get {
return document.TextEditorProperties.VerticalRulerRow;
}
set {
document.TextEditorProperties.VerticalRulerRow = value;
OptionsChanged();
}
}
/// <value>
/// If true line numbers are shown in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(true)]
[Description("If true line numbers are shown in the textarea")]
public bool ShowLineNumbers {
get {
return document.TextEditorProperties.ShowLineNumbers;
}
set {
document.TextEditorProperties.ShowLineNumbers = value;
OptionsChanged();
}
}
/// <value>
/// If true invalid lines are marked in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(true)]
[Description("If true invalid lines are marked in the textarea")]
public bool ShowInvalidLines {
get {
return document.TextEditorProperties.ShowInvalidLines;
}
set {
document.TextEditorProperties.ShowInvalidLines = value;
OptionsChanged();
}
}
/// <value>
/// If true folding is enabled in the textarea
/// </value>
[Category("Appearance")]
[DefaultValue(true)]
[Description("If true folding is enabled in the textarea")]
public bool EnableFolding {
get {
return document.TextEditorProperties.EnableFolding;
}
set {
document.TextEditorProperties.EnableFolding = value;
OptionsChanged();
}
}
[Category("Appearance")]
[DefaultValue(true)]
[Description("If true matching brackets are highlighted")]
public bool ShowMatchingBracket {
get {
return document.TextEditorProperties.ShowMatchingBracket;
}
set {
document.TextEditorProperties.ShowMatchingBracket = value;
OptionsChanged();
}
}
[Category("Appearance")]
[DefaultValue(true)]
[Description("If true the icon bar is displayed")]
public bool IsIconBarVisible {
get {
return document.TextEditorProperties.IsIconBarVisible;
}
set {
document.TextEditorProperties.IsIconBarVisible = value;
OptionsChanged();
}
}
/// <value>
/// The width in spaces of a tab character
/// </value>
[Category("Appearance")]
[DefaultValue(4)]
[Description("The width in spaces of a tab character")]
public int TabIndent {
get {
return document.TextEditorProperties.TabIndent;
}
set {
document.TextEditorProperties.TabIndent = value;
OptionsChanged();
}
}
/// <value>
/// The line viewer style
/// </value>
[Category("Appearance")]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -