##// END OF EJS Templates
Select default title when renaming a notebook...
Kevin Burke -
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 "use strict";
14 14
15 15 var utils = IPython.utils;
16 16
17 17 var SaveWidget = function (selector) {
18 18 this.selector = selector;
19 19 if (this.selector !== undefined) {
20 20 this.element = $(selector);
21 21 this.style();
22 22 this.bind_events();
23 23 }
24 24 };
25 25
26 26
27 27 SaveWidget.prototype.style = function () {
28 28 };
29 29
30 30
31 31 SaveWidget.prototype.bind_events = function () {
32 32 var that = this;
33 33 this.element.find('span#notebook_name').click(function () {
34 34 that.rename_notebook();
35 35 });
36 36 this.element.find('span#notebook_name').hover(function () {
37 37 $(this).addClass("ui-state-hover");
38 38 }, function () {
39 39 $(this).removeClass("ui-state-hover");
40 40 });
41 41 $([IPython.events]).on('notebook_loaded.Notebook', function () {
42 42 that.update_notebook_name();
43 43 that.update_document_title();
44 44 });
45 45 $([IPython.events]).on('notebook_saved.Notebook', function () {
46 46 that.update_notebook_name();
47 47 that.update_document_title();
48 48 });
49 49 $([IPython.events]).on('notebook_save_failed.Notebook', function () {
50 50 that.set_save_status('Autosave Failed!');
51 51 });
52 52 $([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
53 53 that.set_last_checkpoint(data[0]);
54 54 });
55 55
56 56 $([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
57 57 that.set_last_checkpoint(data);
58 58 });
59 59 $([IPython.events]).on('set_dirty.Notebook', function (event, data) {
60 60 that.set_autosaved(data.value);
61 61 });
62 62 };
63 63
64 64
65 65 SaveWidget.prototype.rename_notebook = function () {
66 66 var that = this;
67 67 var dialog = $('<div/>').append(
68 68 $("<p/>").addClass("rename-message")
69 69 .html('Enter a new notebook name:')
70 70 ).append(
71 71 $("<br/>")
72 72 ).append(
73 73 $('<input/>').attr('type','text').attr('size','25')
74 74 .val(IPython.notebook.get_notebook_name())
75 75 );
76 76 IPython.dialog.modal({
77 77 title: "Rename Notebook",
78 78 body: dialog,
79 79 buttons : {
80 80 "Cancel": {},
81 81 "OK": {
82 82 class: "btn-primary",
83 83 click: function () {
84 84 var new_name = $(this).find('input').val();
85 85 if (!IPython.notebook.test_notebook_name(new_name)) {
86 86 $(this).find('.rename-message').html(
87 87 "Invalid notebook name. Notebook names must "+
88 88 "have 1 or more characters and can contain any characters " +
89 89 "except :/\\. Please enter a new notebook name:"
90 90 );
91 91 return false;
92 92 } else {
93 93 IPython.notebook.set_notebook_name(new_name);
94 94 IPython.notebook.save_notebook();
95 95 }
96 96 }}
97 97 },
98 98 open : function (event, ui) {
99 99 var that = $(this);
100 100 // Upon ENTER, click the OK button.
101 101 that.find('input[type="text"]').keydown(function (event, ui) {
102 102 if (event.which === utils.keycodes.ENTER) {
103 103 that.find('.btn-primary').first().click();
104 104 return false;
105 105 }
106 106 });
107 that.find('input[type="text"]').focus();
107 that.find('input[type="text"]').focus().select();
108 108 }
109 109 });
110 110 }
111 111
112 112
113 113 SaveWidget.prototype.update_notebook_name = function () {
114 114 var nbname = IPython.notebook.get_notebook_name();
115 115 this.element.find('span#notebook_name').html(nbname);
116 116 };
117 117
118 118
119 119 SaveWidget.prototype.update_document_title = function () {
120 120 var nbname = IPython.notebook.get_notebook_name();
121 121 document.title = nbname;
122 122 };
123 123
124 124
125 125 SaveWidget.prototype.set_save_status = function (msg) {
126 126 this.element.find('span#autosave_status').html(msg);
127 127 }
128 128
129 129 SaveWidget.prototype.set_checkpoint_status = function (msg) {
130 130 this.element.find('span#checkpoint_status').html(msg);
131 131 }
132 132
133 133 SaveWidget.prototype.set_last_checkpoint = function (checkpoint) {
134 134 if (!checkpoint) {
135 135 this.set_checkpoint_status("");
136 136 return;
137 137 }
138 138 var d = new Date(checkpoint.last_modified);
139 139 this.set_checkpoint_status(
140 140 "Last Checkpoint: " + d.format('mmm dd HH:MM')
141 141 );
142 142 }
143 143
144 144 SaveWidget.prototype.set_autosaved = function (dirty) {
145 145 if (dirty) {
146 146 this.set_save_status("(unsaved changes)");
147 147 } else {
148 148 this.set_save_status("(autosaved)");
149 149 }
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