UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

111 lines 4.63 kB
define(["require", "exports", "rxjs", "./action", "./gui/button", "./gui/icon"], function (require, exports, rxjs_1, action_1, button_1, icon_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function makeAction(desc, abbreviatedDesc, icon, needsInput, fn) { let actualAbbreviatedDesc; let actualIcon; let actualNeedsInput; let actualFn; if (typeof icon === "boolean") { actualAbbreviatedDesc = undefined; actualIcon = abbreviatedDesc; actualNeedsInput = icon; actualFn = needsInput; } else { actualAbbreviatedDesc = abbreviatedDesc; actualIcon = icon; actualNeedsInput = needsInput; actualFn = fn; } return class extends action_1.Action { constructor(editor) { super(editor, desc, actualAbbreviatedDesc, actualIcon, actualNeedsInput); } execute() { actualFn(this.editor); } }; } exports.makeAction = makeAction; // tslint:disable-next-line:variable-name exports.Save = makeAction("Save", icon_1.makeHTML("upload"), false, (editor) => { // tslint:disable-next-line:no-floating-promises editor.save(); }); // tslint:disable-next-line:variable-name exports.Undo = makeAction("Undo", icon_1.makeHTML("undo"), false, (editor) => { editor.undo(); }); // tslint:disable-next-line:variable-name exports.Redo = makeAction("Redo", icon_1.makeHTML("redo"), false, (editor) => { editor.redo(); }); // tslint:disable-next-line:variable-name exports.DecreaseLabelVisibilityLevel = makeAction("Decrease label visibility level", "Decrease label visibility", icon_1.makeHTML("arrow-down"), false, (editor) => { editor.decreaseLabelVisiblityLevel(); }); // tslint:disable-next-line:variable-name exports.IncreaseLabelVisibilityLevel = makeAction("Increase label visibility level", "Increase label visibility", icon_1.makeHTML("arrow-up"), false, (editor) => { editor.increaseLabelVisibilityLevel(); }); /** * An action that toggles the editors attribute hiding. */ class ToggleAttributeHiding extends action_1.Action { constructor(editor) { super(editor, "Toggle attribute hiding", "AH", undefined, false); this.pressed = true; /** * The object on which this class and subclasses may push new events. */ this._events = new rxjs_1.Subject(); /** * The observable on which clients can listen for events. */ this.events = this._events.asObservable(); } execute(data) { if (this.pressed !== data) { this.pressed = data; this.editor.toggleAttributeHiding(); this._events.next({ name: "Pressed", action: this }); } } makeButton(data) { const button = new button_1.ToggleButton(this.pressed, data !== undefined ? this.getDescriptionFor(data) : this.getDescription(), this.getAbbreviatedDescription(), this.getIcon()); button.events.subscribe(() => { this.execute(button.pressed); }); this.events.subscribe(() => { button.pressed = this.pressed; }); return button; } } exports.ToggleAttributeHiding = ToggleAttributeHiding; /** * An action that changes the editor's selection mode. */ class SetSelectionMode extends action_1.Action { constructor(editor, name, icon, desiredMode) { super(editor, `Set selection mode to ${name}`, name, icon, false); this.desiredMode = desiredMode; } execute() { this.editor.selectionMode = this.desiredMode; } makeButton(data) { const button = new button_1.ToggleButton(this.editor.selectionMode === this.desiredMode, data !== undefined ? this.getDescriptionFor(data) : this.getDescription(), this.getAbbreviatedDescription(), this.getIcon()); button.events.subscribe(() => { this.execute(); }); this.editor.selectionModeChanges.subscribe(({ value }) => { button.pressed = value === this.desiredMode; }); return button; } } exports.SetSelectionMode = SetSelectionMode; }); //# sourceMappingURL=editor-actions.js.map