Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/230761
Change subject: Alien context items ...................................................................... Alien context items Handles nodes which otherwise have no context items so we can render generic actions, such as delete. Change-Id: I229123ba94ecdf6f2b55160c0f6c8761dd4d1948 --- M build/modules.json M demos/ve/desktop.html M demos/ve/mobile.html M i18n/en.json A src/ui/contextitems/ve.ui.AlienContextItem.js M src/ui/contexts/ve.ui.LinearContext.js M tests/index.html 7 files changed, 60 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/61/230761/1 diff --git a/build/modules.json b/build/modules.json index 92c6351..ff294a6 100644 --- a/build/modules.json +++ b/build/modules.json @@ -374,6 +374,7 @@ "src/ui/ve.ui.ModeledFactory.js", "src/ui/ve.ui.ContextItem.js", "src/ui/ve.ui.ContextItemFactory.js", + "src/ui/contextitems/ve.ui.AlienContextItem.js", "src/ui/contextitems/ve.ui.AlignableContextItem.js", "src/ui/contextitems/ve.ui.CommentContextItem.js", "src/ui/contextitems/ve.ui.LanguageContextItem.js", diff --git a/demos/ve/desktop.html b/demos/ve/desktop.html index 1ee9319..4974370 100644 --- a/demos/ve/desktop.html +++ b/demos/ve/desktop.html @@ -335,6 +335,7 @@ <script src="../../src/ui/ve.ui.ModeledFactory.js"></script> <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.AlienContextItem.js"></script> <script src="../../src/ui/contextitems/ve.ui.AlignableContextItem.js"></script> <script src="../../src/ui/contextitems/ve.ui.CommentContextItem.js"></script> <script src="../../src/ui/contextitems/ve.ui.LanguageContextItem.js"></script> diff --git a/demos/ve/mobile.html b/demos/ve/mobile.html index 38af42f..de4f1b2 100644 --- a/demos/ve/mobile.html +++ b/demos/ve/mobile.html @@ -337,6 +337,7 @@ <script src="../../src/ui/ve.ui.ModeledFactory.js"></script> <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.AlienContextItem.js"></script> <script src="../../src/ui/contextitems/ve.ui.AlignableContextItem.js"></script> <script src="../../src/ui/contextitems/ve.ui.CommentContextItem.js"></script> <script src="../../src/ui/contextitems/ve.ui.LanguageContextItem.js"></script> diff --git a/i18n/en.json b/i18n/en.json index fe5bede..8108c61 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -22,6 +22,7 @@ "visualeditor-align-widget-left": "Left", "visualeditor-align-widget-right": "Right", "visualeditor-alignablecontextitem-title": "Alignment", + "visualeditor-aliencontextitem-title": "Item", "visualeditor-annotationbutton-bold-tooltip": "Bold", "visualeditor-annotationbutton-code-tooltip": "Computer code", "visualeditor-annotationbutton-italic-tooltip": "Italic", diff --git a/src/ui/contextitems/ve.ui.AlienContextItem.js b/src/ui/contextitems/ve.ui.AlienContextItem.js new file mode 100644 index 0000000..9f063e0 --- /dev/null +++ b/src/ui/contextitems/ve.ui.AlienContextItem.js @@ -0,0 +1,41 @@ +/*! + * VisualEditor AlienContextItem class. + * + * @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org + */ + +/** + * Context item for a Alien. + * + * @class + * @extends ve.ui.ContextItem + * + * @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.AlienContextItem = function VeAlienContextItem( context, model, config ) { + // Parent constructor + ve.ui.AlienContextItem.super.call( this, context, model, config ); + + // Initialization + this.$element.addClass( 've-ui-alienContextItem' ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.AlienContextItem, ve.ui.ContextItem ); + +/* Static Properties */ + +ve.ui.AlienContextItem.static.name = 'alien'; + +ve.ui.AlienContextItem.static.icon = 'puzzle'; + +ve.ui.AlienContextItem.static.label = OO.ui.deferMsg( 'visualeditor-aliencontextitem-title' ); + +ve.ui.AlienContextItem.static.editable = false; + +/* Registration */ + +ve.ui.contextItemFactory.register( ve.ui.AlienContextItem ); diff --git a/src/ui/contexts/ve.ui.LinearContext.js b/src/ui/contexts/ve.ui.LinearContext.js index e0f254e..60f074d 100644 --- a/src/ui/contexts/ve.ui.LinearContext.js +++ b/src/ui/contexts/ve.ui.LinearContext.js @@ -220,7 +220,7 @@ * @inheritdoc */ ve.ui.LinearContext.prototype.getRelatedSources = function () { - var i, len, toolClass, items, tools, models, + var i, len, toolClass, items, tools, models, selectedNode, surfaceModel = this.surface.getModel(), selection = surfaceModel.getSelection(), selectedModels = []; @@ -228,7 +228,7 @@ if ( !this.relatedSources ) { this.relatedSources = []; if ( selection instanceof ve.dm.LinearSelection ) { - selectedModels = this.surface.getModel().getFragment().getSelectedModels(); + selectedModels = surfaceModel.getFragment().getSelectedModels(); } else if ( selection instanceof ve.dm.TableSelection ) { selectedModels = [ surfaceModel.getSelectedNode() ]; } @@ -265,6 +265,18 @@ } ); } } + if ( !this.relatedSources.length ) { + selectedNode = surfaceModel.getSelectedNode(); + // For now we only need alien contexts to show the delete button + if ( selectedNode && this.showDeleteButton() ) { + this.relatedSources.push( { + type: 'item', + embeddable: ve.ui.contextItemFactory.isEmbeddable( 'alien' ), + name: 'alien', + model: selectedNode + } ); + } + } } } diff --git a/tests/index.html b/tests/index.html index f84ec6c..c979d43 100644 --- a/tests/index.html +++ b/tests/index.html @@ -265,6 +265,7 @@ <script src="../src/ui/ve.ui.ModeledFactory.js"></script> <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.AlienContextItem.js"></script> <script src="../src/ui/contextitems/ve.ui.AlignableContextItem.js"></script> <script src="../src/ui/contextitems/ve.ui.CommentContextItem.js"></script> <script src="../src/ui/contextitems/ve.ui.LanguageContextItem.js"></script> -- To view, visit https://gerrit.wikimedia.org/r/230761 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I229123ba94ecdf6f2b55160c0f6c8761dd4d1948 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits