Skip to content

Commit d18a355

Browse files
author
Satvik Kumar
committed
Add support for session constraints to list controller
1 parent 886821f commit d18a355

7 files changed

Lines changed: 103 additions & 17 deletions

File tree

programs/editor/Tools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ define("webodf/editor/Tools", [
174174
paragraphAlignment = createTool(ParagraphAlignment, args.directParagraphStylingEnabled);
175175

176176
// Numbered and bulleted list toggle buttons
177-
toggleLists = createTool(ToggleLists, true);
177+
toggleLists = createTool(ToggleLists, args.listEditingEnabled);
178178

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

programs/editor/widgets/toggleLists.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ define("webodf/editor/widgets/toggleLists", [
7474
return widget;
7575
};
7676

77+
function enableToggleButtons(isEnabled) {
78+
widget.children.forEach(function (element) {
79+
element.setAttribute('disabled', !isEnabled);
80+
});
81+
}
82+
7783
function updateToggleButtons(styleSummary) {
7884
bulletedList.set("checked", styleSummary.isBulletedList, false);
7985
numberedList.set("checked", styleSummary.isNumberedList, false);
@@ -86,13 +92,18 @@ define("webodf/editor/widgets/toggleLists", [
8692
this.setEditorSession = function (session) {
8793
if (editorSession) {
8894
listController.unsubscribe(gui.ListController.listStylingChanged, updateToggleButtons);
95+
listController.unsubscribe(gui.ListController.enabledChanged, enableToggleButtons);
8996
}
9097

9198
editorSession = session;
9299

93100
if (editorSession) {
94101
listController = editorSession.sessionController.getListController();
95102
listController.subscribe(gui.ListController.listStylingChanged, updateToggleButtons);
103+
listController.subscribe(gui.ListController.enabledChanged, enableToggleButtons);
104+
enableToggleButtons(listController.isEnabled());
105+
} else {
106+
enableToggleButtons(false);
96107
}
97108
};
98109

programs/editor/wodocollabtexteditor.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ var Wodo = Wodo || (function () {
177177
paragraphStyleEditingEnabled = isEnabled(editorOptions.paragraphStyleEditingEnabled),
178178
imageEditingEnabled = isEnabled(editorOptions.imageEditingEnabled, true),
179179
hyperlinkEditingEnabled = isEnabled(editorOptions.hyperlinkEditingEnabled, true),
180+
listEditingEnabled = isEnabled(editorOptions.listEditingEnabled),
180181
reviewModeEnabled = isEnabled(editorOptions.reviewModeEnabled, true),
181182
annotationsEnabled = reviewModeEnabled || isEnabled(editorOptions.annotationsEnabled, true),
182183
undoRedoEnabled = false, // no proper mechanism yet for collab
@@ -224,6 +225,7 @@ var Wodo = Wodo || (function () {
224225
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
225226
imageEditingEnabled: imageEditingEnabled,
226227
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
228+
listEditingEnabled: listEditingEnabled,
227229
annotationsEnabled: annotationsEnabled,
228230
zoomingEnabled: zoomingEnabled,
229231
reviewModeEnabled: reviewModeEnabled
@@ -567,6 +569,7 @@ var Wodo = Wodo || (function () {
567569
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
568570
imageInsertingEnabled: imageEditingEnabled,
569571
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
572+
listEditingEnabled: listEditingEnabled,
570573
annotationsEnabled: annotationsEnabled,
571574
undoRedoEnabled: undoRedoEnabled,
572575
zoomingEnabled: zoomingEnabled

programs/editor/wodotexteditor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ var Wodo = Wodo || (function () {
283283
paragraphStyleEditingEnabled = isEnabled(editorOptions.paragraphStyleEditingEnabled),
284284
imageEditingEnabled = isEnabled(editorOptions.imageEditingEnabled),
285285
hyperlinkEditingEnabled = isEnabled(editorOptions.hyperlinkEditingEnabled),
286+
listEditingEnabled = isEnabled(editorOptions.listEditingEnabled),
286287
reviewModeEnabled = Boolean(editorOptions.reviewModeEnabled), // needs to be explicitly enabled
287288
annotationsEnabled = reviewModeEnabled || isEnabled(editorOptions.annotationsEnabled),
288289
undoRedoEnabled = isEnabled(editorOptions.undoRedoEnabled),
@@ -326,6 +327,7 @@ var Wodo = Wodo || (function () {
326327
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
327328
imageEditingEnabled: imageEditingEnabled,
328329
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
330+
listEditingEnabled: listEditingEnabled,
329331
annotationsEnabled: annotationsEnabled,
330332
zoomingEnabled: zoomingEnabled,
331333
reviewModeEnabled: reviewModeEnabled
@@ -656,6 +658,7 @@ var Wodo = Wodo || (function () {
656658
paragraphStyleEditingEnabled: paragraphStyleEditingEnabled,
657659
imageInsertingEnabled: imageEditingEnabled,
658660
hyperlinkEditingEnabled: hyperlinkEditingEnabled,
661+
listEditingEnabled: listEditingEnabled,
659662
annotationsEnabled: annotationsEnabled,
660663
undoRedoEnabled: undoRedoEnabled,
661664
zoomingEnabled: zoomingEnabled,
@@ -727,6 +730,7 @@ var Wodo = Wodo || (function () {
727730
* @param [editorOptions.paragraphStyleEditingEnabled=false] if set to 'true', enables the editing of defined paragraph styles
728731
* @param [editorOptions.imageEditingEnabled=false] if set to 'true', enables the insertion of images
729732
* @param [editorOptions.hyperlinkEditingEnabled=false] if set to 'true', enables the editing of hyperlinks
733+
* @param [editorOptions.listEditingEnabled=false] if set to 'true', enables the editing of lists
730734
* @param [editorOptions.annotationsEnabled=false] if set to 'true', enables the display and the editing of annotations
731735
* @param [editorOptions.undoRedoEnabled=false] if set to 'true', enables the Undo and Redo of editing actions
732736
* @param [editorOptions.zoomingEnabled=false] if set to 'true', enables the zooming tool

webodf/lib/gui/ListController.js

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,22 @@
2727
/**
2828
* @implements {core.Destroyable}
2929
* @param {!ops.Session} session
30+
* @param {!gui.SessionConstraints} sessionConstraints
31+
* @param {!gui.SessionContext} sessionContext
3032
* @param {!string} inputMemberId
3133
* @constructor
3234
*/
33-
gui.ListController = function ListController(session, inputMemberId) {
35+
gui.ListController = function ListController(session, sessionConstraints, sessionContext, inputMemberId) {
3436
"use strict";
3537
var odtDocument = session.getOdtDocument(),
3638
odfUtils = odf.OdfUtils,
3739
eventNotifier = new core.EventNotifier([
38-
gui.ListController.listStylingChanged
40+
gui.ListController.listStylingChanged,
41+
gui.ListController.enabledChanged
3942
]),
40-
/**@type{!gui.ListStyleSummary}*/
43+
/**@type{!gui.ListController.SelectionInfo}*/
4144
lastSignalledSelectionInfo,
42-
/**@type{!core.LazyProperty.<!gui.ListStyleSummary>}*/
45+
/**@type{!core.LazyProperty.<!gui.ListController.SelectionInfo>}*/
4346
cachedSelectionInfo;
4447

4548
/**
@@ -79,33 +82,67 @@ gui.ListController = function ListController(session, inputMemberId) {
7982
}
8083

8184
/**
82-
* @return {!gui.ListStyleSummary}
85+
* @return {!gui.ListController.SelectionInfo}
8386
*/
8487
function getSelectionInfo() {
8588
var cursor = odtDocument.getCursor(inputMemberId),
86-
cursorNode = cursor && cursor.getNode();
89+
cursorNode = cursor && cursor.getNode(),
90+
styleSummary = new gui.ListStyleSummary(cursorNode, odtDocument.getRootNode(), odtDocument.getFormatting()),
91+
isEnabled = true;
8792

88-
return new gui.ListStyleSummary(cursorNode, odtDocument.getRootNode(), odtDocument.getFormatting());
93+
if (sessionConstraints.getState(gui.CommonConstraints.EDIT.REVIEW_MODE) === true) {
94+
isEnabled = sessionContext.isLocalCursorWithinOwnAnnotation();
95+
}
96+
97+
return new gui.ListController.SelectionInfo(isEnabled, styleSummary);
8998
}
9099

91100
/**
92101
* @return {undefined}
93102
*/
94103
function emitSelectionChanges() {
95-
var hasChanged = true,
96-
newStyleSummary = cachedSelectionInfo.value();
104+
var hasStyleChanged = true,
105+
hasEnabledChanged = true,
106+
newSelectionInfo = cachedSelectionInfo.value(),
107+
lastStyleSummary,
108+
newStyleSummary;
97109

98110
if (lastSignalledSelectionInfo) {
99-
hasChanged = lastSignalledSelectionInfo.isNumberedList !== newStyleSummary.isNumberedList ||
100-
lastSignalledSelectionInfo.isBulletedList !== newStyleSummary.isBulletedList;
111+
lastStyleSummary = lastSignalledSelectionInfo.styleSummary;
112+
newStyleSummary = newSelectionInfo.styleSummary;
113+
114+
hasStyleChanged = lastStyleSummary.isNumberedList !== newStyleSummary.isNumberedList ||
115+
lastStyleSummary.isBulletedList !== newStyleSummary.isBulletedList;
116+
117+
hasEnabledChanged = lastSignalledSelectionInfo.isEnabled !== newSelectionInfo.isEnabled;
101118
}
102119

103-
if (hasChanged) {
104-
lastSignalledSelectionInfo = newStyleSummary;
105-
eventNotifier.emit(gui.ListController.listStylingChanged, lastSignalledSelectionInfo);
120+
lastSignalledSelectionInfo = newSelectionInfo;
121+
122+
if (hasStyleChanged) {
123+
eventNotifier.emit(gui.ListController.listStylingChanged, lastSignalledSelectionInfo.styleSummary);
124+
}
125+
126+
if (hasEnabledChanged) {
127+
eventNotifier.emit(gui.ListController.enabledChanged, lastSignalledSelectionInfo.isEnabled);
106128
}
107129
}
108130

131+
/**
132+
* @return {undefined}
133+
*/
134+
function forceSelectionInfoRefresh() {
135+
cachedSelectionInfo.reset();
136+
emitSelectionChanges();
137+
}
138+
139+
/**
140+
* @return {!boolean}
141+
*/
142+
this.isEnabled = function () {
143+
return cachedSelectionInfo.value().isEnabled;
144+
};
145+
109146
/**
110147
* @param {!string} eventid
111148
* @param {!Function} cb
@@ -135,6 +172,7 @@ gui.ListController = function ListController(session, inputMemberId) {
135172
odtDocument.unsubscribe(ops.OdtDocument.signalParagraphChanged, onParagraphChanged);
136173
odtDocument.unsubscribe(ops.OdtDocument.signalParagraphStyleModified, onParagraphStyleModified);
137174
odtDocument.unsubscribe(ops.OdtDocument.signalProcessingBatchEnd, emitSelectionChanges);
175+
sessionConstraints.unsubscribe(gui.CommonConstraints.EDIT.REVIEW_MODE, forceSelectionInfoRefresh);
138176
callback();
139177
};
140178

@@ -148,6 +186,7 @@ gui.ListController = function ListController(session, inputMemberId) {
148186
odtDocument.subscribe(ops.OdtDocument.signalParagraphChanged, onParagraphChanged);
149187
odtDocument.subscribe(ops.OdtDocument.signalParagraphStyleModified, onParagraphStyleModified);
150188
odtDocument.subscribe(ops.OdtDocument.signalProcessingBatchEnd, emitSelectionChanges);
189+
sessionConstraints.subscribe(gui.CommonConstraints.EDIT.REVIEW_MODE, forceSelectionInfoRefresh);
151190

152191
cachedSelectionInfo = new core.LazyProperty(getSelectionInfo);
153192
}
@@ -157,3 +196,30 @@ gui.ListController = function ListController(session, inputMemberId) {
157196

158197
/**@const*/
159198
gui.ListController.listStylingChanged = "listStyling/changed";
199+
200+
/**@const*/
201+
gui.ListController.enabledChanged = "enabled/changed";
202+
203+
/**
204+
* @param {!boolean} isEnabled
205+
* @param {!gui.ListStyleSummary} styleSummary
206+
* @constructor
207+
* @struct
208+
*/
209+
gui.ListController.SelectionInfo = function (isEnabled, styleSummary) {
210+
"use strict";
211+
212+
/**
213+
* Whether the controller is enabled based on the selection
214+
* @type {!boolean}
215+
*/
216+
this.isEnabled = isEnabled;
217+
218+
/**
219+
* Summary of list style information for the selection
220+
* @type {!gui.ListStyleSummary}
221+
*/
222+
this.styleSummary = styleSummary;
223+
};
224+
225+

webodf/lib/gui/SessionController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ gui.SessionControllerOptions = function () {
9090
createParagraphStyleOps = /**@type {function (!number):!Array.<!ops.Operation>}*/ (directFormattingController.createParagraphStyleOps),
9191
textController = new gui.TextController(session, sessionConstraints, sessionContext, inputMemberId, createCursorStyleOp, createParagraphStyleOps),
9292
imageController = new gui.ImageController(session, sessionConstraints, sessionContext, inputMemberId, objectNameGenerator),
93-
listController = new gui.ListController(session, inputMemberId),
93+
listController = new gui.ListController(session, sessionConstraints, sessionContext, inputMemberId),
9494
imageSelector = new gui.ImageSelector(odtDocument.getOdfCanvas()),
9595
shadowCursorIterator = odtDocument.createPositionIterator(odtDocument.getRootNode()),
9696
/**@type{!core.ScheduledTask}*/

webodf/lib/manifest.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@
155155
],
156156
"gui.ListController": [
157157
"core.LazyProperty",
158+
"gui.CommonConstraints",
158159
"gui.ListStyleSummary",
159-
"ops.Session"
160+
"gui.SessionConstraints",
161+
"gui.SessionContext"
160162
],
161163
"gui.ListStyleSummary": [
162164
"odf.Formatting"

0 commit comments

Comments
 (0)