~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/tools.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
20
20
 *
21
 
 * $Id: tools.c 4630 2010-01-31 21:54:47Z eht16 $
 
21
 * $Id: tools.c 4518 2010-01-01 22:55:18Z eht16 $
22
22
 */
23
23
 
24
24
/*
76
76
        entry = gtk_entry_new();
77
77
        if (idx >= 0)
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);
258
258
 
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);
265
265
 
266
266
                /* get selection */
343
343
        {
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));
346
 
                GList *tmp;
 
346
                GList *node, *list;
347
347
                GSList *result_list = NULL;
348
348
                gint j = 0;
349
349
                gint len = 0;
350
350
                gchar **result = NULL;
351
351
                const gchar *text;
352
352
 
353
 
                while (children != NULL)
 
353
                foreach_list(node, children)
354
354
                {
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));
357
357
 
358
358
                        /* first element of the list is the label, so skip it and get the entry element */
359
 
                        tmp = tmp->next;
360
 
 
361
 
                        text = gtk_entry_get_text(GTK_ENTRY(tmp->data));
 
359
                        text = gtk_entry_get_text(GTK_ENTRY(list->next->data));
362
360
 
363
361
                        /* if the content of the entry is non-empty, add it to the result array */
364
362
                        if (text[0] != '\0')
366
364
                                result_list = g_slist_append(result_list, g_strdup(text));
367
365
                                len++;
368
366
                        }
369
 
                        children = children->next;
 
367
                        g_list_free(list);
370
368
                }
371
369
                /* create a new null-terminated array but only if there any commands defined */
372
370
                if (len > 0)
400
398
        GeanyDocument *doc = document_get_current();
401
399
        gint i, len;
402
400
        gboolean enable;
403
 
        GList *children;
 
401
        GList *children, *node;
404
402
 
405
403
        g_return_if_fail(doc != NULL);
406
404
 
409
407
        children = gtk_container_get_children(GTK_CONTAINER(user_data));
410
408
        len = g_list_length(children);
411
409
        i = 0;
412
 
        while (children != NULL)
 
410
        foreach_list(node, children)
413
411
        {
414
412
                if (i == (len - 2))
415
413
                        break; /* stop before the last two elements (the seperator and the set entry) */
416
414
 
417
 
                gtk_widget_set_sensitive(GTK_WIDGET(children->data), enable);
418
 
                children = children->next;
 
415
                gtk_widget_set_sensitive(GTK_WIDGET(node->data), enable);
419
416
                i++;
420
417
        }
 
418
        g_list_free(children);
421
419
}
422
420
 
423
421
 
443
441
}
444
442
 
445
443
 
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)
447
445
{
448
446
        GtkWidget *item;
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));
470
 
 
471
 
        item = gtk_menu_item_new_with_label(label);
472
 
        if (key_idx != -1)
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));
479
468
}
480
469
 
481
470
 
482
471
void tools_create_insert_custom_command_menu_items(void)
483
472
{
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"));
486
474
        GtkWidget *item;
487
 
        GList *me_children;
488
 
        GList *mp_children;
 
475
        GList *me_children, *node;
489
476
        static gboolean signal_set = FALSE;
490
477
 
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)
495
 
        {
496
 
                gtk_widget_destroy(GTK_WIDGET(me_children->data));
497
 
                gtk_widget_destroy(GTK_WIDGET(mp_children->data));
498
 
 
499
 
                me_children = me_children->next;
500
 
                mp_children = mp_children->next;
501
 
        }
502
 
 
 
480
        foreach_list(node, me_children)
 
481
                gtk_widget_destroy(GTK_WIDGET(node->data));
 
482
        g_list_free(me_children);
503
483
 
504
484
        if (ui_prefs.custom_commands == NULL || g_strv_length(ui_prefs.custom_commands) == 0)
505
485
        {
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);
514
490
        }
515
491
        else
516
492
        {
521
497
                {
522
498
                        if (ui_prefs.custom_commands[i][0] != '\0') /* skip empty fields */
523
499
                        {
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);
525
501
                                idx++;
526
502
                        }
527
503
                }
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);
537
510
 
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);
539
512
 
540
513
        if (! signal_set)
541
514
        {
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;