Show More
@@ -20,7 +20,6 var IPython = (function (IPython) { | |||
|
20 | 20 | this.input_prompt_number = null; |
|
21 | 21 | this.outputs = []; |
|
22 | 22 | this.collapsed = false; |
|
23 | this.tooltip_timeout = null; | |
|
24 | 23 | this.clear_out_timeout = null; |
|
25 | 24 | IPython.Cell.apply(this, arguments); |
|
26 | 25 | }; |
@@ -52,19 +51,6 var IPython = (function (IPython) { | |||
|
52 | 51 | this.completer = new IPython.Completer(this); |
|
53 | 52 | }; |
|
54 | 53 | |
|
55 | //TODO, try to diminish the number of parameters. | |
|
56 | CodeCell.prototype.request_tooltip_after_time = function (pre_cursor,time){ | |
|
57 | var that = this; | |
|
58 | if (pre_cursor === "" || pre_cursor === "(" ) { | |
|
59 | // don't do anything if line beggin with '(' or is empty | |
|
60 | } else { | |
|
61 | if(time ==0) | |
|
62 | { IPython.tooltip.request(that, pre_cursor) } | |
|
63 | else | |
|
64 | { IPython.tooltip.pending(that, pre_cursor) } | |
|
65 | } | |
|
66 | }; | |
|
67 | ||
|
68 | 54 | CodeCell.prototype.handle_codemirror_keyevent = function (editor, event) { |
|
69 | 55 | // This method gets called in CodeMirror's onKeyDown/onKeyPress |
|
70 | 56 | // handlers and is used to provide custom key handling. Its return |
@@ -75,15 +61,11 var IPython = (function (IPython) { | |||
|
75 | 61 | return false; |
|
76 | 62 | } |
|
77 | 63 | |
|
78 | // note that we are comparing and setting the time to wait at each key press. | |
|
79 | // a better way might be to generate a new function on each time change and | |
|
80 | // assign it to CodeCell.prototype.request_tooltip_after_time | |
|
81 | var tooltip_wait_time = this.notebook.time_before_tooltip; | |
|
82 | 64 | var tooltip_on_tab = this.notebook.tooltip_on_tab; |
|
83 | 65 | var that = this; |
|
84 | 66 | // whatever key is pressed, first, cancel the tooltip request before |
|
85 | // they are sent, and remove tooltip if any | |
|
86 | if(event.type === 'keydown' ) { | |
|
67 | // they are sent, and remove tooltip if any, except for tab again | |
|
68 | if(event.type === 'keydown' && event.which != key.tab ) { | |
|
87 | 69 | IPython.tooltip.remove_and_cancel_tooltip(); |
|
88 | 70 | }; |
|
89 | 71 | |
@@ -91,13 +73,11 var IPython = (function (IPython) { | |||
|
91 | 73 | if (event.keyCode === key.enter && (event.shiftKey || event.ctrlKey)) { |
|
92 | 74 | // Always ignore shift-enter in CodeMirror as we handle it. |
|
93 | 75 | return true; |
|
94 |
} else if (event.which === 40 && event.type === 'keypress' && t |
|
|
95 |
// triger |
|
|
76 | } else if (event.which === 40 && event.type === 'keypress' && this.notebook.time_before_tooltip >= 0) { | |
|
77 | // triger on keypress (!) otherwise inconsistent event.which depending on plateform | |
|
96 | 78 | // browser and keyboard layout ! |
|
97 | 79 | // Pressing '(' , request tooltip, don't forget to reappend it |
|
98 | var cursor = editor.getCursor(); | |
|
99 | var pre_cursor = editor.getRange({line:cursor.line,ch:0},cursor).trim()+'('; | |
|
100 | that.request_tooltip_after_time(pre_cursor,tooltip_wait_time); | |
|
80 | IPython.tooltip.pending(that); | |
|
101 | 81 | } else if (event.which === key.upArrow) { |
|
102 | 82 | // If we are not at the top, let CM handle the up arrow and |
|
103 | 83 | // prevent the global keydown handler from handling it. |
@@ -126,7 +106,7 var IPython = (function (IPython) { | |||
|
126 | 106 | // is empty. In this case, let CodeMirror handle indentation. |
|
127 | 107 | return false; |
|
128 | 108 | } else if ((pre_cursor.substr(-1) === "("|| pre_cursor.substr(-1) === " ") && tooltip_on_tab ) { |
|
129 | that.request_tooltip_after_time(pre_cursor,0); | |
|
109 | IPython.tooltip.request(that); | |
|
130 | 110 | // Prevent the event from bubbling up. |
|
131 | 111 | event.stop(); |
|
132 | 112 | // Prevent CodeMirror from handling the tab. |
@@ -23,6 +23,14 var IPython = (function (IPython) { | |||
|
23 | 23 | var that = this; |
|
24 | 24 | this._hidden = true; |
|
25 | 25 | |
|
26 | // variable for consecutive call | |
|
27 | this._old_cell = null ; | |
|
28 | this._old_request = null ; | |
|
29 | this._consecutive_conter = 0; | |
|
30 | ||
|
31 | // 'sticky ?' | |
|
32 | this._sticky = false; | |
|
33 | ||
|
26 | 34 | // contain the button in the upper right corner |
|
27 | 35 | this.buttons = $('<div/>') |
|
28 | 36 | .addClass('tooltipbuttons'); |
@@ -33,7 +41,6 var IPython = (function (IPython) { | |||
|
33 | 41 | .addClass('smalltooltip'); |
|
34 | 42 | |
|
35 | 43 | var tooltip = this.tooltip; |
|
36 | var text = this.text; | |
|
37 | 44 | |
|
38 | 45 | // build the buttons menu on the upper right |
|
39 | 46 | |
@@ -42,12 +49,7 var IPython = (function (IPython) { | |||
|
42 | 49 | .addClass("ui-corner-all") //rounded corner |
|
43 | 50 | .attr('role',"button") |
|
44 | 51 | .attr('id','expanbutton') |
|
45 | .click(function(){ | |
|
46 | text.removeClass('smalltooltip'); | |
|
47 | text.addClass('bigtooltip'); | |
|
48 | $('#expanbutton').addClass('hidden'); | |
|
49 | that._cmfocus(); | |
|
50 | }) | |
|
52 | .click(function(){that.expand()}) | |
|
51 | 53 | .append( |
|
52 | 54 | $('<span/>').text('Expand') |
|
53 | 55 | .addClass('ui-icon') |
@@ -63,10 +65,7 var IPython = (function (IPython) { | |||
|
63 | 65 | .addClass('ui-icon-arrowstop-l-n'); |
|
64 | 66 | morelink.append(morespan); |
|
65 | 67 | morelink.click(function(){ |
|
66 | var msg_id = IPython.notebook.kernel.execute(that.name+"?"); | |
|
67 | IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id; | |
|
68 | that.remove_and_cancel_tooltip(); | |
|
69 | that._cmfocus(); | |
|
68 | that.showInPager(); | |
|
70 | 69 | }); |
|
71 | 70 | |
|
72 | 71 | // close the tooltip |
@@ -96,6 +95,22 var IPython = (function (IPython) { | |||
|
96 | 95 | this.tooltip.append(this.text); |
|
97 | 96 | }; |
|
98 | 97 | |
|
98 | Tooltip.prototype.showInPager = function() | |
|
99 | { | |
|
100 | var msg_id = IPython.notebook.kernel.execute(that.name+"?"); | |
|
101 | IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id; | |
|
102 | this.remove_and_cancel_tooltip(); | |
|
103 | this._cmfocus(); | |
|
104 | } | |
|
105 | ||
|
106 | ||
|
107 | Tooltip.prototype.expand = function(){ | |
|
108 | this.text.removeClass('smalltooltip'); | |
|
109 | this.text.addClass('bigtooltip'); | |
|
110 | $('#expanbutton').addClass('hidden'); | |
|
111 | this._cmfocus(); | |
|
112 | } | |
|
113 | ||
|
99 | 114 | // deal with all the logic of hiding the tooltip |
|
100 | 115 | // and reset it's status |
|
101 | 116 | Tooltip.prototype.hide = function() |
@@ -114,11 +129,21 var IPython = (function (IPython) { | |||
|
114 | 129 | }; |
|
115 | 130 | |
|
116 | 131 | |
|
117 | Tooltip.prototype.remove_and_cancel_tooltip = function() { | |
|
132 | Tooltip.prototype.remove_and_cancel_tooltip = function(force) { | |
|
118 | 133 | // note that we don't handle closing directly inside the calltip |
|
119 | 134 | // as in the completer, because it is not focusable, so won't |
|
120 | 135 | // get the event. |
|
121 | this.hide(); | |
|
136 | if(this._sticky == false || force == true) | |
|
137 | { | |
|
138 | this.hide(); | |
|
139 | } | |
|
140 | this.cancel_pending(); | |
|
141 | this._old_cell = null ; | |
|
142 | this._old_request = null ; | |
|
143 | this._consecutive_conter = 0; | |
|
144 | } | |
|
145 | ||
|
146 | Tooltip.prototype.cancel_pending = function(){ | |
|
122 | 147 | if (this.tooltip_timeout != null){ |
|
123 | 148 | clearTimeout(this.tooltip_timeout); |
|
124 | 149 | this.tooltip_timeout = null; |
@@ -128,11 +153,76 var IPython = (function (IPython) { | |||
|
128 | 153 | Tooltip.prototype.pending = function(cell,text) |
|
129 | 154 | { |
|
130 | 155 | var that = this; |
|
131 |
this.tooltip_timeout = setTimeout(function(){that.request(cell |
|
|
156 | this.tooltip_timeout = setTimeout(function(){that.request(cell)} , IPython.notebook.time_before_tooltip); | |
|
132 | 157 | } |
|
133 |
Tooltip.prototype.request = function(cell |
|
|
158 | Tooltip.prototype.request = function(cell) | |
|
134 | 159 | { |
|
135 | IPython.notebook.request_tool_tip(cell, text); | |
|
160 | this.cancel_pending(); | |
|
161 | var editor = cell.code_mirror; | |
|
162 | this.code_mirror = editor; | |
|
163 | var cursor = editor.getCursor(); | |
|
164 | var text = editor.getRange({line:cursor.line,ch:0},cursor).trim(); | |
|
165 | ||
|
166 | if( this._old_cell == cell && this._old_request == text && this._hidden == false) | |
|
167 | { | |
|
168 | this._consecutive_conter = this._consecutive_conter +1; | |
|
169 | } else { | |
|
170 | this._old_cell = cell ; | |
|
171 | this._old_request = text ; | |
|
172 | this._consecutive_conter =0; | |
|
173 | this.cancel_stick(); | |
|
174 | } | |
|
175 | ||
|
176 | if( this._consecutive_conter == 1 ) | |
|
177 | { | |
|
178 | this.expand() | |
|
179 | return; | |
|
180 | } | |
|
181 | else if( this._consecutive_conter == 2) | |
|
182 | { | |
|
183 | this.stick(); | |
|
184 | return; | |
|
185 | } | |
|
186 | else if( this._consecutive_conter == 3) | |
|
187 | { | |
|
188 | console.log('should open in pager'); | |
|
189 | this._old_cell = null ; | |
|
190 | this._cancel_stick | |
|
191 | this._old_request = null ; | |
|
192 | this._consecutive_conter = 0; | |
|
193 | this.showInPager(); | |
|
194 | this._cmfocus(); | |
|
195 | return; | |
|
196 | } | |
|
197 | else if( this._consecutive_conter == 4) | |
|
198 | { | |
|
199 | ||
|
200 | } | |
|
201 | ||
|
202 | if (text === "" || text === "(" ) { | |
|
203 | return; | |
|
204 | // don't do anything if line beggin with '(' or is empty | |
|
205 | } | |
|
206 | IPython.notebook.request_tool_tip(cell, text); | |
|
207 | } | |
|
208 | Tooltip.prototype.cancel_stick = function() | |
|
209 | { | |
|
210 | clearTimeout(this._stick_timeout); | |
|
211 | this._sticky = false; | |
|
212 | } | |
|
213 | ||
|
214 | Tooltip.prototype.stick = function() | |
|
215 | { | |
|
216 | console.log('tooltip will stick for at least 10 sec'); | |
|
217 | var that = this; | |
|
218 | this._sticky = true; | |
|
219 | this._stick_timeout = setTimeout( function(){ | |
|
220 | that._sticky = false; | |
|
221 | console.log('tooltip will not stick anymore'); | |
|
222 | }, 10*1000 | |
|
223 | ); | |
|
224 | ||
|
225 | ||
|
136 | 226 | } |
|
137 | 227 | |
|
138 | 228 | Tooltip.prototype.show = function(reply, codecell) |
@@ -142,9 +232,15 var IPython = (function (IPython) { | |||
|
142 | 232 | var editor = codecell.code_mirror; |
|
143 | 233 | this.name = reply.name; |
|
144 | 234 | this.code_mirror = editor; |
|
235 | ||
|
236 | // do some math to have the tooltip arrow on more or less on left or right | |
|
237 | // width of the editor | |
|
238 | var w= $(this.code_mirror.getScrollerElement()).width(); | |
|
239 | // ofset of the editor | |
|
240 | var o= $(this.code_mirror.getScrollerElement()).offset(); | |
|
145 | 241 | var pos = editor.cursorCoords(); |
|
146 | 242 | var xinit = pos.x; |
|
147 |
var xinter = xinit/ |
|
|
243 | var xinter = o.left + (xinit-o.left)/w*(w-450); | |
|
148 | 244 | var posarrowleft = xinit - xinter; |
|
149 | 245 | |
|
150 | 246 | |
@@ -185,11 +281,11 var IPython = (function (IPython) { | |||
|
185 | 281 | |
|
186 | 282 | } |
|
187 | 283 | |
|
188 | Tooltip.prototype.showInPager = function(){ | |
|
189 | var msg_id = IPython.notebook.kernel.execute(name+"?"); | |
|
284 | Tooltip.prototype.showInPager = function(text){ | |
|
285 | var msg_id = IPython.notebook.kernel.execute(this.name+"?"); | |
|
190 | 286 | IPython.notebook.msg_cell_map[msg_id] = IPython.notebook.get_selected_cell().cell_id; |
|
191 |
th |
|
|
192 | setTimeout(function(){that.code_mirror.focus();}, 50); | |
|
287 | this.remove_and_cancel_tooltip(true); | |
|
288 | this._cmfocus(); | |
|
193 | 289 | } |
|
194 | 290 | |
|
195 | 291 | Tooltip.prototype._cmfocus = function() |
General Comments 0
You need to be logged in to leave comments.
Login now