Trevor Parscal has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/70759


Change subject: ve.ui.ViewRegistry annihilation
......................................................................

ve.ui.ViewRegistry annihilation

Objectives:

* Associate models with tools, rather than dialogs and inspectors
* Move tool/model association utilities to ve.ui.ToolFactory
* Obliterate the view registry

Notes:

The only special case for leaving modelClasses definitions in place is for the 
linkInspector. It uses these for selection expansion.

Because tools can now override the static canEditModel method, we can 
dynamically evaluate a model, rather than be restricted to only comparing 
classes. This will be useful for disabling editors for models that are for some 
reason incomplete or otherwise broken and cannot be safely edited.

Change-Id: I7adf254990112d90f1f808593a9111afc7a116b5
---
M VisualEditor.php
M demos/ve/index.php
M modules/ve/test/index.php
M modules/ve/ui/dialogs/ve.ui.MWMediaEditDialog.js
M modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
M modules/ve/ui/dialogs/ve.ui.MWReferenceListDialog.js
M modules/ve/ui/dialogs/ve.ui.MWTransclusionDialog.js
M modules/ve/ui/inspectors/ve.ui.LinkInspector.js
M modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
M modules/ve/ui/tools/buttons/ve.ui.LinkButtonTool.js
M modules/ve/ui/tools/buttons/ve.ui.MWLinkButtonTool.js
M modules/ve/ui/tools/buttons/ve.ui.MWMediaEditButtonTool.js
M modules/ve/ui/tools/buttons/ve.ui.MWReferenceButtonTool.js
M modules/ve/ui/tools/buttons/ve.ui.MWReferenceListButtonTool.js
M modules/ve/ui/tools/buttons/ve.ui.MWTransclusionButtonTool.js
M modules/ve/ui/tools/ve.ui.DialogButtonTool.js
M modules/ve/ui/tools/ve.ui.InspectorButtonTool.js
M modules/ve/ui/ve.ui.Context.js
M modules/ve/ui/ve.ui.Inspector.js
M modules/ve/ui/ve.ui.Tool.js
M modules/ve/ui/ve.ui.ToolFactory.js
D modules/ve/ui/ve.ui.ViewRegistry.js
M modules/ve/ui/ve.ui.js
23 files changed, 172 insertions(+), 172 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/59/70759/1

diff --git a/VisualEditor.php b/VisualEditor.php
index fdad5e5..49eea7b 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -380,7 +380,6 @@
                        've/ui/ve.ui.Frame.js',
                        've/ui/ve.ui.Window.js',
                        've/ui/ve.ui.WindowSet.js',
-                       've/ui/ve.ui.ViewRegistry.js',
                        've/ui/ve.ui.Inspector.js',
                        've/ui/ve.ui.InspectorFactory.js',
                        've/ui/ve.ui.Dialog.js',
diff --git a/demos/ve/index.php b/demos/ve/index.php
index b8a3850..51b00d7 100644
--- a/demos/ve/index.php
+++ b/demos/ve/index.php
@@ -244,7 +244,6 @@
                <script src="../../modules/ve/ui/ve.ui.Frame.js"></script>
                <script src="../../modules/ve/ui/ve.ui.Window.js"></script>
                <script src="../../modules/ve/ui/ve.ui.WindowSet.js"></script>
-               <script 
src="../../modules/ve/ui/ve.ui.ViewRegistry.js"></script>
                <script src="../../modules/ve/ui/ve.ui.Inspector.js"></script>
                <script 
src="../../modules/ve/ui/ve.ui.InspectorFactory.js"></script>
                <script src="../../modules/ve/ui/ve.ui.Dialog.js"></script>
diff --git a/modules/ve/test/index.php b/modules/ve/test/index.php
index 3c159b9..5c0fa58 100644
--- a/modules/ve/test/index.php
+++ b/modules/ve/test/index.php
@@ -197,7 +197,6 @@
                <script src="../../ve/ui/ve.ui.Frame.js"></script>
                <script src="../../ve/ui/ve.ui.Window.js"></script>
                <script src="../../ve/ui/ve.ui.WindowSet.js"></script>
-               <script src="../../ve/ui/ve.ui.ViewRegistry.js"></script>
                <script src="../../ve/ui/ve.ui.Inspector.js"></script>
                <script src="../../ve/ui/ve.ui.InspectorFactory.js"></script>
                <script src="../../ve/ui/ve.ui.Dialog.js"></script>
