@@ -14,12 +14,17 @@ global.__VP_RAW_LOADER__ = function(path) {
1414 return path ;
1515}
1616
17+ const vpId = 'jupyterlab-visualpython:plugin' ;
18+
19+ const { ICommandPalette } = require ( '@jupyterlab/apputils' ) ;
20+
1721global . $ = $ ;
1822global . vpBase = path . resolve ( __dirname , "lib" ) + '/' ;
1923module . exports = [ {
20- id : 'visualpython:entry' ,
24+ id : vpId ,
2125 autoStart : true ,
22- activate : function ( app ) {
26+ requires : [ ICommandPalette ] ,
27+ activate : function ( app , palette ) {
2328 console . log (
2429 'JupyterLab extension visualpython is activated!'
2530 ) ;
@@ -35,5 +40,30 @@ module.exports = [{
3540 // Add vp to the right area:
3641 var vpPanel = new VpPanel ( app ) ;
3742 app . shell . add ( vpPanel , 'right' , { rank : 900 , type : 'Visual Python' } ) ;
43+
44+ // Add toggle button
45+ let isVpVisible = app . name !== 'JupyterLab' ; // compatible for notebook 7.x (hidden for jupyterlab)
46+ let toggleCommand = 'jupyterlab-visualpython:toggle-panel' ;
47+ let vpLabel = isVpVisible ?'Toggle Visual Python' :'' ;
48+ app . commands . addCommand ( toggleCommand , {
49+ isEnabled : ( ) => isVpVisible ,
50+ isVisible : ( ) => isVpVisible ,
51+ iconClass : 'jp-vp-icon' ,
52+ iconLabel : vpLabel ,
53+ execute : ( ) => {
54+ if ( app . shell . rightCollapsed === true || $ ( '#vp_wrapper' ) . is ( ':visible' ) === false ) {
55+ app . shell . activateById ( 'vp_wrapper' ) ;
56+ } else {
57+ app . shell . collapseRight ( ) ;
58+ }
59+ }
60+ } ) ;
61+
62+ // Add command palette
63+ palette . addItem ( {
64+ command : toggleCommand ,
65+ category : 'Visual Python' ,
66+ label : 'Toggle Visual Python'
67+ } ) ;
3868 }
3969} ] ;
0 commit comments