comparison src/popupwin.c @ 17219:5169811b3044 v8.1.1609

patch 8.1.1609: the user cannot easily close a popup window commit https://github.com/vim/vim/commit/2e62b568e91c36adb16dbcc609665170f09f3845 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 30 18:07:00 2019 +0200 patch 8.1.1609: the user cannot easily close a popup window Problem: The user cannot easily close a popup window. Solution: Add the "close" property. (mostly by Masato Nishihata, closes #4601)
author Bram Moolenaar <Bram@vim.org>
date Sun, 30 Jun 2019 18:15:04 +0200
parents 11f3cf51d43b
children 09fa437d33d8
comparison
equal deleted inserted replaced
17218:210c4c5f783d 17219:5169811b3044
178 || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0) 178 || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0)
179 || (col == 0 && wp->w_popup_border[3] > 0) 179 || (col == 0 && wp->w_popup_border[3] > 0)
180 || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0); 180 || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0);
181 } 181 }
182 182
183 /*
184 * Return TRUE if "row"/"col" is on the "X" button of the popup.
185 * The values are relative to the top-left corner.
186 * Caller should check w_popup_close is POPCLOSE_BUTTON.
187 */
188 int
189 popup_on_X_button(win_T *wp, int row, int col)
190 {
191 return row == 0 && col == popup_width(wp) - 1;
192 }
193
183 // Values set when dragging a popup window starts. 194 // Values set when dragging a popup window starts.
184 static int drag_start_row; 195 static int drag_start_row;
185 static int drag_start_col; 196 static int drag_start_col;
186 static int drag_start_wantline; 197 static int drag_start_wantline;
187 static int drag_start_wantcol; 198 static int drag_start_wantcol;
381 } 392 }
382 393
383 di = dict_find(dict, (char_u *)"drag", -1); 394 di = dict_find(dict, (char_u *)"drag", -1);
384 if (di != NULL) 395 if (di != NULL)
385 wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag"); 396 wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag");
397
398 di = dict_find(dict, (char_u *)"close", -1);
399 if (di != NULL)
400 {
401 int ok = TRUE;
402
403 if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
404 {
405 char_u *s = di->di_tv.vval.v_string;
406
407 if (STRCMP(s, "none") == 0)
408 wp->w_popup_close = POPCLOSE_NONE;
409 else if (STRCMP(s, "button") == 0)
410 wp->w_popup_close = POPCLOSE_BUTTON;
411 else if (STRCMP(s, "click") == 0)
412 wp->w_popup_close = POPCLOSE_CLICK;
413 else
414 ok = FALSE;
415 }
416 else
417 ok = FALSE;
418 if (!ok)
419 semsg(_(e_invargNval), "close", tv_get_string(&di->di_tv));
420 }
386 421
387 str = dict_get_string(dict, (char_u *)"highlight", FALSE); 422 str = dict_get_string(dict, (char_u *)"highlight", FALSE);
388 if (str != NULL) 423 if (str != NULL)
389 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, 424 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
390 str, OPT_FREE|OPT_LOCAL, 0); 425 str, OPT_FREE|OPT_LOCAL, 0);
1070 set_moved_columns(wp, FIND_STRING); 1105 set_moved_columns(wp, FIND_STRING);
1071 } 1106 }
1072 1107
1073 // set default values 1108 // set default values
1074 wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; 1109 wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX;
1110 wp->w_popup_close = POPCLOSE_NONE;
1075 1111
1076 if (type == TYPE_NOTIFICATION) 1112 if (type == TYPE_NOTIFICATION)
1077 { 1113 {
1078 win_T *twp, *nextwin; 1114 win_T *twp, *nextwin;
1079 int height = buf->b_ml.ml_line_count + 3; 1115 int height = buf->b_ml.ml_line_count + 3;
1104 1140
1105 wp->w_wantcol = 10; 1141 wp->w_wantcol = 10;
1106 wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; 1142 wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX;
1107 wp->w_minwidth = 20; 1143 wp->w_minwidth = 20;
1108 wp->w_popup_drag = 1; 1144 wp->w_popup_drag = 1;
1145 wp->w_popup_close = POPCLOSE_CLICK;
1109 for (i = 0; i < 4; ++i) 1146 for (i = 0; i < 4; ++i)
1110 wp->w_popup_border[i] = 1; 1147 wp->w_popup_border[i] = 1;
1111 wp->w_popup_padding[1] = 1; 1148 wp->w_popup_padding[1] = 1;
1112 wp->w_popup_padding[3] = 1; 1149 wp->w_popup_padding[3] = 1;
1113 1150
1237 if (wp->w_close_cb.cb_name != NULL) 1274 if (wp->w_close_cb.cb_name != NULL)
1238 // Careful: This may make "wp" invalid. 1275 // Careful: This may make "wp" invalid.
1239 invoke_popup_callback(wp, arg); 1276 invoke_popup_callback(wp, arg);
1240 1277
1241 popup_close(id); 1278 popup_close(id);
1279 }
1280
1281 /*
1282 * Close popup "wp" because of a mouse click.
1283 */
1284 void
1285 popup_close_for_mouse_click(win_T *wp)
1286 {
1287 typval_T res;
1288
1289 res.v_type = VAR_NUMBER;
1290 res.vval.v_number = -2;
1291 popup_close_and_callback(wp, &res);
1242 } 1292 }
1243 1293
1244 /* 1294 /*
1245 * In a filter: check if the typed key is a mouse event that is used for 1295 * In a filter: check if the typed key is a mouse event that is used for
1246 * dragging the popup. 1296 * dragging the popup.
1813 { 1863 {
1814 dict_add_string(dict, "pos", 1864 dict_add_string(dict, "pos",
1815 (char_u *)poppos_entries[i].pp_name); 1865 (char_u *)poppos_entries[i].pp_name);
1816 break; 1866 break;
1817 } 1867 }
1868
1869 dict_add_string(dict, "close", (char_u *)(
1870 wp->w_popup_close == POPCLOSE_BUTTON ? "button"
1871 : wp->w_popup_close == POPCLOSE_CLICK ? "click" : "none"));
1818 1872
1819 # if defined(FEAT_TIMERS) 1873 # if defined(FEAT_TIMERS)
1820 dict_add_number(dict, "time", wp->w_popup_timer != NULL 1874 dict_add_number(dict, "time", wp->w_popup_timer != NULL
1821 ? (long)wp->w_popup_timer->tr_interval : 0L); 1875 ? (long)wp->w_popup_timer->tr_interval : 0L);
1822 # endif 1876 # endif
2432 screen_puts(buf, row, 2486 screen_puts(buf, row,
2433 wp->w_wincol + total_width - 1, border_attr[2]); 2487 wp->w_wincol + total_width - 1, border_attr[2]);
2434 } 2488 }
2435 } 2489 }
2436 2490
2491 if (wp->w_popup_close == POPCLOSE_BUTTON)
2492 {
2493 // close button goes on top of anything at the top-right corner
2494 buf[mb_char2bytes('X', buf)] = NUL;
2495 screen_puts(buf, wp->w_winrow, wp->w_wincol + total_width - 1,
2496 wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
2497 }
2498
2437 update_popup_transparent(wp, 0); 2499 update_popup_transparent(wp, 0);
2438 2500
2439 // Back to the normal zindex. 2501 // Back to the normal zindex.
2440 screen_zindex = 0; 2502 screen_zindex = 0;
2441 } 2503 }