diff --git a/modules/ve/ui/dialogs/ve.ui.MWMediaEditDialog.js 
b/modules/ve/ui/dialogs/ve.ui.MWMediaEditDialog.js
index 308e0e4..3e76a4e 100644
--- a/modules/ve/ui/dialogs/ve.ui.MWMediaEditDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.MWMediaEditDialog.js
@@ -33,8 +33,6 @@
 
 ve.ui.MWMediaEditDialog.static.icon = 'picture';
 
-ve.ui.MWMediaEditDialog.static.modelClasses = [ ve.dm.MWBlockImageNode ];
-
 ve.ui.MWMediaEditDialog.static.toolbarTools = [
        { 'items': ['undo', 'redo'] },
        { 'items': ['bold', 'italic', 'mwLink', 'clear'] }
@@ -137,5 +135,3 @@
 /* Registration */
 
 ve.ui.dialogFactory.register( 'mwMediaEdit', ve.ui.MWMediaEditDialog );
-
-ve.ui.viewRegistry.register( 'mwMediaEdit', ve.ui.MWMediaEditDialog );
diff --git a/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js 
b/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
index 2296f68..fec2d5a 100644
--- a/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.MWReferenceDialog.js
@@ -33,8 +33,6 @@
 
 ve.ui.MWReferenceDialog.static.icon = 'reference';
 
-ve.ui.MWReferenceDialog.static.modelClasses = [ ve.dm.MWReferenceNode ];
-
 ve.ui.MWReferenceDialog.static.toolbarTools = [
        { 'items': ['undo', 'redo'] },
        { 'items': ['bold', 'italic', 'mwLink', 'clear', 'mwMediaInsert', 
'mwTransclusion'] }
@@ -219,5 +217,3 @@
 /* Registration */
 
 ve.ui.dialogFactory.register( 'mwReference', ve.ui.MWReferenceDialog );
-
-ve.ui.viewRegistry.register( 'mwReference', ve.ui.MWReferenceDialog );
diff --git a/modules/ve/ui/dialogs/ve.ui.MWReferenceListDialog.js 
b/modules/ve/ui/dialogs/ve.ui.MWReferenceListDialog.js
index 7c22c1e..0704897 100644
--- a/modules/ve/ui/dialogs/ve.ui.MWReferenceListDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.MWReferenceListDialog.js
@@ -30,8 +30,6 @@
 
 ve.ui.MWReferenceListDialog.static.icon = 'references';
 
-ve.ui.MWReferenceListDialog.static.modelClasses = [ ve.dm.MWReferenceListNode 
];
-
 /* Methods */
 
 ve.ui.MWReferenceListDialog.prototype.initialize = function () {
@@ -139,5 +137,3 @@
 /* Registration */
 
 ve.ui.dialogFactory.register( 'mwReferenceList', ve.ui.MWReferenceListDialog );
-
-ve.ui.viewRegistry.register( 'mwReferenceList', ve.ui.MWReferenceListDialog );
diff --git a/modules/ve/ui/dialogs/ve.ui.MWTransclusionDialog.js 
b/modules/ve/ui/dialogs/ve.ui.MWTransclusionDialog.js
index 48e35ef..5d2c773 100644
--- a/modules/ve/ui/dialogs/ve.ui.MWTransclusionDialog.js
+++ b/modules/ve/ui/dialogs/ve.ui.MWTransclusionDialog.js
@@ -56,8 +56,6 @@
 
 ve.ui.MWTransclusionDialog.static.icon = 'template';
 
-ve.ui.MWTransclusionDialog.static.modelClasses = [ ve.dm.MWTransclusionNode ];
-
 /* Methods */
 
 ve.ui.MWTransclusionDialog.prototype.initialize = function () {
@@ -609,5 +607,3 @@
 /* Registration */
 
 ve.ui.dialogFactory.register( 'mwTransclusion', ve.ui.MWTransclusionDialog );
-
-ve.ui.viewRegistry.register( 'mwTransclusion', ve.ui.MWTransclusionDialog );
diff --git a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js 
b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
index 2f0551f..0814755 100644
--- a/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.LinkInspector.js
@@ -34,9 +34,15 @@
 
 ve.ui.LinkInspector.static.titleMessage = 'visualeditor-linkinspector-title';
 
-ve.ui.LinkInspector.static.modelClasses = [ ve.dm.LinkAnnotation ];
-
 ve.ui.LinkInspector.static.linkTargetInputWidget = ve.ui.LinkTargetInputWidget;
+
+/**
+ * Annotation models this inspector can edit.
+ *
+ * @static
+ * @property {Function[]}
+ */
+ve.ui.LinkInspector.static.modelClasses = [ ve.dm.LinkAnnotation ];
 
 /* Methods */
 
@@ -214,8 +220,22 @@
         } );
 };
 
+/**
+ * Get matching annotations within a fragment.
+ *
+ * @method
+ * @param {ve.dm.SurfaceFragment} fragment Fragment to get matching 
annotations within
+ * @param {boolean} [all] Get annotations which only cover some of the fragment
+ * @returns {ve.dm.AnnotationSet} Matching annotations
+ */
+ve.ui.LinkInspector.prototype.getMatchingAnnotations = function ( fragment, 
all ) {
+       var modelClasses = this.constructor.static.modelClasses;
+
+       return fragment.getAnnotations( all ).filter( function ( annnotation ) {
+               return ve.isInstanceOfAny( annnotation, modelClasses );
+       } );
+};
+
 /* Registration */
 
 ve.ui.inspectorFactory.register( 'link', ve.ui.LinkInspector );
-
-ve.ui.viewRegistry.register( 'link', ve.ui.LinkInspector );
diff --git a/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js 
b/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
index 6c683e7..6870a2a 100644
--- a/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
+++ b/modules/ve/ui/inspectors/ve.ui.MWLinkInspector.js
@@ -82,5 +82,3 @@
 /* Registration */
 
 ve.ui.inspectorFactory.register( 'mwLink', ve.ui.MWLinkInspector );
-
-ve.ui.viewRegistry.register( 'mwLink', ve.ui.MWLinkInspector );
diff --git a/modules/ve/ui/tools/buttons/ve.ui.LinkButtonTool.js 
b/modules/ve/ui/tools/buttons/ve.ui.LinkButtonTool.js
index 6923c2f..eef67c6 100644
--- a/modules/ve/ui/tools/buttons/ve.ui.LinkButtonTool.js
+++ b/modules/ve/ui/tools/buttons/ve.ui.LinkButtonTool.js
@@ -33,6 +33,8 @@
 
 ve.ui.LinkButtonTool.static.inspector = 'link';
 
+ve.ui.LinkButtonTool.static.modelClasses = [ ve.dm.LinkAnnotation ];
+
 /* Registration */
 
 ve.ui.toolFactory.register( 'link', ve.ui.LinkButtonTool );
diff --git a/modules/ve/ui/tools/buttons/ve.ui.MWLinkButtonTool.js 
b/modules/ve/ui/tools/buttons/ve.ui.MWLinkButtonTool.js
index e1098cb..cebedd2 100644
--- a/modules/ve/ui/tools/buttons/ve.ui.MWLinkButtonTool.js
+++ b/modules/ve/ui/tools/buttons/ve.ui.MWLinkButtonTool.js
@@ -29,6 +29,10 @@
 
 ve.ui.MWLinkButtonTool.static.inspector = 'mwLink';
 
+ve.ui.MWLinkButtonTool.static.modelClasses = [
+       ve.dm.MWExternalLinkAnnotation, ve.dm.MWInternalLinkAnnotation
+];
+
 /* Registration */
 
 ve.ui.toolFactory.register( 'mwLink', ve.ui.MWLinkButtonTool );
diff --git a/modules/ve/ui/tools/buttons/ve.ui.MWMediaEditButtonTool.js 
b/modules/ve/ui/tools/buttons/ve.ui.MWMediaEditButtonTool.js
index 049f1a5..a5e069f 100644
--- a/modules/ve/ui/tools/buttons/ve.ui.MWMediaEditButtonTool.js
+++ b/modules/ve/ui/tools/buttons/ve.ui.MWMediaEditButtonTool.js
@@ -33,6 +33,8 @@
 
 ve.ui.MWMediaEditButtonTool.static.dialog = 'mwMediaEdit';
 
+ve.ui.MWMediaEditButtonTool.static.modelClasses = [ ve.dm.MWBlockImageNode ];
+
 /* Registration */
 
 ve.ui.toolFactory.register( 'mwMediaEdit', ve.ui.MWMediaEditButtonTool );
diff --git a/modules/ve/ui/tools/buttons/ve.ui.MWReferenceButtonTool.js 
b/modules/ve/ui/tools/buttons/ve.ui.MWReferenceButtonTool.js
index 805dc85..42c43b9 100644
--- a/modules/ve/ui/tools/buttons/ve.ui.MWReferenceButtonTool.js
+++ b/modules/ve/ui/tools/buttons/ve.ui.MWReferenceButtonTool.js
@@ -33,6 +33,8 @@
 
 ve.ui.MWReferenceButtonTool.static.dialog = 'mwReference';
 
+ve.ui.MWReferenceButtonTool.static.modelClasses = [ ve.dm.MWReferenceNode ];
+
 /* Registration */
 
 ve.ui.toolFactory.register( 'mwReference', ve.ui.MWReferenceButtonTool );
diff --git a/modules/ve/ui/tools/buttons/ve.ui.MWReferenceListButtonTool.js 
b/modules/ve/ui/tools/buttons/ve.ui.MWReferenceListButtonTool.js
index 4730104..fbc18bd 100644
--- a/modules/ve/ui/tools/buttons/ve.ui.MWReferenceListButtonTool.js
+++ b/modules/ve/ui/tools/buttons/ve.ui.MWReferenceListButtonTool.js
@@ -33,6 +33,8 @@
 
 ve.ui.MWReferenceListButtonTool.static.dialog = 'mwReferenceList';
 
+ve.ui.MWReferenceListButtonTool.static.modelClasses = [ 
ve.dm.MWReferenceListNode ];
+
 /* Registration */
 
 ve.ui.toolFactory.register( 'mwReferenceList', ve.ui.MWReferenceListButtonTool 
);
diff --git a/modules/ve/ui/tools/buttons/ve.ui.MWTransclusionButtonTool.js 
b/modules/ve/ui/tools/buttons/ve.ui.MWTransclusionButtonTool.js
index 3820204..db39213 100644
--- a/modules/ve/ui/tools/buttons/ve.ui.MWTransclusionButtonTool.js
+++ b/modules/ve/ui/tools/buttons/ve.ui.MWTransclusionButtonTool.js
@@ -33,6 +33,8 @@
 
 ve.ui.MWTransclusionButtonTool.static.dialog = 'mwTransclusion';
 
+ve.ui.MWTransclusionButtonTool.static.modelClasses = [ 
ve.dm.MWTransclusionNode ];
+
 /* Registration */
 
 ve.ui.toolFactory.register( 'mwTransclusion', ve.ui.MWTransclusionButtonTool );
diff --git a/modules/ve/ui/tools/ve.ui.DialogButtonTool.js 
b/modules/ve/ui/tools/ve.ui.DialogButtonTool.js
index c9d3030..a546f27 100644
--- a/modules/ve/ui/tools/ve.ui.DialogButtonTool.js
+++ b/modules/ve/ui/tools/ve.ui.DialogButtonTool.js
@@ -37,6 +37,26 @@
  */
 ve.ui.DialogButtonTool.static.dialog = '';
 
+/**
+ * Annotation or node models this tool is related to.
+ *
+ * @static
+ * @property {Function[]}
+ */
+ve.ui.DialogButtonTool.static.modelClasses = [];
+
+/**
+ * Check if this tool can be used on a model.
+ *
+ * @method
+ * @static
+ * @param {ve.dm.Model} model Model to check
+ * @return {boolean} Tool can be used to edit model
+ */
+ve.ui.DialogButtonTool.static.canEditModel = function ( model ) {
+       return ve.isInstanceOfAny( model, this.modelClasses );
+};
+
 /* Methods */
 
 /**
@@ -58,8 +78,6 @@
  */
 ve.ui.DialogButtonTool.prototype.onUpdateState = function ( nodes ) {
        if ( nodes.length ) {
-               this.setActive(
-                       ve.ui.viewRegistry.getViewForNode( nodes[0] ) === 
this.constructor.static.dialog
-               );
+               this.setActive( ve.ui.toolFactory.getToolForNode( nodes[0] ) 
=== this.constructor );
        }
 };
diff --git a/modules/ve/ui/tools/ve.ui.InspectorButtonTool.js 
b/modules/ve/ui/tools/ve.ui.InspectorButtonTool.js
index 9825e80..12d41b2 100644
--- a/modules/ve/ui/tools/ve.ui.InspectorButtonTool.js
+++ b/modules/ve/ui/tools/ve.ui.InspectorButtonTool.js
@@ -36,6 +36,26 @@
  */
 ve.ui.InspectorButtonTool.static.inspector = '';
 
+/**
+ * Annotation or node models this tool is related to.
+ *
+ * @static
+ * @property {Function[]}
+ */
+ve.ui.InspectorButtonTool.static.modelClasses = [];
+
+/**
+ * Check if this tool can be used on a model.
+ *
+ * @method
+ * @static
+ * @param {ve.dm.Model} model Model to check
+ * @return {boolean} Tool can be used to edit model
+ */
+ve.ui.InspectorButtonTool.static.canEditModel = function ( model ) {
+       return ve.isInstanceOfAny( model, this.modelClasses );
+};
+
 /* Methods */
 
 /**
@@ -57,7 +77,6 @@
  */
 ve.ui.InspectorButtonTool.prototype.onUpdateState = function ( nodes, full ) {
        this.setActive(
-               ve.ui.viewRegistry.getViewsForAnnotations( full )
-                       .indexOf( this.constructor.static.inspector ) !== -1
+               ve.ui.toolFactory.getToolsForAnnotations( full ).indexOf( 
this.constructor ) !== -1
        );
 };
diff --git a/modules/ve/ui/ve.ui.Context.js b/modules/ve/ui/ve.ui.Context.js
index 97cca57..1087e0b 100644
--- a/modules/ve/ui/ve.ui.Context.js
+++ b/modules/ve/ui/ve.ui.Context.js
@@ -195,7 +195,7 @@
  * @chainable
  */
 ve.ui.Context.prototype.update = function () {
-       var i, nodes, views, view,
+       var i, nodes, tools, tool,
                fragment = this.surface.getModel().getFragment( null, false ),
                selection = fragment.getRange(),
                inspector = this.inspectors.getCurrent();
@@ -205,7 +205,7 @@
                this.show();
        } else {
                // No inspector is open, or the selection has changed, show a 
menu of available inspectors
-               views = ve.ui.viewRegistry.getViewsForAnnotations( 
fragment.getAnnotations() );
+               tools = ve.ui.toolFactory.getToolsForAnnotations( 
fragment.getAnnotations() );
                nodes = fragment.getCoveredNodes();
                for ( i = 0; i < nodes.length; i++ ) {
                        if ( nodes[i].range && nodes[i].range.isCollapsed() ) {
@@ -214,25 +214,19 @@
                        }
                }
                if ( nodes.length === 1 ) {
-                       view = ve.ui.viewRegistry.getViewForNode( nodes[0].node 
);
-                       if ( view ) {
-                               views.push( view );
+                       tool = ve.ui.toolFactory.getToolForNode( nodes[0].node 
);
+                       if ( tool ) {
+                               tools.push( tool );
                        }
                }
-               for ( i = 0; i < views.length; i++ ) {
-                       if ( !ve.ui.toolFactory.lookup( views[i] ) ) {
-                               views.splice( i, 1 );
-                               i--;
-                       }
-               }
-               if ( views.length ) {
+               if ( tools.length ) {
                        // There's at least one inspectable annotation, build a 
menu and show it
                        this.$menu.empty();
                        if ( this.toolbar ) {
                                this.toolbar.destroy();
                        }
                        this.toolbar = new ve.ui.Toolbar( this.surface );
-                       this.toolbar.addTools( [{ 'name': 'inspectors', 'items' 
: views }] );
+                       this.toolbar.addTools( [{ 'name': 'inspectors', 'items' 
: tools }] );
                        this.$menu.append( this.toolbar.$ );
                        this.show();
                } else if ( this.visible ) {
diff --git a/modules/ve/ui/ve.ui.Inspector.js b/modules/ve/ui/ve.ui.Inspector.js
index f173e3b..dc95636 100644
--- a/modules/ve/ui/ve.ui.Inspector.js
+++ b/modules/ve/ui/ve.ui.Inspector.js
@@ -131,22 +131,6 @@
        this.initialSelection = this.surface.getModel().getSelection();
 };
 
-/**
- * Get matching annotations within a fragment.
- *
- * @method
- * @param {ve.dm.SurfaceFragment} fragment Fragment to get matching 
annotations within
- * @param {boolean} [all] Get annotations which only cover some of the fragment
- * @returns {ve.dm.AnnotationSet} Matching annotations
- */
-ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment, all ) {
-       var constructor = this.constructor;
-
-       return fragment.getAnnotations( all ).filter( function ( annnotation ) {
-               return ve.ui.viewRegistry.isViewRelatedToModel( constructor, 
annnotation );
-       } );
-};
-
 /* Initialization */
 
 ve.ui.Inspector.static.addLocalStylesheets( [ 've.ui.Inspector.css' ] );
diff --git a/modules/ve/ui/ve.ui.Tool.js b/modules/ve/ui/ve.ui.Tool.js
index debd10d..24504f4 100644
--- a/modules/ve/ui/ve.ui.Tool.js
+++ b/modules/ve/ui/ve.ui.Tool.js
@@ -67,6 +67,18 @@
  */
 ve.ui.Tool.static.titleMessage = null;
 
+/**
+ * Check if this tool can be used on a model.
+ *
+ * @method
+ * @static
+ * @param {ve.dm.Model} model Model to check
+ * @return {boolean} Tool can be used to edit model
+ */
+ve.ui.Tool.static.canEditModel = function () {
+       return false;
+};
+
 /* Methods */
 
 /**
diff --git a/modules/ve/ui/ve.ui.ToolFactory.js 
b/modules/ve/ui/ve.ui.ToolFactory.js
index abbfe5e..f945b18 100644
--- a/modules/ve/ui/ve.ui.ToolFactory.js
+++ b/modules/ve/ui/ve.ui.ToolFactory.js
@@ -21,6 +21,79 @@
 
 ve.inheritClass( ve.ui.ToolFactory, ve.Factory );
 
+/* Methods */
+
+/**
+ * Get a list of tools from a set of annotations.
+ *
+ * The most specific tool will be chosen based on inheritance - mostly. The 
order of being added
+ * also matters if the candidate classes aren't all in the same inheritance 
chain, and since object
+ * properties aren't necessarily ordered it's not predictable what the effect 
of ordering will be.
+ *
+ * TODO: Add tracking of order of registration using an array and prioritize 
the most recently
+ * registered candidate.
+ *
+ * @method
+ * @param {ve.dm.AnnotationSet} annotations Annotations to be inspected
+ * @returns {string[]} Symbolic names of tools that can be used to inspect 
annotations
+ */
+ve.ui.ToolFactory.prototype.getToolsForAnnotations = function ( annotations ) {
+       if ( annotations.isEmpty() ) {
+               return [];
+       }
+
+       var i, len, annotation, name, tool, candidateTool, candidateToolName,
+               arr = annotations.get(),
+               matches = [];
+
+       for ( i = 0, len = arr.length; i < len; i++ ) {
+               annotation = arr[i];
+               candidateTool = null;
+               for ( name in this.registry ) {
+                       tool = this.registry[name];
+                       if ( tool.static.canEditModel( annotation ) ) {
+                               if ( !candidateTool || tool.prototype 
instanceof candidateTool ) {
+                                       candidateTool = tool;
+                                       candidateToolName = name;
+                               }
+                       }
+               }
+               if ( candidateTool ) {
+                       matches.push( candidateToolName );
+               }
+       }
+       return matches;
+};
+
+/**
+ * Get a tool for a node.
+ *
+ * The most specific tool will be chosen based on inheritance - mostly. The 
order of being added
+ * also matters if the candidate classes aren't all in the same inheritance 
chain, and since object
+ * properties aren't necessarily ordered it's not predictable what the effect 
of ordering will be.
+ *
+ * TODO: Add tracking of order of registration using an array and prioritize 
the most recently
+ * registered candidate.
+ *
+ * @method
+ * @param {ve.dm.Node} node Node to be edited
+ * @returns {string|undefined} Symbolic name of tool that can be used to edit 
node
+ */
+ve.ui.ToolFactory.prototype.getToolForNode = function ( node ) {
+       var name, tool, candidateTool, candidateToolName;
+
+       for ( name in this.registry ) {
+               tool = this.registry[name];
+               if ( tool.static.canEditModel( node ) ) {
+                       if ( !candidateTool || tool.prototype instanceof 
candidateTool ) {
+                               candidateTool = tool;
+                               candidateToolName = name;
+                       }
+               }
+       }
+       return candidateToolName;
+};
+
 /* Initialization */
 
 ve.ui.toolFactory = new ve.ui.ToolFactory();
diff --git a/modules/ve/ui/ve.ui.ViewRegistry.js 
b/modules/ve/ui/ve.ui.ViewRegistry.js
deleted file mode 100644
index b576490..0000000
--- a/modules/ve/ui/ve.ui.ViewRegistry.js
+++ /dev/null
@@ -1,112 +0,0 @@
-/*!
- * VisualEditor UserInterface ViewRegistry class.
- *
- * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
- * @license The MIT License (MIT); see LICENSE.txt
- */
-
-/**
- * UserInterface view registry.
- *
- * @class
- * @extends ve.Registry
- *
- * @constructor
- */
-ve.ui.ViewRegistry = function VeUiViewRegistry() {
-       // Parent constructor
-       ve.Registry.call( this );
-};
-
-/* Inheritance */
-
-ve.inheritClass( ve.ui.ViewRegistry, ve.Registry );
-
-/* Methods */
-
-ve.ui.ViewRegistry.prototype.isViewRelatedToModel = function ( view, model ) {
-       var classes = view.static.modelClasses || [],
-               i = classes.length;
-
-       while ( classes[--i] ) {
-               if ( model instanceof classes[i] ) {
-                       return true;
-               }
-       }
-       return false;
-};
-
-/**
- * Get a list of views from a set of annotations.
- *
- * The most specific view will be chosen based on inheritance - mostly. The 
order of being added
- * also matters if the candidate classes aren't all in the same inheritance 
chain, and since object
- * properties aren't necessarily ordered it's not predictable what the effect 
of ordering will be.
- *
- * TODO: Add tracking of order of registration using an array and prioritize 
the most recently
- * registered candidate.
- *
- * @method
- * @param {ve.dm.AnnotationSet} annotations Annotations to be inspected
- * @returns {string[]} Symbolic names of views that can be used to inspect 
annotations
- */
-ve.ui.ViewRegistry.prototype.getViewsForAnnotations = function ( annotations ) 
{
-       if ( annotations.isEmpty() ) {
-               return [];
-       }
-
-       var i, len, annotation, name, view, candidateView, candidateViewName,
-               arr = annotations.get(),
-               matches = [];
-
-       for ( i = 0, len = arr.length; i < len; i++ ) {
-               annotation = arr[i];
-               candidateView = null;
-               for ( name in this.registry ) {
-                       view = this.registry[name];
-                       if ( this.isViewRelatedToModel( view, annotation ) ) {
-                               if ( !candidateView || view.prototype 
instanceof candidateView ) {
-                                       candidateView = view;
-                                       candidateViewName = name;
-                               }
-                       }
-               }
-               if ( candidateView ) {
-                       matches.push( candidateViewName );
-               }
-       }
-       return matches;
-};
-
-/**
- * Get a view for a node.
- *
- * The most specific view will be chosen based on inheritance - mostly. The 
order of being added
- * also matters if the candidate classes aren't all in the same inheritance 
chain, and since object
- * properties aren't necessarily ordered it's not predictable what the effect 
of ordering will be.
- *
- * TODO: Add tracking of order of registration using an array and prioritize 
the most recently
- * registered candidate.
- *
- * @method
- * @param {ve.dm.Node} node Node to be edited
- * @returns {string|undefined} Symbolic name of view that can be used to edit 
node
- */
-ve.ui.ViewRegistry.prototype.getViewForNode = function ( node ) {
-       var name, view, candidateView, candidateViewName;
-
-       for ( name in this.registry ) {
-               view = this.registry[name];
-               if ( this.isViewRelatedToModel( view, node ) ) {
-                       if ( !candidateView || view.prototype instanceof 
candidateView ) {
-                               candidateView = view;
-                               candidateViewName = name;
-                       }
-               }
-       }
-       return candidateViewName;
-};
-
-/* Initialization */
-
-ve.ui.viewRegistry = new ve.ui.ViewRegistry();
diff --git a/modules/ve/ui/ve.ui.js b/modules/ve/ui/ve.ui.js
index c9837d4..f9e6435 100644
--- a/modules/ve/ui/ve.ui.js
+++ b/modules/ve/ui/ve.ui.js
@@ -18,5 +18,4 @@
        //'inspectorFactory': Initialized in ve.ui.InspectorFactory.js
        //'toolFactory': Initialized in ve.ui.ToolFactory.js
        //'triggerRegistry' instantiated in ve.ui.TriggerRegistry.js
-       //'viewRegistry' instantiated in ve.ui.ViewRegistry.js
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7adf254990112d90f1f808593a9111afc7a116b5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>

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

Reply via email to