diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 62bc795c0..07b58b93c 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -604,6 +604,25 @@ class NotebookHandler(AuthenticatedHandler): self.set_status(204) self.finish() + +class NotebookCopyHandler(AuthenticatedHandler): + + @web.authenticated + def get(self, notebook_id): + nbm = self.application.notebook_manager + project = nbm.notebook_dir + notebook_id = nbm.copy_notebook(notebook_id) + self.render( + 'notebook.html', project=project, + notebook_id=notebook_id, + base_project_url=u'/', base_kernel_url=u'/', + kill_kernel=False, + read_only=False, + logged_in=self.logged_in, + login_available=self.login_available, + mathjax_url=self.application.ipython_app.mathjax_url, + ) + #----------------------------------------------------------------------------- # RST web service handlers #----------------------------------------------------------------------------- diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index b0360e5b7..34e730b53 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -48,8 +48,8 @@ from .kernelmanager import MappingKernelManager from .handlers import (LoginHandler, LogoutHandler, ProjectDashboardHandler, NewHandler, NamedNotebookHandler, MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler, - ShellHandler, NotebookRootHandler, NotebookHandler, RSTHandler, - AuthenticatedFileHandler, + ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler, + RSTHandler, AuthenticatedFileHandler ) from .notebookmanager import NotebookManager @@ -97,6 +97,7 @@ class NotebookWebApplication(web.Application): (r"/logout", LogoutHandler), (r"/new", NewHandler), (r"/%s" % _notebook_id_regex, NamedNotebookHandler), + (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler), (r"/kernels", MainKernelHandler), (r"/kernels/%s" % _kernel_id_regex, KernelHandler), (r"/kernels/%s/%s" % (_kernel_id_regex, _kernel_action_regex), KernelActionHandler), diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py index 02295c4aa..838b777d1 100644 --- a/IPython/frontend/html/notebook/notebookmanager.py +++ b/IPython/frontend/html/notebook/notebookmanager.py @@ -253,3 +253,11 @@ class NotebookManager(LoggingConfigurable): current.write(nb, f, u'json') return notebook_id + def copy_notebook(self, notebook_id): + """Create a new notebook and returns its notebook_id.""" + last_mod, nb = self.get_notebook_object(notebook_id) + name = nb.metadata.name + '-Copy' + nb.metadata.name = name + notebook_id = self.new_notebook_id(name) + self.save_notebook_object(notebook_id, nb) + return notebook_id diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index 454b642e2..f4ea58076 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -55,6 +55,11 @@ var IPython = (function (IPython) { this.element.find('#rename_notebook').click(function () { IPython.save_widget.rename_notebook(); }); + this.element.find('#copy_notebook').click(function () { + var notebook_id = IPython.save_widget.get_notebook_id(); + var url = $('body').data('baseProjectUrl') + notebook_id + '/copy'; + window.open(url,'_newtab'); + }); this.element.find('#save_notebook').click(function () { IPython.save_widget.save_notebook(); }); diff --git a/IPython/frontend/html/notebook/static/js/savewidget.js b/IPython/frontend/html/notebook/static/js/savewidget.js index 724578127..468226ff6 100644 --- a/IPython/frontend/html/notebook/static/js/savewidget.js +++ b/IPython/frontend/html/notebook/static/js/savewidget.js @@ -88,7 +88,6 @@ var IPython = (function (IPython) { }); } - SaveWidget.prototype.notebook_saved = function () { this.set_document_title(); this.last_saved_name = this.get_notebook_name(); diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index e0f4877e0..1347c1703 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -69,6 +69,7 @@