Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle editing of partially selected lists #813

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion programs/editor/Tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define("webodf/editor/Tools", [
"dijit/form/DropDownButton",
"dijit/Toolbar",
"webodf/editor/widgets/paragraphAlignment",
"webodf/editor/widgets/toggleLists",
"webodf/editor/widgets/simpleStyles",
"webodf/editor/widgets/undoRedoMenu",
"webodf/editor/widgets/toolbarWidgets/currentStyle",
Expand All @@ -42,7 +43,7 @@ define("webodf/editor/Tools", [
"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) {
function (ready, MenuItem, DropDownMenu, Button, DropDownButton, Toolbar, ParagraphAlignment, ToggleLists, SimpleStyles, UndoRedoMenu, CurrentStyle, AnnotationControl, EditHyperlinks, ImageInserter, ParagraphStylesDialog, ZoomSlider, AboutDialog, EditorSession) {
"use strict";

return function Tools(toolbarElementId, args) {
Expand All @@ -59,6 +60,7 @@ define("webodf/editor/Tools", [
undoRedoMenu,
editorSession,
paragraphAlignment,
toggleLists,
imageInserter,
annotationControl,
editHyperlinks,
Expand Down Expand Up @@ -171,6 +173,9 @@ define("webodf/editor/Tools", [
// Paragraph direct alignment buttons
paragraphAlignment = createTool(ParagraphAlignment, args.directParagraphStylingEnabled);

// Numbered and bulleted list toggle buttons
toggleLists = createTool(ToggleLists, args.listEditingEnabled);

// Paragraph Style Selector
currentStyle = createTool(CurrentStyle, args.paragraphStyleSelectingEnabled);

Expand Down
127 changes: 127 additions & 0 deletions programs/editor/widgets/toggleLists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Copyright (C) 2010-2014 KO GmbH <[email protected]>
*
* @licstart
* This file is part of WebODF.
*
* WebODF 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.
*
* WebODF is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
* @licend
*
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/

/*global define,require */

define("webodf/editor/widgets/toggleLists", [
"dijit/form/ToggleButton",
"webodf/editor/EditorSession"],

function (ToggleButton, EditorSession) {
"use strict";

var ToggleLists = function (callback) {
var self = this,
editorSession,
listController,
widget = {},
numberedList,
bulletedList;

numberedList = new ToggleButton({
label: runtime.tr('Numbering'),
disabled: true,
showLabel: false,
checked: false,
iconClass: "dijitEditorIcon dijitEditorIconInsertOrderedList",
onChange: function (checked) {
var success = listController.setNumberedList(checked);
//TODO: remove this when the list controller supports all use cases triggered by this button
if(!success) {
numberedList.set("checked", !checked, false);
}
self.onToolDone();
}
});

bulletedList = new ToggleButton({
label: runtime.tr('Bullets'),
disabled: true,
showLabel: false,
checked: false,
iconClass: "dijitEditorIcon dijitEditorIconInsertUnorderedList",
onChange: function (checked) {
var success = listController.setBulletedList(checked);
//TODO: remove this when the list controller supports all use cases triggered by this button
if(!success) {
bulletedList.set("checked", !checked, false);
}
self.onToolDone();
}
});

widget.children = [numberedList, bulletedList];

widget.startup = function () {
widget.children.forEach(function (element) {
element.startup();
});
};

widget.placeAt = function (container) {
widget.children.forEach(function (element) {
element.placeAt(container);
});
return widget;
};

function enableToggleButtons(isEnabled) {
widget.children.forEach(function (element) {
element.setAttribute('disabled', !isEnabled);
});
}

function updateToggleButtons(styleSummary) {
bulletedList.set("checked", styleSummary.isBulletedList, false);
numberedList.set("checked", styleSummary.isNumberedList, false);

}

this.onToolDone = function () {
};

this.setEditorSession = function (session) {
if (editorSession) {
listController.unsubscribe(gui.ListController.listStylingChanged, updateToggleButtons);
listController.unsubscribe(gui.ListController.enabledChanged, enableToggleButtons);
}

editorSession = session;

if (editorSession) {
listController = editorSession.sessionController.getListController();
listController.subscribe(gui.ListController.listStylingChanged, updateToggleButtons);
listController.subscribe(gui.ListController.enabledChanged, enableToggleButtons);
enableToggleButtons(listController.isEnabled());
} else {
enableToggleButtons(false);
}
};

callback(widget);
};

return ToggleLists;
}
);
3 changes: 3 additions & 0 deletions programs/editor/wodocollabtexteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ var Wodo = Wodo || (function () {
paragraphStyleEditingEnabled = isEnabled(editorOptions.paragraphStyleEditingEnabled),
imageEditingEnabled = isEnabled(editorOptions.imageEditingEnabled, true),
hyperlinkEditingEnabled = isEnabled(editorOptions.hyperlinkEditingEnabled, true),
listEditingEnabled = isEnabled(editorOptions.listEditingEnabled, true),
reviewModeEnabled = isEnabled(editorOptions.reviewModeEnabled, true),
annotationsEnabled = reviewModeEnabled || isEnabled(editorOptions.annotationsEnabled, true),
undoRedoEnabled = false, // no proper mechanism yet for collab
Expand Down Expand Up @@ -224,6 +225,7 @@ var Wodo = Wodo || (function () {
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
imageEditingEnabled: imageEditingEnabled,
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
listEditingEnabled: listEditingEnabled,
annotationsEnabled: annotationsEnabled,
zoomingEnabled: zoomingEnabled,
reviewModeEnabled: reviewModeEnabled
Expand Down Expand Up @@ -567,6 +569,7 @@ var Wodo = Wodo || (function () {
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
imageInsertingEnabled: imageEditingEnabled,
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
listEditingEnabled: listEditingEnabled,
annotationsEnabled: annotationsEnabled,
undoRedoEnabled: undoRedoEnabled,
zoomingEnabled: zoomingEnabled
Expand Down
3 changes: 3 additions & 0 deletions programs/editor/wodotexteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ var Wodo = Wodo || (function () {
paragraphStyleEditingEnabled = isEnabled(editorOptions.paragraphStyleEditingEnabled),
imageEditingEnabled = isEnabled(editorOptions.imageEditingEnabled),
hyperlinkEditingEnabled = isEnabled(editorOptions.hyperlinkEditingEnabled),
listEditingEnabled = isEnabled(editorOptions.listEditingEnabled),
reviewModeEnabled = Boolean(editorOptions.reviewModeEnabled), // needs to be explicitly enabled
annotationsEnabled = reviewModeEnabled || isEnabled(editorOptions.annotationsEnabled),
undoRedoEnabled = isEnabled(editorOptions.undoRedoEnabled),
Expand Down Expand Up @@ -331,6 +332,7 @@ var Wodo = Wodo || (function () {
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
imageEditingEnabled: imageEditingEnabled,
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
listEditingEnabled: listEditingEnabled,
annotationsEnabled: annotationsEnabled,
zoomingEnabled: zoomingEnabled,
reviewModeEnabled: reviewModeEnabled
Expand Down Expand Up @@ -661,6 +663,7 @@ var Wodo = Wodo || (function () {
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
imageInsertingEnabled: imageEditingEnabled,
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
listEditingEnabled: listEditingEnabled,
annotationsEnabled: annotationsEnabled,
undoRedoEnabled: undoRedoEnabled,
zoomingEnabled: zoomingEnabled,
Expand Down
Loading