From be8f252e78a4a17c77c410807416ced80fc062c9 Mon Sep 17 00:00:00 2001 From: Brian Granger Date: Tue, 10 Jan 2012 14:39:02 -0800 Subject: [PATCH] Finishing work on "Make a Copy" functionality. --- IPython/frontend/html/notebook/notebookmanager.py | 14 ++++++++++---- .../frontend/html/notebook/static/js/codecell.js | 11 ++--------- .../frontend/html/notebook/static/js/menubar.js | 1 - .../frontend/html/notebook/static/js/notebook.js | 3 --- .../frontend/html/notebook/static/js/savewidget.js | 3 ++- .../frontend/html/notebook/templates/notebook.html | 2 +- 6 files changed, 15 insertions(+), 19 deletions(-) diff --git a/IPython/frontend/html/notebook/notebookmanager.py b/IPython/frontend/html/notebook/notebookmanager.py index 838b777d1..aaa9fbee0 100644 --- a/IPython/frontend/html/notebook/notebookmanager.py +++ b/IPython/frontend/html/notebook/notebookmanager.py @@ -236,16 +236,21 @@ class NotebookManager(LoggingConfigurable): os.unlink(path) self.delete_notebook_id(notebook_id) - def new_notebook(self): - """Create a new notebook and returns its notebook_id.""" + def increment_filename(self, basename): + """Return a non-used filename of the form basename0.""" i = 0 while True: - name = u'Untitled%i' % i + name = u'%s%i' % (basename,i) path = self.get_path_by_name(name) if not os.path.isfile(path): break else: i = i+1 + return path, name + + def new_notebook(self): + """Create a new notebook and return its notebook_id.""" + path, name = self.increment_filename('Untitled') notebook_id = self.new_notebook_id(name) metadata = current.new_metadata(name=name) nb = current.new_notebook(metadata=metadata) @@ -254,9 +259,10 @@ class NotebookManager(LoggingConfigurable): return notebook_id def copy_notebook(self, notebook_id): - """Create a new notebook and returns its notebook_id.""" + """Copy an existing notebook and return its notebook_id.""" last_mod, nb = self.get_notebook_object(notebook_id) name = nb.metadata.name + '-Copy' + path, name = self.increment_filename(name) nb.metadata.name = name notebook_id = self.new_notebook_id(name) self.save_notebook_object(notebook_id, nb) diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js index 971a1c9c7..f97610edf 100644 --- a/IPython/frontend/html/notebook/static/js/codecell.js +++ b/IPython/frontend/html/notebook/static/js/codecell.js @@ -311,9 +311,6 @@ var IPython = (function (IPython) { { if(this.npressed >fallback_on_tooltip_after && this.prevmatch==matched_text) { - console.log('Ok, you really want to complete after pressing tab '+this.npressed+' times !'); - console.log('You should understand that there is no (more) completion for that !'); - console.log("I'll show you the tooltip, will you stop bothering me ?"); this.request_tooltip_after_time(matched_text+'(',0); return; } @@ -483,12 +480,10 @@ var IPython = (function (IPython) { re = new RegExp("^"+"\%?"+matched_text+typed_characters,""); filterd = matches.filter(function(x){return re.test(x)}); complete_with(filterd,matched_text+typed_characters,autopick,event); - } else if( code == key.esc) { + } else if (code == key.esc) { // dismiss the completer and go back to before invoking it insert(matched_text,event); - } else if( press ){ // abort only on .keypress or esc - // abort with what the user have pressed until now - console.log('aborting with keycode : '+code+' is down :'+down); + } else if (press) { // abort only on .keypress or esc } } select.keydown(function (event) { @@ -790,7 +785,6 @@ var IPython = (function (IPython) { CodeCell.prototype.fromJSON = function (data) { - console.log('Import from JSON:', data); if (data.cell_type === 'code') { if (data.input !== undefined) { this.set_code(data.input); @@ -828,7 +822,6 @@ var IPython = (function (IPython) { data.outputs = outputs; data.language = 'python'; data.collapsed = this.collapsed; - // console.log('Export to JSON:',data); return data; }; diff --git a/IPython/frontend/html/notebook/static/js/menubar.js b/IPython/frontend/html/notebook/static/js/menubar.js index f4ea58076..117120d84 100644 --- a/IPython/frontend/html/notebook/static/js/menubar.js +++ b/IPython/frontend/html/notebook/static/js/menubar.js @@ -31,7 +31,6 @@ var IPython = (function (IPython) { // in the DOM. $(".wijmo-wijmenu-text").parent().bind("click", function () { $('ul#menus').wijmenu("hideAllMenus"); - console.log('I am closing you!'); }); // Make sure we hover over menu items correctly. This is needed when // menu shortcuts are used as they have a slightly different structure diff --git a/IPython/frontend/html/notebook/static/js/notebook.js b/IPython/frontend/html/notebook/static/js/notebook.js index 515091bd7..5684f8983 100644 --- a/IPython/frontend/html/notebook/static/js/notebook.js +++ b/IPython/frontend/html/notebook/static/js/notebook.js @@ -587,17 +587,14 @@ var IPython = (function (IPython) { Notebook.prototype.set_timebeforetooltip = function (time) { - console.log("change time before tooltip to : "+time); this.time_before_tooltip = time; }; Notebook.prototype.set_tooltipontab = function (state) { - console.log("change tooltip on tab to : "+state); this.tooltip_on_tab = state; }; Notebook.prototype.set_smartcompleter = function (state) { - console.log("Smart completion (kwargs first) changed to to : "+state); this.smart_completer = state; }; diff --git a/IPython/frontend/html/notebook/static/js/savewidget.js b/IPython/frontend/html/notebook/static/js/savewidget.js index 468226ff6..c130da781 100644 --- a/IPython/frontend/html/notebook/static/js/savewidget.js +++ b/IPython/frontend/html/notebook/static/js/savewidget.js @@ -120,7 +120,8 @@ var IPython = (function (IPython) { SaveWidget.prototype.update_url = function () { var notebook_id = this.get_notebook_id(); if (notebook_id !== '') { - window.history.replaceState({}, '', notebook_id); + var new_url = '/'+notebook_id; + window.history.replaceState({}, '', new_url); }; }; diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 1347c1703..e20ee4a66 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -68,8 +68,8 @@
  • New
  • Open...
  • -
  • Rename...
  • Make a Copy...
  • +
  • Rename...
  • Save