4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: GTK 2: Can't quit a dialog with <Esc>.
12 GTK 1 and 2: <Enter> always gives a result, even when the default
13 button has been disabled.
14 Solution: Handle these keys explicitly. When no default button is specified
15 use the first one (works mostly like it was before).
19 *** ../vim-6.2.259/src/gui_gtk.c Sun Feb 15 13:08:28 2004
20 --- src/gui_gtk.c Thu Feb 12 12:46:10 2004
24 typedef struct _CancelData
35 dlg_key_press_event(GtkWidget * widget, GdkEventKey * event, CancelData *data)
37 + /* Ignore hitting Enter when there is no default button. */
38 + if (data->ignore_enter && event->keyval == GDK_Return)
41 if (event->keyval != GDK_Escape && event->keyval != GDK_Return)
50 + cancel_data.ignore_enter = FALSE;
53 --def_but; /* 1 is first button */
57 gtk_widget_grab_focus(button[def_but]);
58 gtk_widget_grab_default(button[def_but]);
61 + /* No default, ignore hitting Enter. */
62 + cancel_data.ignore_enter = TRUE;
65 if (textfield != NULL)
68 * GUI used to work this way, and I consider the impact on UI consistency
69 * low enough to justify implementing this as a special Vim feature.
73 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
75 ! if ((event->state & gtk_accelerator_get_default_mod_mask()) == 0)
77 return gtk_window_mnemonic_activate(
78 GTK_WINDOW(widget), event->keyval,
79 gtk_window_get_mnemonic_modifier(GTK_WINDOW(widget)));
81 return FALSE; /* continue emission */
85 * GUI used to work this way, and I consider the impact on UI consistency
86 * low enough to justify implementing this as a special Vim feature.
88 + typedef struct _DialogInfo
90 + int ignore_enter; /* no default button, ignore "Enter" */
91 + int noalt; /* accept accelerators without Alt */
92 + GtkDialog *dialog; /* Widget of the dialog */
97 dialog_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
99 ! DialogInfo *di = (DialogInfo *)data;
101 ! /* Ignore hitting "Enter" if there is no default button. */
102 ! if (di->ignore_enter && event->keyval == GDK_Return)
105 ! /* Close the dialog when hitting "Esc". */
106 ! if (event->keyval == GDK_Escape)
108 ! gtk_dialog_response(di->dialog, GTK_RESPONSE_REJECT);
113 ! && (event->state & gtk_accelerator_get_default_mod_mask()) == 0)
115 return gtk_window_mnemonic_activate(
116 GTK_WINDOW(widget), event->keyval,
117 gtk_window_get_mnemonic_modifier(GTK_WINDOW(widget)));
120 return FALSE; /* continue emission */
126 GtkWidget *entry = NULL;
129 + DialogInfo dialoginfo;
131 dialog = create_message_dialog(type, title, message);
132 + dialoginfo.dialog = GTK_DIALOG(dialog);
133 dialog_add_buttons(GTK_DIALOG(dialog), buttons);
135 if (textfield != NULL)
139 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
140 alignment, TRUE, FALSE, 0);
144 ! /* Allow activation of mnemonic accelerators without pressing <Alt>.
145 ! * For safety, connect this signal handler only if the dialog has
146 ! * no other other interaction widgets but buttons. */
147 ! g_signal_connect(G_OBJECT(dialog), "key_press_event",
148 ! G_CALLBACK(&dialog_key_press_event_cb), NULL);
152 gtk_dialog_set_default_response(GTK_DIALOG(dialog), def_but);
154 /* Show the mouse pointer if it's currently hidden. */
155 gui_mch_mousehide(FALSE);
158 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
159 alignment, TRUE, FALSE, 0);
160 + dialoginfo.noalt = FALSE;
163 ! dialoginfo.noalt = TRUE;
165 ! /* Allow activation of mnemonic accelerators without pressing <Alt> when
166 ! * there is no textfield. Handle pressing Enter and Esc. */
167 ! g_signal_connect(G_OBJECT(dialog), "key_press_event",
168 ! G_CALLBACK(&dialog_key_press_event_cb), &dialoginfo);
172 gtk_dialog_set_default_response(GTK_DIALOG(dialog), def_but);
173 + dialoginfo.ignore_enter = FALSE;
176 + /* No default button, ignore pressing Enter. */
177 + dialoginfo.ignore_enter = TRUE;
179 /* Show the mouse pointer if it's currently hidden. */
180 gui_mch_mousehide(FALSE);
181 *** ../vim-6.2.259/src/version.c Sun Feb 15 13:37:22 2004
182 --- src/version.c Sun Feb 15 13:39:01 2004
186 { /* Add new patch number below this line */
192 hundred-and-one symptoms of being an internet addict:
193 146. You experience ACTUAL physical withdrawal symptoms when away
194 from your 'puter and the net.
196 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
197 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
198 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
199 \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///