2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 #include <sys/types.h>
28 #include <gtk/gtkstock.h>
29 #include <gtk/gtkentry.h>
30 #include <gtk/gtkclist.h>
31 #include <gtk/gtkhbox.h>
32 #include <gtk/gtkvseparator.h>
34 #include "../common/xchat.h"
35 #include "../common/cfgfiles.h"
36 #include "../common/xchatc.h"
37 #include "../common/fe.h"
44 static GtkWidget
*editlist_gui_entry_name
;
45 static GtkWidget
*editlist_gui_entry_cmd
;
46 static GtkWidget
*editlist_gui_window
;
47 static GtkWidget
*editlist_gui_list
;
48 static GSList
*editlist_list
;
49 static char *editlist_file
;
50 static char *editlist_help
;
55 editlist_gui_load (GtkWidget
* listgad
)
58 GSList
*list
= editlist_list
;
63 pop
= (struct popup
*) list
->data
;
66 gtk_clist_append (GTK_CLIST (listgad
), nnew
);
72 editlist_gui_row_unselected (GtkWidget
* clist
, gint row
, gint column
,
73 GdkEventButton
* even
, gpointer none
)
75 gtk_entry_set_text (GTK_ENTRY (editlist_gui_entry_name
), "");
76 gtk_entry_set_text (GTK_ENTRY (editlist_gui_entry_cmd
), "");
80 editlist_gui_row_selected (GtkWidget
* clist
, gint row
, gint column
,
81 GdkEventButton
* even
, gpointer none
)
85 row
= gtkutil_clist_selection (editlist_gui_list
);
88 gtk_clist_get_text (GTK_CLIST (clist
), row
, 0, &name
);
89 gtk_clist_get_text (GTK_CLIST (clist
), row
, 1, &cmd
);
94 gtk_entry_set_text (GTK_ENTRY (editlist_gui_entry_name
), name
);
95 gtk_entry_set_text (GTK_ENTRY (editlist_gui_entry_cmd
), cmd
);
101 editlist_gui_row_unselected (0, 0, 0, 0, 0);
106 editlist_gui_handle_cmd (GtkWidget
* igad
)
111 row
= gtkutil_clist_selection (editlist_gui_list
);
114 reply
= gtk_entry_get_text (GTK_ENTRY (igad
));
115 gtk_clist_set_text (GTK_CLIST (editlist_gui_list
), row
, 1, reply
);
120 editlist_gui_handle_name (GtkWidget
* igad
)
125 row
= gtkutil_clist_selection (editlist_gui_list
);
128 ctcp
= gtk_entry_get_text (GTK_ENTRY (igad
));
129 gtk_clist_set_text (GTK_CLIST (editlist_gui_list
), row
, 0, ctcp
);
134 editlist_gui_addnew (GtkWidget
* igad
)
139 nnew
[0] = _("*NEW*");
140 nnew
[1] = _("EDIT ME");
142 i
= gtk_clist_append (GTK_CLIST (editlist_gui_list
), nnew
);
143 gtk_clist_select_row (GTK_CLIST (editlist_gui_list
), i
, 0);
144 gtk_clist_moveto (GTK_CLIST (editlist_gui_list
), i
, 0, 0.5, 0);
148 editlist_gui_delete (GtkWidget
* igad
)
152 row
= gtkutil_clist_selection (editlist_gui_list
);
155 gtk_clist_unselect_all (GTK_CLIST (editlist_gui_list
));
156 gtk_clist_remove (GTK_CLIST (editlist_gui_list
), row
);
161 editlist_gui_save (GtkWidget
* igad
)
167 fh
= xchat_open_file (editlist_file
, O_TRUNC
| O_WRONLY
| O_CREAT
, 0600, XOF_DOMODE
);
172 if (!gtk_clist_get_text (GTK_CLIST (editlist_gui_list
), i
, 0, &a
))
174 gtk_clist_get_text (GTK_CLIST (editlist_gui_list
), i
, 1, &b
);
175 snprintf (buf
, sizeof (buf
), "NAME %s\nCMD %s\n\n", a
, b
);
176 write (fh
, buf
, strlen (buf
));
180 gtk_widget_destroy (editlist_gui_window
);
181 if (editlist_list
== replace_list
)
183 list_free (&replace_list
);
184 list_loadconf (editlist_file
, &replace_list
, 0);
185 } else if (editlist_list
== popup_list
)
187 list_free (&popup_list
);
188 list_loadconf (editlist_file
, &popup_list
, 0);
189 } else if (editlist_list
== button_list
)
191 GSList
*list
= sess_list
;
192 struct session
*sess
;
193 list_free (&button_list
);
194 list_loadconf (editlist_file
, &button_list
, 0);
197 sess
= (struct session
*) list
->data
;
198 fe_buttons_update (sess
);
201 } else if (editlist_list
== dlgbutton_list
)
203 GSList
*list
= sess_list
;
204 struct session
*sess
;
205 list_free (&dlgbutton_list
);
206 list_loadconf (editlist_file
, &dlgbutton_list
, 0);
209 sess
= (struct session
*) list
->data
;
210 fe_dlgbuttons_update (sess
);
213 } else if (editlist_list
== ctcp_list
)
215 list_free (&ctcp_list
);
216 list_loadconf (editlist_file
, &ctcp_list
, 0);
217 } else if (editlist_list
== command_list
)
219 list_free (&command_list
);
220 list_loadconf (editlist_file
, &command_list
, 0);
221 } else if (editlist_list
== usermenu_list
)
223 list_free (&usermenu_list
);
224 list_loadconf (editlist_file
, &usermenu_list
, 0);
228 list_free (&urlhandler_list
);
229 list_loadconf (editlist_file
, &urlhandler_list
, 0);
235 editlist_gui_help (GtkWidget
* igad
)
237 /* if (editlist_help)*/
238 fe_message (editlist_help
, FE_MSG_INFO
);
242 editlist_gui_sort (GtkWidget
* igad
)
246 row
= gtkutil_clist_selection (editlist_gui_list
);
248 gtk_clist_unselect_row (GTK_CLIST (editlist_gui_list
), row
, 0);
249 gtk_clist_sort (GTK_CLIST (editlist_gui_list
));
253 editlist_gui_movedown (GtkWidget
* igad
)
258 row
= gtkutil_clist_selection (editlist_gui_list
);
261 if (!gtk_clist_get_text (GTK_CLIST (editlist_gui_list
), row
+ 1, 0, &temp
))
263 gtk_clist_freeze (GTK_CLIST (editlist_gui_list
));
264 gtk_clist_swap_rows (GTK_CLIST (editlist_gui_list
), row
, row
+ 1);
265 gtk_clist_thaw (GTK_CLIST (editlist_gui_list
));
267 if (!gtk_clist_row_is_visible (GTK_CLIST (editlist_gui_list
), row
) !=
269 gtk_clist_moveto (GTK_CLIST (editlist_gui_list
), row
, 0, 0.9, 0);
274 editlist_gui_moveup (GtkWidget
* igad
)
278 row
= gtkutil_clist_selection (editlist_gui_list
);
279 if (row
!= -1 && row
> 0)
281 gtk_clist_freeze (GTK_CLIST (editlist_gui_list
));
282 gtk_clist_swap_rows (GTK_CLIST (editlist_gui_list
), row
- 1, row
);
283 gtk_clist_thaw (GTK_CLIST (editlist_gui_list
));
285 if (gtk_clist_row_is_visible (GTK_CLIST (editlist_gui_list
), row
) !=
287 gtk_clist_moveto (GTK_CLIST (editlist_gui_list
), row
, 0, 0.1, 0);
292 editlist_gui_close (void)
294 editlist_gui_window
= 0;
298 editlist_gui_open (char *title1
, char *title2
, GSList
* list
, char *title
, char *wmclass
,
299 char *file
, char *help
)
302 GtkWidget
*vbox
, *hbox
, *button
;
310 titles
[0] = _("Name");
311 titles
[1] = _("Command");
314 if (editlist_gui_window
)
316 mg_bring_tofront (editlist_gui_window
);
320 editlist_list
= list
;
321 editlist_file
= file
;
322 editlist_help
= help
;
324 editlist_gui_window
=
325 mg_create_generic_tab (wmclass
, title
, TRUE
, FALSE
,
326 editlist_gui_close
, NULL
, 450, 250, &vbox
, 0);
328 editlist_gui_list
= gtkutil_clist_new (2, titles
, vbox
, GTK_POLICY_ALWAYS
,
329 editlist_gui_row_selected
, 0,
330 editlist_gui_row_unselected
, 0,
331 GTK_SELECTION_BROWSE
);
332 gtk_clist_set_column_width (GTK_CLIST (editlist_gui_list
), 0, 90);
334 hbox
= gtk_hbox_new (0, 2);
335 gtk_box_pack_end (GTK_BOX (vbox
), hbox
, 0, 0, 0);
336 gtk_widget_show (hbox
);
338 button
= gtkutil_button (hbox
, GTK_STOCK_GO_UP
, 0, editlist_gui_moveup
,
340 gtk_widget_set_usize (button
, 100, 0);
342 button
= gtkutil_button (hbox
, GTK_STOCK_GO_DOWN
, 0, editlist_gui_movedown
,
344 gtk_widget_set_usize (button
, 100, 0);
346 button
= gtk_vseparator_new ();
347 gtk_container_add (GTK_CONTAINER (hbox
), button
);
348 gtk_widget_show (button
);
350 button
= gtkutil_button (hbox
, GTK_STOCK_CANCEL
, 0, gtkutil_destroy
,
351 editlist_gui_window
, _("Cancel"));
352 gtk_widget_set_usize (button
, 100, 0);
354 button
= gtkutil_button (hbox
, GTK_STOCK_SAVE
, 0, editlist_gui_save
,
356 gtk_widget_set_usize (button
, 100, 0);
358 hbox
= gtk_hbox_new (0, 2);
359 gtk_box_pack_end (GTK_BOX (vbox
), hbox
, 0, 0, 0);
360 gtk_widget_show (hbox
);
362 button
= gtkutil_button (hbox
, GTK_STOCK_ADD
, 0, editlist_gui_addnew
,
364 gtk_widget_set_usize (button
, 100, 0);
366 button
= gtkutil_button (hbox
, GTK_STOCK_REMOVE
, 0, editlist_gui_delete
,
368 gtk_widget_set_usize (button
, 100, 0);
370 button
= gtk_vseparator_new ();
371 gtk_container_add (GTK_CONTAINER (hbox
), button
);
372 gtk_widget_show (button
);
374 button
= gtkutil_button (hbox
, GTK_STOCK_SORT_ASCENDING
, 0, editlist_gui_sort
,
376 gtk_widget_set_usize (button
, 100, 0);
378 button
= gtkutil_button (hbox
, GTK_STOCK_HELP
, 0, editlist_gui_help
,
380 gtk_widget_set_usize (button
, 100, 0);
383 gtk_widget_set_sensitive (GTK_WIDGET (button
), FALSE
);
385 hbox
= gtk_hbox_new (0, 2);
386 gtk_box_pack_end (GTK_BOX (vbox
), hbox
, 0, 0, 0);
387 gtk_widget_show (hbox
);
389 editlist_gui_entry_name
= gtk_entry_new_with_max_length (82);
390 gtk_widget_set_usize (editlist_gui_entry_name
, 96, 0);
391 gtk_signal_connect (GTK_OBJECT (editlist_gui_entry_name
), "changed",
392 GTK_SIGNAL_FUNC (editlist_gui_handle_name
), 0);
393 gtk_box_pack_start (GTK_BOX (hbox
), editlist_gui_entry_name
, 0, 0, 0);
394 gtk_widget_show (editlist_gui_entry_name
);
396 editlist_gui_entry_cmd
= gtk_entry_new_with_max_length (255);
397 gtk_signal_connect (GTK_OBJECT (editlist_gui_entry_cmd
), "changed",
398 GTK_SIGNAL_FUNC (editlist_gui_handle_cmd
), 0);
399 gtk_container_add (GTK_CONTAINER (hbox
), editlist_gui_entry_cmd
);
400 gtk_widget_show (editlist_gui_entry_cmd
);
402 hbox
= gtk_hbox_new (0, 2);
403 gtk_box_pack_end (GTK_BOX (vbox
), hbox
, 0, 0, 0);
404 gtk_widget_show (hbox
);
406 editlist_gui_load (editlist_gui_list
);
408 gtk_widget_show (editlist_gui_window
);