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