To: vim-dev@vim.org Subject: Patch 6.1.044 (extra) Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.044 (extra) Problem: GUI: When using the find/replace dialog with text that contains a slash, an invalid substitute command is generated. On Win32 a find doesn't work when 'insertmode' is set. Solution: Escape slashes with a backslash. Make the Win32, Motif and GTK gui use common code for the find/replace dialog. Add the "match case" option for Motif and GTK. Files: src/feature.h, src/proto/gui.pro, src/gui.c, src/gui.h, src/gui_motif.c, src/gui_gtk.c, src/gui_w48.c *** ../vim61.043/src/feature.h Sat Mar 9 16:17:30 2002 --- src/feature.h Wed May 1 19:58:03 2002 *************** *** 980,985 **** --- 980,990 ---- # endif #endif + #if defined(FEAT_GUI_MSWIN) && defined(FEAT_SMALL) + # define MSWIN_FIND_REPLACE /* include code for find/replace dialog */ + # define MSWIN_FR_BUFSIZE 256 + #endif + /* * +clientserver Remote control via the remote_send() function * and the --remote argument *** ../vim61.043/src/proto/gui.pro Fri Mar 22 21:41:26 2002 --- src/proto/gui.pro Tue Apr 30 17:47:17 2002 *************** *** 54,59 **** void display_errors __ARGS((void)); int no_console_input __ARGS((void)); void gui_update_screen __ARGS((void)); ! char_u *get_find_dialog_text __ARGS((char_u *arg, int *wordp)); ! int gui_do_findrepl __ARGS((int flags, char_u *find_text, char_u *repl_text, int down, int exact)); /* vim: set ft=c : */ --- 54,59 ---- void display_errors __ARGS((void)); int no_console_input __ARGS((void)); void gui_update_screen __ARGS((void)); ! char_u *get_find_dialog_text __ARGS((char_u *arg, int *wwordp, int *mcasep)); ! int gui_do_findrepl __ARGS((int flags, char_u *find_text, char_u *repl_text, int down)); /* vim: set ft=c : */ *** ../vim61.043/src/gui.c Fri Mar 22 22:08:42 2002 --- src/gui.c Wed May 1 21:11:42 2002 *************** *** 4013,4020 **** } #endif ! #if defined(FEAT_GUI_GTK) || defined(FEAT_SUN_WORKSHOP) \ ! || defined(FEAT_GUI_MOTIF) || defined(PROTO) /* * Update the current window and the screen. */ --- 4013,4021 ---- } #endif ! #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \ ! || defined(MSWIN_FIND_REPLACE) || defined(FEAT_SUN_WORKSHOP) \ ! || defined(PROTO) /* * Update the current window and the screen. */ *************** *** 4031,4046 **** } #endif ! #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) || defined(PROTO) /* * Get the text to use in a find/replace dialog. Uses the last search pattern * if the argument is empty. * Returns an allocated string. */ char_u * ! get_find_dialog_text(arg, wordp) char_u *arg; ! int *wordp; /* return: TRUE if \< \> found */ { char_u *text; --- 4032,4051 ---- } #endif ! #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \ ! || defined(MSWIN_FIND_REPLACE) || defined(PROTO) ! static void concat_esc __ARGS((garray_T *gap, char_u *text, int what)); ! /* * Get the text to use in a find/replace dialog. Uses the last search pattern * if the argument is empty. * Returns an allocated string. */ char_u * ! get_find_dialog_text(arg, wwordp, mcasep) char_u *arg; ! int *wwordp; /* return: TRUE if \< \> found */ ! int *mcasep; /* return: TRUE if \C found */ { char_u *text; *************** *** 4062,4122 **** len -= 2; } /* Recognize "\" and remove. */ if (len >= 4 && STRNCMP(text, "\\<", 2) == 0 && STRNCMP(text + len - 2, "\\>", 2) == 0) { ! *wordp = TRUE; mch_memmove(text, text + 2, (size_t)(len - 4)); text[len - 4] = NUL; } } } return text; } /* * Handle the press of a button in the find-replace dialog. * Return TRUE when something was added to the input buffer. */ int ! gui_do_findrepl(flags, find_text, repl_text, down, exact) ! int flags; /* one of FR_REPLACE, FR_FINDNEXT, etc. */ char_u *find_text; char_u *repl_text; int down; /* Search downwards. */ - int exact; /* Exact word match. */ { garray_T ga; int i; ga_init2(&ga, 1, 100); ! if (flags == FR_REPLACE) { /* Do the replacement when the text under the cursor matches. */ ! if (STRNCMP(ml_get_cursor(), find_text, STRLEN(find_text)) == 0 && u_save_cursor() == OK) { ! del_bytes((long)STRLEN(find_text), FALSE); ins_str(repl_text); } } ! else if (flags == FR_REPLACEALL) ga_concat(&ga, (char_u *)"%s/"); ga_concat(&ga, (char_u *)"\\V"); ! if (exact) ga_concat(&ga, (char_u *)"\\<"); ! ga_concat(&ga, find_text); ! if (exact) ga_concat(&ga, (char_u *)"\\>"); ! if (flags == FR_REPLACEALL) { ga_concat(&ga, (char_u *)"/"); ! ga_concat(&ga, repl_text); ga_concat(&ga, (char_u *)"/g"); do_cmdline_cmd(ga.ga_data); } --- 4067,4183 ---- len -= 2; } + /* Recognize "\c" and "\C" and remove. */ + if (len >= 2 && *text == '\\' && (text[1] == 'c' || text[1] == 'C')) + { + *mcasep = (text[1] == 'C'); + mch_memmove(text, text + 2, (size_t)(len - 1)); + len -= 2; + } + /* Recognize "\" and remove. */ if (len >= 4 && STRNCMP(text, "\\<", 2) == 0 && STRNCMP(text + len - 2, "\\>", 2) == 0) { ! *wwordp = TRUE; mch_memmove(text, text + 2, (size_t)(len - 4)); text[len - 4] = NUL; } + } } return text; } /* + * Concatenate "text" to grow array "gap", escaping "what" with a backslash. + */ + static void + concat_esc(gap, text, what) + garray_T *gap; + char_u *text; + int what; + { + while (*text != NUL) + { + #ifdef FEAT_MBYTE + int l = (*mb_ptr2len_check)(text); + if (l > 1) + { + while (--l >= 0) + ga_append(gap, *text++); + continue; + } + #endif + if (*text == what) + ga_append(gap, '\\'); + ga_append(gap, *text); + ++text; + } + } + + /* * Handle the press of a button in the find-replace dialog. * Return TRUE when something was added to the input buffer. */ int ! gui_do_findrepl(flags, find_text, repl_text, down) ! int flags; /* one of FRD_REPLACE, FRD_FINDNEXT, etc. */ char_u *find_text; char_u *repl_text; int down; /* Search downwards. */ { garray_T ga; int i; + int type = (flags & FRD_TYPE_MASK); + char_u *p; ga_init2(&ga, 1, 100); ! if (type == FRD_REPLACE) { /* Do the replacement when the text under the cursor matches. */ ! i = STRLEN(find_text); ! p = ml_get_cursor(); ! if (((flags & FRD_MATCH_CASE) ! ? STRNCMP(p, find_text, i) == 0 ! : STRNICMP(p, find_text, i) == 0) && u_save_cursor() == OK) { ! /* A button was pressed thus undo should be synced. */ ! if (no_u_sync == 0) ! u_sync(); ! ! del_bytes((long)i, FALSE); ins_str(repl_text); } } ! else if (type == FRD_REPLACEALL) ga_concat(&ga, (char_u *)"%s/"); ga_concat(&ga, (char_u *)"\\V"); ! if (flags & FRD_MATCH_CASE) ! ga_concat(&ga, (char_u *)"\\C"); ! else ! ga_concat(&ga, (char_u *)"\\c"); ! if (flags & FRD_WHOLE_WORD) ga_concat(&ga, (char_u *)"\\<"); ! if (type == FRD_REPLACEALL || down) ! concat_esc(&ga, find_text, '/'); /* escape slashes */ ! else ! concat_esc(&ga, find_text, '?'); /* escape '?' */ ! if (flags & FRD_WHOLE_WORD) ga_concat(&ga, (char_u *)"\\>"); ! if (type == FRD_REPLACEALL) { + /* A button was pressed, thus undo should be synced. */ + if (no_u_sync == 0) + u_sync(); + ga_concat(&ga, (char_u *)"/"); ! concat_esc(&ga, repl_text, '/'); /* escape slashes */ ga_concat(&ga, (char_u *)"/g"); do_cmdline_cmd(ga.ga_data); } *** ../vim61.043/src/gui.h Sat Mar 9 16:17:30 2002 --- src/gui.h Wed May 1 20:36:02 2002 *************** *** 482,495 **** VW_POS_TOP_CENTER } gui_win_pos_T; ! #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) /* * Flags used to distinguish the different contexts in which the * find/replace callback may be called. */ ! # define FR_FINDNEXT 1 /* Find next in find dialog */ ! # define FR_R_FINDNEXT 2 /* Find next in repl dialog */ ! # define FR_REPLACE 3 ! # define FR_REPLACEALL 4 ! # define FR_UNDO 5 #endif --- 482,500 ---- VW_POS_TOP_CENTER } gui_win_pos_T; ! #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \ ! || defined(MSWIN_FIND_REPLACE) /* * Flags used to distinguish the different contexts in which the * find/replace callback may be called. */ ! # define FRD_FINDNEXT 1 /* Find next in find dialog */ ! # define FRD_R_FINDNEXT 2 /* Find next in repl dialog */ ! # define FRD_REPLACE 3 /* Replace once */ ! # define FRD_REPLACEALL 4 /* Replace remaining matches */ ! # define FRD_UNDO 5 /* Undo replaced text */ ! # define FRD_TYPE_MASK 7 /* Mask for the callback type */ ! /* Flags which change the way searching is done. */ ! # define FRD_WHOLE_WORD 0x08 /* match whole word only */ ! # define FRD_MATCH_CASE 0x10 /* match case */ #endif *** ../vim61.043/src/gui_motif.c Thu Feb 21 21:06:59 2002 --- src/gui_motif.c Wed May 1 20:07:45 2002 *************** *** 2579,2585 **** typedef struct _SharedFindReplace { Widget dialog; /* the main dialog widget */ ! Widget exact; /* 'Exact match' check button */ Widget up; /* search direction 'Up' radio button */ Widget down; /* search direction 'Down' radio button */ Widget what; /* 'Find what' entry text widget */ --- 2579,2586 ---- typedef struct _SharedFindReplace { Widget dialog; /* the main dialog widget */ ! Widget wword; /* 'Exact match' check button */ ! Widget mcase; /* 'match case' check button */ Widget up; /* search direction 'Up' radio button */ Widget down; /* search direction 'Down' radio button */ Widget what; /* 'Find what' entry text widget */ *************** *** 2648,2657 **** long_u flags = (long_u)client_data; char *find_text, *repl_text; Boolean direction_down = TRUE; ! Boolean exact_match = FALSE; SharedFindReplace *sfr; ! if (flags == FR_UNDO) { char_u *save_cpo = p_cpo; --- 2649,2659 ---- long_u flags = (long_u)client_data; char *find_text, *repl_text; Boolean direction_down = TRUE; ! Boolean wword; ! Boolean mcase; SharedFindReplace *sfr; ! if (flags == FRD_UNDO) { char_u *save_cpo = p_cpo; *************** *** 2664,2670 **** } /* Get the search/replace strings from the dialog */ ! if (flags == FR_FINDNEXT) { repl_text = NULL; sfr = &find_widgets; --- 2666,2672 ---- } /* Get the search/replace strings from the dialog */ ! if (flags == FRD_FINDNEXT) { repl_text = NULL; sfr = &find_widgets; *************** *** 2676,2685 **** } find_text = XmTextFieldGetString(sfr->what); XtVaGetValues(sfr->down, XmNset, &direction_down, NULL); ! XtVaGetValues(sfr->exact, XmNset, &exact_match, NULL); (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text, ! direction_down, exact_match); if (find_text != NULL) XtFree(find_text); --- 2678,2692 ---- } find_text = XmTextFieldGetString(sfr->what); XtVaGetValues(sfr->down, XmNset, &direction_down, NULL); ! XtVaGetValues(sfr->wword, XmNset, &wword, NULL); ! XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL); ! if (wword) ! flags |= FRD_WHOLE_WORD; ! if (mcase) ! flags |= FRD_MATCH_CASE; (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text, ! direction_down); if (find_text != NULL) XtFree(find_text); *************** *** 2715,2725 **** Widget separator; Widget input_form; Widget button_form; Widget frame; XmString str; int n; Arg args[6]; ! int exact_word = FALSE; Dimension width; Dimension widest; char_u *entry_text; --- 2722,2734 ---- Widget separator; Widget input_form; Widget button_form; + Widget toggle_form; Widget frame; XmString str; int n; Arg args[6]; ! int wword = FALSE; ! int mcase = !p_ic; Dimension width; Dimension widest; char_u *entry_text; *************** *** 2727,2733 **** frdp = do_replace ? &repl_widgets : &find_widgets; /* Get the search string to use. */ ! entry_text = get_find_dialog_text(arg, &exact_word); /* If the dialog already exists, just raise it. */ if (frdp->dialog) --- 2736,2742 ---- frdp = do_replace ? &repl_widgets : &find_widgets; /* Get the search string to use. */ ! entry_text = get_find_dialog_text(arg, &wword, &mcase); /* If the dialog already exists, just raise it. */ if (frdp->dialog) *************** *** 2745,2751 **** XmTextFieldSetString(frdp->what, (char *)entry_text); vim_free(entry_text); ! XtVaSetValues(frdp->exact, XmNset, exact_word, NULL); return; } --- 2754,2760 ---- XmTextFieldSetString(frdp->what, (char *)entry_text); vim_free(entry_text); ! XtVaSetValues(frdp->wword, XmNset, wword, NULL); return; } *************** *** 2788,2794 **** XtAddCallback(frdp->find, XmNactivateCallback, find_replace_callback, ! (XtPointer) (do_replace ? FR_R_FINDNEXT : FR_FINDNEXT)); if (do_replace) { --- 2797,2803 ---- XtAddCallback(frdp->find, XmNactivateCallback, find_replace_callback, ! (XtPointer) (do_replace ? FRD_R_FINDNEXT : FRD_FINDNEXT)); if (do_replace) { *************** *** 2803,2809 **** NULL); XmStringFree(str); XtAddCallback(frdp->replace, XmNactivateCallback, ! find_replace_callback, (XtPointer)FR_REPLACE); str = XmStringCreateSimple(_("Replace All")); frdp->all = XtVaCreateManagedWidget("replaceAllButton", --- 2812,2818 ---- NULL); XmStringFree(str); XtAddCallback(frdp->replace, XmNactivateCallback, ! find_replace_callback, (XtPointer)FRD_REPLACE); str = XmStringCreateSimple(_("Replace All")); frdp->all = XtVaCreateManagedWidget("replaceAllButton", *************** *** 2816,2822 **** NULL); XmStringFree(str); XtAddCallback(frdp->all, XmNactivateCallback, ! find_replace_callback, (XtPointer)FR_REPLACEALL); str = XmStringCreateSimple(_("Undo")); frdp->undo = XtVaCreateManagedWidget("undoButton", --- 2825,2831 ---- NULL); XmStringFree(str); XtAddCallback(frdp->all, XmNactivateCallback, ! find_replace_callback, (XtPointer)FRD_REPLACEALL); str = XmStringCreateSimple(_("Undo")); frdp->undo = XtVaCreateManagedWidget("undoButton", *************** *** 2829,2835 **** NULL); XmStringFree(str); XtAddCallback(frdp->undo, XmNactivateCallback, ! find_replace_callback, (XtPointer)FR_UNDO); } str = XmStringCreateSimple(_("Cancel")); --- 2838,2844 ---- NULL); XmStringFree(str); XtAddCallback(frdp->undo, XmNactivateCallback, ! find_replace_callback, (XtPointer)FRD_UNDO); } str = XmStringCreateSimple(_("Cancel")); *************** *** 2901,2907 **** NULL); XtAddCallback(frdp->with, XmNactivateCallback, ! find_replace_callback, (XtPointer) FR_R_FINDNEXT); str = XmStringCreateSimple(_("Replace with:")); label_with = XtVaCreateManagedWidget("withLabel", --- 2910,2916 ---- NULL); XtAddCallback(frdp->with, XmNactivateCallback, ! find_replace_callback, (XtPointer) FRD_R_FINDNEXT); str = XmStringCreateSimple(_("Replace with:")); label_with = XtVaCreateManagedWidget("withLabel", *************** *** 2932,2938 **** * Make the entry activation do the search. */ XtAddCallback(frdp->what, XmNactivateCallback, ! find_replace_callback, (XtPointer)FR_FINDNEXT); } XtAddEventHandler(frdp->what, KeyPressMask, False, (XtEventHandler)find_replace_keypress, --- 2941,2947 ---- * Make the entry activation do the search. */ XtAddCallback(frdp->what, XmNactivateCallback, ! find_replace_callback, (XtPointer)FRD_FINDNEXT); } XtAddEventHandler(frdp->what, KeyPressMask, False, (XtEventHandler)find_replace_keypress, *************** *** 3005,3026 **** XtManageChild(frame); } ! str = XmStringCreateSimple(_("Match exact word only")); ! frdp->exact = XtVaCreateManagedWidget("exactToggle", ! xmToggleButtonGadgetClass, frdp->dialog, ! XmNlabelString, str, ! XmNorientation, XmVERTICAL, ! XmNentryAlignment, XmALIGNMENT_BEGINNING, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 4, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, frame, XmNrightOffset, 4, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 4, ! XmNset, exact_word, NULL); XmStringFree(str); if (entry_text != NULL) XmTextFieldSetString(frdp->what, (char *)entry_text); --- 3014,3059 ---- XtManageChild(frame); } ! toggle_form = XtVaCreateWidget("toggleForm", ! xmFormWidgetClass, frdp->dialog, XmNleftAttachment, XmATTACH_FORM, XmNleftOffset, 4, XmNrightAttachment, XmATTACH_WIDGET, XmNrightWidget, frame, XmNrightOffset, 4, + XmNtopAttachment, XmATTACH_WIDGET, + XmNtopWidget, input_form, + XmNtopOffset, 4, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 4, ! NULL); ! ! str = XmStringCreateSimple(_("Match whole word only")); ! frdp->wword = XtVaCreateManagedWidget("wordToggle", ! xmToggleButtonGadgetClass, toggle_form, ! XmNlabelString, str, ! XmNtopAttachment, XmATTACH_FORM, ! XmNtopOffset, 4, ! XmNleftAttachment, XmATTACH_FORM, ! XmNleftOffset, 4, ! XmNset, wword, NULL); XmStringFree(str); + + str = XmStringCreateSimple(_("Match case")); + frdp->mcase = XtVaCreateManagedWidget("caseToggle", + xmToggleButtonGadgetClass, toggle_form, + XmNlabelString, str, + XmNleftAttachment, XmATTACH_FORM, + XmNleftOffset, 4, + XmNtopAttachment, XmATTACH_WIDGET, + XmNtopWidget, frdp->wword, + XmNtopOffset, 4, + XmNset, mcase, + NULL); + XmStringFree(str); + + XtManageChild(toggle_form); if (entry_text != NULL) XmTextFieldSetString(frdp->what, (char *)entry_text); *** ../vim61.043/src/gui_gtk.c Thu Feb 28 16:27:52 2002 --- src/gui_gtk.c Wed May 1 20:07:56 2002 *************** *** 119,125 **** static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog); static void find_direction_cb(GtkWidget *widget, gpointer data); static void find_replace_cb(GtkWidget *widget, unsigned int flags); ! static void exact_match_cb(GtkWidget *widget, gpointer data); static void repl_dir_cb(GtkWidget * widget, gpointer data); /* --- 119,126 ---- static void entry_changed_cb(GtkWidget *entry, GtkWidget *dialog); static void find_direction_cb(GtkWidget *widget, gpointer data); static void find_replace_cb(GtkWidget *widget, unsigned int flags); ! static void wword_match_cb(GtkWidget *widget, gpointer data); ! static void mcase_match_cb(GtkWidget *widget, gpointer data); static void repl_dir_cb(GtkWidget * widget, gpointer data); /* *************** *** 1474,1480 **** typedef struct _SharedFindReplace { GtkWidget *dialog; /* the main dialog widget */ ! GtkWidget *exact; /* 'Exact match' check button */ GtkWidget *up; /* search direction 'Up' radio button */ GtkWidget *down; /* search direction 'Down' radio button */ GtkWidget *what; /* 'Find what' entry text widget */ --- 1475,1482 ---- typedef struct _SharedFindReplace { GtkWidget *dialog; /* the main dialog widget */ ! GtkWidget *wword; /* 'Whole word only' check button */ ! GtkWidget *mcase; /* 'Match case' check button */ GtkWidget *up; /* search direction 'Up' radio button */ GtkWidget *down; /* search direction 'Down' radio button */ GtkWidget *what; /* 'Find what' entry text widget */ *************** *** 1533,1544 **** gboolean sensitive; SharedFindReplace *frdp; char_u *entry_text; ! int exact_word = FALSE; frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); /* Get the search string to use. */ ! entry_text = get_find_dialog_text(arg, &exact_word); /* * If the dialog already exists, just raise it. --- 1535,1547 ---- gboolean sensitive; SharedFindReplace *frdp; char_u *entry_text; ! int wword = FALSE; ! int mcase = !p_ic; frdp = (do_replace) ? (&repl_widgets) : (&find_widgets); /* Get the search string to use. */ ! entry_text = get_find_dialog_text(arg, &wword, &mcase); /* * If the dialog already exists, just raise it. *************** *** 1560,1567 **** if (entry_text != NULL) { gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text); ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->exact), ! (gboolean)exact_word); } gdk_window_raise(frdp->dialog->window); --- 1563,1572 ---- if (entry_text != NULL) { gtk_entry_set_text(GTK_ENTRY(frdp->what), (char *)entry_text); ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword), ! (gboolean)wword); ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase), ! (gboolean)mcase); } gdk_window_raise(frdp->dialog->window); *************** *** 1626,1632 **** frdp->with = gtk_entry_new(); gtk_signal_connect(GTK_OBJECT(frdp->with), "activate", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FR_R_FINDNEXT); gtk_signal_connect_after(GTK_OBJECT(frdp->with), "key_press_event", GTK_SIGNAL_FUNC(find_key_press_event), (gpointer) frdp); --- 1631,1637 ---- frdp->with = gtk_entry_new(); gtk_signal_connect(GTK_OBJECT(frdp->with), "activate", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FRD_R_FINDNEXT); gtk_signal_connect_after(GTK_OBJECT(frdp->with), "key_press_event", GTK_SIGNAL_FUNC(find_key_press_event), (gpointer) frdp); *************** *** 1647,1666 **** */ gtk_signal_connect(GTK_OBJECT(frdp->what), "activate", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FR_FINDNEXT); } ! /* exact match only button */ ! frdp->exact = gtk_check_button_new_with_label(_("Match exact word only")); ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->exact), ! (gboolean)exact_word); ! gtk_signal_connect(GTK_OBJECT(frdp->exact), "clicked", ! GTK_SIGNAL_FUNC(exact_match_cb), NULL); if (do_replace) ! gtk_table_attach(GTK_TABLE(table), frdp->exact, 0, 1023, 3, 4, GTK_FILL, GTK_EXPAND, 2, 2); else ! gtk_table_attach(GTK_TABLE(table), frdp->exact, 0, 1023, 2, 3, GTK_FILL, GTK_EXPAND, 2, 2); tmp = gtk_frame_new(_("Direction")); --- 1652,1684 ---- */ gtk_signal_connect(GTK_OBJECT(frdp->what), "activate", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FRD_FINDNEXT); } ! /* whole word only button */ ! frdp->wword = gtk_check_button_new_with_label(_("Match whole word only")); ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->wword), ! (gboolean)wword); ! gtk_signal_connect(GTK_OBJECT(frdp->wword), "clicked", ! GTK_SIGNAL_FUNC(wword_match_cb), NULL); if (do_replace) ! gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 2, 3, GTK_FILL, GTK_EXPAND, 2, 2); else ! gtk_table_attach(GTK_TABLE(table), frdp->wword, 0, 1023, 1, 2, ! GTK_FILL, GTK_EXPAND, 2, 2); ! ! /* match case button */ ! frdp->mcase = gtk_check_button_new_with_label(_("Match case")); ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(frdp->mcase), ! (gboolean)mcase); ! gtk_signal_connect(GTK_OBJECT(frdp->mcase), "clicked", ! GTK_SIGNAL_FUNC(mcase_match_cb), NULL); ! if (do_replace) ! gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 3, 4, ! GTK_FILL, GTK_EXPAND, 2, 2); ! else ! gtk_table_attach(GTK_TABLE(table), frdp->mcase, 0, 1023, 2, 3, GTK_FILL, GTK_EXPAND, 2, 2); tmp = gtk_frame_new(_("Direction")); *************** *** 1706,1716 **** if (do_replace) gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FR_R_FINDNEXT); else gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FR_FINDNEXT); GTK_WIDGET_SET_FLAGS(frdp->find, GTK_CAN_DEFAULT); gtk_box_pack_start(GTK_BOX(actionarea), frdp->find, FALSE, FALSE, 0); gtk_widget_grab_default(frdp->find); --- 1724,1734 ---- if (do_replace) gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FRD_R_FINDNEXT); else gtk_signal_connect(GTK_OBJECT(frdp->find), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FRD_FINDNEXT); GTK_WIDGET_SET_FLAGS(frdp->find, GTK_CAN_DEFAULT); gtk_box_pack_start(GTK_BOX(actionarea), frdp->find, FALSE, FALSE, 0); gtk_widget_grab_default(frdp->find); *************** *** 1724,1730 **** gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FR_REPLACE); /* 'Replace All' button */ frdp->all = gtk_button_new_with_label(_("Replace All")); --- 1742,1748 ---- gtk_box_pack_start(GTK_BOX(actionarea), frdp->replace, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(frdp->replace), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FRD_REPLACE); /* 'Replace All' button */ frdp->all = gtk_button_new_with_label(_("Replace All")); *************** *** 1733,1739 **** gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FR_REPLACEALL); } /* 'Cancel' button */ --- 1751,1757 ---- gtk_box_pack_start(GTK_BOX(actionarea), frdp->all, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(frdp->all), "clicked", GTK_SIGNAL_FUNC(find_replace_cb), ! (gpointer) FRD_REPLACEALL); } /* 'Cancel' button */ *************** *** 1841,1851 **** { char *find_text, *repl_text; gboolean direction_down = TRUE; - gboolean exact_match = FALSE; SharedFindReplace *sfr; /* Get the search/replace strings from the dialog */ ! if (flags == FR_FINDNEXT) { repl_text = NULL; sfr = &find_widgets; --- 1859,1868 ---- { char *find_text, *repl_text; gboolean direction_down = TRUE; SharedFindReplace *sfr; /* Get the search/replace strings from the dialog */ ! if (flags == FRD_FINDNEXT) { repl_text = NULL; sfr = &find_widgets; *************** *** 1857,1866 **** } find_text = gtk_entry_get_text(GTK_ENTRY(sfr->what)); direction_down = GTK_TOGGLE_BUTTON(sfr->down)->active; ! exact_match = GTK_TOGGLE_BUTTON(sfr->exact)->active; if (gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text, ! (int)direction_down, (int)exact_match)) if (gtk_main_level() > 0) gtk_main_quit(); /* make sure cmd will be handled immediately */ } --- 1874,1886 ---- } find_text = gtk_entry_get_text(GTK_ENTRY(sfr->what)); direction_down = GTK_TOGGLE_BUTTON(sfr->down)->active; ! if (GTK_TOGGLE_BUTTON(sfr->wword)->active) ! flags |= FRD_WHOLE_WORD; ! if (GTK_TOGGLE_BUTTON(sfr->mcase)->active) ! flags |= FRD_MATCH_CASE; if (gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text, ! (int)direction_down)) if (gtk_main_level() > 0) gtk_main_quit(); /* make sure cmd will be handled immediately */ } *************** *** 1912,1927 **** /*ARGSUSED*/ static void ! exact_match_cb(GtkWidget * widget, gpointer data) { ! gboolean exact_match = GTK_TOGGLE_BUTTON(widget)->active; if (find_widgets.dialog) ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(find_widgets.exact), ! exact_match); if (repl_widgets.dialog) ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(repl_widgets.exact), ! exact_match); } static void --- 1932,1961 ---- /*ARGSUSED*/ static void ! wword_match_cb(GtkWidget * widget, gpointer data) ! { ! gboolean active = GTK_TOGGLE_BUTTON(widget)->active; ! ! if (find_widgets.dialog) ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(find_widgets.wword), ! active); ! if (repl_widgets.dialog) ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(repl_widgets.wword), ! active); ! } ! ! /*ARGSUSED*/ ! static void ! mcase_match_cb(GtkWidget * widget, gpointer data) { ! gboolean active = GTK_TOGGLE_BUTTON(widget)->active; if (find_widgets.dialog) ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(find_widgets.mcase), ! active); if (repl_widgets.dialog) ! gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(repl_widgets.mcase), ! active); } static void *** ../vim61.043/src/gui_w48.c Sat Mar 30 17:05:41 2002 --- src/gui_w48.c Wed May 1 21:00:30 2002 *************** *** 44,53 **** # include "glbl_ime.h" #endif - #ifdef FEAT_SMALL - # define MSWIN_FIND_REPLACE /* include code for find/replace dialog */ - # define MSWIN_FR_BUFSIZE 256 - #endif #ifdef FEAT_MENU # define MENUHINTS /* show menu hints in command line */ #endif --- 44,49 ---- *************** *** 141,148 **** static int destroying = FALSE; /* call DestroyWindow() ourselves */ #ifdef MSWIN_FIND_REPLACE ! static UINT s_findrep_msg = 0; static FINDREPLACE s_findrep_struct; #endif static HINSTANCE s_hinst = NULL; --- 137,147 ---- static int destroying = FALSE; /* call DestroyWindow() ourselves */ #ifdef MSWIN_FIND_REPLACE ! static UINT s_findrep_msg = 0; /* set in gui_w[16/32].c */ static FINDREPLACE s_findrep_struct; + static HWND s_findrep_hwnd = NULL; + static int s_findrep_is_find; /* TRUE for find dialog, FALSE + for find/replace dialog */ #endif static HINSTANCE s_hinst = NULL; *************** *** 267,276 **** static UINT s_wait_timer = 0; /* Timer for get char from user */ static int s_timed_out = FALSE; static int dead_key = 0; /* 0 - no dead key, 1 - dead key pressed */ - #ifdef MSWIN_FIND_REPLACE - static HWND s_findrep_hwnd = NULL; - static int s_findrep_is_find; - #endif /* * For control IME. --- 266,271 ---- *************** *** 764,900 **** } #endif ! #if defined(MSWIN_FIND_REPLACE) ! /* ! * Copy the "from" string to the end of cmd[], escaping any '/'. ! */ ! static void ! fr_copy_escape(char *from, char_u *to) ! { ! char *s; ! char_u *d; ! ! d = to + STRLEN(to); ! for (s = from; *s != NUL; ++s) ! { ! if (*s == '/') ! *d++ = '\\'; ! *d++ = *s; ! } ! *d = NUL; ! } ! ! static void ! fr_setwhat(char_u *cmd) ! { ! if (s_findrep_struct.Flags & FR_WHOLEWORD) ! STRCAT(cmd, "\\<"); ! fr_copy_escape(s_findrep_struct.lpstrFindWhat, cmd); ! if (s_findrep_struct.Flags & FR_WHOLEWORD) ! STRCAT(cmd, "\\>"); ! } ! ! static void ! fr_setreplcmd(char_u *cmd) ! { ! STRCAT(cmd, ":%sno/"); ! fr_setwhat(cmd); ! STRCAT(cmd, "/"); ! fr_copy_escape(s_findrep_struct.lpstrReplaceWith, cmd); ! if (s_findrep_struct.Flags & FR_REPLACE) ! STRCAT(cmd, "/gc"); ! else ! STRCAT(cmd, "/g"); ! if (s_findrep_struct.Flags & FR_MATCHCASE) ! STRCAT(cmd, "I"); ! else ! STRCAT(cmd, "i"); ! STRCAT(cmd, "\r"); ! } ! /* * Handle a Find/Replace window message. */ static void _OnFindRepl(void) { ! char_u cmd[MSWIN_FR_BUFSIZE * 2 + 100]; //XXX kludge ! ! /* Add a char before the command if needed */ ! if (State & INSERT) ! cmd[0] = Ctrl_O; ! else if ((State & NORMAL) == 0 && State != CONFIRM) ! cmd[0] = ESC; ! else ! cmd[0] = NUL; ! cmd[1] = NUL; ! if (s_findrep_struct.Flags & FR_DIALOGTERM) ! { ! if (State == CONFIRM) ! add_to_input_buf("q", 1); ! return; ! } if (s_findrep_struct.Flags & FR_FINDNEXT) { ! if (State == CONFIRM) ! STRCAT(cmd, "n"); ! else ! { ! /* Set 'ignorecase' just for this search command. */ ! if (!(s_findrep_struct.Flags & FR_MATCHCASE) == !p_ic) ! { ! if (p_ic) ! STRCAT(cmd, ":set noic\r"); ! else ! STRCAT(cmd, ":set ic\r"); ! if (State & INSERT) ! STRCAT(cmd, "\017"); /* CTRL-O */ ! } ! if (s_findrep_struct.Flags & FR_DOWN) ! STRCAT(cmd, "/"); ! else ! STRCAT(cmd, "?"); ! fr_setwhat(cmd); ! STRCAT(cmd, "\r"); ! if (!(s_findrep_struct.Flags & FR_MATCHCASE) == !p_ic) ! { ! if (State & INSERT) ! STRCAT(cmd, "\017"); /* CTRL-O */ ! if (p_ic) ! STRCAT(cmd, ":set ic\r"); ! else ! STRCAT(cmd, ":set noic\r"); ! } ! } ! /* ! * Give main window the focus back: this is so ! * the cursor isn't hollow. ! */ (void)SetFocus(s_hwnd); } else if (s_findrep_struct.Flags & FR_REPLACE) { ! if (State == CONFIRM) ! STRCAT(cmd, "y"); ! else ! fr_setreplcmd(cmd); ! /* ! * Give main window the focus back: this is to allow ! * handling of the confirmation y/n/a/q stuff. ! */ (void)SetFocus(s_hwnd); } else if (s_findrep_struct.Flags & FR_REPLACEALL) { ! if (State == CONFIRM) ! STRCAT(cmd, "a"); ! else ! fr_setreplcmd(cmd); } - if (*cmd) - add_to_input_buf(cmd, (int)STRLEN(cmd)); } #endif --- 759,808 ---- } #endif ! #ifdef MSWIN_FIND_REPLACE /* * Handle a Find/Replace window message. */ static void _OnFindRepl(void) { ! int flags = 0; ! int down; ! /* if (s_findrep_struct.Flags & FR_DIALOGTERM) nothing to do */ if (s_findrep_struct.Flags & FR_FINDNEXT) { ! flags = FRD_FINDNEXT; ! ! /* Give main window the focus back: this is so the cursor isn't ! * hollow. */ (void)SetFocus(s_hwnd); } else if (s_findrep_struct.Flags & FR_REPLACE) { ! flags = FRD_REPLACE; ! ! /* Give main window the focus back: this is so the cursor isn't ! * hollow. */ (void)SetFocus(s_hwnd); } else if (s_findrep_struct.Flags & FR_REPLACEALL) { ! flags = FRD_REPLACEALL; ! } ! ! if (flags != 0) ! { ! /* Call the generic GUI function to do the actual work. */ ! if (s_findrep_struct.Flags & FR_WHOLEWORD) ! flags |= FRD_WHOLE_WORD; ! if (s_findrep_struct.Flags & FR_MATCHCASE) ! flags |= FRD_MATCH_CASE; ! down = (s_findrep_struct.Flags & FR_DOWN) != 0; ! gui_do_findrepl(flags, s_findrep_struct.lpstrFindWhat, ! s_findrep_struct.lpstrReplaceWith, down); } } #endif *************** *** 1533,1539 **** #ifdef MSWIN_FIND_REPLACE /* Don't process messages used by the dialog */ ! if ((s_findrep_hwnd) && (IsDialogMessage(s_findrep_hwnd, &msg))) { HandleMouseHide(msg.message, msg.lParam); return; --- 1441,1447 ---- #ifdef MSWIN_FIND_REPLACE /* Don't process messages used by the dialog */ ! if (s_findrep_hwnd != NULL && IsDialogMessage(s_findrep_hwnd, &msg)) { HandleMouseHide(msg.message, msg.lParam); return; *************** *** 2038,2064 **** } /* ! * Create the find & replace dialogs * You can't have both at once: ":find" when replace is showing, destroys ! * the replace dialog first. */ #ifdef MSWIN_FIND_REPLACE static void initialise_findrep(char_u *initial_string) { s_findrep_struct.hwndOwner = s_hwnd; s_findrep_struct.Flags = FR_DOWN; ! if (p_ic) ! s_findrep_struct.Flags &= ~FR_MATCHCASE; ! else s_findrep_struct.Flags |= FR_MATCHCASE; ! if (initial_string != NULL && *initial_string != NUL) { ! STRNCPY(s_findrep_struct.lpstrFindWhat, initial_string, s_findrep_struct.wFindWhatLen); s_findrep_struct.lpstrFindWhat[s_findrep_struct.wFindWhatLen - 1] = NUL; s_findrep_struct.lpstrReplaceWith[0] = NUL; } } #endif --- 1946,1980 ---- } /* ! * Create the find & replace dialogs. * You can't have both at once: ":find" when replace is showing, destroys ! * the replace dialog first, and the other way around. */ #ifdef MSWIN_FIND_REPLACE static void initialise_findrep(char_u *initial_string) { + int wword = FALSE; + int mcase = !p_ic; + char_u *entry_text; + + /* Get the search string to use. */ + entry_text = get_find_dialog_text(initial_string, &wword, &mcase); + s_findrep_struct.hwndOwner = s_hwnd; s_findrep_struct.Flags = FR_DOWN; ! if (mcase) s_findrep_struct.Flags |= FR_MATCHCASE; ! if (wword) ! s_findrep_struct.Flags |= FR_WHOLEWORD; ! if (entry_text != NULL && *entry_text != NUL) { ! STRNCPY(s_findrep_struct.lpstrFindWhat, entry_text, s_findrep_struct.wFindWhatLen); s_findrep_struct.lpstrFindWhat[s_findrep_struct.wFindWhatLen - 1] = NUL; s_findrep_struct.lpstrReplaceWith[0] = NUL; } + vim_free(entry_text); } #endif *************** *** 2068,2074 **** #ifdef MSWIN_FIND_REPLACE if (s_findrep_msg != 0) { ! if (IsWindow(s_findrep_hwnd) && (s_findrep_is_find == FALSE)) DestroyWindow(s_findrep_hwnd); if (!IsWindow(s_findrep_hwnd)) --- 1984,1990 ---- #ifdef MSWIN_FIND_REPLACE if (s_findrep_msg != 0) { ! if (IsWindow(s_findrep_hwnd) && !s_findrep_is_find) DestroyWindow(s_findrep_hwnd); if (!IsWindow(s_findrep_hwnd)) *************** *** 2093,2099 **** #ifdef MSWIN_FIND_REPLACE if (s_findrep_msg != 0) { ! if (IsWindow(s_findrep_hwnd) && (s_findrep_is_find == TRUE)) DestroyWindow(s_findrep_hwnd); if (!IsWindow(s_findrep_hwnd)) --- 2009,2015 ---- #ifdef MSWIN_FIND_REPLACE if (s_findrep_msg != 0) { ! if (IsWindow(s_findrep_hwnd) && s_findrep_is_find) DestroyWindow(s_findrep_hwnd); if (!IsWindow(s_findrep_hwnd)) *** ../vim61.043/src/version.c Wed May 1 19:40:35 2002 --- src/version.c Wed May 1 20:51:21 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 44, /**/ -- TIM: That is not an ordinary rabbit ... 'tis the most foul cruel and bad-tempered thing you ever set eyes on. ROBIN: You tit. I soiled my armour I was so scared! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///