Mercurial > vim
diff src/testing.c @ 25006:496221916885 v8.2.3040
patch 8.2.3040: GUI: dropping files not tested
Commit: https://github.com/vim/vim/commit/18d46587b985923ef4b90b19a0cf37a094607fec
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Wed Jun 23 20:46:52 2021 +0200
patch 8.2.3040: GUI: dropping files not tested
Problem: GUI: dropping files not tested.
Solution: Add test_gui_drop_files() and tests. (Yegappan Lakshmanan,
closes #8434)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 23 Jun 2021 21:00:03 +0200 |
parents | 3b1770226f85 |
children | 54c0cb81e6a7 |
line wrap: on
line diff
--- a/src/testing.c +++ b/src/testing.c @@ -1224,7 +1224,7 @@ f_test_setmouse(typval_T *argvars, typva void f_test_gui_mouse_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED) { -#ifdef FEAT_GUI +# ifdef FEAT_GUI int button; int row; int col; @@ -1248,7 +1248,7 @@ f_test_gui_mouse_event(typval_T *argvars mods = tv_get_number(&argvars[4]); gui_send_mouse_event(button, TEXT_X(col - 1), TEXT_Y(row - 1), repeated_click, mods); -#endif +# endif } void @@ -1257,5 +1257,61 @@ f_test_settime(typval_T *argvars, typval time_for_testing = (time_t)tv_get_number(&argvars[0]); } + void +f_test_gui_drop_files(typval_T *argvars UNUSED, typval_T *rettv UNUSED) +{ +# ifdef FEAT_GUI + int row; + int col; + int_u mods; + char_u **fnames; + int count = 0; + list_T *l; + listitem_T *li; + + if (argvars[0].v_type != VAR_LIST + || (argvars[1].v_type) != VAR_NUMBER + || (argvars[2].v_type) != VAR_NUMBER + || (argvars[3].v_type) != VAR_NUMBER) + { + emsg(_(e_invarg)); + return; + } + + row = tv_get_number(&argvars[1]); + col = tv_get_number(&argvars[2]); + mods = tv_get_number(&argvars[3]); + + l = argvars[0].vval.v_list; + if (list_len(l) == 0) + return; + + fnames = ALLOC_MULT(char_u *, list_len(l)); + if (fnames == NULL) + return; + + FOR_ALL_LIST_ITEMS(l, li) + { + // ignore non-string items + if (li->li_tv.v_type != VAR_STRING) + continue; + + fnames[count] = vim_strsave(li->li_tv.vval.v_string); + if (fnames[count] == NULL) + { + while (--count >= 0) + vim_free(fnames[count]); + vim_free(fnames); + return; + } + count++; + } + + if (count > 0) + gui_handle_drop(TEXT_X(col - 1), TEXT_Y(row - 1), mods, fnames, count); + else + vim_free(fnames); +# endif +} #endif // defined(FEAT_EVAL)