Index: trunk/extensions/VisualEditor/VisualEditor.php |
— | — | @@ -102,7 +102,8 @@ |
103 | 103 | 'es/views/es.ToolbarView.js', |
104 | 104 | 'es/tools/es.Tool.js', |
105 | 105 | 'es/tools/es.ButtonTool.js', |
106 | | - 'es/tools/es.AnnotationButtonTool.js' |
| 106 | + 'es/tools/es.AnnotationButtonTool.js', |
| 107 | + 'es/tools/es.ClearButtonTool.js' |
107 | 108 | ), |
108 | 109 | 'styles' => array( |
109 | 110 | 'es/styles/es.SurfaceView.css', |
Index: trunk/extensions/VisualEditor/demo/index.html |
— | — | @@ -135,6 +135,7 @@ |
136 | 136 | <script src="../modules/es/tools/es.Tool.js"></script> |
137 | 137 | <script src="../modules/es/tools/es.ButtonTool.js"></script> |
138 | 138 | <script src="../modules/es/tools/es.AnnotationButtonTool.js"></script> |
| 139 | + <script src="../modules/es/tools/es.ClearButtonTool.js"></script> |
139 | 140 | |
140 | 141 | <!-- Demo --> |
141 | 142 | <script src="../modules/sandbox/sandbox.js"></script> |
Index: trunk/extensions/VisualEditor/modules/es/tools/es.ClearButtonTool.js |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +es.ClearButtonTool = function( toolbar, name ) {
|
| 3 | + es.ButtonTool.call( this, toolbar, name );
|
| 4 | + this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
| 5 | +};
|
| 6 | +
|
| 7 | +es.ClearButtonTool.prototype.onClick = function() {
|
| 8 | + var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
|
| 9 | + this.toolbar.surfaceView.currentSelection,
|
| 10 | + 'clear',
|
| 11 | + /.*/
|
| 12 | + );
|
| 13 | + this.toolbar.surfaceView.model.transact( tx );
|
| 14 | + this.toolbar.surfaceView.clearInsertionAnnotations();
|
| 15 | +};
|
| 16 | +
|
| 17 | +es.ClearButtonTool.prototype.updateState = function( annotations ) {
|
| 18 | + if ( annotations.length === 0 ) {
|
| 19 | + this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
| 20 | + } else {
|
| 21 | + this.$.removeClass( 'es-toolbarButtonTool-disabled' );
|
| 22 | + }
|
| 23 | +};
|
| 24 | +
|
| 25 | +es.Tool.tools.clear = {
|
| 26 | + constructor: es.ClearButtonTool,
|
| 27 | + name: 'clear'
|
| 28 | +};
|
| 29 | +
|
| 30 | +es.extendClass( es.ClearButtonTool, es.ButtonTool ); |
\ No newline at end of file |
Index: trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js |
— | — | @@ -4,12 +4,7 @@ |
5 | 5 | };
|
6 | 6 |
|
7 | 7 | es.AnnotationButtonTool.prototype.onClick = function() {
|
8 | | - var method;
|
9 | | - if ( this.name === 'clear') {
|
10 | | - method = 'clear';
|
11 | | - } else {
|
12 | | - method = this.$.hasClass( 'es-toolbarButtonTool-down' ) ? 'clear' : 'set';
|
13 | | - }
|
| 8 | + var method = this.$.hasClass( 'es-toolbarButtonTool-down' ) ? 'clear' : 'set';
|
14 | 9 |
|
15 | 10 | var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
|
16 | 11 | this.toolbar.surfaceView.currentSelection,
|
— | — | @@ -17,8 +12,19 @@ |
18 | 13 | this.data
|
19 | 14 | );
|
20 | 15 | this.toolbar.surfaceView.model.transact( tx );
|
| 16 | + return false;
|
21 | 17 | };
|
22 | 18 |
|
| 19 | +es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
|
| 20 | + for ( var i = 0; i < annotations.length; i++ ) {
|
| 21 | + if ( annotations[i].type === this.data.type ) {
|
| 22 | + this.$.addClass( 'es-toolbarButtonTool-down' );
|
| 23 | + return;
|
| 24 | + }
|
| 25 | + }
|
| 26 | + this.$.removeClass( 'es-toolbarButtonTool-down' );
|
| 27 | +};
|
| 28 | +
|
23 | 29 | es.Tool.tools.bold = {
|
24 | 30 | constructor: es.AnnotationButtonTool,
|
25 | 31 | name: 'bold',
|
— | — | @@ -31,10 +37,5 @@ |
32 | 38 | data: { 'type': 'textStyle/italic' }
|
33 | 39 | };
|
34 | 40 |
|
35 | | -es.Tool.tools.clear = {
|
36 | | - constructor: es.AnnotationButtonTool,
|
37 | | - name: 'clear',
|
38 | | - data: /.*/
|
39 | | -};
|
40 | 41 |
|
41 | 42 | es.extendClass( es.AnnotationButtonTool, es.ButtonTool ); |
\ No newline at end of file |
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -142,6 +142,7 @@ |
143 | 143 | |
144 | 144 | es.SurfaceView.prototype.addInsertionAnnotation = function( annotation ) { |
145 | 145 | this.insertionAnnotations.push( annotation ); |
| 146 | + this.emitUpdate(); |
146 | 147 | }; |
147 | 148 | |
148 | 149 | es.SurfaceView.prototype.loadInsertionAnnotations = function( annotation ) { |
— | — | @@ -161,10 +162,12 @@ |
162 | 163 | if ( index !== -1 ) { |
163 | 164 | this.insertionAnnotations.splice( index, 1 ); |
164 | 165 | } |
| 166 | + this.emitUpdate(); |
165 | 167 | }; |
166 | 168 | |
167 | 169 | es.SurfaceView.prototype.clearInsertionAnnotations = function() { |
168 | 170 | this.insertionAnnotations = []; |
| 171 | + this.emitUpdate(); |
169 | 172 | }; |
170 | 173 | |
171 | 174 | es.SurfaceView.prototype.getModel = function() { |
Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js |
— | — | @@ -58,10 +58,14 @@ |
59 | 59 | annotations; |
60 | 60 | |
61 | 61 | if( selection.from === selection.to ) { |
62 | | - annotations = this.surfaceView.documentView.model.getAnnotationsFromOffset( selection.to ); |
| 62 | + annotations = this.surfaceView.getInsertionAnnotations(); |
63 | 63 | } else { |
64 | 64 | annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection ); |
65 | 65 | } |
| 66 | + |
| 67 | + for( var i = 0; i < this.tools.length; i++ ) { |
| 68 | + this.tools[i].updateState( annotations ); |
| 69 | + } |
66 | 70 | }; |
67 | 71 | |
68 | 72 | es.ToolbarView.prototype.setup = function() { |