Tchanders has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/332084 )

Change subject: Update actions on live inspectors and preview dialogs
......................................................................

Update actions on live inspectors and preview dialogs

Make inspectors inheriting from MWLiveExtensionInspector
and dialogs inheriting from MWExtensionPreviewDialog
update their 'done' action every time updatePreview is
called. Since both mix in ExtensionWindow, two new methods,
updateActions and isModified are added there.

This should make it more difficult to insert an empty node
accidentally or create a transaction just by opening and
closing an inspector or dialog.

For more complicated dialogs, or inspectors or dialogs
that don't live-update, this behaviour will have to be
implemented separately.

Bug: T155330
Change-Id: Iacafa01fcd419faaec9b112c96be86693a57d561
---
M modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js
M modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
M modules/ve-mw/ui/ve.ui.MWExtensionWindow.js
3 files changed, 32 insertions(+), 0 deletions(-)


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

diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js 
b/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js
index d956d1e..01825c6 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js
+++ b/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js
@@ -80,6 +80,7 @@
                doc = this.previewNode.getDocument();
 
        this.updateMwData( mwData );
+       this.updateActions();
 
        doc.commit(
                ve.dm.TransactionBuilder.static.newFromAttributeChanges(
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js 
b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
index ce9b000..25b934f 100644
--- a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
@@ -120,6 +120,7 @@
        var mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) );
 
        this.updateMwData( mwData );
+       this.updateActions();
 
        this.hideGeneratedContentsError();
 
diff --git a/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js 
b/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js
index 203007c..c2ea83f 100644
--- a/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js
+++ b/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js
@@ -17,6 +17,7 @@
 ve.ui.MWExtensionWindow = function VeUiMWExtensionWindow() {
        this.whitespace = null;
        this.input = null;
+       this.originalMwData = null;
 };
 
 /* Inheritance */
@@ -80,6 +81,7 @@
 
                if ( this.selectedNode ) {
                        this.input.setValueAndWhitespace( 
this.selectedNode.getAttribute( 'mw' ).body.extsrc );
+                       this.originalMwData = this.selectedNode.getAttribute( 
'mw' );
                } else {
                        if ( !this.constructor.static.modelClasses[ 0 
].static.isContent ) {
                                // New nodes should use linebreaks for blocks
@@ -92,6 +94,9 @@
 
                dir = this.constructor.static.dir || data.dir;
                this.input.setDir( dir );
+
+               this.actions.setAbilities( { done: false } );
+               this.input.connect( this, { change: 'updateActions' } );
        }, this );
 };
 
@@ -127,6 +132,31 @@
 };
 
 /**
+ * Update the 'done' action according to whether there are changes
+ */
+ve.ui.MWExtensionWindow.prototype.updateActions = function () {
+       this.actions.setAbilities( { done: this.isModified() } );
+};
+
+/**
+ * Check if mwData would be modified if window contents were applied
+ *
+ * @return {boolean} mwData would be modified
+ */
+ve.ui.MWExtensionWindow.prototype.isModified = function () {
+       var mwDataCopy, modified;
+
+       if ( this.originalMwData ) {
+               mwDataCopy = ve.copy( this.originalMwData );
+               this.updateMwData( mwDataCopy );
+               modified = !ve.compare( this.originalMwData, mwDataCopy );
+       } else {
+               modified = true;
+       }
+       return modified;
+};
+
+/**
  * Create an new data element for the model class associated with this 
inspector
  *
  * @return {Object} Element data

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iacafa01fcd419faaec9b112c96be86693a57d561
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Tchanders <thalia.e.c...@googlemail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to