Merge pull request #987 from minrk/copy-save-first

save before copy if notebook is dirty
This commit is contained in:
Min RK 2016-02-06 19:32:02 +01:00
commit 38464ef4dd
3 changed files with 20 additions and 17 deletions

View File

@ -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();
}
},

View File

@ -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;
});

View File

@ -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);
}
);
});
};
/**