mediawiki-extensions-Visual.../modules/ve/ui/tools/ve.ui.ClearButtonTool.js
Catrope 5e7c14c868 Manage annotations in ve.AnnotationSet object
Introduced the ve.AnnotationSet class to manage sets of annotations. This
is a generalization of ve.OrderedHashSet, a class that manages a set
using an array and an object keyed by hash.

Converted everything that stores, tracks or passes around annotations to
use ve.AnnotationSet. In particular, this means the linear model now
contains AnnotationSets instead of hash-keyed objects.

This allows us to maintain the order of annotations in the linear model,
and will help fix bugs with annotation ordering and splitting.

Change-Id: I50975b0a95f4cc33017a0b59fdede9ed1eff0124
2012-09-06 14:39:38 -07:00

68 lines
1.7 KiB
JavaScript

/**
* VisualEditor user interface ClearButtonTool class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.ClearButtonTool object.
*
* @class
* @constructor
* @extends {ve.ui.ButtonTool}
* @param {ve.ui.Toolbar} toolbar
* @param {String} name
*/
ve.ui.ClearButtonTool = function ( toolbar, name, title ) {
// Inheritance
ve.ui.ButtonTool.call( this, toolbar, name, title );
// Properties
this.$.addClass( 've-ui-toolbarButtonTool-disabled' );
this.pattern = /^(textStyle|link)\//;
};
/* Methods */
ve.ui.ClearButtonTool.prototype.getAnnotations = function () {
var surface = this.toolbar.getSurfaceView(),
model = surface.getModel();
return model.getDocument().getAnnotationsFromRange( model.getSelection(), true );
};
ve.ui.ClearButtonTool.prototype.onClick = function () {
var i,
surfaceView = this.toolbar.getSurfaceView(),
model = surfaceView.getModel(),
annotations = this.getAnnotations(),
arr = annotations.get();
for ( i = 0; i < arr.length; i++ ) {
model.annotate( 'clear', arr[i] );
}
surfaceView.showSelection( model.getSelection() );
surfaceView.contextView.closeInspector();
};
ve.ui.ClearButtonTool.prototype.updateState = function ( annotations ) {
var allAnnotations = this.getAnnotations();
if ( allAnnotations.isEmpty() ) {
this.$.addClass( 've-ui-toolbarButtonTool-disabled' );
} else {
this.$.removeClass( 've-ui-toolbarButtonTool-disabled' );
}
};
/* Registration */
ve.ui.Tool.tools.clear = {
'constructor': ve.ui.ClearButtonTool,
'name': 'clear',
'title': ve.msg( 'visualeditor-clearbutton-tooltip' )
};
/* Inheritance */
ve.extendClass( ve.ui.ClearButtonTool, ve.ui.ButtonTool );