From fdc3cb27103e08bab94a70dc6f083d4233e3dc6c Mon Sep 17 00:00:00 2001 From: Krenair Date: Sat, 31 May 2014 20:09:07 +0100 Subject: [PATCH] MWReferenceDialog: Allow swapping of existing references for others By disabling the selection button instead of hiding it. Also make sure that there are other references before re-enabling it. Bug: 65689 Change-Id: Ifb3d6ab6eacb71909eb13e3a72e971b49e2595c1 --- .../ui/dialogs/ve.ui.MWReferenceDialog.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js index b610532dad..b09a5cd1d2 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js @@ -143,7 +143,7 @@ ve.ui.MWReferenceDialog.prototype.onDocumentTransact = function () { applyDisabled = data.countNoninternalElements() <= 2; this.applyButton.setDisabled( applyDisabled ); - this.selectButton.setDisabled( !applyDisabled ); + this.selectButton.setDisabled( !applyDisabled || this.search.isIndexEmpty() ); }; /** @@ -153,6 +153,10 @@ ve.ui.MWReferenceDialog.prototype.onDocumentTransact = function () { */ ve.ui.MWReferenceDialog.prototype.onSearchSelect = function ( ref ) { if ( ref instanceof ve.dm.MWReferenceModel ) { + if ( this.selectedNode instanceof ve.dm.MWReferenceNode ) { + this.getFragment().removeContent(); + this.selectedNode = null; + } this.useReference( ref ); // HACK - This proves that the interface for ActionDialog is screwed up this.onApplyButtonClick(); @@ -235,6 +239,7 @@ ve.ui.MWReferenceDialog.prototype.applyChanges = function () { } this.referenceModel.insertReferenceNode( surfaceFragment ); } + // Update internal item this.referenceModel.updateInternalItem( surfaceModel ); @@ -327,20 +332,25 @@ ve.ui.MWReferenceDialog.prototype.getSetupProcess = function ( data ) { this.useReference( ve.dm.MWReferenceModel.static.newFromReferenceNode( this.selectedNode ) ); - this.selectButton.$element.hide(); } else { this.useReference( null ); - this.selectButton.$element.show(); this.applyButton.setDisabled( true ); } + this.selectButton.$element.show(); this.applyButton.$element.show(); this.backButton.$element.hide(); this.search.buildIndex( this.getFragment().getDocument().getInternalList() ); - this.selectButton.setDisabled( this.search.isIndexEmpty() ); if ( data.useExisting ) { this.useExistingReference(); } + + // If we're using an existing reference, start off disabled + // If not, set disabled based on whether or not there are any existing ones. + this.selectButton.setDisabled( + this.selectedNode instanceof ve.dm.MWReferenceNode || + this.search.isIndexEmpty() + ); }, this ); };