@@ -2,15 +2,19 @@ import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'
22import { INotebookTracker } from '@jupyterlab/notebook' ;
33import { SidebarIcon } from '../ui-components/SidebarIcon' ;
44import { EverywhereIcons } from '../icons' ;
5- import { ToolbarButton } from '@jupyterlab/apputils' ;
5+ import { ToolbarButton , IToolbarWidgetRegistry } from '@jupyterlab/apputils' ;
66import { DownloadDropdownButton } from '../ui-components/DownloadDropdownButton' ;
77import { Commands } from '../commands' ;
88
99export const notebookPlugin : JupyterFrontEndPlugin < void > = {
1010 id : 'jupytereverywhere:notebook' ,
1111 autoStart : true ,
12- requires : [ INotebookTracker ] ,
13- activate : ( app : JupyterFrontEnd , tracker : INotebookTracker ) => {
12+ requires : [ INotebookTracker , IToolbarWidgetRegistry ] ,
13+ activate : (
14+ app : JupyterFrontEnd ,
15+ tracker : INotebookTracker ,
16+ toolbarRegistry : IToolbarWidgetRegistry
17+ ) => {
1418 const { commands, shell } = app ;
1519 const contents = app . serviceManager . contents ;
1620
@@ -82,51 +86,24 @@ export const notebookPlugin: JupyterFrontEndPlugin<void> = {
8286 app . shell . activateById ( sidebarItem . id ) ;
8387 app . restored . then ( ( ) => app . shell . activateById ( sidebarItem . id ) ) ;
8488
85- /**
86- * Create a "Share" button
87- */
88- const shareButton = new ToolbarButton ( {
89- label : 'Share' ,
90- icon : EverywhereIcons . link ,
91- tooltip : 'Share this notebook' ,
92- onClick : ( ) => {
93- void commands . execute ( Commands . shareNotebookCommand ) ;
94- }
95- } ) ;
96-
97- /**
98- * Create the Download dropdown
99- */
100- const downloadDropdownButton = new DownloadDropdownButton ( commands ) ;
89+ toolbarRegistry . addFactory (
90+ 'Notebook' ,
91+ 'downloadDropdown' ,
92+ ( ) => new DownloadDropdownButton ( commands )
93+ ) ;
10194
102- tracker . widgetAdded . connect ( ( _ , notebookPanel ) => {
103- if ( notebookPanel ) {
104- // Look for the right position to insert the buttons (after the run buttons)
105- let insertIndex = 5 ;
106- const toolbar = notebookPanel . toolbar ;
107-
108- Array . from ( toolbar . names ( ) ) . forEach ( ( name , index ) => {
109- if ( name === 'run-all' ) {
110- insertIndex = index + 1 ;
95+ toolbarRegistry . addFactory (
96+ 'Notebook' ,
97+ 'share' ,
98+ ( ) =>
99+ new ToolbarButton ( {
100+ label : 'Share' ,
101+ icon : EverywhereIcons . link ,
102+ tooltip : 'Share this notebook' ,
103+ onClick : ( ) => {
104+ void commands . execute ( Commands . shareNotebookCommand ) ;
111105 }
112- } ) ;
113-
114- // Add download dropdown button
115- try {
116- toolbar . insertItem ( insertIndex , 'downloadDropdownButton' , downloadDropdownButton ) ;
117- insertIndex ++ ;
118- } catch ( error ) {
119- toolbar . addItem ( 'downloadDropdownButton' , downloadDropdownButton ) ;
120- }
121-
122- // Add the share button
123- try {
124- toolbar . insertItem ( insertIndex , 'shareButton' , shareButton ) ;
125- } catch ( error ) {
126- // Fallback: add at the end
127- toolbar . addItem ( 'shareButton' , shareButton ) ;
128- }
129- }
130- } ) ;
106+ } )
107+ ) ;
131108 }
132109} ;
0 commit comments