From f0aa610290e0f53b59166e368c4a7ad97b2c8f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Wed, 12 Jul 2017 08:48:36 +0200 Subject: [PATCH] Bound ImageUploadButton#isEnabled to ImageUploadCommand#isEnabled. --- src/imageuploadbutton.js | 3 +++ tests/imageuploadbutton.js | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/imageuploadbutton.js b/src/imageuploadbutton.js index 6365a15..b314327 100644 --- a/src/imageuploadbutton.js +++ b/src/imageuploadbutton.js @@ -36,6 +36,7 @@ export default class ImageUploadButton extends Plugin { // Setup `insertImage` button. editor.ui.componentFactory.add( 'insertImage', locale => { const view = new FileDialogButtonView( locale ); + const command = editor.commands.get( 'imageUpload' ); view.set( { label: t( 'Insert image' ), @@ -45,6 +46,8 @@ export default class ImageUploadButton extends Plugin { allowMultipleFiles: true } ); + view.bind( 'isEnabled' ).to( command ); + view.on( 'done', ( evt, files ) => { for ( const file of files ) { editor.execute( 'imageUpload', { file } ); diff --git a/tests/imageuploadbutton.js b/tests/imageuploadbutton.js index 8998613..36e6c85 100644 --- a/tests/imageuploadbutton.js +++ b/tests/imageuploadbutton.js @@ -37,6 +37,19 @@ describe( 'ImageUploadButton', () => { expect( button ).to.be.instanceOf( FileDialogButtonView ); } ); + it( 'should be disabled while ImageUploadCommand is disabled', () => { + const button = editor.ui.componentFactory.create( 'insertImage' ); + const command = editor.commands.get( 'imageUpload' ); + + command.isEnabled = true; + + expect( button.isEnabled ).to.true; + + command.isEnabled = false; + + expect( button.isEnabled ).to.false; + } ); + it( 'should execute imageUpload command', () => { const executeStub = sinon.stub( editor, 'execute' ); const button = editor.ui.componentFactory.create( 'insertImage' );