18
18
* along with this program; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $Id: tools.c 4630 2010-01-31 21:54:47Z eht16 $
21
* $Id: tools.c 4518 2010-01-01 22:55:18Z eht16 $
76
76
entry = gtk_entry_new();
78
78
gtk_entry_set_text(GTK_ENTRY(entry), ui_prefs.custom_commands[idx]);
79
ui_entry_add_clear_icon(entry);
79
ui_entry_add_clear_icon(GTK_ENTRY(entry));
80
80
gtk_entry_set_max_length(GTK_ENTRY(entry), 255);
81
81
gtk_entry_set_width_chars(GTK_ENTRY(entry), 30);
82
82
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
257
257
g_child_watch_add(pid, (GChildWatchFunc) cc_exit_cb, doc);
259
259
/* use GIOChannel to monitor stdout */
260
utils_set_up_io_channel(stdout_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
260
utils_set_up_io_channel(stdout_fd, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
261
261
FALSE, cc_iofunc, NULL);
262
262
/* copy program's stderr to Geany's stdout to help error tracking */
263
utils_set_up_io_channel(stderr_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
263
utils_set_up_io_channel(stderr_fd, G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
264
264
FALSE, cc_iofunc_err, (gpointer)command);
266
266
/* get selection */
344
344
/* get all hboxes which contain a label and an entry element */
345
345
GList *children = gtk_container_get_children(GTK_CONTAINER(cc.box));
347
347
GSList *result_list = NULL;
350
350
gchar **result = NULL;
351
351
const gchar *text;
353
while (children != NULL)
353
foreach_list(node, children)
355
355
/* get the contents of each hbox */
356
tmp = gtk_container_get_children(GTK_CONTAINER(children->data));
356
list = gtk_container_get_children(GTK_CONTAINER(node->data));
358
358
/* first element of the list is the label, so skip it and get the entry element */
361
text = gtk_entry_get_text(GTK_ENTRY(tmp->data));
359
text = gtk_entry_get_text(GTK_ENTRY(list->next->data));
363
361
/* if the content of the entry is non-empty, add it to the result array */
364
362
if (text[0] != '\0')
409
407
children = gtk_container_get_children(GTK_CONTAINER(user_data));
410
408
len = g_list_length(children);
412
while (children != NULL)
410
foreach_list(node, children)
414
412
if (i == (len - 2))
415
413
break; /* stop before the last two elements (the seperator and the set entry) */
417
gtk_widget_set_sensitive(GTK_WIDGET(children->data), enable);
418
children = children->next;
415
gtk_widget_set_sensitive(GTK_WIDGET(node->data), enable);
418
g_list_free(children);
446
static void cc_insert_custom_command_items(GtkMenu *me, GtkMenu *mp, gchar *label, gint idx)
444
static void cc_insert_custom_command_items(GtkMenu *me, gchar *label, gint idx)
449
447
gint key_idx = -1;
467
465
gtk_widget_show(item);
468
466
g_signal_connect(item, "activate", G_CALLBACK(cc_on_custom_command_activate),
469
467
GINT_TO_POINTER(idx));
471
item = gtk_menu_item_new_with_label(label);
473
gtk_widget_add_accelerator(item, "activate", gtk_accel_group_new(),
474
kb->key, kb->mods, GTK_ACCEL_VISIBLE);
475
gtk_container_add(GTK_CONTAINER(mp), item);
476
gtk_widget_show(item);
477
g_signal_connect(item, "activate", G_CALLBACK(cc_on_custom_command_activate),
478
GINT_TO_POINTER(idx));
482
471
void tools_create_insert_custom_command_menu_items(void)
484
473
GtkMenu *menu_edit = GTK_MENU(ui_lookup_widget(main_widgets.window, "send_selection_to2_menu"));
485
GtkMenu *menu_popup = GTK_MENU(ui_lookup_widget(main_widgets.editor_menu, "send_selection_to1_menu"));
475
GList *me_children, *node;
489
476
static gboolean signal_set = FALSE;
491
478
/* first clean the menus to be able to rebuild them */
492
479
me_children = gtk_container_get_children(GTK_CONTAINER(menu_edit));
493
mp_children = gtk_container_get_children(GTK_CONTAINER(menu_popup));
494
while (me_children != NULL)
496
gtk_widget_destroy(GTK_WIDGET(me_children->data));
497
gtk_widget_destroy(GTK_WIDGET(mp_children->data));
499
me_children = me_children->next;
500
mp_children = mp_children->next;
480
foreach_list(node, me_children)
481
gtk_widget_destroy(GTK_WIDGET(node->data));
482
g_list_free(me_children);
504
484
if (ui_prefs.custom_commands == NULL || g_strv_length(ui_prefs.custom_commands) == 0)
507
487
gtk_container_add(GTK_CONTAINER(menu_edit), item);
508
488
gtk_widget_set_sensitive(item, FALSE);
509
489
gtk_widget_show(item);
510
item = gtk_menu_item_new_with_label(_("No custom commands defined."));
511
gtk_container_add(GTK_CONTAINER(menu_popup), item);
512
gtk_widget_set_sensitive(item, FALSE);
513
gtk_widget_show(item);
522
498
if (ui_prefs.custom_commands[i][0] != '\0') /* skip empty fields */
524
cc_insert_custom_command_items(menu_edit, menu_popup, ui_prefs.custom_commands[i], idx);
500
cc_insert_custom_command_items(menu_edit, ui_prefs.custom_commands[i], idx);
531
507
item = gtk_separator_menu_item_new();
532
508
gtk_container_add(GTK_CONTAINER(menu_edit), item);
533
509
gtk_widget_show(item);
534
item = gtk_separator_menu_item_new();
535
gtk_container_add(GTK_CONTAINER(menu_popup), item);
536
gtk_widget_show(item);
538
cc_insert_custom_command_items(menu_edit, menu_popup, _("Set Custom Commands"), -1);
511
cc_insert_custom_command_items(menu_edit, _("Set Custom Commands"), -1);
540
513
if (! signal_set)
542
g_signal_connect(ui_lookup_widget(main_widgets.editor_menu, "send_selection_to1"),
543
"activate", G_CALLBACK(cc_on_custom_command_menu_activate), menu_popup);
544
515
g_signal_connect(ui_lookup_widget(main_widgets.window, "send_selection_to2"),
545
516
"activate", G_CALLBACK(cc_on_custom_command_menu_activate), menu_edit);
546
517
signal_set = TRUE;