1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1446
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------
Patch 8.1.1446
Problem: Popup window callback not implemented yet.
Solution: Implement the callback.
Files: runtime/doc/popup.txt, src/popupwin.c, src/structs.h,
src/evalfunc.c, src/window.c, src/testdir/test_popupwin.vim
*** ../vim-8.1.1445/runtime/doc/popup.txt 2019-06-01 22:15:10.215177111 +0200
--- runtime/doc/popup.txt 2019-06-01 22:45:17.811027656 +0200
***************
*** 90,95 ****
--- 90,96 ----
IMPLEMENTATION:
- Code is in popupwin.c
+ - Fix positioning with border and padding.
- Why does 'nrformats' leak from the popup window buffer???
- Make redrawing more efficient and avoid flicker.
Store popup info in a mask, use the mask in screen_line()
***************
*** 133,142 ****
< In case of failure zero is returned.
! popup_close({id}) *popup_close()*
Close popup {id}. The window and the associated buffer will
be deleted.
popup_dialog({text}, {options}) *popup_dialog()*
{not implemented yet}
--- 134,148 ----
< In case of failure zero is returned.
! popup_close({id} [, {result}]) *popup_close()*
Close popup {id}. The window and the associated buffer will
be deleted.
+ If the popup has a callback it will be called just before the
+ popup window is deleted. If the optional {result} is present
+ it will be passed as the second argument of the callback.
+ Otherwise zero is passed to the callback.
+
popup_dialog({text}, {options}) *popup_dialog()*
{not implemented yet}
***************
*** 145,150 ****
--- 151,157 ----
\ 'pos': 'center',
\ 'zindex': 200,
\ 'border': [],
+ \ 'padding': [],
\})
< Use {options} to change the properties.
***************
*** 166,171 ****
--- 173,179 ----
popup_atcursor({text}, {options}) *popup_atcursor()*
+ {not implemented yet: close when cursor moves}
Show the {text} above the cursor, and close it when the cursor
moves. This works like: >
call popup_create({text}, {
***************
*** 394,400 ****
|popup-filter|
callback a callback to be used when the popup closes, e.g. when
using |popup_filter_menu()|, see |popup-callback|.
- {not implemented yet}
Depending on the "zindex" the popup goes under or above other popups. The
completion menu (|popup-menu|) has zindex 100. For messages that occur for a
--- 402,407 ----
***************
*** 477,487 ****
POPUP CALLBACK *popup-callback*
- {not implemented yet}
A callback that is invoked when the popup closes. Used by
! |popup_filter_menu()|. Invoked with two arguments: the ID of the popup and
! the result, which would usually be an index in the popup lines, or whatever
! the filter wants to pass.
==============================================================================
3. Examples *popup-examples*
--- 484,495 ----
POPUP CALLBACK *popup-callback*
A callback that is invoked when the popup closes. Used by
! |popup_filter_menu()|.
!
! The callback is invoked with two arguments: the ID of the popup window and the
! result, which could be an index in the popup lines, or whatever was passed as
! the second argument of `popup_close()`.
==============================================================================
3. Examples *popup-examples*
*** ../vim-8.1.1445/src/popupwin.c 2019-06-01 22:15:10.211177120 +0200
--- src/popupwin.c 2019-06-01 22:38:42.421014923 +0200
***************
*** 201,206 ****
--- 201,215 ----
wp->w_p_wrap = nr != 0;
}
+ di = dict_find(dict, (char_u *)"callback", -1);
+ if (di != NULL)
+ {
+ callback_T callback = get_callback(&di->di_tv);
+
+ if (callback.cb_name != NULL)
+ set_callback(&wp->w_close_cb, &callback);
+ }
+
di = dict_find(dict, (char_u *)"filter", -1);
if (di != NULL)
{
***************
*** 632,645 ****
}
/*
* popup_close({id})
*/
void
f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
{
int id = (int)tv_get_number(argvars);
! popup_close(id);
}
/*
--- 641,693 ----
}
/*
+ * Invoke the close callback for window "wp" with value "result".
+ * Careful: The callback may make "wp" invalid!
+ */
+ static void
+ invoke_popup_callback(win_T *wp, typval_T *result)
+ {
+ typval_T rettv;
+ int dummy;
+ typval_T argv[3];
+
+ argv[0].v_type = VAR_NUMBER;
+ argv[0].vval.v_number = (varnumber_T)wp->w_id;
+
+ if (result != NULL && result->v_type != VAR_UNKNOWN)
+ copy_tv(result, &argv[1]);
+ else
+ {
+ argv[1].v_type = VAR_NUMBER;
+ argv[1].vval.v_number = 0;
+ }
+
+ argv[2].v_type = VAR_UNKNOWN;
+
+ call_callback(&wp->w_close_cb, -1,
+ &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
+ if (result != NULL)
+ clear_tv(&argv[1]);
+ clear_tv(&rettv);
+ }
+
+ /*
* popup_close({id})
*/
void
f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
{
int id = (int)tv_get_number(argvars);
+ win_T *wp = find_popup_win(id);
! if (wp != NULL)
! {
! if (wp->w_close_cb.cb_name != NULL)
! // Careful: This may make "wp" invalid.
! invoke_popup_callback(wp, &argvars[1]);
!
! popup_close(id);
! }
}
/*
***************
*** 688,693 ****
--- 736,742 ----
/*
* Close a popup window by Window-id.
+ * Does not invoke the callback.
*/
void
popup_close(int id)
*** ../vim-8.1.1445/src/structs.h 2019-06-01 22:15:10.211177120 +0200
--- src/structs.h 2019-06-01 22:36:44.253601570 +0200
***************
*** 2894,2899 ****
--- 2894,2900 ----
int w_border_char[8]; // popup border characters
varnumber_T w_popup_last_changedtick; // b:changedtick when position was
// computed
+ callback_T w_close_cb; // popup close callback
callback_T w_filter_cb; // popup filter callback
# if defined(FEAT_TIMERS)
timer_T *w_popup_timer; // timer for closing popup window
*** ../vim-8.1.1445/src/evalfunc.c 2019-06-01 13:28:30.265829531 +0200
--- src/evalfunc.c 2019-06-01 22:23:58.965206463 +0200
***************
*** 810,816 ****
#endif
#ifdef FEAT_TEXT_PROP
{"popup_atcursor", 2, 2, f_popup_atcursor},
! {"popup_close", 1, 1, f_popup_close},
{"popup_create", 2, 2, f_popup_create},
{"popup_getoptions", 1, 1, f_popup_getoptions},
{"popup_getpos", 1, 1, f_popup_getpos},
--- 810,816 ----
#endif
#ifdef FEAT_TEXT_PROP
{"popup_atcursor", 2, 2, f_popup_atcursor},
! {"popup_close", 1, 2, f_popup_close},
{"popup_create", 2, 2, f_popup_create},
{"popup_getoptions", 1, 1, f_popup_getoptions},
{"popup_getpos", 1, 1, f_popup_getpos},
*** ../vim-8.1.1445/src/window.c 2019-06-01 22:15:10.215177111 +0200
--- src/window.c 2019-06-01 22:36:56.873539136 +0200
***************
*** 4845,4850 ****
--- 4845,4851 ----
remove_winbar(wp);
#endif
#ifdef FEAT_TEXT_PROP
+ free_callback(&wp->w_close_cb);
free_callback(&wp->w_filter_cb);
for (i = 0; i < 4; ++i)
VIM_CLEAR(wp->w_border_highlight[i]);
*** ../vim-8.1.1445/src/testdir/test_popupwin.vim 2019-06-01 22:15:10.215177111 +0200
--- src/testdir/test_popupwin.vim 2019-06-01 22:41:48.592082968 +0200
***************
*** 586,588 ****
--- 586,598 ----
delfunc MyPopupFilter
popupclear
endfunc
+
+ func Test_popup_close_callback()
+ func PopupDone(id, result)
+ let g:result = a:result
+ endfunc
+ let winid = popup_create('something', {'callback': 'PopupDone'})
+ redraw
+ call popup_close(winid, 'done')
+ call assert_equal('done', g:result)
+ endfunc
*** ../vim-8.1.1445/src/version.c 2019-06-01 22:15:10.215177111 +0200
--- src/version.c 2019-06-01 22:48:33.361971805 +0200
***************
*** 769,770 ****
--- 769,772 ----
{ /* Add new patch number below this line */
+ /**/
+ 1446,
/**/
--
hundred-and-one symptoms of being an internet addict:
82. AT&T names you Customer of the Month for the third consecutive time.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|