DLynch has uploaded a new change for review.
https://gerrit.wikimedia.org/r/253055
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.
As an example usage, back up the LinkContextItem with it.
(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
M i18n/en.json
M i18n/qqq.json
A src/ui/contextitems/ve.ui.AnnotationContextItem.js
M src/ui/contextitems/ve.ui.LinkContextItem.js
M tests/index.html
8 files changed, 76 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/55/253055/1
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/i18n/en.json b/i18n/en.json
index e6cafcd..62cf1f7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -43,6 +43,7 @@
"visualeditor-content-select-all": "Select all",
"visualeditor-contextitemwidget-label-secondary": "Edit",
"visualeditor-contextitemwidget-label-remove": "Delete",
+ "visualeditor-contextitemwidget-label-clear": "Clear",
"visualeditor-dialog-action-apply": "Apply changes",
"visualeditor-dialog-action-cancel": "Cancel",
"visualeditor-dialog-action-done": "Done",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 939cc59..9da7490 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -51,6 +51,7 @@
"visualeditor-content-select-all": "Label for select all
command.\n{{Identical|Select all}}",
"visualeditor-contextitemwidget-label-secondary": "Label for the edit
action on a context item.\n{{Identical|Edit}}",
"visualeditor-contextitemwidget-label-remove": "Label for the remove
action on a context item.\n{{Identical|Delete}}",
+ "visualeditor-contextitemwidget-label-clear": "Label for the clear
action on a context item.\n{{Identical|Clear}}",
"visualeditor-dialog-action-apply": "Label text for button to apply
changes made in dialog.\n\nSee also:\n*
{{msg-mw|Visualeditor-dialog-action-cancel}}\n*
{{msg-mw|Visualeditor-dialog-action-done}}\n*
{{msg-mw|Visualeditor-dialog-action-goback}}\n*
{{msg-mw|Visualeditor-dialog-action-insert}}\n{{Identical|Apply change}}",
"visualeditor-dialog-action-cancel": "Label text for button to exit
from dialog without making changes.\n\nSee also:\n*
{{msg-mw|Visualeditor-dialog-action-apply}}\n*
{{msg-mw|Visualeditor-dialog-action-done}}\n*
{{msg-mw|Visualeditor-dialog-action-goback}}\n*
{{msg-mw|Visualeditor-dialog-action-insert}}\n{{Identical|Cancel}}",
"visualeditor-dialog-action-done": "Label text for button to finish
using a dialog.\n\nSee also:\n* {{msg-mw|Visualeditor-dialog-action-apply}}\n*
{{msg-mw|Visualeditor-dialog-action-cancel}}\n*
{{msg-mw|Visualeditor-dialog-action-goback}}\n*
{{msg-mw|Visualeditor-dialog-action-insert}}\n{{Identical|Done}}",
diff --git a/src/ui/contextitems/ve.ui.AnnotationContextItem.js
b/src/ui/contextitems/ve.ui.AnnotationContextItem.js
new file mode 100644
index 0000000..3915056
--- /dev/null
+++ b/src/ui/contextitems/ve.ui.AnnotationContextItem.js
@@ -0,0 +1,67 @@
+/*!
+ * 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( {
+ label: ve.msg(
'visualeditor-contextitemwidget-label-clear' ),
+ flags: [ 'destructive' ]
+ } );
+ } else {
+ this.clearButton = new OO.ui.ButtonWidget( {
+ framed: false,
+ icon: 'remove',
+ flags: [ 'destructive' ]
+ } );
+ }
+ if ( this.isClearable() ) {
+ this.actionButtons.addItems( [ this.clearButton ] );
+ }
+ this.clearButton.connect( this, { click: 'onClearButtonClick' } );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.AnnotationContextItem, ve.ui.LinearContextItem );
+
+/* Static Properties */
+
+ve.ui.AnnotationContextItem.static.clearable = false;
+
+/* Methods */
+
+ve.ui.AnnotationContextItem.prototype.isClearable = function () {
+ return this.constructor.static.clearable;
+};
+
+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.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/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: newchange
Gerrit-Change-Id: I3b1b553d2e148e2a50df897b8bc5b29412bdbca7
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits