jenkins-bot has submitted this change and it was merged. ( 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, 61 insertions(+), 4 deletions(-) Approvals: Esanders: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js index d956d1e..7da260a 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWExtensionPreviewDialog.js @@ -19,8 +19,7 @@ // Parent constructor ve.ui.MWExtensionPreviewDialog.super.apply( this, arguments ); - // Late bind onChangeHandler to a debounced updatePreview - this.onChangeHandler = ve.debounce( this.updatePreview.bind( this ), 250 ); + this.updatePreviewDebounced = ve.debounce( this.updatePreview.bind( this ), 250 ); }; /* Inheritance */ @@ -73,6 +72,16 @@ }; /** + * @inheritdoc + */ +ve.ui.MWExtensionPreviewDialog.prototype.onChange = function () { + // Parent method + ve.ui.MWExtensionPreviewDialog.super.prototype.onChange.call( this ); + + this.updatePreviewDebounced(); +}; + +/** * Update the node rendering to reflect the current content in the dialog. */ ve.ui.MWExtensionPreviewDialog.prototype.updatePreview = function () { diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js index ce9b000..595dec9 100644 --- a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js +++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js @@ -19,8 +19,7 @@ // Parent constructor ve.ui.MWLiveExtensionInspector.super.apply( this, arguments ); - // Late bind onChangeHandler to a debounced updatePreview - this.onChangeHandler = ve.debounce( this.updatePreview.bind( this ), 250 ); + this.updatePreviewDebounced = ve.debounce( this.updatePreview.bind( this ), 250 ); }; /* Inheritance */ @@ -114,6 +113,16 @@ }; /** + * @inheritdoc + */ +ve.ui.MWLiveExtensionInspector.prototype.onChange = function () { + // Parent method + ve.ui.MWLiveExtensionInspector.super.prototype.onChange.call( this ); + + this.updatePreviewDebounced(); +}; + +/** * Update the node rendering to reflect the current content in the inspector. */ ve.ui.MWLiveExtensionInspector.prototype.updatePreview = function () { diff --git a/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js b/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js index 203007c..0794f5e 100644 --- a/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js +++ b/modules/ve-mw/ui/ve.ui.MWExtensionWindow.js @@ -17,6 +17,9 @@ ve.ui.MWExtensionWindow = function VeUiMWExtensionWindow() { this.whitespace = null; this.input = null; + this.originalMwData = null; + + this.onChangeHandler = ve.debounce( this.onChange.bind( this ), 0 ); }; /* Inheritance */ @@ -80,6 +83,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 +96,9 @@ dir = this.constructor.static.dir || data.dir; this.input.setDir( dir ); + + this.actions.setAbilities( { done: false } ); + this.input.connect( this, { change: 'onChangeHandler' } ); }, this ); }; @@ -127,6 +134,38 @@ }; /** + * Handle change event. + */ +ve.ui.MWExtensionWindow.prototype.onChange = function () { + this.updateActions(); +}; + +/** + * 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: merged Gerrit-Change-Id: Iacafa01fcd419faaec9b112c96be86693a57d561 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Tchanders <thalia.e.c...@googlemail.com> Gerrit-Reviewer: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Tchanders <thalia.e.c...@googlemail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits