8
0

selectallui.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module select-all/selectallui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import selectAllIcon from '../theme/icons/select-all.svg';
  11. /**
  12. * The select all UI feature.
  13. *
  14. * It registers the `'selectAll'` UI button in the editor's
  15. * {@link module:ui/componentfactory~ComponentFactory component factory}. When clicked, the button
  16. * executes the {@link module:select-all/selectallcommand~SelectAllCommand select all command}.
  17. *
  18. * @extends module:core/plugin~Plugin
  19. */
  20. export default class SelectAllUI extends Plugin {
  21. /**
  22. * @inheritDoc
  23. */
  24. static get pluginName() {
  25. return 'SelectAllUI';
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. init() {
  31. const editor = this.editor;
  32. editor.ui.componentFactory.add( 'selectAll', locale => {
  33. const command = editor.commands.get( 'selectAll' );
  34. const view = new ButtonView( locale );
  35. const t = locale.t;
  36. view.set( {
  37. label: t( 'Select all' ),
  38. icon: selectAllIcon,
  39. keystroke: 'Ctrl+A',
  40. tooltip: true
  41. } );
  42. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  43. // Execute the command.
  44. this.listenTo( view, 'execute', () => {
  45. editor.execute( 'selectAll' );
  46. editor.editing.view.focus();
  47. } );
  48. return view;
  49. } );
  50. }
  51. }