AceEditor
Namespace: Wisej.Web.Ext.AceEditor
Assembly: Wisej.Web.Ext.AceEditor (4.1.0.0)
Integrates the AceEditor (https://ace.c9.io/) widget.
- C#
- VB.NET
public class AceEditor : Widget
Public Class AceEditor
Inherits Widget
Ace is an embeddable code editor written in JavaScript. It matches the features and performance of native editors such as Sublime, Vim and TextMate.
Example:
The following example adds a C# code editor to a page and reads the code when the user clicks a button:
private AceEditor aceEditor;
private void Page1_Load(object sender, EventArgs e)
{
this.aceEditor = new AceEditor
{
Dock = DockStyle.Fill,
Language = "csharp",
Theme = "monokai",
FontSize = 14,
Text = "public class Hello\r\n{\r\n}"
};
this.aceEditor.TextChanged += aceEditor_TextChanged;
this.panelEditor.Controls.Add(this.aceEditor);
}
private void aceEditor_TextChanged(object sender, EventArgs e)
{
this.labelStatus.Text = $"{this.aceEditor.Text.Length} characters";
}
private void buttonSave_Click(object sender, EventArgs e)
{
File.WriteAllText(Application.MapPath("Code/Hello.cs"), this.aceEditor.Text);
}
Constructors
AceEditor()
Initializes a new instance of AceEditor.
The new editor shows the gutter, line numbers, indent guides and the print margin at column 80, and sends text changes to the server 1000 milliseconds after the user stops typing (see AutoUpdateDelay).
Example:
var editor = new AceEditor();
editor.Language = "javascript";
editor.Theme = "github";
editor.ShowPrintMargin = false;
editor.Text = "function hello() {\n return 'Hello';\n}";
this.Controls.Add(editor);
Properties
AutoUpdateDelay
Int32: Sets the amount of in time in milliseconds to wait before updating the server that the content of the editor has changed while the user is typing. A value of 0 disables it. (Default: 1000)
DisplayIndentGuides
Boolean: Shows or hides the indent guides. (Default: True)
FontSize
Nullable<Single>: Returns or sets the FontSize. (Default: null)
InitScript
String: Overridden to create our initialization script.
Language
String: Returns or sets the language. (Default: "")
Options
Object: Returns or sets the options to use for this instance of the AceEditor.
Packages
List<Package>: Overridden to return our list of script resources.
PrintMarginColumn
Int32: Returns or sets the print margin column position. (Default: 80)
ReadOnly
Boolean: If readOnly is true, then the editor is set to read-only mode, and none of the content can change. (Default: False)
ShowGutter
Boolean: Shows or hides the gutter. (Default: True)
ShowLineNumbers
Boolean: Shows or hides the line numbers in the gutter. (Default: True)
ShowPrintMargin
Boolean: Shows or hides the print margin. (Default: True)
Text
String: Returns or sets the text displayed in the editor. (Default: "")
Theme
String: Returns or sets the theme. (Default: "")
Methods
OnGotFocus(e)
| Parameter | Type | Description |
|---|---|---|
| e | EventArgs |
OnWidgetEvent(e)
| Parameter | Type | Description |
|---|---|---|
| e | WidgetEventArgs |
Redo()
Performs a redo operation on the document, reimplementing the last change.
Only changes that were reverted with Undo (or with the undo keyboard shortcut) can be redone. The operation runs in the editor on the client. The Text property is updated when the resulting change is sent back to the server.
Example:
private void buttonRedo_Click(object sender, EventArgs e)
{
this.aceEditor.Redo();
this.aceEditor.Focus();
}
Undo()
Performs an undo operation on the document, reverting the last change.
The operation runs in the editor on the client. The Text property is updated when the resulting change is sent back to the server.
Example:
The following example connects the editor to Undo and Redo buttons on a toolbar:
private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
if (e.Button == this.buttonUndo)
this.aceEditor.Undo();
else if (e.Button == this.buttonRedo)
this.aceEditor.Redo();
}