Mercurial > vim
comparison src/popupwin.c @ 16800:12e3a3afdb6a v8.1.1402
patch 8.1.1402: "timer" option of popup windows not supported
commit https://github.com/vim/vim/commit/51fe3b14f63da2b985bcd7b4c50fbe34ae84ea48
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 26 20:10:06 2019 +0200
patch 8.1.1402: "timer" option of popup windows not supported
Problem: "timer" option of popup windows not supported.
Solution: Implement the "timer" option. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/4439)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 26 May 2019 20:15:05 +0200 |
parents | 5f98d80d116a |
children | f5487021fdad |
comparison
equal
deleted
inserted
replaced
16799:3c72f9c278b5 | 16800:12e3a3afdb6a |
---|---|
20 * popup window "wp". | 20 * popup window "wp". |
21 */ | 21 */ |
22 static void | 22 static void |
23 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict) | 23 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict) |
24 { | 24 { |
25 int nr; | |
26 | |
25 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); | 27 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); |
26 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); | 28 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); |
27 wp->w_winrow = dict_get_number(dict, (char_u *)"line"); | 29 wp->w_winrow = dict_get_number(dict, (char_u *)"line"); |
28 wp->w_wincol = dict_get_number(dict, (char_u *)"col"); | 30 wp->w_wincol = dict_get_number(dict, (char_u *)"col"); |
29 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); | 31 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); |
32 | |
33 // Add timer to close the popup after some time. | |
34 nr = dict_get_number(dict, (char_u *)"time"); | |
35 if (nr > 0) | |
36 { | |
37 char_u cbbuf[50]; | |
38 char_u *ptr = cbbuf; | |
39 typval_T tv; | |
40 | |
41 vim_snprintf((char *)cbbuf, sizeof(cbbuf), | |
42 "{_ -> popup_close(%d)}", wp->w_id); | |
43 if (get_lambda_tv(&ptr, &tv, TRUE) == OK) | |
44 { | |
45 wp->w_popup_timer = create_timer(nr, 0); | |
46 wp->w_popup_timer->tr_callback = | |
47 vim_strsave(partial_name(tv.vval.v_partial)); | |
48 func_ref(wp->w_popup_timer->tr_callback); | |
49 wp->w_popup_timer->tr_partial = tv.vval.v_partial; | |
50 } | |
51 } | |
52 | |
30 } | 53 } |
31 | 54 |
32 /* | 55 /* |
33 * popup_create({text}, {options}) | 56 * popup_create({text}, {options}) |
34 */ | 57 */ |
175 int nr = (int)tv_get_number(argvars); | 198 int nr = (int)tv_get_number(argvars); |
176 | 199 |
177 popup_close(nr); | 200 popup_close(nr); |
178 } | 201 } |
179 | 202 |
203 static void | |
204 popup_undisplay(win_T *wp) | |
205 { | |
206 if (wp->w_winrow + wp->w_height >= cmdline_row) | |
207 clear_cmdline = TRUE; | |
208 win_free_popup(wp); | |
209 redraw_all_later(NOT_VALID); | |
210 } | |
211 | |
180 /* | 212 /* |
181 * Close a popup window by Window-id. | 213 * Close a popup window by Window-id. |
182 */ | 214 */ |
183 void | 215 void |
184 popup_close(int id) | 216 popup_close(int id) |
193 { | 225 { |
194 if (prev == NULL) | 226 if (prev == NULL) |
195 first_popupwin = wp->w_next; | 227 first_popupwin = wp->w_next; |
196 else | 228 else |
197 prev->w_next = wp->w_next; | 229 prev->w_next = wp->w_next; |
198 win_free_popup(wp); | 230 popup_undisplay(wp); |
199 redraw_all_later(NOT_VALID); | |
200 return; | 231 return; |
201 } | 232 } |
202 | 233 |
203 // go through tab-local popups | 234 // go through tab-local popups |
204 FOR_ALL_TABPAGES(tp) | 235 FOR_ALL_TABPAGES(tp) |
220 { | 251 { |
221 if (prev == NULL) | 252 if (prev == NULL) |
222 *root = wp->w_next; | 253 *root = wp->w_next; |
223 else | 254 else |
224 prev->w_next = wp->w_next; | 255 prev->w_next = wp->w_next; |
225 win_free_popup(wp); | 256 popup_undisplay(wp); |
226 redraw_all_later(NOT_VALID); | |
227 return; | 257 return; |
228 } | 258 } |
229 } | 259 } |
230 | 260 |
231 void | 261 void |