浏览代码

Updated Toolbar bindings to the latest architecture.

Aleksander Nowodzinski 9 年之前
父节点
当前提交
7b9d53f0a9
共有 2 个文件被更改,包括 7 次插入50 次删除
  1. 5 13
      packages/ckeditor5-ui/src/bindings/toolbar.js
  2. 2 37
      packages/ckeditor5-ui/tests/bindings/toolbar.js

+ 5 - 13
packages/ckeditor5-ui/src/bindings/toolbar.js

@@ -5,15 +5,17 @@
 
 'use strict';
 
+import ToolbarBindingsMixin from './toolbarbindingsmixin.js';
 import BaseToolbar from '../toolbar/toolbar.js';
 
 /**
  * The editor toolbar controller class.
  *
+ * See {@link ui.toolbar.Toolbar}.
+ *
  * @memberOf ui.bindings
  * @extends ui.toolbar.Toolbar
  */
-
 export default class Toolbar extends BaseToolbar {
 	/**
 	 * Creates a new toolbar instance.
@@ -27,16 +29,6 @@ export default class Toolbar extends BaseToolbar {
 
 		this.editor = editor;
 	}
-
-	/**
-	 * Adds buttons to the toolbar. Buttons are taken from the {@link ui.editorUI.EditorUI#featureComponents}
-	 * factory.
-	 *
-	 * @param {String[]} buttons The name of the buttons to add to the toolbar.
-	 */
-	addButtons( buttons ) {
-		for ( let button of buttons ) {
-			this.add( 'buttons', this.editor.ui.featureComponents.create( button ) );
-		}
-	}
 }
+
+Object.assign( Toolbar.prototype, ToolbarBindingsMixin );

+ 2 - 37
packages/ckeditor5-ui/tests/bindings/toolbar.js

@@ -10,19 +10,17 @@
 import Editor from '/ckeditor5/editor/editor.js';
 import Model from '/ckeditor5/ui/model.js';
 import View from '/ckeditor5/ui/view.js';
-import Controller from '/ckeditor5/ui/controller.js';
 import Toolbar from '/ckeditor5/ui/bindings/toolbar.js';
 
 describe( 'Toolbar', () => {
-	let toolbar, view, model, editor;
+	let toolbar, model, editor;
 
 	beforeEach( () => {
 		editor = new Editor();
 		model = new Model( {
 			isActive: false
 		} );
-		view = new View( model );
-		toolbar = new Toolbar( model, view, editor );
+		toolbar = new Toolbar( model, new View(), editor );
 	} );
 
 	describe( 'constructor', () => {
@@ -30,37 +28,4 @@ describe( 'Toolbar', () => {
 			expect( toolbar ).to.have.property( 'editor', editor );
 		} );
 	} );
-
-	describe( 'addButtons', () => {
-		it( 'creates buttons for each button name', () => {
-			const createSpy = sinon.spy( () => new Controller() );
-
-			editor.ui = {
-				featureComponents: {
-					create: createSpy
-				}
-			};
-
-			toolbar.addButtons( [ 'foo', 'bar' ] );
-
-			expect( createSpy.callCount ).to.equal( 2 );
-			expect( createSpy.firstCall.calledWith( 'foo' ) ).to.be.true;
-			expect( createSpy.secondCall.calledWith( 'bar' ) ).to.be.true;
-		} );
-
-		it( 'adds created components to the collection of buttons', () => {
-			const component = new Controller();
-			const createSpy = sinon.spy( () => component );
-
-			editor.ui = {
-				featureComponents: {
-					create: createSpy
-				}
-			};
-
-			toolbar.addButtons( [ 'foo' ] );
-
-			expect( toolbar.collections.get( 'buttons' ).get( 0 ) ).to.equal( component );
-		} );
-	} );
 } );