Skip to main content

AceEditor

Namespace: Wisej.Web.Ext.AceEditor

Assembly: Wisej.Web.Ext.AceEditor (4.1.0.0)

Integrates the AceEditor (https://ace.c9.io/) widget.

public class AceEditor : 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​

Instance member 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​

Instance member 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)

Instance member DisplayIndentGuides​

Boolean: Shows or hides the indent guides. (Default: True)

Instance member FontSize​

Nullable<Single>: Returns or sets the FontSize. (Default: null)

Instance member InitScript​

String: Overridden to create our initialization script.

Instance member Language​

String: Returns or sets the language. (Default: "")

Instance member Options​

Object: Returns or sets the options to use for this instance of the AceEditor.

Instance member Packages​

List<Package>: Overridden to return our list of script resources.

Instance member PrintMarginColumn​

Int32: Returns or sets the print margin column position. (Default: 80)

Instance member ReadOnly​

Boolean: If readOnly is true, then the editor is set to read-only mode, and none of the content can change. (Default: False)

Instance member ShowGutter​

Boolean: Shows or hides the gutter. (Default: True)

Instance member ShowLineNumbers​

Boolean: Shows or hides the line numbers in the gutter. (Default: True)

Instance member ShowPrintMargin​

Boolean: Shows or hides the print margin. (Default: True)

Instance member Text​

String: Returns or sets the text displayed in the editor. (Default: "")

Instance member Theme​

String: Returns or sets the theme. (Default: "")

Methods​

Protected member OnGotFocus(e)​

ParameterTypeDescription
eEventArgs

Protected member OnWidgetEvent(e)​

ParameterTypeDescription
eWidgetEventArgs

Instance member 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();
}

Instance member 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();
}

Implements​