Finishing work on "Make a Copy" functionality.

This commit is contained in:
Brian Granger 2012-01-10 14:39:02 -08:00 committed by MinRK
parent 8cd495c38f
commit be8f252e78
6 changed files with 15 additions and 19 deletions

View File

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

View File

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

View File

@ -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

View File

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

View File

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

View File

@ -68,8 +68,8 @@
<li id="new_notebook"><span class="wijmo-wijmenu-text">New</span></li>
<li id="open_notebook"><span class="wijmo-wijmenu-text">Open...</span></li>
<li></li>
<li id="rename_notebook"><span class="wijmo-wijmenu-text">Rename...</span></li>
<li id="copy_notebook"><span class="wijmo-wijmenu-text">Make a Copy...</span></li>
<li id="rename_notebook"><span class="wijmo-wijmenu-text">Rename...</span></li>
<li id="save_notebook">
<div>
<span class="wijmo-wijmenu-text">Save</span>