mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-15 04:00:34 +08:00
Merge pull request #987 from minrk/copy-save-first
save before copy if notebook is dirty
This commit is contained in:
commit
38464ef4dd
@ -545,9 +545,6 @@ define(function(require){
|
||||
'duplicate-notebook':{
|
||||
help: "Create an open a copy of current notebook",
|
||||
handler : function (env, event) {
|
||||
if (env.notebook.dirty) {
|
||||
env.notebook.save_notebook({async : false});
|
||||
}
|
||||
env.notebook.copy_notebook();
|
||||
}
|
||||
},
|
||||
|
@ -112,9 +112,6 @@ define([
|
||||
), IPython._target);
|
||||
});
|
||||
this.element.find('#copy_notebook').click(function () {
|
||||
if (that.notebook.dirty) {
|
||||
that.notebook.save_notebook({async : false});
|
||||
}
|
||||
that.notebook.copy_notebook();
|
||||
return false;
|
||||
});
|
||||
|
@ -2592,23 +2592,32 @@ define(function (require) {
|
||||
|
||||
/**
|
||||
* Make a copy of the current notebook.
|
||||
* If the notebook has unsaved changes, it is saved first.
|
||||
*/
|
||||
Notebook.prototype.copy_notebook = function () {
|
||||
var that = this;
|
||||
var base_url = this.base_url;
|
||||
var w = window.open('', IPython._target);
|
||||
var parent = utils.url_path_split(this.notebook_path)[0];
|
||||
this.contents.copy(this.notebook_path, parent).then(
|
||||
function (data) {
|
||||
w.location = utils.url_path_join(
|
||||
base_url, 'notebooks', utils.encode_uri_components(data.path)
|
||||
);
|
||||
},
|
||||
function(error) {
|
||||
w.close();
|
||||
that.events.trigger('notebook_copy_failed', error);
|
||||
}
|
||||
);
|
||||
var p;
|
||||
if (this.dirty) {
|
||||
p = this.save_notebook();
|
||||
} else {
|
||||
p = Promise.resolve();
|
||||
}
|
||||
return p.then(function () {
|
||||
return that.contents.copy(that.notebook_path, parent).then(
|
||||
function (data) {
|
||||
w.location = utils.url_path_join(
|
||||
base_url, 'notebooks', utils.encode_uri_components(data.path)
|
||||
);
|
||||
},
|
||||
function(error) {
|
||||
w.close();
|
||||
that.events.trigger('notebook_copy_failed', error);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user