jenkins-bot has submitted this change and it was merged.

Change subject: Add ve.ui.AnnotationContextItem
......................................................................


Add ve.ui.AnnotationContextItem

Some context items appear on annotations. For them, pressing "delete"
is ambiguous, because it might mean to delete the annotation and it
might mean to delete the annotation-plus-content. So, create a new
ContextItem abstract class which can be inherited from, to enable
a "clear annotations" button in the context popup.

Implement it on Link and Language contextitems.

Remove the 'remove' action fron AnnotationInspector, since it's now
superfluous.

(Also, we currently restrict isDeletable to only be true for aliens.)

Bug: T98272
Change-Id: I3b1b553d2e148e2a50df897b8bc5b29412bdbca7
---
M build/modules.json
M demos/ve/desktop.html
M demos/ve/mobile.html
A src/ui/contextitems/ve.ui.AnnotationContextItem.js
M src/ui/contextitems/ve.ui.LanguageContextItem.js
M src/ui/contextitems/ve.ui.LinkContextItem.js
M src/ui/inspectors/ve.ui.AnnotationInspector.js
M tests/index.html
8 files changed, 91 insertions(+), 21 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/build/modules.json b/build/modules.json
index 7b7b8b2..73e51db 100644
--- a/build/modules.json
+++ b/build/modules.json
@@ -393,6 +393,7 @@
                        "src/ui/ve.ui.ContextItem.js",
                        "src/ui/ve.ui.ContextItemFactory.js",
                        "src/ui/contextitems/ve.ui.LinearContextItem.js",
+                       "src/ui/contextitems/ve.ui.AnnotationContextItem.js",
                        "src/ui/contextitems/ve.ui.TableContextItem.js",
                        "src/ui/contextitems/ve.ui.AlienContextItem.js",
                        "src/ui/contextitems/ve.ui.AlignableContextItem.js",
diff --git a/demos/ve/desktop.html b/demos/ve/desktop.html
index c8426b5..8084f68 100644
--- a/demos/ve/desktop.html
+++ b/demos/ve/desktop.html
@@ -354,6 +354,7 @@
                <script src="../../src/ui/ve.ui.ContextItem.js"></script>
                <script src="../../src/ui/ve.ui.ContextItemFactory.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.LinearContextItem.js"></script>
+               <script 
src="../../src/ui/contextitems/ve.ui.AnnotationContextItem.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.TableContextItem.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.AlienContextItem.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.AlignableContextItem.js"></script>
diff --git a/demos/ve/mobile.html b/demos/ve/mobile.html
index 725926e..b918049 100644
--- a/demos/ve/mobile.html
+++ b/demos/ve/mobile.html
@@ -356,6 +356,7 @@
                <script src="../../src/ui/ve.ui.ContextItem.js"></script>
                <script src="../../src/ui/ve.ui.ContextItemFactory.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.LinearContextItem.js"></script>
+               <script 
src="../../src/ui/contextitems/ve.ui.AnnotationContextItem.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.TableContextItem.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.AlienContextItem.js"></script>
                <script 
src="../../src/ui/contextitems/ve.ui.AlignableContextItem.js"></script>
diff --git a/src/ui/contextitems/ve.ui.AnnotationContextItem.js 
b/src/ui/contextitems/ve.ui.AnnotationContextItem.js
new file mode 100644
index 0000000..3b0d13c
--- /dev/null
+++ b/src/ui/contextitems/ve.ui.AnnotationContextItem.js
@@ -0,0 +1,82 @@
+/*!
+ * VisualEditor AnnotationContextItem class.
+ *
+ * @copyright 2011-2015 VisualEditor Team and others; see 
http://ve.mit-license.org
+ */
+
+/**
+ * Context item for an annotation.
+ *
+ * @class
+ * @abstract
+ * @extends ve.ui.LinearContextItem
+ *
+ * @param {ve.ui.Context} context Context item is in
+ * @param {ve.dm.Model} model Model item is related to
+ * @param {Object} config Configuration options
+ */
+ve.ui.AnnotationContextItem = function VeUiAnnotationontextItem( context, 
model, config ) {
+       // Parent constructor
+       ve.ui.AnnotationContextItem.super.call( this, context, model, config );
+
+       // Initialization
+       this.$element.addClass( 've-ui-annotationContextItem' );
+
+       if ( !this.context.isMobile() ) {
+               this.clearButton = new OO.ui.ButtonWidget( {
+                       title: this.constructor.static.clearMsg,
+                       icon: this.constructor.static.clearIcon,
+                       flags: [ 'destructive' ]
+               } );
+       } else {
+               this.clearButton = new OO.ui.ButtonWidget( {
+                       framed: false,
+                       icon: this.constructor.static.clearIcon,
+                       flags: [ 'destructive' ]
+               } );
+       }
+       if ( this.isClearable() ) {
+               this.actionButtons.addItems( [ this.clearButton ], 0 );
+       }
+       this.clearButton.connect( this, { click: 'onClearButtonClick' } );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.AnnotationContextItem, ve.ui.LinearContextItem );
+
+/* Static Properties */
+
+ve.ui.AnnotationContextItem.static.clearable = true;
+ve.ui.AnnotationContextItem.static.clearIcon = 'cancel';
+ve.ui.AnnotationContextItem.static.clearMsg = OO.ui.deferMsg( 
'visualeditor-clearbutton-tooltip' );
+
+/* Methods */
+
+/**
+ * Check if item is clearable.
+ *
+ * @return {boolean} Item is clearable
+ */
+ve.ui.AnnotationContextItem.prototype.isClearable = function () {
+       return this.constructor.static.clearable;
+};
+
+/**
+ * Handle clear button click events.
+ *
+ * @localdoc Removes any modelClasses annotations from the current fragment
+ *
+ * @protected
+ */
+ve.ui.AnnotationContextItem.prototype.onClearButtonClick = function () {
+       var i, len,
+               modelClasses = this.constructor.static.modelClasses,
+               fragment = this.getFragment(),
+               annotations = fragment.getAnnotations( true ).filter( function 
( annotation ) {
+                       return ve.isInstanceOfAny( annotation, modelClasses );
+               } ).get();
+       for ( i = 0, len = annotations.length; i < len; i++ ) {
+               fragment.expandLinearSelection( 'annotation', annotations[ i ] 
).annotateContent( 'clear', annotations[ i ] );
+       }
+};
diff --git a/src/ui/contextitems/ve.ui.LanguageContextItem.js 
b/src/ui/contextitems/ve.ui.LanguageContextItem.js
index 8822002..d53c879 100644
--- a/src/ui/contextitems/ve.ui.LanguageContextItem.js
+++ b/src/ui/contextitems/ve.ui.LanguageContextItem.js
@@ -24,7 +24,7 @@
 
 /* Inheritance */
 
