##// END OF EJS Templates
rename shouldn't create a checkpoint
MinRK -
Show More
@@ -1,158 +1,158
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // SaveWidget
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13
14 14 var utils = IPython.utils;
15 15
16 16 var SaveWidget = function (selector) {
17 17 this.selector = selector;
18 18 if (this.selector !== undefined) {
19 19 this.element = $(selector);
20 20 this.style();
21 21 this.bind_events();
22 22 }
23 23 };
24 24
25 25
26 26 SaveWidget.prototype.style = function () {
27 27 this.element.find('span#save_widget').addClass('ui-widget');
28 28 this.element.find('span#notebook_name').addClass('ui-widget');
29 29 this.element.find('span#autosave_status').addClass('ui-widget')
30 30 .css({border: 'none'});
31 31 this.element.find('span#checkpoint_status').addClass('ui-widget')
32 32 .css({border: 'none', 'margin-left': '20px'});
33 33 };
34 34
35 35
36 36 SaveWidget.prototype.bind_events = function () {
37 37 var that = this;
38 38 this.element.find('span#notebook_name').click(function () {
39 39 that.rename_notebook();
40 40 });
41 41 this.element.find('span#notebook_name').hover(function () {
42 42 $(this).addClass("ui-state-hover");
43 43 }, function () {
44 44 $(this).removeClass("ui-state-hover");
45 45 });
46 46 $([IPython.events]).on('notebook_loaded.Notebook', function () {
47 47 that.set_last_saved();
48 48 that.update_notebook_name();
49 49 that.update_document_title();
50 50 });
51 51 $([IPython.events]).on('notebook_saved.Notebook', function () {
52 52 that.set_last_saved();
53 53 that.update_notebook_name();
54 54 that.update_document_title();
55 55 });
56 56 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
57 57 that.set_save_status('Last Save Failed!');
58 58 });
59 59 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
60 60 that.set_last_checkpoint(data);
61 61 });
62 62
63 63 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
64 64 that.set_last_checkpoint(data);
65 65 });
66 66 };
67 67
68 68
69 69 SaveWidget.prototype.rename_notebook = function () {
70 70 var that = this;
71 71 var dialog = $('<div/>');
72 72 dialog.append(
73 73 $('<p/>').html('Enter a new notebook name:')
74 74 .css({'margin-bottom': '10px'})
75 75 );
76 76 dialog.append(
77 77 $('<input/>').attr('type','text').attr('size','25')
78 78 .addClass('ui-widget ui-widget-content')
79 79 .attr('value',IPython.notebook.get_notebook_name())
80 80 );
81 81 // $(document).append(dialog);
82 82 dialog.dialog({
83 83 resizable: false,
84 84 modal: true,
85 85 title: "Rename Notebook",
86 86 closeText: "",
87 87 close: function(event, ui) {$(this).dialog('destroy').remove();},
88 88 buttons : {
89 89 "OK": function () {
90 90 var new_name = $(this).find('input').attr('value');
91 91 if (!IPython.notebook.test_notebook_name(new_name)) {
92 92 $(this).find('h3').html(
93 93 "Invalid notebook name. Notebook names must "+
94 94 "have 1 or more characters and can contain any characters " +
95 95 "except :/\\. Please enter a new notebook name:"
96 96 );
97 97 } else {
98 98 IPython.notebook.set_notebook_name(new_name);
99 IPython.notebook.save_checkpoint();
99 IPython.notebook.save_notebook();
100 100 $(this).dialog('close');
101 101 }
102 102 },
103 103 "Cancel": function () {
104 104 $(this).dialog('close');
105 105 }
106 106 },
107 107 open : function (event, ui) {
108 108 var that = $(this);
109 109 // Upon ENTER, click the OK button.
110 110 that.find('input[type="text"]').keydown(function (event, ui) {
111 111 if (event.which === utils.keycodes.ENTER) {
112 112 that.parent().find('button').first().click();
113 113 }
114 114 });
115 115 }
116 116 });
117 117 }
118 118
119 119
120 120 SaveWidget.prototype.update_notebook_name = function () {
121 121 var nbname = IPython.notebook.get_notebook_name();
122 122 this.element.find('span#notebook_name').html(nbname);
123 123 };
124 124
125 125
126 126 SaveWidget.prototype.update_document_title = function () {
127 127 var nbname = IPython.notebook.get_notebook_name();
128 128 document.title = nbname;
129 129 };
130 130
131 131
132 132 SaveWidget.prototype.set_save_status = function (msg) {
133 133 this.element.find('span#autosave_status').html(msg);
134 134 }
135 135
136 136 SaveWidget.prototype.set_checkpoint_status = function (msg) {
137 137 this.element.find('span#checkpoint_status').html(msg);
138 138 }
139 139
140 140 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
141 141 var d = new Date(checkpoint.last_modified);
142 142 this.set_checkpoint_status(
143 143 "Last Checkpoint: " + d.format('mmm dd HH:MM')
144 144 );
145 145 }
146 146
147 147 SaveWidget.prototype.set_last_saved = function () {
148 148 var d = new Date();
149 149 this.set_save_status('(autosaved: '+d.format('mmm dd HH:MM') + ')');
150 150 };
151 151
152 152
153 153 IPython.SaveWidget = SaveWidget;
154 154
155 155 return IPython;
156 156
157 157 }(IPython));
158 158
General Comments 0
You need to be logged in to leave comments. Login now