Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * Visual Workshop integration by Gordon Prieur |
| 5 | * |
| 6 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 7 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 8 | * See README.txt for an overview of the Vim source code. |
| 9 | */ |
| 10 | |
| 11 | #ifdef HAVE_CONFIG_H |
| 12 | # include "auto/config.h" |
| 13 | #endif |
| 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 16 | #include <sys/types.h> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | #include <netdb.h> |
| 18 | #include <netinet/in.h> |
| 19 | #include <errno.h> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | #include <sys/socket.h> |
| 21 | #ifdef HAVE_LIBGEN_H |
| 22 | # include <libgen.h> |
| 23 | #endif |
| 24 | #include <unistd.h> |
| 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <ctype.h> |
| 28 | |
| 29 | #include <X11/Intrinsic.h> |
| 30 | #include <Xm/Xm.h> |
| 31 | #include <Xm/PushB.h> |
| 32 | |
| 33 | #include "integration.h" /* <EditPlugin/integration.h> */ |
| 34 | |
| 35 | #include "vim.h" |
| 36 | #include "version.h" |
| 37 | #include "gui_beval.h" |
| 38 | #include "workshop.h" |
| 39 | |
| 40 | void workshop_hotkeys(Boolean); |
| 41 | |
| 42 | static Boolean isShowing(int); |
| 43 | static win_T *get_window(buf_T *); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 44 | static void updatePriority(Boolean); |
| 45 | static char *addUniqueMnemonic(char *, char *); |
| 46 | static char *fixup(char *); |
| 47 | static char *get_selection(buf_T *); |
| 48 | static char *append_selection(int, char *, int *, int *); |
| 49 | static void load_buffer_by_name(char *, int); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 50 | static void load_window(char *, int lnum); |
| 51 | static void warp_to_pc(int); |
| 52 | #ifdef FEAT_BEVAL |
Bram Moolenaar | ba07ce3 | 2010-01-06 18:25:34 +0100 | [diff] [blame] | 53 | void workshop_beval_cb(BalloonEval *, int); |
| 54 | static int computeIndex(int, char_u *, int); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 55 | #endif |
| 56 | static char *fixAccelText(char *); |
| 57 | static void addMenu(char *, char *, char *); |
| 58 | static char *lookupVerb(char *, int); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 59 | static void coloncmd(char *, Boolean); |
| 60 | |
| 61 | extern Widget vimShell; |
| 62 | extern Widget textArea; |
| 63 | extern XtAppContext app_context; |
| 64 | |
| 65 | static int tbpri; /* ToolBar priority */ |
| 66 | int usingSunWorkShop = 0; /* set if -ws flag is used */ |
| 67 | char curMenuName[BUFSIZ]; |
| 68 | char curMenuPriority[BUFSIZ]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 69 | |
| 70 | static Boolean workshopInitDone = False; |
| 71 | static Boolean workshopHotKeysEnabled = False; |
| 72 | |
| 73 | /* |
| 74 | * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it |
| 75 | * here because its C++. |
| 76 | */ |
| 77 | enum |
| 78 | { |
| 79 | GPLineEval_EVALUATE, /* evaluate expression */ |
| 80 | GPLineEval_INDIRECT, /* evaluate *<expression> */ |
| 81 | GPLineEval_TYPE /* type of expression */ |
| 82 | }; |
| 83 | |
| 84 | /* |
| 85 | * Store each verb in the MenuMap. This lets us map from a verb to a menu. |
| 86 | * There may be multiple matches for a single verb in this table. |
| 87 | */ |
| 88 | #define MENU_INC 50 /* menuMap incremental size increases */ |
| 89 | typedef struct |
| 90 | { |
| 91 | char *name; /* name of the menu */ |
| 92 | char *accel; /* optional accelerator key */ |
| 93 | char *verb; /* menu verb */ |
| 94 | } MenuMap; |
| 95 | static MenuMap *menuMap; /* list of verb/menu mappings */ |
| 96 | static int menuMapSize; /* current size of menuMap */ |
| 97 | static int menuMapMax; /* allocated size of menuMap */ |
| 98 | static char *initialFileCmd; /* save command but defer doing it */ |
| 99 | |
| 100 | |
| 101 | void |
| 102 | workshop_init() |
| 103 | { |
| 104 | char_u buf[64]; |
| 105 | int is_dirty = FALSE; |
| 106 | int width, height; |
| 107 | XtInputMask mask; |
| 108 | |
| 109 | /* |
| 110 | * Turn on MenuBar, ToolBar, and Footer. |
| 111 | */ |
| 112 | STRCPY(buf, p_go); |
| 113 | if (vim_strchr(p_go, GO_MENUS) == NULL) |
| 114 | { |
| 115 | STRCAT(buf, "m"); |
| 116 | is_dirty = TRUE; |
| 117 | } |
| 118 | if (vim_strchr(p_go, GO_TOOLBAR) == NULL) |
| 119 | { |
| 120 | STRCAT(buf, "T"); |
| 121 | is_dirty = TRUE; |
| 122 | } |
| 123 | if (vim_strchr(p_go, GO_FOOTER) == NULL) |
| 124 | { |
| 125 | STRCAT(buf, "F"); |
| 126 | is_dirty = TRUE; |
| 127 | } |
| 128 | if (is_dirty) |
| 129 | set_option_value((char_u *)"go", 0L, buf, 0); |
| 130 | |
| 131 | /* |
| 132 | * Set size from workshop_get_width_height(). |
| 133 | */ |
| 134 | width = height = 0; |
| 135 | if (workshop_get_width_height(&width, &height)) |
| 136 | { |
| 137 | XtVaSetValues(vimShell, |
| 138 | XmNwidth, width, |
| 139 | XmNheight, height, |
| 140 | NULL); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Now read in the initial messages from eserve. |
| 145 | */ |
| 146 | while ((mask = XtAppPending(app_context)) |
| 147 | && (mask & XtIMAlternateInput) && !workshopInitDone) |
| 148 | XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput); |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | workshop_postinit() |
| 153 | { |
| 154 | do_cmdline_cmd((char_u *)initialFileCmd); |
| 155 | ALT_INPUT_LOCK_OFF; |
| 156 | free(initialFileCmd); |
| 157 | initialFileCmd = NULL; |
| 158 | } |
| 159 | |
| 160 | void |
| 161 | ex_wsverb(exarg_T *eap) |
| 162 | { |
| 163 | msg_clr_cmdline(); |
| 164 | workshop_perform_verb((char *) eap->arg, NULL); |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Editor name |
| 169 | * This string is recognized by eserve and should be all lower case. |
| 170 | * This is how the editor detects that it is talking to gvim instead |
| 171 | * of NEdit, for example, when the connection is initiated from the editor. |
| 172 | */ |
| 173 | char * |
| 174 | workshop_get_editor_name() |
| 175 | { |
| 176 | return "gvim"; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Version number of the editor. |
| 181 | * This number is communicated along with the protocol |
| 182 | * version to the application. |
| 183 | */ |
| 184 | char * |
| 185 | workshop_get_editor_version() |
| 186 | { |
| 187 | return Version; |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Answer functions: called by eserve |
| 192 | */ |
| 193 | |
| 194 | /* |
| 195 | * Name: |
| 196 | * workshop_load_file |
| 197 | * |
| 198 | * Function: |
| 199 | * Load a given file into the WorkShop buffer. |
| 200 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 201 | void |
| 202 | workshop_load_file( |
| 203 | char *filename, /* the file to load */ |
| 204 | int line, /* an optional line number (or 0) */ |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 205 | char *frameid UNUSED) /* used for multi-frame support */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 206 | { |
| 207 | #ifdef WSDEBUG_TRACE |
| 208 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 209 | wstrace("workshop_load_file(%s, %d)\n", filename, line); |
| 210 | #endif |
| 211 | |
| 212 | #ifdef FEAT_BEVAL |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 213 | bevalServers |= BEVAL_WORKSHOP; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 214 | #endif |
| 215 | |
| 216 | load_window(filename, line); |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * Reload the WorkShop buffer |
| 221 | */ |
| 222 | void |
| 223 | workshop_reload_file( |
| 224 | char *filename, |
| 225 | int line) |
| 226 | { |
| 227 | #ifdef WSDEBUG_TRACE |
| 228 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 229 | wstrace("workshop_reload_file(%s, %d)\n", filename, line); |
| 230 | #endif |
| 231 | load_window(filename, line); |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | workshop_show_file( |
| 236 | char *filename) |
| 237 | { |
| 238 | #ifdef WSDEBUG_TRACE |
| 239 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 240 | wstrace("workshop_show_file(%s)\n", filename); |
| 241 | #endif |
| 242 | |
| 243 | load_window(filename, 0); |
| 244 | } |
| 245 | |
| 246 | void |
| 247 | workshop_goto_line( |
| 248 | char *filename, |
| 249 | int lineno) |
| 250 | { |
| 251 | #ifdef WSDEBUG_TRACE |
| 252 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 253 | wstrace("workshop_goto_line(%s, %d)\n", filename, lineno); |
| 254 | #endif |
| 255 | |
| 256 | load_window(filename, lineno); |
| 257 | } |
| 258 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 259 | void |
| 260 | workshop_front_file( |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 261 | char *filename UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 262 | { |
| 263 | #ifdef WSDEBUG_TRACE |
| 264 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 265 | wstrace("workshop_front_file()\n"); |
| 266 | #endif |
| 267 | /* |
| 268 | * Assumption: This function will always be called after a call to |
| 269 | * workshop_show_file(), so the file is always showing. |
| 270 | */ |
| 271 | if (vimShell != NULL) |
| 272 | XRaiseWindow(gui.dpy, XtWindow(vimShell)); |
| 273 | } |
| 274 | |
| 275 | void |
| 276 | workshop_save_file( |
| 277 | char *filename) |
| 278 | { |
| 279 | char cbuf[BUFSIZ]; /* build vim command here */ |
| 280 | |
| 281 | #ifdef WSDEBUG_TRACE |
| 282 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 283 | wstrace("workshop_save_file(%s)\n", filename); |
| 284 | #endif |
| 285 | |
| 286 | /* Save the given file */ |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 287 | vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 288 | coloncmd(cbuf, TRUE); |
| 289 | } |
| 290 | |
| 291 | void |
| 292 | workshop_save_files() |
| 293 | { |
| 294 | /* Save the given file */ |
| 295 | #ifdef WSDEBUG_TRACE |
| 296 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 297 | wstrace("workshop_save_files()\n"); |
| 298 | #endif |
| 299 | |
| 300 | add_to_input_buf((char_u *) ":wall\n", 6); |
| 301 | } |
| 302 | |
| 303 | void |
| 304 | workshop_quit() |
| 305 | { |
| 306 | #ifdef WSDEBUG_TRACE |
| 307 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 308 | wstrace("workshop_quit()\n"); |
| 309 | #endif |
| 310 | |
| 311 | add_to_input_buf((char_u *) ":qall\n", 6); |
| 312 | } |
| 313 | |
| 314 | void |
| 315 | workshop_minimize() |
| 316 | { |
| 317 | #ifdef WSDEBUG_TRACE |
| 318 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 319 | wstrace("workshop_minimize()\n"); |
| 320 | #endif |
| 321 | workshop_minimize_shell(vimShell); |
| 322 | } |
| 323 | void |
| 324 | workshop_maximize() |
| 325 | { |
| 326 | #ifdef WSDEBUG_TRACE |
| 327 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 328 | wstrace("workshop_maximize()\n"); |
| 329 | #endif |
| 330 | |
| 331 | workshop_maximize_shell(vimShell); |
| 332 | } |
| 333 | |
| 334 | void |
| 335 | workshop_add_mark_type( |
| 336 | int idx, |
| 337 | char *colorspec, |
| 338 | char *sign) |
| 339 | { |
| 340 | char gbuf[BUFSIZ]; /* buffer for sign name */ |
| 341 | char cibuf[BUFSIZ]; /* color information */ |
| 342 | char cbuf[BUFSIZ]; /* command buffer */ |
| 343 | char *bp; |
| 344 | |
| 345 | #ifdef WSDEBUG_TRACE |
| 346 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 347 | { |
| 348 | char *cp; |
| 349 | |
| 350 | cp = strrchr(sign, '/'); |
| 351 | if (cp == NULL) |
| 352 | cp = sign; |
| 353 | else |
| 354 | cp++; /* skip '/' character */ |
| 355 | wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx, |
| 356 | colorspec && *colorspec ? colorspec : "<None>", cp); |
| 357 | } |
| 358 | #endif |
| 359 | |
| 360 | /* |
| 361 | * Isolate the basename of sign in gbuf. We will use this for the |
| 362 | * GroupName in the highlight command sent to vim. |
| 363 | */ |
| 364 | STRCPY(gbuf, gettail((char_u *)sign)); |
| 365 | bp = strrchr(gbuf, '.'); |
| 366 | if (bp != NULL) |
| 367 | *bp = NUL; |
| 368 | |
| 369 | if (gbuf[0] != '-' && gbuf[1] != NUL) |
| 370 | { |
| 371 | if (colorspec != NULL && *colorspec) |
| 372 | { |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 373 | vim_snprintf(cbuf, sizeof(cbuf), |
| 374 | "highlight WS%s guibg=%s", gbuf, colorspec); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 375 | coloncmd(cbuf, FALSE); |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 376 | vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 377 | } |
| 378 | else |
| 379 | cibuf[0] = NUL; |
| 380 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 381 | vim_snprintf(cbuf, sizeof(cbuf), |
| 382 | "sign define %d %s icon=%s", idx, cibuf, sign); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 383 | coloncmd(cbuf, TRUE); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | void |
| 388 | workshop_set_mark( |
| 389 | char *filename, /* filename which gets the mark */ |
| 390 | int lineno, /* line number which gets the mark */ |
| 391 | int markId, /* unique mark identifier */ |
| 392 | int idx) /* which mark to use */ |
| 393 | { |
| 394 | char cbuf[BUFSIZ]; /* command buffer */ |
| 395 | |
| 396 | /* Set mark in a given file */ |
| 397 | #ifdef WSDEBUG_TRACE |
| 398 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 399 | wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n", |
| 400 | filename, lineno, markId, idx); |
| 401 | #endif |
| 402 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 403 | vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 404 | markId, lineno, idx, filename); |
| 405 | coloncmd(cbuf, TRUE); |
| 406 | } |
| 407 | |
| 408 | void |
| 409 | workshop_change_mark_type( |
| 410 | char *filename, /* filename which gets the mark */ |
| 411 | int markId, /* unique mark identifier */ |
| 412 | int idx) /* which mark to use */ |
| 413 | { |
| 414 | char cbuf[BUFSIZ]; /* command buffer */ |
| 415 | |
| 416 | /* Change mark type */ |
| 417 | #ifdef WSDEBUG_TRACE |
| 418 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 419 | wstrace("workshop_change_mark_type(%s, %d, %d)\n", |
| 420 | filename, markId, idx); |
| 421 | #endif |
| 422 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 423 | vim_snprintf(cbuf, sizeof(cbuf), |
| 424 | "sign place %d name=%d file=%s", markId, idx, filename); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 425 | coloncmd(cbuf, TRUE); |
| 426 | } |
| 427 | |
| 428 | /* |
| 429 | * Goto the given mark in a file (e.g. show it). |
| 430 | * If message is not null, display it in the footer. |
| 431 | */ |
| 432 | void |
| 433 | workshop_goto_mark( |
| 434 | char *filename, |
| 435 | int markId, |
| 436 | char *message) |
| 437 | { |
| 438 | char cbuf[BUFSIZ]; /* command buffer */ |
| 439 | |
| 440 | /* Goto mark */ |
| 441 | #ifdef WSDEBUG_TRACE |
| 442 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 443 | wstrace("workshop_goto_mark(%s, %d (id), %s)\n", |
| 444 | filename, markId, message && *message && |
| 445 | !(*message == ' ' && message[1] == NULL) ? |
| 446 | message : "<None>"); |
| 447 | #endif |
| 448 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 449 | vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 450 | coloncmd(cbuf, TRUE); |
| 451 | if (message != NULL && *message != NUL) |
| 452 | gui_mch_set_footer((char_u *)message); |
| 453 | } |
| 454 | |
| 455 | void |
| 456 | workshop_delete_mark( |
| 457 | char *filename, |
| 458 | int markId) |
| 459 | { |
| 460 | char cbuf[BUFSIZ]; /* command buffer */ |
| 461 | |
| 462 | /* Delete mark */ |
| 463 | #ifdef WSDEBUG_TRACE |
| 464 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 465 | wstrace("workshop_delete_mark(%s, %d (id))\n", |
| 466 | filename, markId); |
| 467 | #endif |
| 468 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 469 | vim_snprintf(cbuf, sizeof(cbuf), |
| 470 | "sign unplace %d file=%s", markId, filename); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 471 | coloncmd(cbuf, TRUE); |
| 472 | } |
| 473 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 474 | int |
| 475 | workshop_get_mark_lineno( |
| 476 | char *filename, |
| 477 | int markId) |
| 478 | { |
| 479 | buf_T *buf; /* buffer containing filename */ |
| 480 | int lineno; /* line number of filename in buf */ |
| 481 | |
| 482 | /* Get mark line number */ |
| 483 | #ifdef WSDEBUG_TRACE |
| 484 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 485 | wstrace("workshop_get_mark_lineno(%s, %d)\n", |
| 486 | filename, markId); |
| 487 | #endif |
| 488 | |
| 489 | lineno = 0; |
| 490 | buf = buflist_findname((char_u *)filename); |
| 491 | if (buf != NULL) |
| 492 | lineno = buf_findsign(buf, markId); |
| 493 | |
| 494 | return lineno; |
| 495 | } |
| 496 | |
| 497 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 498 | /* |
| 499 | * Are there any moved marks? If so, call workshop_move_mark on |
| 500 | * each of them now. This is how eserve can find out if for example |
| 501 | * breakpoints have moved when a program has been recompiled and |
| 502 | * reloaded into dbx. |
| 503 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 504 | void |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 505 | workshop_moved_marks(char *filename UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 506 | { |
| 507 | #ifdef WSDEBUG_TRACE |
| 508 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 509 | wstrace("XXXworkshop_moved_marks(%s)\n", filename); |
| 510 | #endif |
| 511 | } |
| 512 | |
| 513 | int |
| 514 | workshop_get_font_height() |
| 515 | { |
| 516 | XmFontList fontList; /* fontList made from gui.norm_font */ |
| 517 | XmString str; |
| 518 | Dimension w; |
| 519 | Dimension h; |
| 520 | |
| 521 | #ifdef WSDEBUG_TRACE |
| 522 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 523 | wstrace("workshop_get_font_height()\n"); |
| 524 | #endif |
| 525 | |
| 526 | /* Pick the proper signs for this font size */ |
| 527 | fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font); |
| 528 | h = 0; |
| 529 | if (fontList != NULL) |
| 530 | { |
| 531 | str = XmStringCreateLocalized("A"); |
| 532 | XmStringExtent(fontList, str, &w, &h); |
| 533 | XmStringFree(str); |
| 534 | XmFontListFree(fontList); |
| 535 | } |
| 536 | |
| 537 | return (int)h; |
| 538 | } |
| 539 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 540 | void |
| 541 | workshop_footer_message( |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 542 | char *message, |
| 543 | int severity UNUSED) /* severity is currently unused */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 544 | { |
| 545 | #ifdef WSDEBUG_TRACE |
| 546 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 547 | wstrace("workshop_footer_message(%s, %d)\n", message, severity); |
| 548 | #endif |
| 549 | |
| 550 | gui_mch_set_footer((char_u *) message); |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | * workshop_menu_begin() is passed the menu name. We determine its mnemonic |
| 555 | * here and store its name and priority. |
| 556 | */ |
| 557 | void |
| 558 | workshop_menu_begin( |
| 559 | char *label) |
| 560 | { |
| 561 | vimmenu_T *menu; /* pointer to last menu */ |
| 562 | int menuPriority = 0; /* priority of new menu */ |
| 563 | char mnembuf[64]; /* store menubar mnemonics here */ |
| 564 | char *name; /* label with a mnemonic */ |
| 565 | char *p; /* used to find mnemonics */ |
| 566 | int idx; /* index into mnembuf */ |
| 567 | |
| 568 | #ifdef WSDEBUG_TRACE |
| 569 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 570 | wstrace("workshop_menu_begin()\n"); |
| 571 | #endif |
| 572 | |
| 573 | /* |
| 574 | * Look through all existing (non-PopUp and non-Toolbar) menus |
| 575 | * and gather their mnemonics. Use this list to decide what |
| 576 | * mnemonic should be used for label. |
| 577 | */ |
| 578 | |
| 579 | idx = 0; |
| 580 | mnembuf[idx++] = 'H'; /* H is mnemonic for Help */ |
| 581 | for (menu = root_menu; menu != NULL; menu = menu->next) |
| 582 | { |
| 583 | if (menu_is_menubar(menu->name)) |
| 584 | { |
| 585 | p = strchr((char *)menu->name, '&'); |
| 586 | if (p != NULL) |
| 587 | mnembuf[idx++] = *++p; |
| 588 | } |
| 589 | if (menu->next != NULL |
| 590 | && strcmp((char *) menu->next->dname, "Help") == 0) |
| 591 | { |
| 592 | menuPriority = menu->priority + 10; |
| 593 | break; |
| 594 | } |
| 595 | } |
| 596 | mnembuf[idx++] = NUL; |
| 597 | name = addUniqueMnemonic(mnembuf, label); |
| 598 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 599 | vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 600 | sprintf(curMenuPriority, "%d.0", menuPriority); |
| 601 | } |
| 602 | |
| 603 | /* |
| 604 | * Append the name and priority to strings to be used in vim menu commands. |
| 605 | */ |
| 606 | void |
| 607 | workshop_submenu_begin( |
| 608 | char *label) |
| 609 | { |
| 610 | #ifdef WSDEBUG_TRACE |
| 611 | if (ws_debug && ws_dlevel & WS_TRACE |
| 612 | && strncmp(curMenuName, "ToolBar", 7) != 0) |
| 613 | wstrace("workshop_submenu_begin(%s)\n", label); |
| 614 | #endif |
| 615 | |
| 616 | strcat(curMenuName, "."); |
| 617 | strcat(curMenuName, fixup(label)); |
| 618 | |
| 619 | updatePriority(True); |
| 620 | } |
| 621 | |
| 622 | /* |
| 623 | * Remove the submenu name and priority from curMenu*. |
| 624 | */ |
| 625 | |
| 626 | void |
| 627 | workshop_submenu_end() |
| 628 | { |
| 629 | char *p; |
| 630 | |
| 631 | #ifdef WSDEBUG_TRACE |
| 632 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE) |
| 633 | && strncmp(curMenuName, "ToolBar", 7) != 0) |
| 634 | wstrace("workshop_submenu_end()\n"); |
| 635 | #endif |
| 636 | |
| 637 | p = strrchr(curMenuPriority, '.'); |
| 638 | ASSERT(p != NULL); |
| 639 | *p = NUL; |
| 640 | |
| 641 | p = strrchr(curMenuName, '.'); |
| 642 | ASSERT(p != NULL); |
| 643 | *p = NUL; |
| 644 | } |
| 645 | |
| 646 | /* |
| 647 | * This is where menus are really made. Each item will generate an amenu vim |
| 648 | * command. The globals curMenuName and curMenuPriority contain the name and |
| 649 | * priority of the parent menu tree. |
| 650 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 651 | void |
| 652 | workshop_menu_item( |
| 653 | char *label, |
| 654 | char *verb, |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 655 | char *accelerator UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 656 | char *acceleratorText, |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 657 | char *name UNUSED, |
| 658 | char *filepos UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 659 | char *sensitive) |
| 660 | { |
| 661 | char cbuf[BUFSIZ]; |
| 662 | char namebuf[BUFSIZ]; |
| 663 | char accText[BUFSIZ]; |
| 664 | |
| 665 | #ifdef WSDEBUG_TRACE |
| 666 | if (WSDLEVEL(WS_TRACE_VERBOSE) |
| 667 | && strncmp(curMenuName, "ToolBar", 7) != 0) |
| 668 | { |
| 669 | if (ws_dlevel & WS_TRACE_VERBOSE) |
| 670 | wsdebug("workshop_menu_item(\n" |
| 671 | "\tlabel = \"%s\",\n" |
| 672 | "\tverb = %s,\n" |
| 673 | "\taccelerator = %s,\n" |
| 674 | "\tacceleratorText = \"%s\",\n" |
| 675 | "\tname = %s,\n" |
| 676 | "\tfilepos = %s,\n" |
| 677 | "\tsensitive = %s)\n", |
| 678 | label && *label ? label : "<None>", |
| 679 | verb && *verb ? verb : "<None>", |
| 680 | accelerator && *accelerator ? |
| 681 | accelerator : "<None>", |
| 682 | acceleratorText && *acceleratorText ? |
| 683 | acceleratorText : "<None>", |
| 684 | name && *name ? name : "<None>", |
| 685 | filepos && *filepos ? filepos : "<None>", |
| 686 | sensitive); |
| 687 | else if (ws_dlevel & WS_TRACE) |
| 688 | wstrace("workshop_menu_item(\"%s\", %s)\n", |
| 689 | label && *label ? label : "<None>", |
| 690 | verb && *verb ? verb : "<None>", sensitive); |
| 691 | } |
| 692 | #endif |
| 693 | #ifdef WSDEBUG_SENSE |
| 694 | if (ws_debug) |
| 695 | wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb, |
| 696 | *sensitive == '1' ? "Sensitive" : "Insensitive"); |
| 697 | #endif |
| 698 | |
| 699 | if (acceleratorText != NULL) |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 700 | vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 701 | else |
| 702 | accText[0] = NUL; |
| 703 | updatePriority(False); |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 704 | vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label)); |
| 705 | vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 706 | curMenuPriority, namebuf, accText, verb); |
| 707 | |
| 708 | coloncmd(cbuf, TRUE); |
| 709 | addMenu(namebuf, fixAccelText(acceleratorText), verb); |
| 710 | |
| 711 | if (*sensitive == '0') |
| 712 | { |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 713 | vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 714 | coloncmd(cbuf, TRUE); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | /* |
| 719 | * This function is called when a complete WorkShop menu description has been |
| 720 | * sent over from eserve. We do some menu cleanup. |
| 721 | */ |
| 722 | |
| 723 | void |
| 724 | workshop_menu_end() |
| 725 | { |
| 726 | Boolean using_tearoff; /* set per current option setting */ |
| 727 | |
| 728 | #ifdef WSDEBUG_TRACE |
| 729 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 730 | wstrace("workshop_menu_end()\n"); |
| 731 | #endif |
| 732 | |
| 733 | using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL; |
| 734 | gui_mch_toggle_tearoffs(using_tearoff); |
| 735 | } |
| 736 | |
| 737 | void |
| 738 | workshop_toolbar_begin() |
| 739 | { |
| 740 | #ifdef WSDEBUG_TRACE |
| 741 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 742 | wstrace("workshop_toolbar_begin()\n"); |
| 743 | #endif |
| 744 | |
| 745 | coloncmd("aunmenu ToolBar", True); |
| 746 | tbpri = 10; |
| 747 | } |
| 748 | |
| 749 | void |
| 750 | workshop_toolbar_end() |
| 751 | { |
| 752 | char_u buf[64]; |
| 753 | |
| 754 | #ifdef WSDEBUG_TRACE |
| 755 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 756 | { |
| 757 | wstrace("workshop_toolbar_end()\n"); |
| 758 | } |
| 759 | #endif |
| 760 | |
| 761 | /* |
| 762 | * Turn on ToolBar. |
| 763 | */ |
| 764 | STRCPY(buf, p_go); |
| 765 | if (vim_strchr(p_go, 'T') == NULL) |
| 766 | { |
| 767 | STRCAT(buf, "T"); |
| 768 | set_option_value((char_u *)"go", 0L, buf, 0); |
| 769 | } |
| 770 | workshopInitDone = True; |
| 771 | } |
| 772 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 773 | void |
| 774 | workshop_toolbar_button( |
| 775 | char *label, |
| 776 | char *verb, |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 777 | char *senseVerb UNUSED, |
| 778 | char *filepos UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 779 | char *help, |
| 780 | char *sense, |
| 781 | char *file, |
| 782 | char *left) |
| 783 | { |
| 784 | char cbuf[BUFSIZ + MAXPATHLEN]; |
| 785 | char namebuf[BUFSIZ]; |
| 786 | static int tbid = 1; |
| 787 | char_u *p; |
| 788 | |
| 789 | #ifdef WSDEBUG_TRACE |
| 790 | if (WSDLEVEL(WS_TRACE_VERBOSE)) |
| 791 | wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n" |
| 792 | "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n", |
| 793 | label && *label ? label : "<None>", |
| 794 | verb && *verb ? verb : "<None>", |
| 795 | senseVerb && *senseVerb ? senseVerb : "<None>", |
| 796 | filepos && *filepos ? filepos : "<None>", |
| 797 | help && *help ? help : "<None>", |
| 798 | sense && *sense ? sense : "<None>", |
| 799 | file && *file ? file : "<None>", |
| 800 | left && *left ? left : "<None>"); |
| 801 | else if (WSDLEVEL(WS_TRACE)) |
| 802 | wstrace("workshop_toolbar_button(\"%s\", %s)\n", |
| 803 | label && *label ? label : "<None>", |
| 804 | verb && *verb ? verb : "<None>"); |
| 805 | #endif |
| 806 | #ifdef WSDEBUG_SENSE |
| 807 | if (ws_debug) |
| 808 | wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb, |
| 809 | *sense == '1' ? "Sensitive" : "Insensitive"); |
| 810 | #endif |
| 811 | |
| 812 | if (left && *left && atoi(left) > 0) |
| 813 | { |
| 814 | /* Add a separator (but pass the width passed after the ':') */ |
| 815 | sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>", |
| 816 | tbpri - 5, tbid++, left); |
| 817 | |
| 818 | coloncmd(cbuf, True); |
| 819 | } |
| 820 | |
| 821 | p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. "); |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 822 | vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 823 | vim_free(p); |
| 824 | STRCPY(cbuf, "amenu <silent> "); |
| 825 | if (file != NULL && *file != NUL) |
| 826 | { |
| 827 | p = vim_strsave_escaped((char_u *)file, (char_u *)" "); |
Bram Moolenaar | a800b42 | 2010-06-27 01:15:55 +0200 | [diff] [blame] | 828 | vim_snprintf_add(cbuf, sizeof(cbuf), "icon=%s ", p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 829 | vim_free(p); |
| 830 | } |
Bram Moolenaar | a800b42 | 2010-06-27 01:15:55 +0200 | [diff] [blame] | 831 | vim_snprintf_add(cbuf, sizeof(cbuf),"1.%d %s :wsverb %s<CR>", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 832 | tbpri, namebuf, verb); |
| 833 | |
| 834 | /* Define the menu item */ |
| 835 | coloncmd(cbuf, True); |
| 836 | |
| 837 | if (*sense == '0') |
| 838 | { |
| 839 | /* If menu isn't sensitive at startup... */ |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 840 | vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 841 | coloncmd(cbuf, True); |
| 842 | } |
| 843 | |
| 844 | if (help && *help) |
| 845 | { |
| 846 | /* Do the tooltip */ |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 847 | vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 848 | coloncmd(cbuf, True); |
| 849 | } |
| 850 | |
| 851 | addMenu(namebuf, NULL, verb); |
| 852 | tbpri += 10; |
| 853 | } |
| 854 | |
| 855 | void |
| 856 | workshop_frame_sensitivities( |
| 857 | VerbSense *vs) /* list of verbs to (de)sensitize */ |
| 858 | { |
| 859 | VerbSense *vp; /* iterate through vs */ |
| 860 | char *menu_name; /* used in menu lookup */ |
| 861 | int cnt; /* count of verbs to skip */ |
| 862 | int len; /* length of nonvariant part of command */ |
| 863 | char cbuf[4096]; |
| 864 | |
| 865 | #ifdef WSDEBUG_TRACE |
| 866 | if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4)) |
| 867 | { |
| 868 | wsdebug("workshop_frame_sensitivities(\n"); |
| 869 | for (vp = vs; vp->verb != NULL; vp++) |
| 870 | wsdebug("\t%-25s%d\n", vp->verb, vp->sense); |
| 871 | wsdebug(")\n"); |
| 872 | } |
| 873 | else if (WSDLEVEL(WS_TRACE)) |
| 874 | wstrace("workshop_frame_sensitivities()\n"); |
| 875 | #endif |
| 876 | #ifdef WSDEBUG_SENSE |
| 877 | if (ws_debug) |
| 878 | for (vp = vs; vp->verb != NULL; vp++) |
| 879 | wsdebug("change: %-21.20s%-21.20s(%s)\n", |
| 880 | "", vp->verb, vp->sense == 1 ? |
| 881 | "Sensitive" : "Insensitive"); |
| 882 | #endif |
| 883 | |
| 884 | /* |
| 885 | * Look for all matching menu entries for the verb. There may be more |
| 886 | * than one if the verb has both a menu and toolbar entry. |
| 887 | */ |
| 888 | for (vp = vs; vp->verb != NULL; vp++) |
| 889 | { |
| 890 | cnt = 0; |
| 891 | strcpy(cbuf, "amenu"); |
| 892 | strcat(cbuf, " "); |
| 893 | strcat(cbuf, vp->sense ? "enable" : "disable"); |
| 894 | strcat(cbuf, " "); |
| 895 | len = strlen(cbuf); |
| 896 | while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL) |
| 897 | { |
| 898 | strcpy(&cbuf[len], menu_name); |
| 899 | coloncmd(cbuf, FALSE); |
| 900 | } |
| 901 | } |
| 902 | gui_update_menus(0); |
| 903 | gui_mch_flush(); |
| 904 | } |
| 905 | |
| 906 | void |
| 907 | workshop_set_option( |
| 908 | char *option, /* name of a supported option */ |
| 909 | char *value) /* value to set option to */ |
| 910 | { |
| 911 | char cbuf[BUFSIZ]; /* command buffer */ |
| 912 | |
| 913 | #ifdef WSDEBUG_TRACE |
| 914 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 915 | { |
| 916 | wstrace("workshop_set_option(%s, %s)\n", option, value); |
| 917 | } |
| 918 | #endif |
| 919 | |
| 920 | cbuf[0] = NUL; |
| 921 | switch (*option) /* switch on 1st letter */ |
| 922 | { |
| 923 | case 's': |
| 924 | if (strcmp(option, "syntax") == 0) |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 925 | vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 926 | else if (strcmp(option, "savefiles") == 0) |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 927 | { |
| 928 | /* XXX - Not yet implemented */ |
| 929 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 930 | break; |
| 931 | |
| 932 | case 'l': |
| 933 | if (strcmp(option, "lineno") == 0) |
| 934 | sprintf(cbuf, "set %snu", |
| 935 | (strcmp(value, "on") == 0) ? "" : "no"); |
| 936 | break; |
| 937 | |
| 938 | case 'p': |
| 939 | if (strcmp(option, "parentheses") == 0) |
| 940 | sprintf(cbuf, "set %ssm", |
| 941 | (strcmp(value, "on") == 0) ? "" : "no"); |
| 942 | break; |
| 943 | |
| 944 | case 'w': |
| 945 | /* this option is set by a direct call */ |
| 946 | #ifdef WSDEBUG |
| 947 | wsdebug("workshop_set_option: " |
| 948 | "Got unexpected workshopkeys option"); |
| 949 | #endif |
| 950 | break; |
| 951 | |
| 952 | case 'b': /* these options are set from direct calls */ |
| 953 | if (option[7] == NUL && strcmp(option, "balloon") == 0) |
| 954 | { |
| 955 | #ifdef WSDEBUG |
| 956 | /* set by direct call to workshop_balloon_mode */ |
| 957 | wsdebug("workshop_set_option: " |
| 958 | "Got unexpected ballooneval option"); |
| 959 | #endif |
| 960 | } |
| 961 | else if (strcmp(option, "balloondelay") == 0) |
| 962 | { |
| 963 | #ifdef WSDEBUG |
| 964 | /* set by direct call to workshop_balloon_delay */ |
| 965 | wsdebug("workshop_set_option: " |
| 966 | "Got unexpected balloondelay option"); |
| 967 | #endif |
| 968 | } |
| 969 | break; |
| 970 | } |
| 971 | if (cbuf[0] != NUL) |
| 972 | coloncmd(cbuf, TRUE); |
| 973 | } |
| 974 | |
| 975 | |
| 976 | void |
| 977 | workshop_balloon_mode( |
| 978 | Boolean on) |
| 979 | { |
| 980 | char cbuf[BUFSIZ]; /* command buffer */ |
| 981 | |
| 982 | #ifdef WSDEBUG_TRACE |
| 983 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 984 | wstrace("workshop_balloon_mode(%s)\n", on ? "True" : "False"); |
| 985 | #endif |
| 986 | |
| 987 | sprintf(cbuf, "set %sbeval", on ? "" : "no"); |
| 988 | coloncmd(cbuf, TRUE); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | void |
| 993 | workshop_balloon_delay( |
| 994 | int delay) |
| 995 | { |
| 996 | char cbuf[BUFSIZ]; /* command buffer */ |
| 997 | |
| 998 | #ifdef WSDEBUG_TRACE |
| 999 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 1000 | wstrace("workshop_balloon_delay(%d)\n", delay); |
| 1001 | #endif |
| 1002 | |
| 1003 | sprintf(cbuf, "set bdlay=%d", delay); |
| 1004 | coloncmd(cbuf, TRUE); |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | void |
| 1009 | workshop_show_balloon_tip( |
| 1010 | char *tip) |
| 1011 | { |
| 1012 | #ifdef WSDEBUG_TRACE |
| 1013 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 1014 | wstrace("workshop_show_balloon_tip(%s)\n", tip); |
| 1015 | #endif |
| 1016 | |
| 1017 | if (balloonEval != NULL) |
| 1018 | gui_mch_post_balloon(balloonEval, (char_u *)tip); |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | void |
| 1023 | workshop_hotkeys( |
| 1024 | Boolean on) |
| 1025 | { |
| 1026 | char cbuf[BUFSIZ]; /* command buffer */ |
| 1027 | MenuMap *mp; /* iterate over menuMap entries */ |
| 1028 | |
| 1029 | #ifdef WSDEBUG_TRACE |
| 1030 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 1031 | wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False"); |
| 1032 | #endif |
| 1033 | |
| 1034 | workshopHotKeysEnabled = on; |
| 1035 | if (workshopHotKeysEnabled) |
| 1036 | for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) |
| 1037 | { |
| 1038 | if (mp->accel != NULL) |
| 1039 | { |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1040 | vim_snprintf(cbuf, sizeof(cbuf), |
| 1041 | "map %s :wsverb %s<CR>", mp->accel, mp->verb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1042 | coloncmd(cbuf, TRUE); |
| 1043 | } |
| 1044 | } |
| 1045 | else |
| 1046 | for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) |
| 1047 | { |
| 1048 | if (mp->accel != NULL) |
| 1049 | { |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1050 | vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1051 | coloncmd(cbuf, TRUE); |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /* |
| 1057 | * A button in the toolbar has been pushed. |
| 1058 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1059 | int |
| 1060 | workshop_get_positions( |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1061 | void *clientData UNUSED, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1062 | char **filename, /* output data */ |
| 1063 | int *curLine, /* output data */ |
| 1064 | int *curCol, /* output data */ |
| 1065 | int *selStartLine, /* output data */ |
| 1066 | int *selStartCol, /* output data */ |
| 1067 | int *selEndLine, /* output data */ |
| 1068 | int *selEndCol, /* output data */ |
| 1069 | int *selLength, /* output data */ |
| 1070 | char **selection) /* output data */ |
| 1071 | { |
| 1072 | static char ffname[MAXPATHLEN]; |
| 1073 | |
| 1074 | #ifdef WSDEBUG_TRACE |
| 1075 | if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) |
| 1076 | wstrace("workshop_get_positions(%#x, \"%s\", ...)\n", |
| 1077 | clientData, (curbuf && curbuf->b_sfname != NULL) |
| 1078 | ? (char *)curbuf->b_sfname : "<None>"); |
| 1079 | #endif |
| 1080 | |
Bram Moolenaar | a40b466 | 2008-11-28 10:47:47 +0000 | [diff] [blame] | 1081 | if (curbuf->b_ffname == NULL) |
| 1082 | ffname[0] = NUL; |
| 1083 | else |
| 1084 | /* copy so nobody can change b_ffname */ |
| 1085 | strcpy(ffname, (char *) curbuf->b_ffname); |
| 1086 | *filename = ffname; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1087 | *curLine = curwin->w_cursor.lnum; |
| 1088 | *curCol = curwin->w_cursor.col; |
| 1089 | |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 1090 | if (curbuf->b_visual.vi_mode == 'v' && |
| 1091 | equalpos(curwin->w_cursor, curbuf->b_visual.vi_end)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1092 | { |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 1093 | *selStartLine = curbuf->b_visual.vi_start.lnum; |
| 1094 | *selStartCol = curbuf->b_visual.vi_start.col; |
| 1095 | *selEndLine = curbuf->b_visual.vi_end.lnum; |
| 1096 | *selEndCol = curbuf->b_visual.vi_end.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1097 | *selection = get_selection(curbuf); |
| 1098 | if (*selection) |
| 1099 | *selLength = strlen(*selection); |
| 1100 | else |
| 1101 | *selLength = 0; |
| 1102 | } |
| 1103 | else |
| 1104 | { |
| 1105 | *selStartLine = *selEndLine = -1; |
| 1106 | *selStartCol = *selEndCol = -1; |
| 1107 | *selLength = 0; |
| 1108 | *selection = ""; |
| 1109 | } |
| 1110 | |
| 1111 | return True; |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | /************************************************************************ |
| 1117 | * Utility functions |
| 1118 | ************************************************************************/ |
| 1119 | |
| 1120 | static char * |
| 1121 | get_selection( |
| 1122 | buf_T *buf) /* buffer whose selection we want */ |
| 1123 | { |
| 1124 | pos_T *start; /* start of the selection */ |
| 1125 | pos_T *end; /* end of the selection */ |
| 1126 | char *lp; /* pointer to actual line data */ |
| 1127 | int llen; /* length of actual line data */ |
| 1128 | char *sp; /* pointer to selection buffer */ |
| 1129 | int slen; /* string length in selection buffer */ |
| 1130 | int size; /* size of selection buffer */ |
| 1131 | char *new_sp; /* temp pointer to new sp */ |
| 1132 | int lnum; /* line number we are appending */ |
| 1133 | |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 1134 | if (buf->b_visual.vi_mode == 'v') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1135 | { |
Bram Moolenaar | a23ccb8 | 2006-02-27 00:08:02 +0000 | [diff] [blame] | 1136 | start = &buf->b_visual.vi_start; |
| 1137 | end = &buf->b_visual.vi_end; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1138 | if (start->lnum == end->lnum) |
| 1139 | { |
| 1140 | /* selection is all on one line */ |
| 1141 | lp = (char *) ml_get_pos(start); |
| 1142 | llen = end->col - start->col + 1; |
| 1143 | sp = (char *) malloc(llen + 1); |
| 1144 | if (sp != NULL) |
| 1145 | { |
| 1146 | strncpy(sp, lp, llen); |
| 1147 | sp[llen] = NUL; |
| 1148 | } |
| 1149 | } |
| 1150 | else |
| 1151 | { |
| 1152 | /* multi-line selection */ |
| 1153 | lp = (char *) ml_get_pos(start); |
| 1154 | llen = strlen(lp); |
| 1155 | sp = (char *) malloc(BUFSIZ + llen); |
| 1156 | if (sp != NULL) |
| 1157 | { |
| 1158 | size = BUFSIZ + llen; |
| 1159 | strcpy(sp, lp); |
| 1160 | sp[llen] = '\n'; |
| 1161 | slen = llen + 1; |
| 1162 | |
| 1163 | lnum = start->lnum + 1; |
| 1164 | while (lnum < end->lnum) |
| 1165 | sp = append_selection(lnum++, sp, &size, &slen); |
| 1166 | |
| 1167 | lp = (char *) ml_get(end->lnum); |
| 1168 | llen = end->col + 1; |
| 1169 | if ((slen + llen) >= size) |
| 1170 | { |
| 1171 | new_sp = (char *) |
| 1172 | realloc(sp, slen + llen + 1); |
| 1173 | if (new_sp != NULL) |
| 1174 | { |
| 1175 | size += llen + 1; |
| 1176 | sp = new_sp; |
| 1177 | } |
| 1178 | } |
| 1179 | if ((slen + llen) < size) |
| 1180 | { |
| 1181 | strncpy(&sp[slen], lp, llen); |
| 1182 | sp[slen + llen] = NUL; |
| 1183 | } |
| 1184 | |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | else |
| 1189 | sp = NULL; |
| 1190 | |
| 1191 | return sp; |
| 1192 | } |
| 1193 | |
| 1194 | static char * |
| 1195 | append_selection( |
| 1196 | int lnum, /* line number to append */ |
| 1197 | char *sp, /* pointer to selection buffer */ |
| 1198 | int *size, /* ptr to size of sp */ |
| 1199 | int *slen) /* ptr to length of selection string */ |
| 1200 | { |
| 1201 | char *lp; /* line of data from buffer */ |
| 1202 | int llen; /* strlen of lp */ |
| 1203 | char *new_sp; /* temp pointer to new sp */ |
| 1204 | |
| 1205 | lp = (char *)ml_get((linenr_T)lnum); |
| 1206 | llen = strlen(lp); |
| 1207 | |
| 1208 | if ((*slen + llen) <= *size) |
| 1209 | { |
| 1210 | new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen); |
| 1211 | if (*new_sp != NUL) |
| 1212 | { |
| 1213 | *size = BUFSIZ + *slen + llen; |
| 1214 | sp = new_sp; |
| 1215 | } |
| 1216 | } |
| 1217 | if ((*slen + llen) > *size) |
| 1218 | { |
| 1219 | strcat(&sp[*slen], lp); |
| 1220 | *slen += llen; |
| 1221 | sp[*slen++] = '\n'; |
| 1222 | } |
| 1223 | |
| 1224 | return sp; |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | static void |
| 1230 | load_buffer_by_name( |
| 1231 | char *filename, /* the file to load */ |
| 1232 | int lnum) /* an optional line number (or 0) */ |
| 1233 | { |
| 1234 | char lnumbuf[16]; /* make line number option for :e */ |
| 1235 | char cbuf[BUFSIZ]; /* command buffer */ |
| 1236 | |
| 1237 | if (lnum > 0) |
| 1238 | sprintf(lnumbuf, "+%d", lnum); |
| 1239 | else |
| 1240 | lnumbuf[0] = NUL; |
| 1241 | |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1242 | vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1243 | coloncmd(cbuf, False); |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | static void |
| 1248 | load_window( |
| 1249 | char *filename, /* filename to load */ |
| 1250 | int lnum) /* linenumber to go to */ |
| 1251 | { |
| 1252 | buf_T *buf; /* buffer filename is stored in */ |
| 1253 | win_T *win; /* window filenme is displayed in */ |
| 1254 | |
| 1255 | /* |
| 1256 | * Make sure filename is displayed and is the current window. |
| 1257 | */ |
| 1258 | |
| 1259 | buf = buflist_findname((char_u *)filename); |
| 1260 | if (buf == NULL || (win = get_window(buf)) == NULL) |
| 1261 | { |
| 1262 | /* No buffer or buffer is not in current window */ |
| 1263 | /* wsdebug("load_window: load_buffer_by_name(\"%s\", %d)\n", |
| 1264 | filename, lnum); */ |
| 1265 | load_buffer_by_name(filename, lnum); |
| 1266 | } |
| 1267 | else |
| 1268 | { |
Bram Moolenaar | a8ffcbb | 2010-06-21 06:15:46 +0200 | [diff] [blame] | 1269 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1270 | /* buf is in a window */ |
| 1271 | if (win != curwin) |
| 1272 | { |
| 1273 | win_enter(win, False); |
Bram Moolenaar | a8ffcbb | 2010-06-21 06:15:46 +0200 | [diff] [blame] | 1274 | /* wsdebug("load_window: window enter %s\n", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | win->w_buffer->b_sfname); */ |
| 1276 | } |
Bram Moolenaar | a8ffcbb | 2010-06-21 06:15:46 +0200 | [diff] [blame] | 1277 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1278 | if (lnum > 0 && win->w_cursor.lnum != lnum) |
| 1279 | { |
| 1280 | warp_to_pc(lnum); |
| 1281 | /* wsdebug("load_window: warp to %s[%d]\n", |
| 1282 | win->w_buffer->b_sfname, lnum); */ |
| 1283 | } |
| 1284 | } |
| 1285 | out_flush(); |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | static void |
| 1291 | warp_to_pc( |
| 1292 | int lnum) /* line number to warp to */ |
| 1293 | { |
Bram Moolenaar | 720c710 | 2007-05-10 18:07:50 +0000 | [diff] [blame] | 1294 | char lbuf[256]; /* build line command here */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1295 | |
| 1296 | if (lnum > 0) |
| 1297 | { |
| 1298 | if (State & INSERT) |
| 1299 | add_to_input_buf((char_u *) "\033", 1); |
| 1300 | if (isShowing(lnum)) |
| 1301 | sprintf(lbuf, "%dG", lnum); |
| 1302 | else |
| 1303 | sprintf(lbuf, "%dz.", lnum); |
| 1304 | add_to_input_buf((char_u *) lbuf, strlen(lbuf)); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | static Boolean |
| 1309 | isShowing( |
| 1310 | int lnum) /* tell if line number is showing */ |
| 1311 | { |
| 1312 | return lnum >= curwin->w_topline && lnum < curwin->w_botline; |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | static win_T * |
| 1318 | get_window( |
| 1319 | buf_T *buf) /* buffer to find window for */ |
| 1320 | { |
| 1321 | win_T *wp = NULL; /* window filename is in */ |
| 1322 | |
| 1323 | for (wp = firstwin; wp != NULL; wp = W_NEXT(wp)) |
| 1324 | if (buf == wp->w_buffer) |
| 1325 | break; |
| 1326 | return wp; |
| 1327 | } |
| 1328 | |
| 1329 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1330 | static void |
| 1331 | updatePriority( |
| 1332 | Boolean subMenu) /* if True then start new submenu pri */ |
| 1333 | { |
| 1334 | int pri; /* priority of this menu/item */ |
| 1335 | char *p; |
| 1336 | |
| 1337 | p = strrchr(curMenuPriority, '.'); |
| 1338 | ASSERT(p != NULL); |
| 1339 | *p++ = NUL; |
| 1340 | |
| 1341 | pri = atoi(p) + 10; /* our new priority */ |
| 1342 | |
| 1343 | if (subMenu) |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1344 | vim_snprintf(curMenuPriority, sizeof(curMenuPriority), |
| 1345 | "%s.%d.0", curMenuPriority, pri); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1346 | else |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1347 | vim_snprintf(curMenuPriority, sizeof(curMenuPriority), |
| 1348 | "%s.%d", curMenuPriority, pri); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | static char * |
| 1352 | addUniqueMnemonic( |
| 1353 | char *mnemonics, /* currently used mnemonics */ |
| 1354 | char *label) /* label of menu needing mnemonic */ |
| 1355 | { |
| 1356 | static char name[BUFSIZ]; /* buffer for the updated name */ |
| 1357 | char *p; /* pointer into label */ |
| 1358 | char *found; /* pointer to possible mnemonic */ |
| 1359 | |
| 1360 | found = NULL; |
| 1361 | for (p = label; *p != NUL; p++) |
| 1362 | if (strchr(mnemonics, *p) == 0) |
| 1363 | if (found == NULL || (isupper((int)*p) && islower((int)*found))) |
| 1364 | found = p; |
| 1365 | |
| 1366 | if (found != NULL) |
| 1367 | { |
| 1368 | strncpy(name, label, (found - label)); |
| 1369 | strcat(name, "&"); |
| 1370 | strcat(name, found); |
| 1371 | } |
| 1372 | else |
| 1373 | strcpy(name, label); |
| 1374 | |
| 1375 | return name; |
| 1376 | } |
| 1377 | |
| 1378 | /* |
| 1379 | * Some characters in a menu name must be escaped in vim. Since this is vim |
| 1380 | * specific, it must be done on this side. |
| 1381 | */ |
| 1382 | static char * |
| 1383 | fixup( |
| 1384 | char *label) |
| 1385 | { |
| 1386 | static char buf[BUFSIZ]; |
| 1387 | char *bp; /* pointer into buf */ |
| 1388 | char *lp; /* pointer into label */ |
| 1389 | |
| 1390 | lp = label; |
| 1391 | bp = buf; |
| 1392 | while (*lp != NUL) |
| 1393 | { |
| 1394 | if (*lp == ' ' || *lp == '.') |
| 1395 | *bp++ = '\\'; |
| 1396 | *bp++ = *lp++; |
| 1397 | } |
| 1398 | *bp = NUL; |
| 1399 | |
| 1400 | return buf; |
| 1401 | } |
| 1402 | |
| 1403 | |
| 1404 | #ifdef NOHANDS_SUPPORT_FUNCTIONS |
| 1405 | |
| 1406 | /* For the NoHands test suite */ |
| 1407 | |
| 1408 | char * |
| 1409 | workshop_test_getcurrentfile() |
| 1410 | { |
| 1411 | char *filename, *selection; |
| 1412 | int curLine, curCol, selStartLine, selStartCol, selEndLine; |
| 1413 | int selEndCol, selLength; |
| 1414 | |
| 1415 | if (workshop_get_positions( |
| 1416 | NULL, &filename, &curLine, &curCol, &selStartLine, |
| 1417 | &selStartCol, &selEndLine, &selEndCol, &selLength, |
| 1418 | &selection)) |
| 1419 | return filename; |
| 1420 | else |
| 1421 | return NULL; |
| 1422 | } |
| 1423 | |
| 1424 | int |
| 1425 | workshop_test_getcursorrow() |
| 1426 | { |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
| 1430 | int |
| 1431 | workshop_test_getcursorcol() |
| 1432 | { |
| 1433 | char *filename, *selection; |
| 1434 | int curLine, curCol, selStartLine, selStartCol, selEndLine; |
| 1435 | int selEndCol, selLength; |
| 1436 | |
| 1437 | if (workshop_get_positions( |
| 1438 | NULL, &filename, &curLine, &curCol, &selStartLine, |
| 1439 | &selStartCol, &selEndLine, &selEndCol, &selLength, |
| 1440 | &selection)) |
| 1441 | return curCol; |
| 1442 | else |
| 1443 | return -1; |
| 1444 | } |
| 1445 | |
| 1446 | char * |
| 1447 | workshop_test_getcursorrowtext() |
| 1448 | { |
| 1449 | return NULL; |
| 1450 | } |
| 1451 | |
| 1452 | char * |
| 1453 | workshop_test_getselectedtext() |
| 1454 | { |
| 1455 | char *filename, *selection; |
| 1456 | int curLine, curCol, selStartLine, selStartCol, selEndLine; |
| 1457 | int selEndCol, selLength; |
| 1458 | |
| 1459 | if (workshop_get_positions( |
| 1460 | NULL, &filename, &curLine, &curCol, &selStartLine, |
| 1461 | &selStartCol, &selEndLine, &selEndCol, &selLength, |
| 1462 | &selection)) |
| 1463 | return selection; |
| 1464 | else |
| 1465 | return NULL; |
| 1466 | } |
| 1467 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1468 | void |
Bram Moolenaar | 4bdbbf7 | 2009-05-21 21:27:43 +0000 | [diff] [blame] | 1469 | workshop_save_sensitivity(char *filename UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1470 | { |
| 1471 | } |
| 1472 | |
| 1473 | #endif |
| 1474 | |
| 1475 | static char * |
| 1476 | fixAccelText( |
| 1477 | char *ap) /* original acceleratorText */ |
| 1478 | { |
| 1479 | char buf[256]; /* build in temp buffer */ |
| 1480 | char *shift; /* shift string of "" */ |
| 1481 | |
| 1482 | if (ap == NULL) |
| 1483 | return NULL; |
| 1484 | |
| 1485 | /* If the accelerator is shifted use the vim form */ |
| 1486 | if (strncmp("Shift+", ap, 6) == 0) |
| 1487 | { |
| 1488 | shift = "S-"; |
| 1489 | ap += 6; |
| 1490 | } |
| 1491 | else |
| 1492 | shift = ""; |
| 1493 | |
| 1494 | if (*ap == 'F' && atoi(&ap[1]) > 0) |
| 1495 | { |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1496 | vim_snprintf(buf, sizeof(buf), "<%s%s>", shift, ap); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1497 | return strdup(buf); |
| 1498 | } |
| 1499 | else |
| 1500 | return NULL; |
| 1501 | } |
| 1502 | |
| 1503 | #ifdef FEAT_BEVAL |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 1504 | void |
| 1505 | workshop_beval_cb( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1506 | BalloonEval *beval, |
| 1507 | int state) |
| 1508 | { |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 1509 | win_T *wp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1510 | char_u *text; |
| 1511 | int type; |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 1512 | linenr_T lnum; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1513 | int col; |
| 1514 | int idx; |
| 1515 | char buf[MAXPATHLEN * 2]; |
| 1516 | static int serialNo = -1; |
| 1517 | |
| 1518 | if (!p_beval) |
| 1519 | return; |
| 1520 | |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 1521 | if (get_beval_info(beval, FALSE, &wp, &lnum, &text, &col) == OK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1522 | { |
| 1523 | if (text && text[0]) |
| 1524 | { |
| 1525 | /* Send debugger request */ |
| 1526 | if (strlen((char *) text) > (MAXPATHLEN/2)) |
| 1527 | { |
| 1528 | /* |
| 1529 | * The user has probably selected the entire |
| 1530 | * buffer or something like that - don't attempt |
| 1531 | * to evaluate it |
| 1532 | */ |
| 1533 | return; |
| 1534 | } |
| 1535 | |
| 1536 | /* |
| 1537 | * WorkShop expects the col to be a character index, not |
| 1538 | * a column number. Compute the index from col. Also set |
| 1539 | * line to 0 because thats what dbx expects. |
| 1540 | */ |
| 1541 | idx = computeIndex(col, text, beval->ts); |
| 1542 | if (idx > 0) |
| 1543 | { |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 1544 | lnum = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1545 | |
| 1546 | /* |
| 1547 | * If successful, it will respond with a balloon cmd. |
| 1548 | */ |
| 1549 | if (state & ControlMask) |
| 1550 | /* Evaluate *(expression) */ |
| 1551 | type = (int)GPLineEval_INDIRECT; |
| 1552 | else if (state & ShiftMask) |
| 1553 | /* Evaluate type(expression) */ |
| 1554 | type = (int)GPLineEval_TYPE; |
| 1555 | else |
| 1556 | /* Evaluate value(expression) */ |
| 1557 | type = (int)GPLineEval_EVALUATE; |
| 1558 | |
| 1559 | /* Send request to dbx */ |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1560 | vim_snprintf(buf, sizeof(buf), "toolVerb debug.balloonEval " |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 1561 | "%s %ld,0 %d,0 %d,%d %ld %s\n", |
| 1562 | (char *)wp->w_buffer->b_ffname, |
| 1563 | (long)lnum, idx, type, serialNo++, |
| 1564 | (long)strlen((char *)text), (char *)text); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1565 | balloonEval = beval; |
| 1566 | workshop_send_message(buf); |
| 1567 | } |
| 1568 | } |
| 1569 | } |
| 1570 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1571 | |
| 1572 | static int |
| 1573 | computeIndex( |
| 1574 | int wantedCol, |
| 1575 | char_u *line, |
| 1576 | int ts) |
| 1577 | { |
| 1578 | int col = 0; |
| 1579 | int idx = 0; |
| 1580 | |
| 1581 | while (line[idx]) |
| 1582 | { |
| 1583 | if (line[idx] == '\t') |
| 1584 | col += ts - (col % ts); |
| 1585 | else |
| 1586 | col++; |
| 1587 | idx++; |
| 1588 | if (col >= wantedCol) |
| 1589 | return idx; |
| 1590 | } |
| 1591 | |
| 1592 | return -1; |
| 1593 | } |
Bram Moolenaar | ba07ce3 | 2010-01-06 18:25:34 +0100 | [diff] [blame] | 1594 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1595 | |
| 1596 | static void |
| 1597 | addMenu( |
| 1598 | char *menu, /* menu name */ |
| 1599 | char *accel, /* accelerator text (optional) */ |
| 1600 | char *verb) /* WorkShop action-verb */ |
| 1601 | { |
| 1602 | MenuMap *newMap; |
| 1603 | char cbuf[BUFSIZ]; |
| 1604 | |
| 1605 | if (menuMapSize >= menuMapMax) |
| 1606 | { |
| 1607 | newMap = realloc(menuMap, |
| 1608 | sizeof(MenuMap) * (menuMapMax + MENU_INC)); |
| 1609 | if (newMap != NULL) |
| 1610 | { |
| 1611 | menuMap = newMap; |
| 1612 | menuMapMax += MENU_INC; |
| 1613 | } |
| 1614 | } |
| 1615 | if (menuMapSize < menuMapMax) |
| 1616 | { |
| 1617 | menuMap[menuMapSize].name = strdup(menu); |
| 1618 | menuMap[menuMapSize].accel = accel && *accel ? strdup(accel) : NULL; |
| 1619 | menuMap[menuMapSize++].verb = strdup(verb); |
| 1620 | if (accel && workshopHotKeysEnabled) |
| 1621 | { |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 1622 | vim_snprintf(cbuf, sizeof(cbuf), |
| 1623 | "map %s :wsverb %s<CR>", accel, verb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1624 | coloncmd(cbuf, TRUE); |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | static char * |
| 1630 | nameStrip( |
| 1631 | char *raw) /* menu name, possibly with & chars */ |
| 1632 | { |
| 1633 | static char buf[BUFSIZ]; /* build stripped name here */ |
| 1634 | char *bp = buf; |
| 1635 | |
| 1636 | while (*raw) |
| 1637 | { |
| 1638 | if (*raw != '&') |
| 1639 | *bp++ = *raw; |
| 1640 | raw++; |
| 1641 | } |
| 1642 | *bp = NUL; |
| 1643 | return buf; |
| 1644 | } |
| 1645 | |
| 1646 | |
| 1647 | static char * |
| 1648 | lookupVerb( |
| 1649 | char *verb, |
| 1650 | int skip) /* number of matches to skip */ |
| 1651 | { |
| 1652 | int i; /* loop iterator */ |
| 1653 | |
| 1654 | for (i = 0; i < menuMapSize; i++) |
| 1655 | if (strcmp(menuMap[i].verb, verb) == 0 && skip-- == 0) |
| 1656 | return nameStrip(menuMap[i].name); |
| 1657 | |
| 1658 | return NULL; |
| 1659 | } |
| 1660 | |
| 1661 | |
| 1662 | static void |
| 1663 | coloncmd( |
| 1664 | char *cmd, /* the command to print */ |
| 1665 | Boolean force) /* force cursor update */ |
| 1666 | { |
| 1667 | char_u *cpo_save = p_cpo; |
| 1668 | |
| 1669 | #ifdef WSDEBUG |
| 1670 | if (WSDLEVEL(WS_TRACE_COLONCMD)) |
| 1671 | wsdebug("Cmd: %s\n", cmd); |
| 1672 | #endif |
| 1673 | |
| 1674 | p_cpo = empty_option; |
| 1675 | |
| 1676 | ALT_INPUT_LOCK_ON; |
| 1677 | do_cmdline_cmd((char_u *)cmd); |
| 1678 | ALT_INPUT_LOCK_OFF; |
| 1679 | |
| 1680 | p_cpo = cpo_save; |
| 1681 | |
| 1682 | if (force) |
| 1683 | gui_update_screen(); |
| 1684 | } |
| 1685 | |
| 1686 | /* |
| 1687 | * setDollarVim - Given the run directory, search for the vim install |
| 1688 | * directory and set $VIM. |
| 1689 | * |
| 1690 | * We can be running out of SUNWspro/bin or out of |
| 1691 | * SUNWspro/contrib/contrib6/vim5.6/bin so we check |
| 1692 | * relative to both of these directories. |
| 1693 | */ |
| 1694 | static void |
| 1695 | setDollarVim( |
| 1696 | char *rundir) |
| 1697 | { |
| 1698 | char buf[MAXPATHLEN]; |
| 1699 | char *cp; |
| 1700 | |
| 1701 | /* |
| 1702 | * First case: Running from <install-dir>/SUNWspro/bin |
| 1703 | */ |
| 1704 | strcpy(buf, rundir); |
| 1705 | strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/" |
| 1706 | VIM_VERSION_NODOT "/syntax/syntax.vim"); |
| 1707 | if (access(buf, R_OK) == 0) |
| 1708 | { |
| 1709 | strcpy(buf, "SPRO_WSDIR="); |
| 1710 | strcat(buf, rundir); |
| 1711 | cp = strrchr(buf, '/'); |
| 1712 | if (cp != NULL) |
| 1713 | strcpy(cp, "/WS6U2"); |
| 1714 | putenv(strdup(buf)); |
| 1715 | |
| 1716 | strcpy(buf, "VIM="); |
| 1717 | strcat(buf, rundir); |
| 1718 | strcat(buf, "/../contrib/contrib6/vim" VIM_VERSION_SHORT "/share/vim/" |
| 1719 | VIM_VERSION_NODOT); |
| 1720 | putenv(strdup(buf)); |
| 1721 | return; |
| 1722 | } |
| 1723 | |
| 1724 | /* |
| 1725 | * Second case: Probably running from |
| 1726 | * <install-dir>/SUNWspro/contrib/contrib6/vim5.6/bin |
| 1727 | */ |
| 1728 | strcpy(buf, rundir); |
| 1729 | strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT |
| 1730 | "/share/vim/" VIM_VERSION_NODOT "/syntax/syntax.vim"); |
| 1731 | if (access(buf, R_OK) == 0) |
| 1732 | { |
| 1733 | strcpy(buf, "SPRO_WSDIR="); |
| 1734 | strcat(buf, rundir); |
| 1735 | cp = strrchr(buf, '/'); |
| 1736 | if (cp != NULL) |
| 1737 | strcpy(cp, "../../../../WS6U2"); |
| 1738 | putenv(strdup(buf)); |
| 1739 | |
| 1740 | strcpy(buf, "VIM="); |
| 1741 | strcat(buf, rundir); |
| 1742 | strcat(buf, "/../../../contrib/contrib6/vim" VIM_VERSION_SHORT |
| 1743 | "/share/vim/" VIM_VERSION_NODOT); |
| 1744 | putenv(strdup(buf)); |
| 1745 | return; |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | /* |
| 1750 | * findYourself - Find the directory we are running from. This is used to |
| 1751 | * set $VIM. We need to set this because users can install |
| 1752 | * the package in a different directory than the compiled |
| 1753 | * directory. This is a Sun Visual WorkShop requirement! |
| 1754 | * |
| 1755 | * Note: We override a user's $VIM because it won't have the |
| 1756 | * WorkShop specific files. S/he may not like this but its |
| 1757 | * better than getting the wrong files (especially as the |
| 1758 | * user is likely to have $VIM set to 5.4 or later). |
| 1759 | */ |
| 1760 | void |
| 1761 | findYourself( |
| 1762 | char *argv0) |
| 1763 | { |
| 1764 | char *runpath = NULL; |
| 1765 | char *path; |
| 1766 | char *pathbuf; |
| 1767 | |
| 1768 | if (*argv0 == '/') |
| 1769 | runpath = strdup(argv0); |
| 1770 | else if (*argv0 == '.' || strchr(argv0, '/')) |
| 1771 | { |
| 1772 | runpath = (char *) malloc(MAXPATHLEN); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1773 | if (getcwd(runpath, MAXPATHLEN) == NULL) |
| 1774 | runpath[0] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1775 | strcat(runpath, "/"); |
| 1776 | strcat(runpath, argv0); |
| 1777 | } |
| 1778 | else |
| 1779 | { |
| 1780 | path = getenv("PATH"); |
| 1781 | if (path != NULL) |
| 1782 | { |
| 1783 | runpath = (char *) malloc(MAXPATHLEN); |
| 1784 | pathbuf = strdup(path); |
| 1785 | path = strtok(pathbuf, ":"); |
| 1786 | do |
| 1787 | { |
| 1788 | strcpy(runpath, path); |
| 1789 | strcat(runpath, "/"); |
| 1790 | strcat(runpath, argv0); |
| 1791 | if (access(runpath, X_OK) == 0) |
| 1792 | break; |
| 1793 | } while ((path = strtok(NULL, ":")) != NULL); |
| 1794 | free(pathbuf); |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | if (runpath != NULL) |
| 1799 | { |
| 1800 | char runbuf[MAXPATHLEN]; |
| 1801 | |
| 1802 | /* |
| 1803 | * We found the run directory. Now find the install dir. |
| 1804 | */ |
| 1805 | (void)vim_FullName((char_u *)runpath, (char_u *)runbuf, MAXPATHLEN, 1); |
| 1806 | path = strrchr(runbuf, '/'); |
| 1807 | if (path != NULL) |
| 1808 | *path = NUL; /* remove the vim/gvim name */ |
| 1809 | path = strrchr(runbuf, '/'); |
| 1810 | if (path != NULL) |
| 1811 | { |
| 1812 | if (strncmp(path, "/bin", 4) == 0) |
| 1813 | setDollarVim(runbuf); |
| 1814 | else if (strncmp(path, "/src", 4) == 0) |
| 1815 | { |
| 1816 | *path = NUL; /* development tree */ |
| 1817 | setDollarVim(runbuf); |
| 1818 | } |
| 1819 | } |
| 1820 | free(runpath); |
| 1821 | } |
| 1822 | } |