-OO.inheritClass( ve.ui.LanguageContextItem, ve.ui.LinearContextItem );
+OO.inheritClass( ve.ui.LanguageContextItem, ve.ui.AnnotationContextItem );
 
 /* Static Properties */
 
diff --git a/src/ui/contextitems/ve.ui.LinkContextItem.js 
b/src/ui/contextitems/ve.ui.LinkContextItem.js
index a80dfb2..4562614 100644
--- a/src/ui/contextitems/ve.ui.LinkContextItem.js
+++ b/src/ui/contextitems/ve.ui.LinkContextItem.js
@@ -24,7 +24,7 @@
 
 /* Inheritance */
 
-OO.inheritClass( ve.ui.LinkContextItem, ve.ui.LinearContextItem );
+OO.inheritClass( ve.ui.LinkContextItem, ve.ui.AnnotationContextItem );
 
 /* Static Properties */
 
@@ -40,6 +40,8 @@
 
 ve.ui.LinkContextItem.static.commandName = 'link';
 
+ve.ui.LinkContextItem.static.clearable = true;
+
 /* Methods */
 
 /**
diff --git a/src/ui/inspectors/ve.ui.AnnotationInspector.js 
b/src/ui/inspectors/ve.ui.AnnotationInspector.js
index 5a7ba20..1c10735 100644
--- a/src/ui/inspectors/ve.ui.AnnotationInspector.js
+++ b/src/ui/inspectors/ve.ui.AnnotationInspector.js
@@ -44,12 +44,6 @@
 // from the inspector performs.
 ve.ui.AnnotationInspector.static.actions = [
        {
-               action: 'remove',
-               label: OO.ui.deferMsg( 'visualeditor-inspector-remove-tooltip' 
),
-               flags: 'destructive',
-               modes: 'edit'
-       },
-       {
                action: 'done',
                label: OO.ui.deferMsg( 'visualeditor-dialog-action-done' ),
                flags: [ 'progressive', 'primary' ],
@@ -149,18 +143,6 @@
                return this.initialSelection.isCollapsed() ? 'insert' : 'edit';
        }
        return '';
-};
-
-/**
- * @inheritdoc
- */
-ve.ui.AnnotationInspector.prototype.getActionProcess = function ( action ) {
-       if ( action === 'remove' ) {
-               return new OO.ui.Process( function () {
-                       this.close( { action: 'remove' } );
-               }, this );
-       }
-       return ve.ui.AnnotationInspector.super.prototype.getActionProcess.call( 
this, action );
 };
 
 /**
@@ -271,7 +253,7 @@
                                insertText = false,
                                replace = false,
                                annotation = this.getAnnotation(),
-                               remove = data.action === 'remove' || ( 
data.action === 'done' && this.shouldRemoveAnnotation() ),
+                               remove = data.action === 'done' && 
this.shouldRemoveAnnotation(),
                                surfaceModel = this.fragment.getSurface(),
                                fragment = surfaceModel.getFragment( 
this.initialSelection, false ),
                                selection = this.fragment.getSelection();
diff --git a/tests/index.html b/tests/index.html
index 2e50499..beb63c1 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -281,6 +281,7 @@
                <script src="../src/ui/ve.ui.ContextItem.js"></script>
                <script src="../src/ui/ve.ui.ContextItemFactory.js"></script>
                <script 
src="../src/ui/contextitems/ve.ui.LinearContextItem.js"></script>
+               <script 
src="../src/ui/contextitems/ve.ui.AnnotationContextItem.js"></script>
                <script 
src="../src/ui/contextitems/ve.ui.TableContextItem.js"></script>
                <script 
src="../src/ui/contextitems/ve.ui.AlienContextItem.js"></script>
                <script 
src="../src/ui/contextitems/ve.ui.AlignableContextItem.js"></script>

-- 
To view, visit https://gerrit.wikimedia.org/r/253055
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3b1b553d2e148e2a50df897b8bc5b29412bdbca7
Gerrit-PatchSet: 5
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to