Show More
@@ -10,11 +10,19 | |||
|
10 | 10 | //============================================================================ |
|
11 | 11 | // |
|
12 | 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 | 22 | var IPython = (function (IPython) { |
|
15 | 23 | |
|
16 | 24 | var utils = IPython.utils; |
|
17 | ||
|
25 | ||
|
18 | 26 | // tooltip constructor |
|
19 | 27 | var Tooltip = function () { |
|
20 | 28 | var that = this; |
@@ -22,13 +30,12 var IPython = (function (IPython) { | |||
|
22 | 30 | |
|
23 | 31 | // handle to html |
|
24 | 32 | this.tooltip = $('#tooltip'); |
|
25 | var tooltip = this.tooltip; | |
|
26 | 33 | this._hidden = true; |
|
27 | 34 | |
|
28 | 35 | // variable for consecutive call |
|
29 | 36 | this._old_cell = null ; |
|
30 | 37 | this._old_request = null ; |
|
31 | this._consecutive_conter = 0; | |
|
38 | this._consecutive_counter = 0; | |
|
32 | 39 | |
|
33 | 40 | // 'sticky ?' |
|
34 | 41 | this._sticky = false; |
@@ -93,16 +100,35 var IPython = (function (IPython) { | |||
|
93 | 100 | this.tooltip.append(this.buttons); |
|
94 | 101 | this.tooltip.append(this.arrow); |
|
95 | 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 | 123 | Tooltip.prototype.showInPager = function() |
|
99 | 124 | { |
|
100 | var that = this; | |
|
101 | var callbacks = {'execute_reply': $.proxy(that._handle_execute_reply,that)} | |
|
102 | var msg_id = IPython.notebook.kernel.execute(this.name+"?", callbacks); | |
|
125 | // reexecute last call in pager by appending ? to show back in pager | |
|
126 | var that = this; | |
|
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 |
|
|
|
105 |
|
|
|
130 | this.remove_and_cancel_tooltip(); | |
|
131 | this._cmfocus(); | |
|
106 | 132 | } |
|
107 | 133 | |
|
108 | 134 | // grow the tooltip verticaly |
@@ -137,7 +163,7 var IPython = (function (IPython) { | |||
|
137 | 163 | this.cancel_pending(); |
|
138 | 164 | this._old_cell = null ; |
|
139 | 165 | this._old_request = null ; |
|
140 | this._consecutive_conter = 0; | |
|
166 | this._consecutive_counter = 0; | |
|
141 | 167 | } |
|
142 | 168 | |
|
143 | 169 | // cancel autocall done after '(' for example. |
@@ -157,6 +183,8 var IPython = (function (IPython) { | |||
|
157 | 183 | |
|
158 | 184 | Tooltip.prototype._request_tooltip = function(func) |
|
159 | 185 | { |
|
186 | // use internally just to maek the request to the kernel | |
|
187 | ||
|
160 | 188 | // Feel free to shorten this logic if you are better |
|
161 | 189 | // than me in regEx |
|
162 | 190 | // basicaly you shoul be able to get xxx.xxx.xxx from |
@@ -182,52 +210,47 var IPython = (function (IPython) { | |||
|
182 | 210 | // make an imediate completion request |
|
183 | 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 | 217 | this.cancel_pending(); |
|
186 | 218 | var editor = cell.code_mirror; |
|
187 | this.code_mirror = editor; | |
|
188 | 219 | var cursor = editor.getCursor(); |
|
189 | 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 | 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 | 231 | } else { |
|
195 | this._old_cell = cell ; | |
|
196 |
this. |
|
|
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 | ||
|
232 | // else reset | |
|
233 | this.reset_tabs_function(cell,text); | |
|
224 | 234 | } |
|
225 | ||
|
235 | ||
|
236 | // don't do anything if line beggin with '(' or is empty | |
|
226 | 237 | if (text === "" || text === "(" ) { |
|
227 | 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 | 256 | // cancel the option of having the tooltip to stick |
@@ -257,6 +280,7 var IPython = (function (IPython) { | |||
|
257 | 280 | // move the bubble if it is not hidden |
|
258 | 281 | // otherwise fade it |
|
259 | 282 | var editor = this.code_mirror; |
|
283 | this.name = reply.name; | |
|
260 | 284 | |
|
261 | 285 | // do some math to have the tooltip arrow on more or less on left or right |
|
262 | 286 | // width of the editor |
General Comments 0
You need to be logged in to leave comments.
Login now