diff --git a/IPython/html/static/edit/js/editor.js b/IPython/html/static/edit/js/editor.js index 4a0a453..d59c4cb 100644 --- a/IPython/html/static/edit/js/editor.js +++ b/IPython/html/static/edit/js/editor.js @@ -81,6 +81,7 @@ function($, }); that.save_enabled = true; that.generation = cm.changeGeneration(); + that.events.trigger("file_loaded.Editor", model); }, function(error) { cm.setValue("Error! " + error.message + @@ -89,8 +90,26 @@ function($, } ); }; + + Editor.prototype.get_filename = function () { + return utils.url_path_split(this.file_path)[1]; + + } - Editor.prototype.save = function() { + Editor.prototype.rename = function (new_name) { + /** rename the file */ + var that = this; + var parent = utils.url_path_split(this.file_path)[0]; + var new_path = utils.url_path_join(parent, new_name); + return this.contents.rename(this.file_path, new_path).then( + function (json) { + that.file_path = json.path; + that.events.trigger('file_renamed.Editor', json); + } + ); + }; + + Editor.prototype.save = function () { /** save the file */ if (!this.save_enabled) { console.log("Not saving, save disabled"); @@ -105,8 +124,8 @@ function($, var that = this; // record change generation for isClean this.generation = this.codemirror.changeGeneration(); - return this.contents.save(this.file_path, model).then(function() { - that.events.trigger("save_succeeded.TextEditor"); + return this.contents.save(this.file_path, model).then(function(data) { + that.events.trigger("file_saved.Editor", data); }); }; diff --git a/IPython/html/static/edit/js/main.js b/IPython/html/static/edit/js/main.js index 2bcaf6a..7c839a8 100644 --- a/IPython/html/static/edit/js/main.js +++ b/IPython/html/static/edit/js/main.js @@ -10,6 +10,7 @@ require([ 'services/config', 'edit/js/editor', 'edit/js/menubar', + 'edit/js/savewidget', 'edit/js/notificationarea', 'custom/custom', ], function( @@ -21,6 +22,7 @@ require([ configmod, editmod, menubar, + savewidget, notificationarea ){ page = new page.Page(); @@ -48,6 +50,11 @@ require([ events: events, }); + var save_widget = new savewidget.SaveWidget('span#save_widget', { + editor: editor, + events: events, + }); + var notification_area = new notificationarea.EditorNotificationArea( '#notification_area', { events: events, diff --git a/IPython/html/static/edit/js/savewidget.js b/IPython/html/static/edit/js/savewidget.js new file mode 100644 index 0000000..89069c5 --- /dev/null +++ b/IPython/html/static/edit/js/savewidget.js @@ -0,0 +1,202 @@ +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'base/js/namespace', + 'jquery', + 'base/js/utils', + 'base/js/dialog', + 'base/js/keyboard', + 'moment', +], function(IPython, $, utils, dialog, keyboard, moment) { + "use strict"; + + var SaveWidget = function (selector, options) { + this.editor = undefined; + this.selector = selector; + this.events = options.events; + this.editor = options.editor; + this._last_modified = undefined; + this.keyboard_manager = options.keyboard_manager; + if (this.selector !== undefined) { + this.element = $(selector); + this.bind_events(); + } + }; + + + SaveWidget.prototype.bind_events = function () { + var that = this; + this.element.find('span.filename').click(function () { + that.rename({editor: that.editor}); + }); + this.events.on('file_loaded.Editor', function (evt, model) { + that.update_filename(model.name); + that.update_document_title(model.name); + that.update_last_modified(model.last_modified); + }); + this.events.on('file_saved.Editor', function (evt, model) { + that.update_filename(model.name); + that.update_document_title(model.name); + that.update_last_modified(model.last_modified); + }); + this.events.on('file_renamed.Editor', function (evt, model) { + that.update_filename(model.name); + that.update_document_title(model.name); + that.update_address_bar(model.path); + }); + this.events.on('file_save_failed.Editor', function () { + that.set_save_status('Save Failed!'); + }); + }; + + + SaveWidget.prototype.rename = function (options) { + options = options || {}; + var that = this; + var dialog_body = $('
').append( + $("").addClass("rename-message") + .text('Enter a new filename:') + ).append( + $("