Trevor Parscal has uploaded a new change for review.

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


Change subject: Fixes for tool group re-population
......................................................................

Fixes for tool group re-population

When registering a tool after a tool group was built, re-population would end 
up removing all tools in the group - this was because we weren't considering 
tools already assigned to the group to be "available".

Also, when requesting a tool by name which is not available, the system would 
explode, we now check that the tool exists before proceeding with telling the 
factory to create it.

The original patch (I28905b195d5a616363780cccbdfd3aa1cc463f56) didn't really 
solve the problem completely, but did motivate me to sit down and fix this, so 
that's positive.

Thank you to Eranroz.

Change-Id: I937a0cc42ff141db594a804e6577cfb2dcf1a6e5
---
M src/OO.ui.ToolGroup.js
1 file changed, 8 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/85/107485/1

diff --git a/src/OO.ui.ToolGroup.js b/src/OO.ui.ToolGroup.js
index 9b9dc52..2b46a97 100644
--- a/src/OO.ui.ToolGroup.js
+++ b/src/OO.ui.ToolGroup.js
@@ -218,6 +218,7 @@
  */
 OO.ui.ToolGroup.prototype.populate = function () {
        var i, len, name, tool,
+               toolFactory = this.toolbar.getToolFactory(),
                names = {},
                add = [],
                remove = [],
@@ -228,12 +229,16 @@
        // Build a list of needed tools
        for ( i = 0, len = list.length; i < len; i++ ) {
                name = list[i];
-               if ( this.toolbar.isToolAvailable( name ) ) {
+               if (
+                       // Tool exists
+                       toolFactory.lookup( name ) &&
+                       // Tool is available or is already in this group
+                       ( this.toolbar.isToolAvailable( name ) || 
this.tools[name] )
+               ) {
                        tool = this.tools[name];
                        if ( !tool ) {
                                // Auto-initialize tools on first use
-                               this.tools[name] = tool =
-                                       this.toolbar.getToolFactory().create( 
name, this );
+                               this.tools[name] = tool = toolFactory.create( 
name, this );
                                tool.updateLabel();
                        }
                        this.toolbar.reserveTool( tool );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I937a0cc42ff141db594a804e6577cfb2dcf1a6e5
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
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