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

« back to all changes in this revision

Viewing changes to src/toolbar.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., 675 Mass Ave, Cambridge, MA 02139, USA.
20
20
 *
21
 
 * $Id: toolbar.c 4630 2010-01-31 21:54:47Z eht16 $
22
 
 */
23
 
 
24
 
 
25
 
/** @file toolbar.c
26
 
 * Utility functions to create the toolbar.
27
 
 */
 
21
 * $Id: toolbar.c 4941 2010-05-22 19:39:03Z eht16 $
 
22
 */
 
23
 
 
24
/**
 
25
 * @file toolbar.h
 
26
 * Toolbar (prefs).
 
27
 */
 
28
/* Utility functions to create the toolbar */
28
29
 
29
30
#include "geany.h"
30
31
#include "support.h"
287
288
        if (main_status.main_window_realized)
288
289
        {
289
290
                GeanyDocument *doc = document_get_current();
 
291
                gboolean doc_changed = (doc != NULL) ? doc->changed : FALSE;
290
292
 
291
293
                ui_document_buttons_update();
292
 
                ui_save_buttons_toggle(doc->changed); /* update save all */
 
294
                ui_save_buttons_toggle(doc_changed); /* update save all */
293
295
                ui_update_popup_reundo_items(doc);
294
296
 
295
297
                toolbar_apply_settings();
315
317
}
316
318
 
317
319
 
 
320
static void toolbar_notify_style_cb(GObject *object, GParamSpec *arg1, gpointer data)
 
321
{
 
322
        const gchar *arg_name = g_param_spec_get_name(arg1);
 
323
        gint value;
 
324
 
 
325
        if (toolbar_prefs.use_gtk_default_style && utils_str_equal(arg_name, "gtk-toolbar-style"))
 
326
        {
 
327
                value = ui_get_gtk_settings_integer(arg_name, toolbar_prefs.icon_style);
 
328
                gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), value);
 
329
        }
 
330
        else if (toolbar_prefs.use_gtk_default_icon && utils_str_equal(arg_name, "gtk-toolbar-size"))
 
331
        {
 
332
                value = ui_get_gtk_settings_integer(arg_name, toolbar_prefs.icon_size);
 
333
                gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), value);
 
334
        }
 
335
}
 
336
 
 
337
 
318
338
GtkWidget *toolbar_init(void)
319
339
{
320
340
        GtkWidget *toolbar;
323
343
        GtkAction *action_build;
324
344
        GtkAction *action_searchentry;
325
345
        GtkAction *action_gotoentry;
 
346
        GtkSettings *gtk_settings;
326
347
 
327
348
        uim = gtk_ui_manager_new();
328
349
        group = gtk_action_group_new("GeanyToolbar");
331
352
        gtk_action_group_add_actions(group, ui_entries, ui_entries_n, NULL);
332
353
 
333
354
        /* Create our custom actions */
334
 
        action_new = geany_menu_button_action_new("New", NULL, _("Create a new file"), GTK_STOCK_NEW);
 
355
        action_new = geany_menu_button_action_new(
 
356
                "New", NULL,
 
357
                _("Create a new file"),
 
358
                _("Create a new file from a template"),
 
359
                GTK_STOCK_NEW);
335
360
        g_signal_connect(action_new, "button-clicked", G_CALLBACK(on_toolbutton_new_clicked), NULL);
336
361
        gtk_action_group_add_action(group, action_new);
337
362
 
338
363
        action_open = geany_menu_button_action_new(
339
 
                "Open", NULL, _("Open an existing file"), GTK_STOCK_OPEN);
 
364
                "Open", NULL,
 
365
                _("Open an existing file"),
 
366
                _("Open a recent file"),
 
367
                GTK_STOCK_OPEN);
340
368
        g_signal_connect(action_open, "button-clicked", G_CALLBACK(on_toolbutton_open_clicked), NULL);
341
369
        gtk_action_group_add_action(group, action_open);
342
370
 
343
371
        action_build = geany_menu_button_action_new(
344
 
                "Build", NULL, _("Build the current file"), GEANY_STOCK_BUILD);
 
372
                "Build", NULL,
 
373
                _("Build the current file"),
 
374
                _("Choose more build actions"),
 
375
                GEANY_STOCK_BUILD);
345
376
        g_signal_connect(action_build, "button-clicked",
346
377
                G_CALLBACK(build_toolbutton_build_clicked), NULL);
347
378
        gtk_action_group_add_action(group, action_build);
364
395
 
365
396
        toolbar = toolbar_reload(NULL);
366
397
 
 
398
        gtk_settings = gtk_widget_get_settings(GTK_WIDGET(toolbar));
 
399
        if (gtk_settings != NULL)
 
400
        {
 
401
                g_signal_connect(gtk_settings, "notify::gtk-toolbar-style",
 
402
                        G_CALLBACK(toolbar_notify_style_cb), NULL);
 
403
        }
 
404
 
367
405
        return toolbar;
368
406
}
369
407
 
372
410
{
373
411
        static GtkWidget *hbox_menubar = NULL;
374
412
        static GtkWidget *menubar = NULL;
375
 
        static GtkWidget *menubar_toolbar_separator = NULL;
 
413
        GtkWidget *menubar_toolbar_separator = NULL;
376
414
        GtkWidget *parent;
 
415
        GtkToolItem *first_item;
377
416
 
378
417
        if (menubar == NULL)
379
418
        {       /* cache widget pointers */
380
419
                hbox_menubar = ui_lookup_widget(main_widgets.window, "hbox_menubar");
381
420
                menubar = ui_lookup_widget(main_widgets.window, "menubar1");
382
 
 
383
 
                menubar_toolbar_separator = GTK_WIDGET(gtk_separator_tool_item_new());
384
 
                gtk_toolbar_insert(GTK_TOOLBAR(main_widgets.toolbar),
385
 
                        GTK_TOOL_ITEM(menubar_toolbar_separator), 0);
 
421
        }
 
422
        /* the separator between the menubar and the toolbar */
 
423
        first_item = gtk_toolbar_get_nth_item(GTK_TOOLBAR(main_widgets.toolbar), 0);
 
424
        if (first_item != NULL && GTK_IS_SEPARATOR_TOOL_ITEM(first_item))
 
425
        {
 
426
                gtk_widget_destroy(GTK_WIDGET(first_item));
386
427
        }
387
428
 
388
429
        parent = gtk_widget_get_parent(main_widgets.toolbar);
405
446
                }
