@@ -6,7 +6,11 @@ import {
6
6
} from '@phosphor/widgets' ;
7
7
8
8
import {
9
- ObservableValue
9
+ ToolbarButton
10
+ } from '@jupyterlab/apputils' ;
11
+
12
+ import {
13
+ ObservableValue , URLExt
10
14
} from '@jupyterlab/coreutils' ;
11
15
12
16
import {
@@ -17,6 +21,9 @@ import {
17
21
GitHubDrive
18
22
} from './contents' ;
19
23
24
+ const MY_BINDER_BASE_URL = 'https://mybinder.org/v2/gh' ;
25
+ const GITHUB_BASE_URL = 'https://github.com' ;
26
+
20
27
/**
21
28
* Widget for hosting the GitHub filebrowser.
22
29
*/
@@ -30,17 +37,39 @@ class GitHubFileBrowser extends Widget {
30
37
this . _browser = browser ;
31
38
this . _drive = drive ;
32
39
33
- const userLabel = new Widget ( ) ;
34
- userLabel . addClass ( 'jp-GitHubUserLabel' ) ;
35
- userLabel . node . textContent = 'User:' ;
36
- this . _browser . toolbar . addItem ( 'label' , userLabel ) ;
37
-
38
40
this . userName = new GitHubEditableName ( drive . user , '<Edit User>' ) ;
39
41
this . userName . addClass ( 'jp-GitHubEditableUserName' ) ;
40
42
this . userName . node . title = 'User' ;
41
43
this . _browser . toolbar . addItem ( 'user' , this . userName ) ;
42
44
this . userName . name . changed . connect ( this . _onUserChanged , this ) ;
43
45
46
+ const openGitHubButton = new ToolbarButton ( {
47
+ onClick : ( ) => {
48
+ const user = this . _drive . user ;
49
+ const path = this . _browser . model . path ;
50
+ const repo = path . split ( '/' ) [ 0 ] . split ( ':' ) [ 1 ] ;
51
+ const repoPath = URLExt . join ( ...path . split ( '/' ) . slice ( 1 ) ) ;
52
+ const url = URLExt . join ( GITHUB_BASE_URL , user , repo ,
53
+ 'tree' , 'master' , repoPath ) ;
54
+ window . open ( url ) ;
55
+ } ,
56
+ className : 'jp-GitHubIcon' ,
57
+ tooltip : 'Open this repository on GitHub'
58
+ } ) ;
59
+ this . _browser . toolbar . addItem ( 'GitHub' , openGitHubButton ) ;
60
+
61
+ const launchBinderButton = new ToolbarButton ( {
62
+ onClick : ( ) => {
63
+ const user = this . _drive . user ;
64
+ const repo = this . _browser . model . path . split ( '/' ) [ 0 ] . split ( ':' ) [ 1 ] ;
65
+ const url = URLExt . join ( MY_BINDER_BASE_URL , user , repo , 'master' ) ;
66
+ window . open ( url + '?urlpath=lab' ) ;
67
+ } ,
68
+ tooltip : 'Launch this repository on mybinder.org' ,
69
+ className : 'jp-MyBinderButton'
70
+ } ) ;
71
+ this . _browser . toolbar . addItem ( 'binder' , launchBinderButton ) ;
72
+
44
73
this . _drive . rateLimitedState . changed . connect ( this . _updateErrorPanel , this ) ;
45
74
this . _drive . validUserState . changed . connect ( this . _updateErrorPanel , this ) ;
46
75
}
@@ -182,8 +211,6 @@ class GitHubErrorPanel extends Widget {
182
211
}
183
212
184
213
185
-
186
-
187
214
/**
188
215
* A module-Private namespace.
189
216
*/
@@ -202,13 +229,10 @@ namespace Private {
202
229
* or has been canceled.
203
230
*/
204
231
function changeField ( text : HTMLElement , edit : HTMLInputElement ) : Promise < string > {
205
- // Replace the text node with an the input element,
206
- // setting the value and width of the input element to
207
- // the same as the text node.
232
+ // Replace the text node with an the input element.
208
233
let parent = text . parentElement as HTMLElement ;
209
234
let initialValue = text . textContent ;
210
235
edit . value = initialValue ;
211
- parent . style . width = String ( parent . offsetWidth + 3 ) + 'px' ;
212
236
parent . replaceChild ( edit , text ) ;
213
237
edit . focus ( ) ;
214
238
@@ -222,10 +246,8 @@ namespace Private {
222
246
223
247
return new Promise < string > ( ( resolve , reject ) => {
224
248
edit . onblur = ( ) => {
225
- // Restore the correct width and set the
226
- // text content of the original node, then
249
+ // Set the text content of the original node, then
227
250
// replace the node.
228
- parent . style . width = '' ;
229
251
parent . replaceChild ( text , edit ) ;
230
252
text . textContent = edit . value || initialValue ;
231
253
resolve ( edit . value ) ;
0 commit comments