diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-17 15:45:25 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-17 15:45:25 +0100 |
commit | bb1969b6ab28120c93b77817e7b6075e1aecf663 (patch) | |
tree | aaf6408f1b42e6edae706eaa69b009138c14ad74 /src/workshop.c | |
parent | e40742526e6ea272c64ca393d7364e4023f4122c (diff) |
patch 8.1.0763: nobody is using the Sun Workshop supportv8.1.0763
Problem: Nobody is using the Sun Workshop support.
Solution: Remove the Workshop support.
Diffstat (limited to 'src/workshop.c')
-rw-r--r-- | src/workshop.c | 1830 |
1 files changed, 0 insertions, 1830 deletions
diff --git a/src/workshop.c b/src/workshop.c deleted file mode 100644 index 3de4df1f8d..0000000000 --- a/src/workshop.c +++ /dev/null @@ -1,1830 +0,0 @@ -/* vi:set ts=8 sts=4 sw=4 noet: - * - * VIM - Vi IMproved by Bram Moolenaar - * Visual Workshop integration by Gordon Prieur - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - * See README.txt for an overview of the Vim source code. - */ - -#include "protodef.h" -#ifdef HAVE_CONFIG_H -# include "auto/config.h" -#endif -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <netdb.h> -#include <netinet/in.h> -#include <sys/socket.h> -#ifdef HAVE_LIBGEN_H -# include <libgen.h> -#endif -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <ctype.h> - -#include <X11/Intrinsic.h> -#include <Xm/Xm.h> -#include <Xm/PushB.h> - -#include "integration.h" /* <EditPlugin/integration.h> */ - -#include "vim.h" -#include "version.h" -#include "workshop.h" - -void workshop_hotkeys(Boolean); - -static Boolean isShowing(int); -static win_T *get_window(buf_T *); -static void updatePriority(Boolean); -static char *addUniqueMnemonic(char *, char *); -static char *fixup(char *); -static char *get_selection(buf_T *); -static char *append_selection(int, char *, int *, int *); -static void load_window(char *, int lnum); -static void warp_to_pc(int); -#ifdef FEAT_BEVAL_GUI -void workshop_beval_cb(BalloonEval *, int); -# ifdef FEAT_VARTABS -static int computeIndex(int, char_u *, int, int *); -# else -static int computeIndex(int, char_u *, int); -# endif -#endif -static char *fixAccelText(char *); -static void addMenu(char *, char *, char *); -static char *lookupVerb(char *, int); -static void coloncmd(char *, Boolean); - -extern Widget vimShell; -extern Widget textArea; -extern XtAppContext app_context; - -static int tbpri; /* ToolBar priority */ -int usingSunWorkShop = 0; /* set if -ws flag is used */ -char curMenuName[BUFSIZ]; -char curMenuPriority[BUFSIZ]; - -static Boolean workshopInitDone = False; -static Boolean workshopHotKeysEnabled = False; - -/* - * The following enum is from <gp_dbx/gp_dbx_common.h>. We can't include it - * here because it's C++. - */ -enum -{ - GPLineEval_EVALUATE, /* evaluate expression */ - GPLineEval_INDIRECT, /* evaluate *<expression> */ - GPLineEval_TYPE /* type of expression */ -}; - -/* - * Store each verb in the MenuMap. This lets us map from a verb to a menu. - * There may be multiple matches for a single verb in this table. - */ -#define MENU_INC 50 /* menuMap incremental size increases */ -typedef struct -{ - char *name; /* name of the menu */ - char *accel; /* optional accelerator key */ - char *verb; /* menu verb */ -} MenuMap; -static MenuMap *menuMap; /* list of verb/menu mappings */ -static int menuMapSize; /* current size of menuMap */ -static int menuMapMax; /* allocated size of menuMap */ -static char *initialFileCmd; /* save command but defer doing it */ - - - void -workshop_init(void) -{ - char_u buf[64]; - int is_dirty = FALSE; - int width, height; - XtInputMask mask; - - /* - * Turn on MenuBar, ToolBar, and Footer. - */ - STRCPY(buf, p_go); - if (vim_strchr(p_go, GO_MENUS) == NULL) - { - STRCAT(buf, "m"); - is_dirty = TRUE; - } - if (vim_strchr(p_go, GO_TOOLBAR) == NULL) - { - STRCAT(buf, "T"); - is_dirty = TRUE; - } - if (vim_strchr(p_go, GO_FOOTER) == NULL) - { - STRCAT(buf, "F"); - is_dirty = TRUE; - } - if (is_dirty) - set_option_value((char_u *)"go", 0L, buf, 0); - - /* - * Set size from workshop_get_width_height(). - */ - width = height = 0; - if (workshop_get_width_height(&width, &height)) - { - XtVaSetValues(vimShell, - XmNwidth, width, - XmNheight, height, - NULL); - } - - /* - * Now read in the initial messages from eserve. - */ - while ((mask = XtAppPending(app_context)) - && (mask & XtIMAlternateInput) && !workshopInitDone) - XtAppProcessEvent(app_context, (XtInputMask)XtIMAlternateInput); -} - - void -workshop_postinit(void) -{ - do_cmdline_cmd((char_u *)initialFileCmd); - ALT_INPUT_LOCK_OFF; - free(initialFileCmd); - initialFileCmd = NULL; -} - - void -ex_wsverb(exarg_T *eap) -{ - msg_clr_cmdline(); - workshop_perform_verb((char *) eap->arg, NULL); -} - -/* - * Editor name - * This string is recognized by eserve and should be all lower case. - * This is how the editor detects that it is talking to gvim instead - * of NEdit, for example, when the connection is initiated from the editor. - */ - char * -workshop_get_editor_name(void) -{ - return "gvim"; -} - -/* - * Version number of the editor. - * This number is communicated along with the protocol - * version to the application. - */ - char * -workshop_get_editor_version(void) -{ - return Version; -} - -/* - * Answer functions: called by eserve - */ - -/* - * Name: - * workshop_load_file - * - * Function: - * Load a given file into the WorkShop buffer. - */ - void -workshop_load_file( - char *filename, /* the file to load */ - int line, /* an optional line number (or 0) */ - char *frameid UNUSED) /* used for multi-frame support */ -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_load_file(%s, %d)\n", filename, line); -#endif - -#ifdef FEAT_BEVAL_GUI - bevalServers |= BEVAL_WORKSHOP; -#endif - - load_window(filename, line); -} - -/* - * Reload the WorkShop buffer - */ - void -workshop_reload_file( - char *filename, - int line) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_reload_file(%s, %d)\n", filename, line); -#endif - load_window(filename, line); -} - - void -workshop_show_file( - char *filename) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_show_file(%s)\n", filename); -#endif - - load_window(filename, 0); -} - - void -workshop_goto_line( - char *filename, - int lineno) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_goto_line(%s, %d)\n", filename, lineno); -#endif - - load_window(filename, lineno); -} - - void -workshop_front_file( - char *filename UNUSED) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_front_file()\n"); -#endif - /* - * Assumption: This function will always be called after a call to - * workshop_show_file(), so the file is always showing. - */ - if (vimShell != NULL) - XRaiseWindow(gui.dpy, XtWindow(vimShell)); -} - - void -workshop_save_file( - char *filename) -{ - char cbuf[BUFSIZ]; /* build vim command here */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_save_file(%s)\n", filename); -#endif - - /* Save the given file */ - vim_snprintf(cbuf, sizeof(cbuf), "w %s", filename); - coloncmd(cbuf, TRUE); -} - - void -workshop_save_files(void) -{ - /* Save the given file */ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_save_files()\n"); -#endif - - add_to_input_buf((char_u *) ":wall\n", 6); -} - - void -workshop_quit(void) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_quit()\n"); -#endif - - add_to_input_buf((char_u *) ":qall\n", 6); -} - - void -workshop_minimize(void) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_minimize()\n"); -#endif - workshop_minimize_shell(vimShell); -} - void -workshop_maximize(void) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_maximize()\n"); -#endif - - workshop_maximize_shell(vimShell); -} - - void -workshop_add_mark_type( - int idx, - char *colorspec, - char *sign) -{ - char gbuf[BUFSIZ]; /* buffer for sign name */ - char cibuf[BUFSIZ]; /* color information */ - char cbuf[BUFSIZ]; /* command buffer */ - char *bp; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - { - char *cp; - - cp = strrchr(sign, '/'); - if (cp == NULL) - cp = sign; - else - cp++; /* skip '/' character */ - wstrace("workshop_add_mark_type(%d, \"%s\", \"%s\")\n", idx, - colorspec && *colorspec ? colorspec : "<None>", cp); - } -#endif - - /* - * Isolate the basename of sign in gbuf. We will use this for the - * GroupName in the highlight command sent to vim. - */ - STRCPY(gbuf, gettail((char_u *)sign)); - bp = strrchr(gbuf, '.'); - if (bp != NULL) - *bp = NUL; - - if (gbuf[0] != '-' && gbuf[1] != NUL) - { - if (colorspec != NULL && *colorspec) - { - vim_snprintf(cbuf, sizeof(cbuf), - "highlight WS%s guibg=%s", gbuf, colorspec); - coloncmd(cbuf, FALSE); - vim_snprintf(cibuf, sizeof(cibuf), "linehl=WS%s", gbuf); - } - else - cibuf[0] = NUL; - - vim_snprintf(cbuf, sizeof(cbuf), - "sign define %d %s icon=%s", idx, cibuf, sign); - coloncmd(cbuf, TRUE); - } -} - - void -workshop_set_mark( - char *filename, /* filename which gets the mark */ - int lineno, /* line number which gets the mark */ - int markId, /* unique mark identifier */ - int idx) /* which mark to use */ -{ - char cbuf[BUFSIZ]; /* command buffer */ - - /* Set mark in a given file */ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_set_mark(%s, %d (ln), %d (id), %d (idx))\n", - filename, lineno, markId, idx); -#endif - - vim_snprintf(cbuf, sizeof(cbuf), "sign place %d line=%d name=%d file=%s", - markId, lineno, idx, filename); - coloncmd(cbuf, TRUE); -} - - void -workshop_change_mark_type( - char *filename, /* filename which gets the mark */ - int markId, /* unique mark identifier */ - int idx) /* which mark to use */ -{ - char cbuf[BUFSIZ]; /* command buffer */ - - /* Change mark type */ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_change_mark_type(%s, %d, %d)\n", - filename, markId, idx); -#endif - - vim_snprintf(cbuf, sizeof(cbuf), - "sign place %d name=%d file=%s", markId, idx, filename); - coloncmd(cbuf, TRUE); -} - -/* - * Goto the given mark in a file (e.g. show it). - * If message is not null, display it in the footer. - */ - void -workshop_goto_mark( - char *filename, - int markId, - char *message) -{ - char cbuf[BUFSIZ]; /* command buffer */ - - /* Goto mark */ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_goto_mark(%s, %d (id), %s)\n", - filename, markId, message && *message && - !(*message == ' ' && message[1] == NULL) ? - message : "<None>"); -#endif - - vim_snprintf(cbuf, sizeof(cbuf), "sign jump %d file=%s", markId, filename); - coloncmd(cbuf, TRUE); - if (message != NULL && *message != NUL) - gui_mch_set_footer((char_u *)message); -} - - void -workshop_delete_mark( - char *filename, - int markId) -{ - char cbuf[BUFSIZ]; /* command buffer */ - - /* Delete mark */ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_delete_mark(%s, %d (id))\n", - filename, markId); -#endif - - vim_snprintf(cbuf, sizeof(cbuf), - "sign unplace %d file=%s", markId, filename); - coloncmd(cbuf, TRUE); -} - - int -workshop_get_mark_lineno( - char *filename, - int markId) -{ - buf_T *buf; /* buffer containing filename */ - int lineno; /* line number of filename in buf */ - - /* Get mark line number */ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_get_mark_lineno(%s, %d)\n", - filename, markId); -#endif - - lineno = 0; - buf = buflist_findname((char_u *)filename); - if (buf != NULL) - lineno = buf_findsign(buf, markId, NULL); - - return lineno; -} - - -/* - * Are there any moved marks? If so, call workshop_move_mark on - * each of them now. This is how eserve can find out if for example - * breakpoints have moved when a program has been recompiled and - * reloaded into dbx. - */ - void -workshop_moved_marks(char *filename UNUSED) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("XXXworkshop_moved_marks(%s)\n", filename); -#endif -} - - int -workshop_get_font_height(void) -{ - XmFontList fontList; /* fontList made from gui.norm_font */ - XmString str; - Dimension w; - Dimension h; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_get_font_height()\n"); -#endif - - /* Pick the proper signs for this font size */ - fontList = gui_motif_create_fontlist((XFontStruct *)gui.norm_font); - h = 0; - if (fontList != NULL) - { - str = XmStringCreateLocalized("A"); - XmStringExtent(fontList, str, &w, &h); - XmStringFree(str); - XmFontListFree(fontList); - } - - return (int)h; -} - - void -workshop_footer_message( - char *message, - int severity UNUSED) /* severity is currently unused */ -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_footer_message(%s, %d)\n", message, severity); -#endif - - gui_mch_set_footer((char_u *) message); -} - -/* - * workshop_menu_begin() is passed the menu name. We determine its mnemonic - * here and store its name and priority. - */ - void -workshop_menu_begin( - char *label) -{ - vimmenu_T *menu; /* pointer to last menu */ - int menuPriority = 0; /* priority of new menu */ - char mnembuf[64]; /* store menubar mnemonics here */ - char *name; /* label with a mnemonic */ - char *p; /* used to find mnemonics */ - int idx; /* index into mnembuf */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_menu_begin()\n"); -#endif - - /* - * Look through all existing (non-PopUp and non-Toolbar) menus - * and gather their mnemonics. Use this list to decide what - * mnemonic should be used for label. - */ - - idx = 0; - mnembuf[idx++] = 'H'; /* H is mnemonic for Help */ - for (menu = root_menu; menu != NULL; menu = menu->next) - { - if (menu_is_menubar(menu->name)) - { - p = strchr((char *)menu->name, '&'); - if (p != NULL) - mnembuf[idx++] = *++p; - } - if (menu->next != NULL - && strcmp((char *) menu->next->dname, "Help") == 0) - { - menuPriority = menu->priority + 10; - break; - } - } - mnembuf[idx++] = NUL; - name = addUniqueMnemonic(mnembuf, label); - - vim_snprintf(curMenuName, sizeof(curMenuName), "%s", name); - sprintf(curMenuPriority, "%d.0", menuPriority); -} - -/* - * Append the name and priority to strings to be used in vim menu commands. - */ - void -workshop_submenu_begin( - char *label) -{ -#ifdef WSDEBUG_TRACE - if (ws_debug && ws_dlevel & WS_TRACE - && strncmp(curMenuName, "ToolBar", 7) != 0) - wstrace("workshop_submenu_begin(%s)\n", label); -#endif - - strcat(curMenuName, "."); - strcat(curMenuName, fixup(label)); - - updatePriority(True); -} - -/* - * Remove the submenu name and priority from curMenu*. - */ - - void -workshop_submenu_end(void) -{ - char *p; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE) - && strncmp(curMenuName, "ToolBar", 7) != 0) - wstrace("workshop_submenu_end()\n"); -#endif - - p = strrchr(curMenuPriority, '.'); - ASSERT(p != NULL); - *p = NUL; - - p = strrchr(curMenuName, '.'); - ASSERT(p != NULL); - *p = NUL; -} - -/* - * This is where menus are really made. Each item will generate an amenu vim - * command. The globals curMenuName and curMenuPriority contain the name and - * priority of the parent menu tree. - */ - void -workshop_menu_item( - char *label, - char *verb, - char *accelerator UNUSED, - char *acceleratorText, - char *name UNUSED, - char *filepos UNUSED, - char *sensitive) -{ - char cbuf[BUFSIZ]; - char namebuf[BUFSIZ]; - char accText[BUFSIZ]; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE) - && strncmp(curMenuName, "ToolBar", 7) != 0) - { - if (ws_dlevel & WS_TRACE_VERBOSE) - wsdebug("workshop_menu_item(\n" - "\tlabel = \"%s\",\n" - "\tverb = %s,\n" - "\taccelerator = %s,\n" - "\tacceleratorText = \"%s\",\n" - "\tname = %s,\n" - "\tfilepos = %s,\n" - "\tsensitive = %s)\n", - label && *label ? label : "<None>", - verb && *verb ? verb : "<None>", - accelerator && *accelerator ? - accelerator : "<None>", - acceleratorText && *acceleratorText ? - acceleratorText : "<None>", - name && *name ? name : "<None>", - filepos && *filepos ? filepos : "<None>", - sensitive); - else if (ws_dlevel & WS_TRACE) - wstrace("workshop_menu_item(\"%s\", %s)\n", - label && *label ? label : "<None>", - verb && *verb ? verb : "<None>", sensitive); - } -#endif -#ifdef WSDEBUG_SENSE - if (ws_debug) - wstrace("menu: %-21.20s%-21.20s(%s)\n", label, verb, - *sensitive == '1' ? "Sensitive" : "Insensitive"); -#endif - - if (acceleratorText != NULL) - vim_snprintf(accText, sizeof(accText), "<Tab>%s", acceleratorText); - else - accText[0] = NUL; - updatePriority(False); - vim_snprintf(namebuf, sizeof(namebuf), "%s.%s", curMenuName, fixup(label)); - vim_snprintf(cbuf, sizeof(cbuf), "amenu %s %s%s\t:wsverb %s<CR>", - curMenuPriority, namebuf, accText, verb); - - coloncmd(cbuf, TRUE); - addMenu(namebuf, fixAccelText(acceleratorText), verb); - - if (*sensitive == '0') - { - vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf); - coloncmd(cbuf, TRUE); - } -} - -/* - * This function is called when a complete WorkShop menu description has been - * sent over from eserve. We do some menu cleanup. - */ - - void -workshop_menu_end(void) -{ - Boolean using_tearoff; /* set per current option setting */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_menu_end()\n"); -#endif - - using_tearoff = vim_strchr(p_go, GO_TEAROFF) != NULL; - gui_mch_toggle_tearoffs(using_tearoff); -} - - void -workshop_toolbar_begin(void) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_toolbar_begin()\n"); -#endif - - coloncmd("aunmenu ToolBar", True); - tbpri = 10; -} - - void -workshop_toolbar_end(void) -{ - char_u buf[64]; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - { - wstrace("workshop_toolbar_end()\n"); - } -#endif - - /* - * Turn on ToolBar. - */ - STRCPY(buf, p_go); - if (vim_strchr(p_go, 'T') == NULL) - { - STRCAT(buf, "T"); - set_option_value((char_u *)"go", 0L, buf, 0); - } - workshopInitDone = True; -} - - void -workshop_toolbar_button( - char *label, - char *verb, - char *senseVerb UNUSED, - char *filepos UNUSED, - char *help, - char *sense, - char *file, - char *left) -{ - char cbuf[BUFSIZ + MAXPATHLEN]; - char namebuf[BUFSIZ]; - static int tbid = 1; - char_u *p; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE)) - wsdebug("workshop_toolbar_button(\"%s\", %s, %s,\n" - "\t%s, \"%s\", %s,\n\t\"%s\",\n\t<%s>)\n", - label && *label ? label : "<None>", - verb && *verb ? verb : "<None>", - senseVerb && *senseVerb ? senseVerb : "<None>", - filepos && *filepos ? filepos : "<None>", - help && *help ? help : "<None>", - sense && *sense ? sense : "<None>", - file && *file ? file : "<None>", - left && *left ? left : "<None>"); - else if (WSDLEVEL(WS_TRACE)) - wstrace("workshop_toolbar_button(\"%s\", %s)\n", - label && *label ? label : "<None>", - verb && *verb ? verb : "<None>"); -#endif -#ifdef WSDEBUG_SENSE - if (ws_debug) - wsdebug("button: %-21.20s%-21.20s(%s)\n", label, verb, - *sense == '1' ? "Sensitive" : "Insensitive"); -#endif - - if (left && *left && atoi(left) > 0) - { - /* Add a separator (but pass the width passed after the ':') */ - sprintf(cbuf, "amenu 1.%d ToolBar.-sep%d:%s- <nul>", - tbpri - 5, tbid++, left); - - coloncmd(cbuf, True); - } - - p = vim_strsave_escaped((char_u *)label, (char_u *)"\\. "); - vim_snprintf(namebuf, sizeof(namebuf), "ToolBar.%s", p); - vim_free(p); - STRCPY(cbuf, "amenu <silent> "); - if (file != NULL && *file != NUL) - { - p = vim_strsave_escaped((char_u *)file, (char_u *)" "); - vim_snprintf_add(cbuf, sizeof(cbuf), "icon=%s ", p); - vim_free(p); - } - vim_snprintf_add(cbuf, sizeof(cbuf),"1.%d %s :wsverb %s<CR>", - tbpri, namebuf, verb); - - /* Define the menu item */ - coloncmd(cbuf, True); - - if (*sense == '0') - { - /* If menu isn't sensitive at startup... */ - vim_snprintf(cbuf, sizeof(cbuf), "amenu disable %s", namebuf); - coloncmd(cbuf, True); - } - - if (help && *help) - { - /* Do the tooltip */ - vim_snprintf(cbuf, sizeof(cbuf), "tmenu %s %s", namebuf, help); - coloncmd(cbuf, True); - } - - addMenu(namebuf, NULL, verb); - tbpri += 10; -} - - void -workshop_frame_sensitivities( - VerbSense *vs) /* list of verbs to (de)sensitize */ -{ - VerbSense *vp; /* iterate through vs */ - char *menu_name; /* used in menu lookup */ - int cnt; /* count of verbs to skip */ - int len; /* length of nonvariant part of command */ - char cbuf[4096]; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE) || WSDLEVEL(4)) - { - wsdebug("workshop_frame_sensitivities(\n"); - for (vp = vs; vp->verb != NULL; vp++) - wsdebug("\t%-25s%d\n", vp->verb, vp->sense); - wsdebug(")\n"); - } - else if (WSDLEVEL(WS_TRACE)) - wstrace("workshop_frame_sensitivities()\n"); -#endif -#ifdef WSDEBUG_SENSE - if (ws_debug) - for (vp = vs; vp->verb != NULL; vp++) - wsdebug("change: %-21.20s%-21.20s(%s)\n", - "", vp->verb, vp->sense == 1 ? - "Sensitive" : "Insensitive"); -#endif - - /* - * Look for all matching menu entries for the verb. There may be more - * than one if the verb has both a menu and toolbar entry. - */ - for (vp = vs; vp->verb != NULL; vp++) - { - cnt = 0; - strcpy(cbuf, "amenu"); - strcat(cbuf, " "); - strcat(cbuf, vp->sense ? "enable" : "disable"); - strcat(cbuf, " "); - len = strlen(cbuf); - while ((menu_name = lookupVerb(vp->verb, cnt++)) != NULL) - { - strcpy(&cbuf[len], menu_name); - coloncmd(cbuf, FALSE); - } - } - gui_update_menus(0); - gui_mch_flush(); -} - - void -workshop_set_option( - char *option, /* name of a supported option */ - char *value) /* value to set option to */ -{ - char cbuf[BUFSIZ]; /* command buffer */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - { - wstrace("workshop_set_option(%s, %s)\n", option, value); - } -#endif - - cbuf[0] = NUL; - switch (*option) /* switch on 1st letter */ - { - case 's': - if (strcmp(option, "syntax") == 0) - vim_snprintf(cbuf, sizeof(cbuf), "syntax %s", value); - else if (strcmp(option, "savefiles") == 0) - { - /* XXX - Not yet implemented */ - } - break; - - case 'l': - if (strcmp(option, "lineno") == 0) - sprintf(cbuf, "set %snu", - (strcmp(value, "on") == 0) ? "" : "no"); - break; - - case 'p': - if (strcmp(option, "parentheses") == 0) - sprintf(cbuf, "set %ssm", - (strcmp(value, "on") == 0) ? "" : "no"); - break; - - case 'w': - /* this option is set by a direct call */ -#ifdef WSDEBUG - wsdebug("workshop_set_option: " - "Got unexpected workshopkeys option"); -#endif - break; - - case 'b': /* these options are set from direct calls */ - if (option[7] == NUL && strcmp(option, "balloon") == 0) - { -#ifdef WSDEBUG - /* set by direct call to workshop_balloon_mode */ - wsdebug("workshop_set_option: " - "Got unexpected ballooneval option"); -#endif - } - else if (strcmp(option, "balloondelay") == 0) - { -#ifdef WSDEBUG - /* set by direct call to workshop_balloon_delay */ - wsdebug("workshop_set_option: " - "Got unexpected balloondelay option"); -#endif - } - break; - } - if (cbuf[0] != NUL) - coloncmd(cbuf, TRUE); -} - - - void -workshop_balloon_mode( - Boolean on) -{ - char cbuf[BUFSIZ]; /* command buffer */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_balloon_mode(%s)\n", on ? "True" : "False"); -#endif - - sprintf(cbuf, "set %sbeval", on ? "" : "no"); - coloncmd(cbuf, TRUE); -} - - - void -workshop_balloon_delay( - int delay) -{ - char cbuf[BUFSIZ]; /* command buffer */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_balloon_delay(%d)\n", delay); -#endif - - sprintf(cbuf, "set bdlay=%d", delay); - coloncmd(cbuf, TRUE); -} - - - void -workshop_show_balloon_tip( - char *tip) -{ -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_show_balloon_tip(%s)\n", tip); -#endif - - if (balloonEval != NULL) - gui_mch_post_balloon(balloonEval, (char_u *)tip); -} - - - void -workshop_hotkeys( - Boolean on) -{ - char cbuf[BUFSIZ]; /* command buffer */ - MenuMap *mp; /* iterate over menuMap entries */ - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_hotkeys(%s)\n", on ? "True" : "False"); -#endif - - workshopHotKeysEnabled = on; - if (workshopHotKeysEnabled) - for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) - { - if (mp->accel != NULL) - { - vim_snprintf(cbuf, sizeof(cbuf), - "map %s :wsverb %s<CR>", mp->accel, mp->verb); - coloncmd(cbuf, TRUE); - } - } - else - for (mp = menuMap; mp < &menuMap[menuMapSize]; mp++) - { - if (mp->accel != NULL) - { - vim_snprintf(cbuf, sizeof(cbuf), "unmap %s", mp->accel); - coloncmd(cbuf, TRUE); - } - } -} - -/* - * A button in the toolbar has been pushed. - */ - int -workshop_get_positions( - void *clientData UNUSED, - char **filename, /* output data */ - int *curLine, /* output data */ - int *curCol, /* output data */ - int *selStartLine, /* output data */ - int *selStartCol, /* output data */ - int *selEndLine, /* output data */ - int *selEndCol, /* output data */ - int *selLength, /* output data */ - char **selection) /* output data */ -{ - static char ffname[MAXPATHLEN]; - -#ifdef WSDEBUG_TRACE - if (WSDLEVEL(WS_TRACE_VERBOSE | WS_TRACE)) - wstrace("workshop_get_positions(%#x, \"%s\", ...)\n", - clientData, (curbuf && curbuf->b_sfname != NULL) - ? (char *)curbuf->b_sfname : "<None>"); -#endif - - if (curbuf->b_ffname == NULL) - ffname[0] = NUL; - else - /* copy so nobody can change b_ffname */ - strcpy(ffname, (char *) curbuf->b_ffname); - *filename = ffname; - *curLine = curwin->w_cursor.lnum; - *curCol = curwin->w_cursor.col; - - if (curbuf->b_visual.vi_mode == 'v' && - EQUAL_POS(curwin->w_cursor, curbuf->b_visual.vi_end)) - { - *selStartLine = curbuf->b_visual.vi_start.lnum; - *selStartCol = curbuf->b_visual.vi_start.col; - *selEndLine = curbuf->b_visual.vi_end.lnum; - *selEndCol = curbuf->b_visual.vi_end.col; - *selection = get_selection(curbuf); - if (*selection) - *selLength = strlen(*selection); - else - *selLength = 0; - } - else - { - *selStartLine = *selEndLine = -1; - *selStartCol = *selEndCol = -1; - *selLength = 0; - *selection = ""; - } - - return True; -} - - - -/************************************************************************ - * Utility functions - ************************************************************************/ - - static char * -get_selection( - buf_T *buf) /* buffer whose selection we want */ -{ - pos_T *start; /* start of the selection */ - pos_T *end; /* end of the selection */ - char *lp; /* pointer to actual line data */ - int llen; /* length of actual line data */ - char *sp; /* pointer to selection buffer */ - int slen; /* string length in selection buffer */ - int size; /* size of selection buffer */ - char *new_sp; /* temp pointer to new sp */ - int lnum; /* line number we are appending */ - - if (buf->b_visual.vi_mode == 'v') - { - start = &buf->b_visual.vi_start; - end = &buf->b_visual.vi_end; - if (start->lnum == end->lnum) - { - /* selection is all on one line */ - lp = (char *) ml_get_pos(start); - llen = end->col - start->col + 1; - sp = (char *) malloc(llen + 1); - if (sp != NULL) - { - strncpy(sp, lp, llen); - sp[llen] = NUL; - } - } - else - { - /* multi-line selection */ - lp = (char *) ml_get_pos(start); - llen = strlen(lp); - sp = (char *) malloc(BUFSIZ + llen); - if (sp != NULL) - { - size = BUFSIZ + llen; - strcpy(sp, lp); - sp[llen] = '\n'; - slen = llen + 1; - - lnum = start->lnum + 1; - while (lnum < end->lnum) - sp = append_selection(lnum++, sp, &size, &slen); - - lp = (char *) ml_get(end->lnum); - llen = end->col + 1; - if ((slen + llen) >= size) - { - new_sp = (char *) - realloc(sp, slen + llen + 1); - if (new_sp != NULL) - { - size += llen + 1; - sp = new_sp; - } - } - if ((slen + llen) < size) - { - strncpy(&sp[slen], lp, llen); - sp[slen + llen] = NUL; - } - - } - } - } - else - sp = NULL; - - return sp; -} - - static char * -append_selection( - int lnum, /* line number to append */ - char *sp, /* pointer to selection buffer */ - int *size, /* ptr to size of sp */ - int *slen) /* ptr to length of selection string */ -{ - char *lp; /* line of data from buffer */ - int llen; /* strlen of lp */ - char *new_sp; /* temp pointer to new sp */ - - lp = (char *)ml_get((linenr_T)lnum); - llen = strlen(lp); - - if ((*slen + llen) <= *size) - { - new_sp = (char *) realloc((void *) sp, BUFSIZ + *slen + llen); - if (*new_sp != NUL) - { - *size = BUFSIZ + *slen + llen; - sp = new_sp; - } - } - if ((*slen + llen) > *size) - { - strcat(&sp[*slen], lp); - *slen += llen; - sp[*slen++] = '\n'; - } - - return sp; -} - - - static void -load_buffer_by_name( - char *filename, /* the file to load */ - int lnum) /* an optional line number (or 0) */ -{ - char lnumbuf[16]; /* make line number option for :e */ - char cbuf[BUFSIZ]; /* command buffer */ - - if (lnum > 0) - sprintf(lnumbuf, "+%d", lnum); - else - lnumbuf[0] = NUL; - - vim_snprintf(cbuf, sizeof(cbuf), "e %s %s", lnumbuf, filename); - coloncmd(cbuf, False); -} |