diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index be9a2e40c..8296a0662 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -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(); } }, diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index ae4a432af..61d8e4524 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -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; }); diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 3847ce1c7..3cd85b1ed 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -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); + } + ); + }); }; /**