406
447
                else
407
448
                        gtk_box_pack_start(GTK_BOX(hbox_menubar), main_widgets.toolbar, TRUE, TRUE, 0);
 
449
 
 
450
                /* the separator between the menubar and the toolbar */
 
451
                menubar_toolbar_separator = GTK_WIDGET(gtk_separator_tool_item_new());
 
452
                gtk_widget_show(menubar_toolbar_separator);
 
453
                gtk_toolbar_insert(GTK_TOOLBAR(main_widgets.toolbar),
 
454
                        GTK_TOOL_ITEM(menubar_toolbar_separator), 0);
408
455
        }
409
456
        else
410
457
        {
429
476
                        gtk_box_reorder_child(GTK_BOX(box), main_widgets.toolbar, 1);
430
477
                }
431
478
        }
432
 
        /* the separator between the menubar and the toolbar */
433
 
        ui_widget_show_hide(menubar_toolbar_separator, toolbar_prefs.append_to_menu);
434
479
        /* we need to adjust the packing flags for the menubar to expand it if it is alone in the
435
480
         * hbox and not expand it if the toolbar is appended */
436
481
        gtk_box_set_child_packing(GTK_BOX(hbox_menubar), menubar,
473
518
 
474
519
void toolbar_finalize(void)
475
520
{
476
 
        g_object_unref(geany_menu_button_action_get_menu(
477
 
                                        GEANY_MENU_BUTTON_ACTION(toolbar_get_action_by_name("Open"))));
 
521
        GeanyMenubuttonAction *open_action = GEANY_MENU_BUTTON_ACTION(toolbar_get_action_by_name("Open"));
 
522
        g_object_unref(geany_menu_button_action_get_menu(open_action));
 
523
        geany_menu_button_action_set_menu(open_action, NULL);
478
524
 
479
525
        /* unref'ing the GtkUIManager object will destroy all its widgets unless they were ref'ed */
480
526
        g_object_unref(uim);
494
540
}
495
541
 
496
542
 
 
543
/* sets the icon style of the toolbar */
 
544
static void toolbar_set_icon_style(void)
 
545
{
 
546
        gint icon_style;
 
547
 
 
548
        icon_style = toolbar_prefs.icon_style;
 
549
 
 
550
        if (toolbar_prefs.use_gtk_default_style)
 
551
                icon_style = ui_get_gtk_settings_integer("gtk-toolbar-style", toolbar_prefs.icon_style);
 
552
 
 
553
        gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), icon_style);
 
554
}
 
555
 
 
556
 
 
557
/* sets the icon size of the toolbar */
 
558
static void toolbar_set_icon_size(void)
 
559
{
 
560
        gint icon_size;
 
561
 
 
562
        icon_size = toolbar_prefs.icon_size;
 
563
 
 
564
        if (toolbar_prefs.use_gtk_default_icon)
 
565
                icon_size = ui_get_gtk_settings_integer("gtk-toolbar-icon-size", toolbar_prefs.icon_size);
 
566
 
 
567
        gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), icon_size);
 
568
}
 
569
 
 
570
 
497
571
void toolbar_apply_settings(void)
498
572
{
499
 
        /* sets the icon style of the toolbar */
500
 
        switch (toolbar_prefs.icon_style)
501
 
        {
502
 
                case GTK_TOOLBAR_BOTH:
503
 
                {
504
 
                        /*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "images_and_text1")), TRUE);*/
505
 
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(ui_widgets.toolbar_menu, "images_and_text2")), TRUE);
506
 
                        break;
507
 
                }
508
 
                case GTK_TOOLBAR_ICONS:
509
 
                {
510
 
                        /*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "images_only1")), TRUE);*/
511
 
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(ui_widgets.toolbar_menu, "images_only2")), TRUE);
512
 
                        break;
513
 
                }
514
 
                case GTK_TOOLBAR_TEXT:
515
 
                {
516
 
                        /*gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "text_only1")), TRUE);*/
517
 
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ui_lookup_widget(ui_widgets.toolbar_menu, "text_only2")), TRUE);
518
 
                        break;
519
 
                }
520
 
        }
521
 
        gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_style);
522
 
 
523
 
        /* sets the icon size of the toolbar, use user preferences (.gtkrc) if not set */
524
 
        if (toolbar_prefs.icon_size == GTK_ICON_SIZE_SMALL_TOOLBAR ||
525
 
                toolbar_prefs.icon_size == GTK_ICON_SIZE_LARGE_TOOLBAR ||
526
 
                toolbar_prefs.icon_size == GTK_ICON_SIZE_MENU)
527
 
        {
528
 
                gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size);
529
 
        }
 
573
        toolbar_set_icon_style();
 
574
        toolbar_set_icon_size();
530
575
}
531
576
 
532
577
 
583
628
        }
584
629
}
585
630
 
 
631
 
586
632
static const GMarkupParser tb_editor_xml_parser =
587
633
{
588
634
        tb_editor_handler_start_element, NULL, NULL, NULL, NULL