Skip to content

Commit

Permalink
TextEditor: basic context menufor clipboard items, select all, and de…
Browse files Browse the repository at this point in the history
…lete (references #8)

These are are built-in items supported by Flash/AIR. Custom items not yet supported.
  • Loading branch information
joshtynjala committed Jan 13, 2022
1 parent b2d1357 commit 8c7d5cc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/moonshine/editor/text/TextEditor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TextEditor extends FeathersControl implements IFocusObject implements ISta
_selectionMananger = new SelectionManager(this);
_colorManager = new ColorManager(this, invalidateVisibleLines);
_findReplaceManager = new FindReplaceManager(this);
createContextMenu();
this.text = text;
addEventListener(TextEditorChangeEvent.TEXT_CHANGE, textEditor_textChangeHandler);
addEventListener(FocusEvent.FOCUS_IN, textEditor_focusInHandler);
Expand Down Expand Up @@ -1321,6 +1322,23 @@ class TextEditor extends FeathersControl implements IFocusObject implements ISta
}
}

private function createContextMenu():Void {
#if flash
if (flash.ui.ContextMenu.isSupported) {
var contextMenu = new flash.ui.ContextMenu();
contextMenu.hideBuiltInItems();
var clipboardItems = new flash.ui.ContextMenuClipboardItems();
clipboardItems.clear = true;
clipboardItems.copy = true;
clipboardItems.cut = true;
clipboardItems.paste = true;
contextMenu.clipboardItems = clipboardItems;
contextMenu.clipboardMenu = true;
this.contextMenu = contextMenu;
}
#end
}

private function textEditor_focusInHandler(event:FocusEvent):Void {
if (stage != null && stage.focus != _listView) {
event.stopImmediatePropagation();
Expand Down

0 comments on commit 8c7d5cc

Please sign in to comment.