123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- define("webodf/editor/Tools", [
- "dojo/ready",
- "dijit/MenuItem",
- "dijit/DropDownMenu",
- "dijit/form/Button",
- "dijit/form/DropDownButton",
- "dijit/Toolbar",
- "webodf/editor/widgets/paragraphAlignment",
- "webodf/editor/widgets/simpleStyles",
- "webodf/editor/widgets/undoRedoMenu",
- "webodf/editor/widgets/toolbarWidgets/currentStyle",
- "webodf/editor/widgets/annotation",
- "webodf/editor/widgets/editHyperlinks",
- "webodf/editor/widgets/imageInserter",
- "webodf/editor/widgets/paragraphStylesDialog",
- "webodf/editor/widgets/zoomSlider",
- "webodf/editor/widgets/aboutDialog",
- "webodf/editor/EditorSession"],
- function (ready, MenuItem, DropDownMenu, Button, DropDownButton, Toolbar, ParagraphAlignment, SimpleStyles, UndoRedoMenu, CurrentStyle, AnnotationControl, EditHyperlinks, ImageInserter, ParagraphStylesDialog, ZoomSlider, AboutDialog, EditorSession) {
- "use strict";
- return function Tools(toolbarElementId, args) {
- var tr = runtime.tr,
- onToolDone = args.onToolDone,
- loadOdtFile = args.loadOdtFile,
- saveOdtFile = args.saveOdtFile,
- saveAsOdtFile = args.saveAsOdtFile,
- downloadOdtFile = args.downloadOdtFile,
- close = args.close,
- toolbar,
- loadButton, saveButton, closeButton, aboutButton,
- saveAsButton, downloadButton,
- formatDropDownMenu, formatMenuButton,
- paragraphStylesMenuItem, paragraphStylesDialog,
- editorSession,
- aboutDialog,
- sessionSubscribers = [];
- function placeAndStartUpWidget(widget) {
- widget.placeAt(toolbar);
- widget.startup();
- }
-
- function createTool(Tool, enabled, config) {
- var tool = null;
- if (enabled) {
- if (config) {
- tool = new Tool(config, placeAndStartUpWidget);
- } else {
- tool = new Tool(placeAndStartUpWidget);
- }
- sessionSubscribers.push(tool);
- tool.onToolDone = onToolDone;
- tool.setEditorSession(editorSession);
- }
- return tool;
- }
- function handleCursorMoved(cursor) {
- var disabled = cursor.getSelectionType() === ops.OdtCursor.RegionSelection;
- if (formatMenuButton) {
- formatMenuButton.setAttribute('disabled', disabled);
- }
- }
- function setEditorSession(session) {
- if (editorSession) {
- editorSession.unsubscribe(EditorSession.signalCursorMoved, handleCursorMoved);
- }
- editorSession = session;
- if (editorSession) {
- editorSession.subscribe(EditorSession.signalCursorMoved, handleCursorMoved);
- }
- sessionSubscribers.forEach(function (subscriber) {
- subscriber.setEditorSession(editorSession);
- });
- [saveButton, saveAsButton, downloadButton, closeButton, formatMenuButton].forEach(function (button) {
- if (button) {
- button.setAttribute('disabled', !editorSession);
- }
- });
- }
- this.setEditorSession = setEditorSession;
-
- this.destroy = function (callback) {
-
-
-
-
-
-
-
-
- var widgets = dijit.findWidgets(document.body);
- dojo.forEach(widgets, function(w) {
- w.destroyRecursive(false);
- });
- callback();
- };
-
- ready(function () {
- toolbar = new Toolbar({}, toolbarElementId);
-
- if (args.aboutEnabled) {
- aboutButton = new Button({
- label: tr('About WebODF Text Editor'),
- showLabel: false,
- iconClass: 'webodfeditor-dijitWebODFIcon'
- });
- aboutDialog = new AboutDialog(function (dialog) {
- aboutButton.onClick = function () {
- dialog.startup();
- dialog.show();
- };
- });
- aboutDialog.onToolDone = onToolDone;
- aboutButton.placeAt(toolbar);
- }
-
- if (loadOdtFile) {
- loadButton = new Button({
- label: tr('Open'),
- showLabel: false,
- iconClass: 'dijitIcon dijitIconFolderOpen',
- onClick: function () {
- loadOdtFile();
- }
- });
- loadButton.placeAt(toolbar);
- }
-
- if (saveOdtFile) {
- saveButton = new Button({
- label: tr('Save'),
- showLabel: false,
- disabled: true,
- iconClass: 'dijitEditorIcon dijitEditorIconSave',
- onClick: function () {
- saveOdtFile();
- onToolDone();
- }
- });
- saveButton.placeAt(toolbar);
- }
-
- if (saveAsOdtFile) {
- saveAsButton = new Button({
- label: tr('Save as...'),
- showLabel: false,
- disabled: true,
- iconClass: 'webodfeditor-dijitSaveAsIcon',
- onClick: function () {
- saveAsOdtFile();
- onToolDone();
- }
- });
- saveAsButton.placeAt(toolbar);
- }
-
- if (downloadOdtFile) {
- downloadButton = new Button({
- label: tr('Download'),
- showLabel: true,
- disabled: true,
- style: {
- float: 'right'
- },
- onClick: function () {
- downloadOdtFile();
- onToolDone();
- }
- });
- downloadButton.placeAt(toolbar);
- }
-
- if (args.paragraphStyleEditingEnabled) {
- formatDropDownMenu = new DropDownMenu({});
- paragraphStylesMenuItem = new MenuItem({
- label: tr("Paragraph...")
- });
- formatDropDownMenu.addChild(paragraphStylesMenuItem);
- paragraphStylesDialog = new ParagraphStylesDialog(function (dialog) {
- paragraphStylesMenuItem.onClick = function () {
- if (editorSession) {
- dialog.startup();
- dialog.show();
- }
- };
- });
- sessionSubscribers.push(paragraphStylesDialog);
- paragraphStylesDialog.onToolDone = onToolDone;
- formatMenuButton = new DropDownButton({
- dropDown: formatDropDownMenu,
- disabled: true,
- label: tr('Format'),
- iconClass: "dijitIconEditTask"
- });
- formatMenuButton.placeAt(toolbar);
- }
-
- createTool(UndoRedoMenu, args.undoRedoEnabled);
-
- createTool(AnnotationControl, args.annotationsEnabled);
-
- createTool(SimpleStyles, args.directTextStylingEnabled);
-
- createTool(ParagraphAlignment, args.directParagraphStylingEnabled);
-
- createTool(CurrentStyle, args.paragraphStyleSelectingEnabled);
-
- createTool(ZoomSlider, args.zoomingEnabled);
-
- createTool(EditHyperlinks, args.hyperlinkEditingEnabled);
-
- createTool(ImageInserter, args.imageInsertingEnabled);
-
- if (close) {
- closeButton = new Button({
- label: tr('Close'),
- showLabel: false,
- disabled: true,
- iconClass: 'dijitEditorIcon dijitEditorIconCancel',
- style: {
- float: 'right'
- },
- onClick: function () {
- close();
- }
- });
- closeButton.placeAt(toolbar);
- }
-
-
-
-
-
-
- if (window.wodo_plugins) {
- window.wodo_plugins.forEach(function (plugin) {
- runtime.log("Creating plugin: "+plugin.id);
- require([plugin.id], function (Plugin) {
- runtime.log("Creating as tool now: "+plugin.id);
- createTool(Plugin, true, plugin.config);
- });
- });
- }
- setEditorSession(editorSession);
- });
- };
- });
|