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 */
159198gui . 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+
0 commit comments