Skip to content

Commit 31c8163

Browse files
committed
Add github and mybinder buttons to toolbar.
1 parent dbee1d2 commit 31c8163

File tree

4 files changed

+117
-23
lines changed

4 files changed

+117
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@jupyterlab/docregistry": "^0.12.0",
3939
"@jupyterlab/filebrowser": "^0.12.0",
4040
"@jupyterlab/services": "^0.51.0",
41-
"@phosphor/widgets": "^1.3.0"
41+
"@phosphor/widgets": "^1.5.0"
4242
},
4343
"devDependencies": {
4444
"rimraf": "^2.5.2",

src/browser.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
} from '@phosphor/widgets';
77

88
import {
9-
ObservableValue
9+
ToolbarButton
10+
} from '@jupyterlab/apputils';
11+
12+
import {
13+
ObservableValue, URLExt
1014
} from '@jupyterlab/coreutils';
1115

1216
import {
@@ -17,6 +21,9 @@ import {
1721
GitHubDrive
1822
} from './contents';
1923

24+
const MY_BINDER_BASE_URL = 'https://mybinder.org/v2/gh';
25+
const GITHUB_BASE_URL = 'https://github.com';
26+
2027
/**
2128
* Widget for hosting the GitHub filebrowser.
2229
*/
@@ -30,17 +37,39 @@ class GitHubFileBrowser extends Widget {
3037
this._browser = browser;
3138
this._drive = drive;
3239

33-
const userLabel = new Widget();
34-
userLabel.addClass('jp-GitHubUserLabel');
35-
userLabel.node.textContent = 'User:';
36-
this._browser.toolbar.addItem('label', userLabel);
37-
3840
this.userName = new GitHubEditableName(drive.user, '<Edit User>');
3941
this.userName.addClass('jp-GitHubEditableUserName');
4042
this.userName.node.title = 'User';
4143
this._browser.toolbar.addItem('user', this.userName);
4244
this.userName.name.changed.connect(this._onUserChanged, this);
4345

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+
4473
this._drive.rateLimitedState.changed.connect(this._updateErrorPanel, this);
4574
this._drive.validUserState.changed.connect(this._updateErrorPanel, this);
4675
}
@@ -182,8 +211,6 @@ class GitHubErrorPanel extends Widget {
182211
}
183212

184213

185-
186-
187214
/**
188215
* A module-Private namespace.
189216
*/
@@ -202,13 +229,10 @@ namespace Private {
202229
* or has been canceled.
203230
*/
204231
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.
208233
let parent = text.parentElement as HTMLElement;
209234
let initialValue = text.textContent;
210235
edit.value = initialValue;
211-
parent.style.width = String(parent.offsetWidth+3)+'px';
212236
parent.replaceChild(edit, text);
213237
edit.focus();
214238

@@ -222,10 +246,8 @@ namespace Private {
222246

223247
return new Promise<string>((resolve, reject) => {
224248
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
227250
// replace the node.
228-
parent.style.width = '';
229251
parent.replaceChild(text, edit);
230252
text.textContent = edit.value || initialValue;
231253
resolve(edit.value);

style/binder.svg

Lines changed: 68 additions & 0 deletions
Loading

style/index.css

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,12 @@
2020
height: 100%;
2121
}
2222

23-
.jp-GitHubBrowser .jp-GitHubUserLabel {
24-
width: auto;
25-
text-align: left;
26-
font-size: large;
27-
}
28-
2923
.jp-GitHubBrowser .jp-GitHubEditableName {
30-
width: auto;
3124
overflow: hidden;
3225
white-space: nowrap;
3326
text-align: center;
3427
font-size: large;
28+
flex: 8 8;
3529
}
3630

3731
.jp-GitHubBrowser .jp-GitHubEditableNameInput {
@@ -93,3 +87,13 @@
9387
text-align: center;
9488
padding: 12px;
9589
}
90+
91+
.jp-MyBinderButton {
92+
flex: 1 1;
93+
background-image: url(binder.svg);
94+
}
95+
96+
.jp-GitHubBrowser .jp-GitHubIcon {
97+
flex: 1 1;
98+
background-image: url(octocat.png);
99+
}

0 commit comments

Comments
 (0)