diff --git a/CMakeLists.txt b/CMakeLists.txt index 735da26f..16662545 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,6 +307,7 @@ set(LIBJSFILES lib/packages.js lib/runtime.js lib/core/Base64.js lib/gui/KeyboardHandler.js lib/gui/Clipboard.js lib/gui/DirectTextStyler.js + lib/gui/DirectParagraphStyler.js lib/gui/SessionController.js lib/ops/MemberModel.js lib/ops/TrivialMemberModel.js diff --git a/programs/editor/EditorSession.js b/programs/editor/EditorSession.js index 65f656ac..5b292a08 100644 --- a/programs/editor/EditorSession.js +++ b/programs/editor/EditorSession.js @@ -54,7 +54,6 @@ define("webodf/editor/EditorSession", [ runtime.loadClass("gui.SessionController"); runtime.loadClass("gui.SessionView"); runtime.loadClass("gui.TrivialUndoManager"); - runtime.loadClass("gui.StyleHelper"); runtime.loadClass("core.EventNotifier"); /** @@ -74,7 +73,6 @@ define("webodf/editor/EditorSession", [ textns = odf.Namespaces.textns, fontStyles = document.createElement('style'), formatting = odtDocument.getFormatting(), - styleHelper = new gui.StyleHelper(formatting), domUtils = new core.DomUtils(), eventNotifier = new core.EventNotifier([ EditorSession.signalMemberAdded, @@ -92,15 +90,6 @@ define("webodf/editor/EditorSession", [ this.sessionView = new gui.SessionView(config.viewOptions, session, caretManager); this.availableFonts = []; - function isTrueForSelection(predicate) { - var cursor = odtDocument.getCursor(localMemberId); - // no own cursor yet/currently added? - if (!cursor) { - return false; - } - return predicate(cursor.getSelectedRange()); - } - /* * @return {Array.{!string}} */ @@ -299,11 +288,6 @@ define("webodf/editor/EditorSession", [ return formatting.getAvailableParagraphStyles(); }; - this.isAlignedLeft = isTrueForSelection.bind(self, styleHelper.isAlignedLeft); - this.isAlignedCenter = isTrueForSelection.bind(self, styleHelper.isAlignedCenter); - this.isAlignedRight = isTrueForSelection.bind(self, styleHelper.isAlignedRight); - this.isAlignedJustified = isTrueForSelection.bind(self, styleHelper.isAlignedJustified); - this.getCurrentParagraphStyle = function () { return currentNamedStyleName; }; @@ -485,12 +469,6 @@ define("webodf/editor/EditorSession", [ return array; }; - this.getCurrentSelectionStyles = function() { - var cursor = odtDocument.getCursor(localMemberId), - range = cursor && cursor.getSelectedRange(); - return range && styleHelper.getAppliedStyles(range); - }; - function undoStackModified(e) { self.emit(EditorSession.signalUndoStackChanged, e); } diff --git a/programs/editor/widgets/paragraphAlignment.js b/programs/editor/widgets/paragraphAlignment.js index 0dd9b5a4..efa4e049 100644 --- a/programs/editor/widgets/paragraphAlignment.js +++ b/programs/editor/widgets/paragraphAlignment.js @@ -36,16 +36,15 @@ /*global define,require,document */ define("webodf/editor/widgets/paragraphAlignment", [ - "webodf/editor/EditorSession", "dijit/form/ToggleButton", "dijit/form/Button"], - function (EditorSession, ToggleButton, Button) { + function (ToggleButton, Button) { "use strict"; var ParagraphAlignment = function (callback) { var widget = {}, - editorSession, + directParagraphStyler, justifyLeft, justifyCenter, justifyRight, @@ -55,75 +54,68 @@ define("webodf/editor/widgets/paragraphAlignment", [ justifyLeft = new ToggleButton({ label: document.translator('justifyLeft'), + disabled: true, showLabel: false, checked: false, iconClass: "dijitEditorIcon dijitEditorIconJustifyLeft", onChange: function () { - editorSession.sessionController.alignParagraphLeft(); + directParagraphStyler.alignParagraphLeft(); } }); justifyCenter = new ToggleButton({ label: document.translator('justifyCenter'), + disabled: true, showLabel: false, checked: false, iconClass: "dijitEditorIcon dijitEditorIconJustifyCenter", onChange: function () { - editorSession.sessionController.alignParagraphCenter(); + directParagraphStyler.alignParagraphCenter(); } }); justifyRight = new ToggleButton({ label: document.translator('justifyRight'), + disabled: true, showLabel: false, checked: false, iconClass: "dijitEditorIcon dijitEditorIconJustifyRight", onChange: function () { - editorSession.sessionController.alignParagraphRight(); + directParagraphStyler.alignParagraphRight(); } }); justifyFull = new ToggleButton({ label: document.translator('justifyFull'), + disabled: true, showLabel: false, checked: false, iconClass: "dijitEditorIcon dijitEditorIconJustifyFull", onChange: function () { - editorSession.sessionController.alignParagraphJustified(); + directParagraphStyler.alignParagraphJustified(); } }); outdent = new Button({ label: document.translator('outdent'), + disabled: true, showLabel: false, - disabled: false, iconClass: "dijitEditorIcon dijitEditorIconOutdent", onClick: function () { - editorSession.sessionController.outdent(); + directParagraphStyler.outdent(); } }); indent = new Button({ label: document.translator('indent'), + disabled: true, showLabel: false, - disabled: false, iconClass: "dijitEditorIcon dijitEditorIconIndent", onClick: function () { - editorSession.sessionController.indent(); + directParagraphStyler.indent(); } }); - function checkStyleButtons() { - // The 3rd parameter is false to avoid firing onChange when setting the value - // programmatically. - justifyLeft.set('checked', editorSession.isAlignedLeft(), false); - justifyCenter.set('checked', editorSession.isAlignedCenter(), false); - justifyRight.set('checked', editorSession.isAlignedRight(), false); - justifyFull.set('checked', editorSession.isAlignedJustified(), false); - } - - - widget.children = [justifyLeft, justifyCenter, justifyRight, @@ -145,19 +137,40 @@ define("webodf/editor/widgets/paragraphAlignment", [ return widget; }; + function updateStyleButtons(changes) { + var buttons = { + isAlignedLeft: justifyLeft, + isAlignedCenter: justifyCenter, + isAlignedRight: justifyRight, + isAlignedJustified: justifyFull + }; + + Object.keys(changes).forEach(function (key) { + var button = buttons[key]; + if (button) { + // The 3rd parameter to set(...) is false to avoid firing onChange when setting the value programmatically. + button.set('checked', changes[key], false); + } + }); + } + this.setEditorSession = function(session) { - if (editorSession) { - editorSession.unsubscribe(EditorSession.signalCursorMoved, checkStyleButtons); - editorSession.unsubscribe(EditorSession.signalParagraphChanged, checkStyleButtons); - editorSession.unsubscribe(EditorSession.signalParagraphStyleModified, checkStyleButtons); + if (directParagraphStyler) { + directParagraphStyler.unsubscribe(gui.DirectParagraphStyler.paragraphStylingChanged, updateStyleButtons); } - editorSession = session; - if (editorSession) { - editorSession.subscribe(EditorSession.signalCursorMoved, checkStyleButtons); - editorSession.subscribe(EditorSession.signalParagraphChanged, checkStyleButtons); - editorSession.subscribe(EditorSession.signalParagraphStyleModified, checkStyleButtons); - checkStyleButtons(); + directParagraphStyler = session && session.sessionController.getDirectParagraphStyler(); + if (directParagraphStyler) { + directParagraphStyler.subscribe(gui.DirectParagraphStyler.paragraphStylingChanged, updateStyleButtons); } + widget.children.forEach(function (element) { + element.setAttribute('disabled', !directParagraphStyler); + }); + updateStyleButtons({ + isAlignedLeft: directParagraphStyler ? directParagraphStyler.isAlignedLeft() : false, + isAlignedCenter: directParagraphStyler ? directParagraphStyler.isAlignedCenter() : false, + isAlignedRight: directParagraphStyler ? directParagraphStyler.isAlignedRight() : false, + isAlignedJustified: directParagraphStyler ? directParagraphStyler.isAlignedJustified() : false + }); }; callback(widget); diff --git a/webodf/lib/gui/DirectParagraphStyler.js b/webodf/lib/gui/DirectParagraphStyler.js new file mode 100644 index 00000000..66f28ca3 --- /dev/null +++ b/webodf/lib/gui/DirectParagraphStyler.js @@ -0,0 +1,288 @@ +/** + * @license + * Copyright (C) 2013 KO GmbH + * + * @licstart + * The JavaScript code in this page is free software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * (GNU AGPL) as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. The code is distributed + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU AGPL for more details. + * + * As additional permission under GNU AGPL version 3 section 7, you + * may distribute non-source (e.g., minimized or compacted) forms of + * that code without the copy of the GNU GPL normally required by + * section 4, provided you include this license notice and a URL + * through which recipients can access the Corresponding Source. + * + * As a special exception to the AGPL, any HTML file which merely makes function + * calls to this code, and for that purpose includes it by reference shall be + * deemed a separate work for copyright law purposes. In addition, the copyright + * holders of this code give you permission to combine this code with free + * software libraries that are released under the GNU LGPL. You may copy and + * distribute such a system following the terms of the GNU AGPL for this code + * and the LGPL for the libraries. If you modify this code, you may extend this + * exception to your version of the code, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your + * version. + * + * This license applies to this entire compilation. + * @licend + * @source: http://www.webodf.org/ + * @source: http://gitorious.org/webodf/webodf/ + */ + +/*global core, ops, odf, gui, runtime*/ + +runtime.loadClass("core.EventNotifier"); +runtime.loadClass("core.Utils"); +runtime.loadClass("odf.OdfUtils"); +runtime.loadClass("ops.OpAddParagraphStyle"); +runtime.loadClass("ops.OpSetParagraphStyle"); +runtime.loadClass("gui.StyleHelper"); + +/** + * @constructor + * @param {!ops.Session} session + * @param {!string} inputMemberId + * @param {!odf.StyleNameGenerator} styleNameGenerator + */ +gui.DirectParagraphStyler = function DirectParagraphStyler(session, inputMemberId, styleNameGenerator) { + "use strict"; + + var odtDocument = session.getOdtDocument(), + utils = new core.Utils(), + odfUtils = new odf.OdfUtils(), + styleHelper = new gui.StyleHelper(odtDocument.getFormatting()), + eventNotifier = new core.EventNotifier([gui.DirectParagraphStyler.paragraphStylingChanged]), + // cached values + isAlignedLeftValue, + isAlignedCenterValue, + isAlignedRightValue, + isAlignedJustifiedValue; + + function updatedCachedValues() { + var cursor = odtDocument.getCursor(inputMemberId), + range = cursor && cursor.getSelectedRange(), + diffMap; + + function noteChange(oldValue, newValue, id) { + if (oldValue !== newValue) { + if (diffMap === undefined) { + diffMap = {}; + } + diffMap[id] = newValue; + } + return newValue; + } + // TODO: these are mutually exclusive values usually, so just one value with the alignment style might be enough + // but in a range with multiple paragraphs there could be multiple alignment styles, which should be reflected somehow + isAlignedLeftValue = noteChange(isAlignedLeftValue, range ? styleHelper.isAlignedLeft(range) : false, 'isAlignedLeft'); + isAlignedCenterValue = noteChange(isAlignedCenterValue, range ? styleHelper.isAlignedCenter(range) : false, 'isAlignedCenter'); + isAlignedRightValue = noteChange(isAlignedRightValue, range ? styleHelper.isAlignedRight(range) : false, 'isAlignedRight'); + isAlignedJustifiedValue = noteChange(isAlignedJustifiedValue, range ? styleHelper.isAlignedJustified(range) : false, 'isAlignedJustified'); + + if (diffMap) { + eventNotifier.emit(gui.DirectParagraphStyler.paragraphStylingChanged, diffMap); + } + } + + function onCursorAdded(cursor) { + if (cursor.getMemberId() === inputMemberId) { + updatedCachedValues(); + } + } + + function onCursorRemoved(memberId) { + if (memberId === inputMemberId) { + updatedCachedValues(); + } + } + + function onCursorMoved(cursor) { + if (cursor.getMemberId() === inputMemberId) { + updatedCachedValues(); + } + } + + function onParagraphStyleModified() { + // TODO: check if the cursor (selection) is actually affected + updatedCachedValues(); + } + + function onParagraphChanged(args) { + var cursor = odtDocument.getCursor(inputMemberId); + + if (cursor && odtDocument.getParagraphElement(cursor.getNode()) === args.paragraphElement) { + updatedCachedValues(); + } + } + + this.isAlignedLeft = function() { + return isAlignedLeftValue; + }; + + this.isAlignedCenter = function() { + return isAlignedCenterValue; + }; + + this.isAlignedRight = function() { + return isAlignedRightValue; + }; + + this.isAlignedJustified = function() { + return isAlignedJustifiedValue; + }; + + /** + * @param {!function(!Object) : !Object} applyDirectStyling + */ + function applyParagraphDirectStyling(applyDirectStyling) { + var range = odtDocument.getCursor(inputMemberId).getSelectedRange(), + position = odtDocument.getCursorPosition(inputMemberId), + paragraphs = odfUtils.getParagraphElements(range), + formatting = odtDocument.getFormatting(); + + paragraphs.forEach(function(paragraph) { + var paragraphStartPoint = position + odtDocument.getDistanceFromCursor(inputMemberId, paragraph, 0), + paragraphStyleName = paragraph.getAttributeNS(odf.Namespaces.textns, "style-name"), + newParagraphStyleName = styleNameGenerator.generateName(), + opAddParagraphStyle, + opSetParagraphStyle, + paragraphProperties; + + // getDistanceFromCursor returns the last position before the node & offset + // The first index of the paragraph may not be walkable + paragraphStartPoint += 1; + + if (paragraphStyleName) { + paragraphProperties = formatting.createDerivedStyleObject(paragraphStyleName, "paragraph", {}); + } + paragraphProperties = applyDirectStyling(paragraphProperties || {}); + opAddParagraphStyle = new ops.OpAddParagraphStyle(); + opAddParagraphStyle.init({ + memberid: inputMemberId, + styleName: newParagraphStyleName, + isAutomaticStyle: true, + setProperties: paragraphProperties + }); + + opSetParagraphStyle = new ops.OpSetParagraphStyle(); + opSetParagraphStyle.init({ + memberid: inputMemberId, + styleName: newParagraphStyleName, + position: paragraphStartPoint + }); + + session.enqueue(opAddParagraphStyle); + session.enqueue(opSetParagraphStyle); + }); + } + + function applySimpleParagraphDirectStyling(styleOverrides) { + applyParagraphDirectStyling(function(paragraphStyle) { return utils.mergeObjects(paragraphStyle, styleOverrides); }); + } + + function alignParagraph(alignment) { + applySimpleParagraphDirectStyling({"style:paragraph-properties" : {"fo:text-align" : alignment}}); + } + + this.alignParagraphLeft = function() { + alignParagraph('left'); + return true; + }; + + this.alignParagraphCenter = function() { + alignParagraph('center'); + return true; + }; + + this.alignParagraphRight = function() { + alignParagraph('right'); + return true; + }; + + this.alignParagraphJustified = function() { + alignParagraph('justify'); + return true; + }; + + function modifyParagraphIndent(direction, paragraphStyle) { + var tabStopDistance = odtDocument.getFormatting().getDefaultTabStopDistance(), + paragraphProperties = paragraphStyle["style:paragraph-properties"], + indentValue = paragraphProperties && paragraphProperties["fo:margin-left"], + indent = indentValue && odfUtils.parseLength(indentValue), + newIndent; + + if (indent && indent.unit === tabStopDistance.unit) { + newIndent = (indent.value + (direction * tabStopDistance.value)) + indent.unit; + } else { + // TODO unit-conversion would allow indent to work irrespective of the paragraph's indent type + newIndent = (direction * tabStopDistance.value) + tabStopDistance.unit; + } + + return utils.mergeObjects(paragraphStyle, {"style:paragraph-properties" : {"fo:margin-left" : newIndent}}); + } + + this.indent = function() { + applyParagraphDirectStyling(modifyParagraphIndent.bind(null, 1)); + return true; + }; + + this.outdent = function() { + applyParagraphDirectStyling(modifyParagraphIndent.bind(null, -1)); + return true; + }; + + + /** + * @param {!string} eventid + * @param {!Function} cb + * @return {undefined} + */ + this.subscribe = function (eventid, cb) { + eventNotifier.subscribe(eventid, cb); + }; + + /** + * @param {!string} eventid + * @param {!Function} cb + * @return {undefined} + */ + this.unsubscribe = function (eventid, cb) { + eventNotifier.unsubscribe(eventid, cb); + }; + + /** + * @param {!function(!Object=)} callback, passing an error object in case of error + * @return {undefined} + */ + this.destroy = function(callback) { + odtDocument.unsubscribe(ops.OdtDocument.signalCursorAdded, onCursorAdded); + odtDocument.unsubscribe(ops.OdtDocument.signalCursorRemoved, onCursorRemoved); + odtDocument.unsubscribe(ops.OdtDocument.signalCursorMoved, onCursorMoved); + odtDocument.unsubscribe(ops.OdtDocument.signalParagraphStyleModified, onParagraphStyleModified); + odtDocument.unsubscribe(ops.OdtDocument.signalParagraphChanged, onParagraphChanged); + callback(); + }; + + function init() { + odtDocument.subscribe(ops.OdtDocument.signalCursorAdded, onCursorAdded); + odtDocument.subscribe(ops.OdtDocument.signalCursorRemoved, onCursorRemoved); + odtDocument.subscribe(ops.OdtDocument.signalCursorMoved, onCursorMoved); + odtDocument.subscribe(ops.OdtDocument.signalParagraphStyleModified, onParagraphStyleModified); + odtDocument.subscribe(ops.OdtDocument.signalParagraphChanged, onParagraphChanged); + updatedCachedValues(); + } + + init(); +}; + +/**@const*/gui.DirectParagraphStyler.paragraphStylingChanged = "paragraphStyling/changed"; + +(function () { + "use strict"; + return gui.DirectParagraphStyler; +}()); + diff --git a/webodf/lib/gui/SessionController.js b/webodf/lib/gui/SessionController.js index 2e39d40b..9798e829 100644 --- a/webodf/lib/gui/SessionController.js +++ b/webodf/lib/gui/SessionController.js @@ -48,6 +48,7 @@ runtime.loadClass("ops.OpRemoveAnnotation"); runtime.loadClass("gui.Clipboard"); runtime.loadClass("gui.KeyboardHandler"); runtime.loadClass("gui.DirectTextStyler"); +runtime.loadClass("gui.DirectParagraphStyler"); /** * @constructor @@ -69,6 +70,7 @@ gui.SessionController = (function () { gui.SessionController = function SessionController(session, inputMemberId, args) { var /**@type{!Window}*/window = /**@type{!Window}*/(runtime.getWindow()), odtDocument = session.getOdtDocument(), + utils = new core.Utils(), domUtils = new core.DomUtils(), odfUtils = new odf.OdfUtils(), clipboard = new gui.Clipboard(), @@ -77,10 +79,10 @@ gui.SessionController = (function () { keyboardMovementsFilter = new core.PositionFilterChain(), baseFilter = odtDocument.getPositionFilter(), clickStartedWithinContainer = false, + styleNameGenerator = new odf.StyleNameGenerator("auto" + utils.hashString(inputMemberId) + "_", odtDocument.getFormatting()), undoManager = null, directTextStyler = args && args.directStylingEnabled ? new gui.DirectTextStyler(session, inputMemberId) : null, - utils = new core.Utils(), - styleNameGenerator = new odf.StyleNameGenerator("auto" + utils.hashString(inputMemberId) + "_", odtDocument.getFormatting()); + directParagraphStyler = args && args.directStylingEnabled ? new gui.DirectParagraphStyler(session, inputMemberId, styleNameGenerator) : null; runtime.assert(window !== null, "Expected to be run in an environment which has a global window, like a browser."); @@ -1153,92 +1155,6 @@ gui.SessionController = (function () { // Expect that each mouse-up event is preceded by a mouse down that will update clickStartedWithinContainer } - /** - * - * @param {!function(!Object) : !Object} applyDirectStyling - */ - function applyParagraphDirectStyling(applyDirectStyling) { - var range = odtDocument.getCursor(inputMemberId).getSelectedRange(), - position = odtDocument.getCursorPosition(inputMemberId), - paragraphs = odfUtils.getParagraphElements(range), - formatting = odtDocument.getFormatting(); - - paragraphs.forEach(function(paragraph) { - var paragraphStartPoint = position + odtDocument.getDistanceFromCursor(inputMemberId, paragraph, 0), - paragraphStyleName = paragraph.getAttributeNS(odf.Namespaces.textns, "style-name"), - newParagraphStyleName = styleNameGenerator.generateName(), - opAddParagraphStyle, - opSetParagraphStyle, - paragraphProperties; - - // getDistanceFromCursor returns the last position before the node & offset - // The first index of the paragraph may not be walkable - paragraphStartPoint += 1; - - if (paragraphStyleName) { - paragraphProperties = formatting.createDerivedStyleObject(paragraphStyleName, "paragraph", {}); - } - paragraphProperties = applyDirectStyling(paragraphProperties || {}); - opAddParagraphStyle = new ops.OpAddParagraphStyle(); - opAddParagraphStyle.init({ - memberid: inputMemberId, - styleName: newParagraphStyleName, - isAutomaticStyle: true, - setProperties: paragraphProperties - }); - session.enqueue(opAddParagraphStyle); - - opSetParagraphStyle = new ops.OpSetParagraphStyle(); - opSetParagraphStyle.init({ - memberid: inputMemberId, - styleName: newParagraphStyleName, - position: paragraphStartPoint - }); - session.enqueue(opSetParagraphStyle); - }); - } - - function applySimpleParagraphDirectStyling(styleOverrides) { - applyParagraphDirectStyling(function(paragraphStyle) { return utils.mergeObjects(paragraphStyle, styleOverrides); }); - } - - function alignParagraphLeft() { - applySimpleParagraphDirectStyling({"style:paragraph-properties" : {"fo:text-align" : 'left'}}); - return true; - } - - function alignParagraphCenter() { - applySimpleParagraphDirectStyling({"style:paragraph-properties" : {"fo:text-align" : 'center'}}); - return true; - } - - function alignParagraphRight() { - applySimpleParagraphDirectStyling({"style:paragraph-properties" : {"fo:text-align" : 'right'}}); - return true; - } - - function alignParagraphJustified() { - applySimpleParagraphDirectStyling({"style:paragraph-properties" : {"fo:text-align" : 'justify'}}); - return true; - } - - function modifyParagraphIndent(direction, paragraphStyle) { - var tabStopDistance = odtDocument.getFormatting().getDefaultTabStopDistance(), - paragraphProperties = paragraphStyle["style:paragraph-properties"], - indentValue = paragraphProperties && paragraphProperties["fo:margin-left"], - indent = indentValue && odfUtils.parseLength(indentValue), - newIndent; - - if (indent && indent.unit === tabStopDistance.unit) { - newIndent = (indent.value + (direction * tabStopDistance.value)) + indent.unit; - } else { - // TODO unit-conversion would allow indent to work irrespective of the paragraph's indent type - newIndent = (direction * tabStopDistance.value) + tabStopDistance.unit; - } - - return utils.mergeObjects(paragraphStyle, {"style:paragraph-properties" : {"fo:margin-left" : newIndent}}); - } - /** * @return {undefined} */ @@ -1306,21 +1222,6 @@ gui.SessionController = (function () { } }; - this.alignParagraphLeft = alignParagraphLeft; - this.alignParagraphCenter = alignParagraphCenter; - this.alignParagraphRight = alignParagraphRight; - this.alignParagraphJustified = alignParagraphJustified; - - this.indent = function() { - applyParagraphDirectStyling(modifyParagraphIndent.bind(null, 1)); - return true; - }; - - this.outdent = function() { - applyParagraphDirectStyling(modifyParagraphIndent.bind(null, -1)); - return true; - }; - /** * @return {!string} */ @@ -1371,17 +1272,28 @@ gui.SessionController = (function () { return directTextStyler; }; + /** + * @returns {?gui.DirectParagraphStyler} + */ + this.getDirectParagraphStyler = function () { + return directParagraphStyler; + }; + /** * @param {!function(!Object=)} callback, passing an error object in case of error * @return {undefined} */ this.destroy = function(callback) { + var destroyDirectTextStyler = directTextStyler ? directTextStyler.destroy : function(cb) { cb(); }, + destroyDirectParagraphStyler = directParagraphStyler ? directParagraphStyler.destroy : function(cb) { cb(); }; // TODO: check if anything else needs to be cleaned up - if (directTextStyler) { - directTextStyler.destroy(callback); - } else { - callback(); - } + destroyDirectTextStyler(function(err) { + if (err) { + callback(err); + } else { + destroyDirectParagraphStyler(callback); + } + }); }; function init() { @@ -1433,10 +1345,12 @@ gui.SessionController = (function () { keyDownHandler.bind(keyCode.I, modifier.Meta, directTextStyler.toggleItalic); keyDownHandler.bind(keyCode.U, modifier.Meta, directTextStyler.toggleUnderline); } - keyDownHandler.bind(keyCode.L, modifier.MetaShift, alignParagraphLeft); - keyDownHandler.bind(keyCode.E, modifier.MetaShift, alignParagraphCenter); - keyDownHandler.bind(keyCode.R, modifier.MetaShift, alignParagraphRight); - keyDownHandler.bind(keyCode.J, modifier.MetaShift, alignParagraphJustified); + if (directParagraphStyler) { + keyDownHandler.bind(keyCode.L, modifier.MetaShift, directParagraphStyler.alignParagraphLeft); + keyDownHandler.bind(keyCode.E, modifier.MetaShift, directParagraphStyler.alignParagraphCenter); + keyDownHandler.bind(keyCode.R, modifier.MetaShift, directParagraphStyler.alignParagraphRight); + keyDownHandler.bind(keyCode.J, modifier.MetaShift, directParagraphStyler.alignParagraphJustified); + } keyDownHandler.bind(keyCode.Z, modifier.Meta, undo); keyDownHandler.bind(keyCode.Z, modifier.MetaShift, redo); } else { @@ -1446,10 +1360,12 @@ gui.SessionController = (function () { keyDownHandler.bind(keyCode.I, modifier.Ctrl, directTextStyler.toggleItalic); keyDownHandler.bind(keyCode.U, modifier.Ctrl, directTextStyler.toggleUnderline); } - keyDownHandler.bind(keyCode.L, modifier.CtrlShift, alignParagraphLeft); - keyDownHandler.bind(keyCode.E, modifier.CtrlShift, alignParagraphCenter); - keyDownHandler.bind(keyCode.R, modifier.CtrlShift, alignParagraphRight); - keyDownHandler.bind(keyCode.J, modifier.CtrlShift, alignParagraphJustified); + if (directParagraphStyler) { + keyDownHandler.bind(keyCode.L, modifier.CtrlShift, directParagraphStyler.alignParagraphLeft); + keyDownHandler.bind(keyCode.E, modifier.CtrlShift, directParagraphStyler.alignParagraphCenter); + keyDownHandler.bind(keyCode.R, modifier.CtrlShift, directParagraphStyler.alignParagraphRight); + keyDownHandler.bind(keyCode.J, modifier.CtrlShift, directParagraphStyler.alignParagraphJustified); + } keyDownHandler.bind(keyCode.Z, modifier.Ctrl, undo); keyDownHandler.bind(keyCode.Z, modifier.CtrlShift, redo); } diff --git a/webodf/lib/manifest.js b/webodf/lib/manifest.js index 6abfbcc6..a0d894d9 100644 --- a/webodf/lib/manifest.js +++ b/webodf/lib/manifest.js @@ -59,6 +59,7 @@ "gui/Clipboard.js", "gui/PresenterUI.js", "gui/DirectTextStyler.js", + "gui/DirectParagraphStyler.js", "gui/SessionController.js", "gui/CaretManager.js", "gui/EditInfoHandle.js", diff --git a/webodf/tests/tests.html b/webodf/tests/tests.html index 14de962f..8afa2a35 100644 --- a/webodf/tests/tests.html +++ b/webodf/tests/tests.html @@ -71,6 +71,7 @@ +