##// END OF EJS Templates
Merge pull request #2291 from ellisonbg/rmplugin...
Merge pull request #2291 from ellisonbg/rmplugin Remove old plugin system

File last commit:

r8172:cdac56e3
r8514:2e9bf5c2 merge
Show More
savewidget.js
139 lines | 4.8 KiB | application/javascript | JavascriptLexer
Brian E. Granger
More review changes....
r4609 //----------------------------------------------------------------------------
// Copyright (C) 2008-2011 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
Brian E. Granger
Minors fixes and initial work on save widget....
r4369
//============================================================================
Brian E. Granger
More review changes....
r4609 // SaveWidget
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 //============================================================================
var IPython = (function (IPython) {
var utils = IPython.utils;
var SaveWidget = function (selector) {
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 this.selector = selector;
if (this.selector !== undefined) {
this.element = $(selector);
this.style();
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 this.bind_events();
}
};
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 SaveWidget.prototype.style = function () {
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#save_widget').addClass('ui-widget');
this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content');
Brian Granger
Improving the save notification....
r5874 this.element.find('span#save_status').addClass('ui-widget ui-widget-content')
.css({border: 'none', 'margin-left': '20px'});
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 };
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 SaveWidget.prototype.bind_events = function () {
var that = this;
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#notebook_name').click(function () {
that.rename_notebook();
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372 });
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#notebook_name').hover(function () {
$(this).addClass("ui-state-hover");
}, function () {
$(this).removeClass("ui-state-hover");
Brian E. Granger
Save button becomes Rename when the notebook name changes.
r4630 });
Brian Granger
Major refactoring of saving, notification....
r6047 $([IPython.events]).on('notebook_loaded.Notebook', function () {
that.set_last_saved();
that.update_notebook_name();
that.update_document_title();
});
$([IPython.events]).on('notebook_saved.Notebook', function () {
that.set_last_saved();
that.update_notebook_name();
that.update_document_title();
});
$([IPython.events]).on('notebook_save_failed.Notebook', function () {
MinRK
increase duration of save messages...
r7527 that.set_save_status('Last Save Failed!');
Brian Granger
Major refactoring of saving, notification....
r6047 });
Felix Werner
Update document title and last_saved_name only after a successful save.
r5006 };
Brian Granger
Improved notebook renaming....
r5859 SaveWidget.prototype.rename_notebook = function () {
var that = this;
var dialog = $('<div/>');
dialog.append(
$('<h3/>').html('Enter a new notebook name:')
.css({'margin-bottom': '10px'})
);
dialog.append(
Brian Granger
More minor theme/styling changes.
r5871 $('<input/>').attr('type','text').attr('size','25')
Brian Granger
Solid first go at jquery-ui based menus.
r5869 .addClass('ui-widget ui-widget-content')
Brian Granger
Major refactoring of saving, notification....
r6047 .attr('value',IPython.notebook.get_notebook_name())
Brian Granger
Improved notebook renaming....
r5859 );
Brian Granger
Remove Rename dialog from the DOM upon closing it.
r5872 // $(document).append(dialog);
Brian Granger
Improved notebook renaming....
r5859 dialog.dialog({
resizable: false,
modal: true,
title: "Rename Notebook",
closeText: "",
Brian Granger
Fixing bug in dialog closing, drafting print css.
r5873 close: function(event, ui) {$(this).dialog('destroy').remove();},
Brian Granger
Improved notebook renaming....
r5859 buttons : {
"OK": function () {
var new_name = $(this).find('input').attr('value');
Brian Granger
Major refactoring of saving, notification....
r6047 if (!IPython.notebook.test_notebook_name(new_name)) {
Brian Granger
Improved notebook renaming....
r5859 $(this).find('h3').html(
Brian Granger
Disallow empty notebook names.
r5955 "Invalid notebook name. Notebook names must "+
"have 1 or more characters and can contain any characters " +
Brian Granger
Make : invalid in filenames in the Notebook JS code.
r7229 "except :/\\. Please enter a new notebook name:"
Brian Granger
Improved notebook renaming....
r5859 );
} else {
Brian Granger
Major refactoring of saving, notification....
r6047 IPython.notebook.set_notebook_name(new_name);
IPython.notebook.save_notebook();
Brian Granger
Improved notebook renaming....
r5859 $(this).dialog('close');
}
},
"Cancel": function () {
$(this).dialog('close');
}
Brian Granger
ENTER submits the rename notebook dialog.
r7246 },
open : function (event, ui) {
var that = $(this);
// Upon ENTER, click the OK button.
Brian Granger
Making the input text area watch for `ENTER` in nb renames.
r7247 that.find('input[type="text"]').keydown(function (event, ui) {
Brian Granger
Using IPython.utils.keycodes in the nb rename dialog.
r7248 if (event.which === utils.keycodes.ENTER) {
Brian Granger
ENTER submits the rename notebook dialog.
r7246 that.parent().find('button').first().click();
}
});
Brian Granger
Improved notebook renaming....
r5859 }
});
}
Brian E. Granger
Adding keyboard shortcuts.
r4645
Brian Granger
Major refactoring of saving, notification....
r6047 SaveWidget.prototype.update_notebook_name = function () {
var nbname = IPython.notebook.get_notebook_name();
Brian Granger
Improved notebook renaming....
r5859 this.element.find('span#notebook_name').html(nbname);
Stefan van der Walt
Clean up javascript based on js2-mode feedback.
r5479 };
Brian E. Granger
Work on save widget, kernel status widget and notebook section.
r4372
Brian E. Granger
Minors fixes and initial work on save widget....
r4369
Brian Granger
Major refactoring of saving, notification....
r6047 SaveWidget.prototype.update_document_title = function () {
var nbname = IPython.notebook.get_notebook_name();
Brian E. Granger
Misc changes to the notebook....
r5104 document.title = nbname;
Brian E. Granger
Browser window title follows the name of the notebook.
r4549 };
Brian E. Granger
Massive work on the notebook document format....
r4484
Brian Granger
Major refactoring of saving, notification....
r6047 SaveWidget.prototype.set_save_status = function (msg) {
this.element.find('span#save_status').html(msg);
}
Brian E. Granger
Massive work on the notebook document format....
r4484
Brian Granger
Improving the save notification....
r5874 SaveWidget.prototype.set_last_saved = function () {
var d = new Date();
Brian Granger
Major refactoring of saving, notification....
r6047 this.set_save_status('Last saved: '+d.format('mmm dd h:MM TT'));
Brian E. Granger
Save button becomes Rename when the notebook name changes.
r4630 };
Brian E. Granger
Minors fixes and initial work on save widget....
r4369 IPython.SaveWidget = SaveWidget;
return IPython;
}(IPython));