18
18
* along with this program; if not, write to the Free Software
19
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
* $Id: toolbar.c 4630 2010-01-31 21:54:47Z eht16 $
26
* Utility functions to create the toolbar.
21
* $Id: toolbar.c 4941 2010-05-22 19:39:03Z eht16 $
28
/* Utility functions to create the toolbar */
30
31
#include "support.h"
287
288
if (main_status.main_window_realized)
289
290
GeanyDocument *doc = document_get_current();
291
gboolean doc_changed = (doc != NULL) ? doc->changed : FALSE;
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);
295
297
toolbar_apply_settings();
320
static void toolbar_notify_style_cb(GObject *object, GParamSpec *arg1, gpointer data)
322
const gchar *arg_name = g_param_spec_get_name(arg1);
325
if (toolbar_prefs.use_gtk_default_style && utils_str_equal(arg_name, "gtk-toolbar-style"))
327
value = ui_get_gtk_settings_integer(arg_name, toolbar_prefs.icon_style);
328
gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), value);
330
else if (toolbar_prefs.use_gtk_default_icon && utils_str_equal(arg_name, "gtk-toolbar-size"))
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);
318
338
GtkWidget *toolbar_init(void)
320
340
GtkWidget *toolbar;
323
343
GtkAction *action_build;
324
344
GtkAction *action_searchentry;
325
345
GtkAction *action_gotoentry;
346
GtkSettings *gtk_settings;
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);
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(
357
_("Create a new file"),
358
_("Create a new file from a template"),
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);
338
363
action_open = geany_menu_button_action_new(
339
"Open", NULL, _("Open an existing file"), GTK_STOCK_OPEN);
365
_("Open an existing file"),
366
_("Open a recent file"),
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);
343
371
action_build = geany_menu_button_action_new(
344
"Build", NULL, _("Build the current file"), GEANY_STOCK_BUILD);
373
_("Build the current file"),
374
_("Choose more build actions"),
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);
365
396
toolbar = toolbar_reload(NULL);
398
gtk_settings = gtk_widget_get_settings(GTK_WIDGET(toolbar));
399
if (gtk_settings != NULL)
401
g_signal_connect(gtk_settings, "notify::gtk-toolbar-style",
402
G_CALLBACK(toolbar_notify_style_cb), NULL);
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;
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");
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);
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))
426
gtk_widget_destroy(GTK_WIDGET(first_item));
388
429
parent = gtk_widget_get_parent(main_widgets.toolbar);
407
448
gtk_box_pack_start(GTK_BOX(hbox_menubar), main_widgets.toolbar, TRUE, TRUE, 0);
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);
429
476
gtk_box_reorder_child(GTK_BOX(box), main_widgets.toolbar, 1);
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,
474
519
void toolbar_finalize(void)
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);
479
525
/* unref'ing the GtkUIManager object will destroy all its widgets unless they were ref'ed */
480
526
g_object_unref(uim);
543
/* sets the icon style of the toolbar */
544
static void toolbar_set_icon_style(void)
548
icon_style = toolbar_prefs.icon_style;
550
if (toolbar_prefs.use_gtk_default_style)
551
icon_style = ui_get_gtk_settings_integer("gtk-toolbar-style", toolbar_prefs.icon_style);
553
gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), icon_style);
557
/* sets the icon size of the toolbar */
558
static void toolbar_set_icon_size(void)
562
icon_size = toolbar_prefs.icon_size;
564
if (toolbar_prefs.use_gtk_default_icon)
565
icon_size = ui_get_gtk_settings_integer("gtk-toolbar-icon-size", toolbar_prefs.icon_size);
567
gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), icon_size);
497
571
void toolbar_apply_settings(void)
499
/* sets the icon style of the toolbar */
500
switch (toolbar_prefs.icon_style)
502
case GTK_TOOLBAR_BOTH:
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);
508
case GTK_TOOLBAR_ICONS:
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);
514
case GTK_TOOLBAR_TEXT:
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);
521
gtk_toolbar_set_style(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_style);
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)
528
gtk_toolbar_set_icon_size(GTK_TOOLBAR(main_widgets.toolbar), toolbar_prefs.icon_size);
573
toolbar_set_icon_style();
574
toolbar_set_icon_size();