Skip to content

Commit b96d758

Browse files
authored
Merge pull request #3264 from takluyver/i3263
Change the path to create notebooks in when navigating directories
2 parents ae7d39a + 51acfb6 commit b96d758

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

notebook/static/tree/js/newnotebook.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ define([
1313
var NewNotebookWidget = function (selector, options) {
1414
this.selector = selector;
1515
this.base_url = options.base_url;
16-
this.notebook_path = options.notebook_path;
1716
this.contents = options.contents;
1817
this.events = options.events;
1918
this.default_kernel = null;
@@ -74,12 +73,13 @@ define([
7473
this.events.trigger('kernelspecs_loaded.KernelSpec', data.kernelspecs);
7574
};
7675

77-
NewNotebookWidget.prototype.new_notebook = function (kernel_name) {
76+
NewNotebookWidget.prototype.new_notebook = function (kernel_name, evt) {
7877
/** create and open a new notebook */
7978
var that = this;
8079
kernel_name = kernel_name || this.default_kernel;
8180
var w = window.open(undefined, IPython._target);
82-
this.contents.new_untitled(that.notebook_path, {type: "notebook"}).then(
81+
var dir_path = $('body').attr('data-notebook-path');
82+
this.contents.new_untitled(dir_path, {type: "notebook"}).then(
8383
function (data) {
8484
var url = utils.url_path_join(
8585
that.base_url, 'notebooks',
@@ -107,6 +107,9 @@ define([
107107
}
108108
});
109109
});
110+
if (evt !== undefined) {
111+
evt.preventDefault();
112+
}
110113
};
111114

112115
return {'NewNotebookWidget': NewNotebookWidget};

notebook/static/tree/js/notebooklist.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ define([
169169
console.warn('Error during New file creation', e);
170170
});
171171
that.load_sessions();
172+
e.preventDefault();
172173
});
173174
$('#new-folder').click(function(e) {
174175
that.contents.new_untitled(that.notebook_path || '', {type: 'directory'})
@@ -189,6 +190,7 @@ define([
189190
console.warn('Error during New directory creation', e);
190191
});
191192
that.load_sessions();
193+
e.preventDefault();
192194
});
193195

194196
// Bind events for action buttons.
@@ -373,8 +375,8 @@ define([
373375
breadcrumb.append(root);
374376
var path_parts = [];
375377
this.notebook_path.split('/').forEach(function(path_part) {
376-
path_parts.push(path_part)
377-
var path = path_parts.join('/')
378+
path_parts.push(path_part);
379+
var path = path_parts.join('/');
378380
var url = utils.url_path_join(
379381
that.base_url,
380382
'/tree',
@@ -399,6 +401,7 @@ define([
399401

400402
NotebookList.prototype.update_location = function (path) {
401403
this.notebook_path = path;
404+
$('body').attr('data-notebook-path', path);
402405
// Update the file tree list without reloading the page
403406
this.load_list();
404407
};

0 commit comments

Comments
 (0)