Show More
@@ -10,11 +10,19 b'' | |||||
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 | // |
|
11 | // | |
12 | // you can set the autocall time by setting `IPython.tooltip.time_before_tooltip` in ms |
|
12 | // you can set the autocall time by setting `IPython.tooltip.time_before_tooltip` in ms | |
|
13 | // | |||
|
14 | // you can configure the differents action of pressing tab several times in a row by | |||
|
15 | // setting/appending different fonction in the array | |||
|
16 | // IPython.tooltip.tabs_functions | |||
|
17 | // | |||
|
18 | // eg : | |||
|
19 | // IPython.tooltip.tabs_functions[4] = function(){console.log('this is the action of the 4th tab pressing')} | |||
|
20 | // | |||
13 |
|
21 | |||
14 | var IPython = (function (IPython) { |
|
22 | var IPython = (function (IPython) { | |
15 |
|
23 | |||
16 | var utils = IPython.utils; |
|
24 | var utils = IPython.utils; | |
17 |
|
25 | |||
18 | // tooltip constructor |
|
26 | // tooltip constructor | |
19 | var Tooltip = function () { |
|
27 | var Tooltip = function () { | |
20 | var that = this; |
|
28 | var that = this; | |
@@ -22,13 +30,12 b' var IPython = (function (IPython) {' | |||||
22 |
|
30 | |||
23 | // handle to html |
|
31 | // handle to html | |
24 | this.tooltip = $('#tooltip'); |
|
32 | this.tooltip = $('#tooltip'); | |
25 | var tooltip = this.tooltip; |
|
|||
26 | this._hidden = true; |
|
33 | this._hidden = true; | |
27 |
|
34 | |||
28 | // variable for consecutive call |
|
35 | // variable for consecutive call | |
29 | this._old_cell = null ; |
|
36 | this._old_cell = null ; | |
30 | this._old_request = null ; |
|
37 | this._old_request = null ; | |
31 | this._consecutive_conter = 0; |
|
38 | this._consecutive_counter = 0; | |
32 |
|
39 | |||
33 | // 'sticky ?' |
|
40 | // 'sticky ?' | |
34 | this._sticky = false; |
|
41 | this._sticky = false; | |
@@ -93,16 +100,35 b' var IPython = (function (IPython) {' | |||||
93 | this.tooltip.append(this.buttons); |
|
100 | this.tooltip.append(this.buttons); | |
94 | this.tooltip.append(this.arrow); |
|
101 | this.tooltip.append(this.arrow); | |
95 | this.tooltip.append(this.text); |
|
102 | this.tooltip.append(this.text); | |
|
103 | ||||
|
104 | this.tabs_functions = [ | |||
|
105 | function(){that.expand()}, | |||
|
106 | function(){that.stick()}, | |||
|
107 | function(){ | |||
|
108 | that.cancel_stick(); | |||
|
109 | that.showInPager(); | |||
|
110 | that._cmfocus(); | |||
|
111 | } | |||
|
112 | ]; | |||
|
113 | // call after all the tabs function above have bee call to clean their effects | |||
|
114 | // if necessary | |||
|
115 | this.reset_tabs_function = function(cell,text){ | |||
|
116 | this._old_cell = (cell)? cell : null ; | |||
|
117 | this._old_request = (text) ? text : null ; | |||
|
118 | this._consecutive_counter = 0; | |||
|
119 | this.cancel_stick(); | |||
|
120 | } | |||
96 | }; |
|
121 | }; | |
97 |
|
122 | |||
98 | Tooltip.prototype.showInPager = function() |
|
123 | Tooltip.prototype.showInPager = function() | |
99 | { |
|
124 | { | |
100 | var that = this; |
|
125 | // reexecute last call in pager by appending ? to show back in pager | |
101 | var callbacks = {'execute_reply': $.proxy(that._handle_execute_reply,that)} |
|
126 | var that = this; | |
102 | var msg_id = IPython.notebook.kernel.execute(this.name+"?", callbacks); |
|
127 | var callbacks = {'execute_reply': $.proxy(that._handle_execute_reply,that)} | |
|
128 | var msg_id = IPython.notebook.kernel.execute(this.name+"?", callbacks); | |||
103 |
|
129 | |||
104 |
|
|
130 | this.remove_and_cancel_tooltip(); | |
105 |
|
|
131 | this._cmfocus(); | |
106 | } |
|
132 | } | |
107 |
|
133 | |||
108 | // grow the tooltip verticaly |
|
134 | // grow the tooltip verticaly | |
@@ -137,7 +163,7 b' var IPython = (function (IPython) {' | |||||
137 | this.cancel_pending(); |
|
163 | this.cancel_pending(); | |
138 | this._old_cell = null ; |
|
164 | this._old_cell = null ; | |
139 | this._old_request = null ; |
|
165 | this._old_request = null ; | |
140 | this._consecutive_conter = 0; |
|
166 | this._consecutive_counter = 0; | |
141 | } |
|
167 | } | |
142 |
|
168 | |||
143 | // cancel autocall done after '(' for example. |
|
169 | // cancel autocall done after '(' for example. | |
@@ -157,6 +183,8 b' var IPython = (function (IPython) {' | |||||
157 |
|
183 | |||
158 | Tooltip.prototype._request_tooltip = function(func) |
|
184 | Tooltip.prototype._request_tooltip = function(func) | |
159 | { |
|
185 | { | |
|
186 | // use internally just to maek the request to the kernel | |||
|
187 | ||||
160 | // Feel free to shorten this logic if you are better |
|
188 | // Feel free to shorten this logic if you are better | |
161 | // than me in regEx |
|
189 | // than me in regEx | |
162 | // basicaly you shoul be able to get xxx.xxx.xxx from |
|
190 | // basicaly you shoul be able to get xxx.xxx.xxx from | |
@@ -182,52 +210,47 b' var IPython = (function (IPython) {' | |||||
182 | // make an imediate completion request |
|
210 | // make an imediate completion request | |
183 | Tooltip.prototype.request = function(cell) |
|
211 | Tooltip.prototype.request = function(cell) | |
184 | { |
|
212 | { | |
|
213 | // request(codecell) | |||
|
214 | // Deal with extracting the text from the cell and counting | |||
|
215 | // call in a row | |||
|
216 | ||||
185 | this.cancel_pending(); |
|
217 | this.cancel_pending(); | |
186 | var editor = cell.code_mirror; |
|
218 | var editor = cell.code_mirror; | |
187 | this.code_mirror = editor; |
|
|||
188 | var cursor = editor.getCursor(); |
|
219 | var cursor = editor.getCursor(); | |
189 | var text = editor.getRange({line:cursor.line,ch:0},cursor).trim(); |
|
220 | var text = editor.getRange({line:cursor.line,ch:0},cursor).trim(); | |
|
221 | ||||
|
222 | // need a permanent handel to codemirror for future auto recall | |||
|
223 | this.code_mirror = editor; | |||
|
224 | ||||
190 |
|
225 | |||
|
226 | // now we treat the different kind of keypress | |||
|
227 | // first if same cell, same text, increment counter by 1 | |||
191 | if( this._old_cell == cell && this._old_request == text && this._hidden == false) |
|
228 | if( this._old_cell == cell && this._old_request == text && this._hidden == false) | |
192 | { |
|
229 | { | |
193 | this._consecutive_conter = this._consecutive_conter +1; |
|
230 | this._consecutive_counter = this._consecutive_counter +1; | |
194 | } else { |
|
231 | } else { | |
195 | this._old_cell = cell ; |
|
232 | // else reset | |
196 |
this. |
|
233 | this.reset_tabs_function(cell,text); | |
197 | this._consecutive_conter =0; |
|
|||
198 | this.cancel_stick(); |
|
|||
199 | } |
|
|||
200 |
|
||||
201 | if( this._consecutive_conter == 1 ) |
|
|||
202 | { |
|
|||
203 | this.expand() |
|
|||
204 | return; |
|
|||
205 | } |
|
|||
206 | else if( this._consecutive_conter == 2) |
|
|||
207 | { |
|
|||
208 | this.stick(); |
|
|||
209 | return; |
|
|||
210 | } |
|
|||
211 | else if( this._consecutive_conter == 3) |
|
|||
212 | { |
|
|||
213 | this._old_cell = null ; |
|
|||
214 | this.cancel_stick(); |
|
|||
215 | this._old_request = null ; |
|
|||
216 | this._consecutive_conter = 0; |
|
|||
217 | this.showInPager(); |
|
|||
218 | this._cmfocus(); |
|
|||
219 | return; |
|
|||
220 | } |
|
|||
221 | else if( this._consecutive_conter == 4) |
|
|||
222 | { |
|
|||
223 |
|
||||
224 | } |
|
234 | } | |
225 |
|
235 | |||
|
236 | // don't do anything if line beggin with '(' or is empty | |||
226 | if (text === "" || text === "(" ) { |
|
237 | if (text === "" || text === "(" ) { | |
227 | return; |
|
238 | return; | |
228 | // don't do anything if line beggin with '(' or is empty |
|
|||
229 | } |
|
239 | } | |
230 | this._request_tooltip(text); |
|
240 | ||
|
241 | if (this._consecutive_counter == 0) { | |||
|
242 | // make a kernel request | |||
|
243 | this._request_tooltip(text); | |||
|
244 | } else if (this._consecutive_counter == this.tabs_functions.length) { | |||
|
245 | // then if we are at the end of list function, reset | |||
|
246 | // and call the last function after | |||
|
247 | this.tabs_functions[this._consecutive_counter-1](); | |||
|
248 | this.reset_tabs_function(cell,text); | |||
|
249 | } else { | |||
|
250 | // otherwise, call the nth function of the list | |||
|
251 | this.tabs_functions[this._consecutive_counter-1](); | |||
|
252 | } | |||
|
253 | return; | |||
231 | } |
|
254 | } | |
232 |
|
255 | |||
233 | // cancel the option of having the tooltip to stick |
|
256 | // cancel the option of having the tooltip to stick | |
@@ -257,6 +280,7 b' var IPython = (function (IPython) {' | |||||
257 | // move the bubble if it is not hidden |
|
280 | // move the bubble if it is not hidden | |
258 | // otherwise fade it |
|
281 | // otherwise fade it | |
259 | var editor = this.code_mirror; |
|
282 | var editor = this.code_mirror; | |
|
283 | this.name = reply.name; | |||
260 |
|
284 | |||
261 | // do some math to have the tooltip arrow on more or less on left or right |
|
285 | // do some math to have the tooltip arrow on more or less on left or right | |
262 | // width of the editor |
|
286 | // width of the editor |
General Comments 0
You need to be logged in to leave comments.
Login now