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