@@ -14,12 +14,17 @@ global.__VP_RAW_LOADER__ = function(path) {
14
14
return path ;
15
15
}
16
16
17
+ const vpId = 'jupyterlab-visualpython:plugin' ;
18
+
19
+ const { ICommandPalette } = require ( '@jupyterlab/apputils' ) ;
20
+
17
21
global . $ = $ ;
18
22
global . vpBase = path . resolve ( __dirname , "lib" ) + '/' ;
19
23
module . exports = [ {
20
- id : 'visualpython:entry' ,
24
+ id : vpId ,
21
25
autoStart : true ,
22
- activate : function ( app ) {
26
+ requires : [ ICommandPalette ] ,
27
+ activate : function ( app , palette ) {
23
28
console . log (
24
29
'JupyterLab extension visualpython is activated!'
25
30
) ;
@@ -35,5 +40,30 @@ module.exports = [{
35
40
// Add vp to the right area:
36
41
var vpPanel = new VpPanel ( app ) ;
37
42
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
+ } ) ;
38
68
}
39
69
} ] ;
0 commit comments