2
2
* ui_utils.c - this file is part of Geany, a fast and lightweight IDE
4
* Copyright 2006-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5
* Copyright 2006-2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
4
* Copyright 2006-2011 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5
* Copyright 2006-2011 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7
7
* This program is free software; you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License as published by
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: ui_utils.c 5383 2010-11-08 13:13:33Z ntrel $
21
* $Id: ui_utils.c 5944 2011-09-22 11:52:58Z ntrel $
24
24
/** @file ui_utils.h
661
661
gboolean dirty_tabs = FALSE;
663
663
if (ui_prefs.allow_always_save)
664
enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0 ? TRUE : FALSE;
666
666
ui_widget_set_sensitive(widgets.save_buttons[0], enable);
667
667
ui_widget_set_sensitive(widgets.save_buttons[1], enable);
720
720
add_doc_widget("menu_reload_as1");
721
721
add_doc_widget("menu_select_all1");
722
722
add_doc_widget("insert_date1");
723
add_doc_widget("insert_alternative_white_space1");
723
724
add_doc_widget("menu_format1");
724
725
add_doc_widget("commands2");
725
726
add_doc_widget("menu_open_selected_file1");
727
728
add_doc_widget("find1");
728
729
add_doc_widget("find_next1");
729
730
add_doc_widget("find_previous1");
731
add_doc_widget("go_to_next_marker1");
732
add_doc_widget("go_to_previous_marker1");
730
733
add_doc_widget("replace1");
731
734
add_doc_widget("find_nextsel1");
732
735
add_doc_widget("find_prevsel1");
733
736
add_doc_widget("find_usage1");
734
737
add_doc_widget("find_document_usage1");
738
add_doc_widget("mark_all1");
735
739
add_doc_widget("go_to_line1");
736
740
add_doc_widget("goto_tag_definition1");
737
741
add_doc_widget("goto_tag_declaration1");
742
add_doc_widget("reset_indentation1");
738
743
add_doc_toolitem("Close");
739
744
add_doc_toolitem("CloseAll");
740
745
add_doc_toolitem("Search");
750
755
add_doc_toolitem("Paste");
751
756
add_doc_toolitem("Delete");
752
757
add_doc_toolitem("Save");
758
add_doc_toolitem("SaveAs");
753
759
add_doc_toolitem("SaveAll");
754
760
add_doc_toolitem("Compile");
755
761
add_doc_toolitem("Run");
1444
/* Adds a :activate-backwards signal emitted by default when <Shift>Return is pressed */
1445
void ui_entry_add_activate_backward_signal(GtkEntry *entry)
1447
static gboolean installed = FALSE;
1449
g_return_if_fail(GTK_IS_ENTRY(entry));
1451
if (G_UNLIKELY(! installed))
1453
GtkBindingSet *binding_set;
1457
/* try to handle the unexpected case where GTK would already have installed the signal */
1458
if (g_signal_lookup("activate-backward", G_TYPE_FROM_INSTANCE(entry)))
1460
g_warning("Signal GtkEntry:activate-backward is unexpectedly already installed");
1464
g_signal_new("activate-backward", G_TYPE_FROM_INSTANCE(entry),
1465
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, 0, NULL, NULL,
1466
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1467
binding_set = gtk_binding_set_by_class(GTK_ENTRY_GET_CLASS(entry));
1468
gtk_binding_entry_add_signal(binding_set, GDK_Return, GDK_SHIFT_MASK, "activate-backward", 0);
1438
1473
static void add_to_size_group(GtkWidget *widget, gpointer size_group)
1440
1475
g_return_if_fail(GTK_IS_SIZE_GROUP(size_group));
1591
1626
gtk_tree_selection_select_iter(treesel, &iter);
1593
1628
break; /* found next message */
1595
1630
if (! tree_model_iter_get_next(model, &iter, down))
1908
1943
GtkStockItem items[] =
1910
{ GEANY_STOCK_SAVE_ALL, _("Save All"), 0, 0, GETTEXT_PACKAGE },
1911
{ GEANY_STOCK_CLOSE_ALL, _("Close All"), 0, 0, GETTEXT_PACKAGE },
1912
{ GEANY_STOCK_BUILD, _("Build"), 0, 0, GETTEXT_PACKAGE }
1945
{ GEANY_STOCK_SAVE_ALL, N_("Save All"), 0, 0, GETTEXT_PACKAGE },
1946
{ GEANY_STOCK_CLOSE_ALL, N_("Close All"), 0, 0, GETTEXT_PACKAGE },
1947
{ GEANY_STOCK_BUILD, N_("Build"), 0, 0, GETTEXT_PACKAGE }
1915
1950
len = G_N_ELEMENTS(items);
2031
2066
StashGroup *group = stash_group_new(PACKAGE);
2033
/* hidden prefs (don't overwrite them so users can edit them manually) */
2034
configuration_add_pref_group(group, FALSE);
2035
stash_group_set_write_once(group, TRUE);
2069
configuration_add_various_pref_group(group);
2037
2071
stash_group_add_boolean(group, &interface_prefs.show_symbol_list_expanders,
2038
2072
"show_symbol_list_expanders", TRUE);
2044
2078
"statusbar_template", "");
2045
2079
stash_group_add_boolean(group, &ui_prefs.new_document_after_close,
2046
2080
"new_document_after_close", FALSE);
2081
stash_group_add_boolean(group, &interface_prefs.msgwin_status_visible,
2082
"msgwin_status_visible", TRUE);
2083
stash_group_add_boolean(group, &interface_prefs.msgwin_compiler_visible,
2084
"msgwin_compiler_visible", TRUE);
2085
stash_group_add_boolean(group, &interface_prefs.msgwin_messages_visible,
2086
"msgwin_messages_visible", TRUE);
2087
stash_group_add_boolean(group, &interface_prefs.msgwin_scribble_visible,
2088
"msgwin_scribble_visible", TRUE);
2163
* Sets @a text as the contents of the tooltip for @a widget.
2165
* @param widget The widget the tooltip should be set for.
2166
* @param text The text for the tooltip.
2205
* Sets @a text as the contents of the tooltip for @a widget.
2207
* @param widget The widget the tooltip should be set for.
2208
* @param text The text for the tooltip.
2211
* @deprecated 0.21 use gtk_widget_set_tooltip_text() instead
2170
2213
void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text)
2172
#if GTK_CHECK_VERSION(2, 12, 0)
2173
2215
gtk_widget_set_tooltip_text(widget, text);
2175
static GtkTooltips *tooltips = NULL;
2177
if (G_UNLIKELY(tooltips == NULL))
2178
tooltips = GTK_TOOLTIPS(ui_lookup_widget(main_widgets.window, "tooltips"));
2180
gtk_tooltips_set_tip(tooltips, widget, text, NULL);
2229
2263
GtkWidget *bar = gtk_progress_bar_new();
2231
/* Set the progressbar's height to 1 to fit it in the statusbar */
2232
gtk_widget_set_size_request(bar, -1, 1);
2233
gtk_box_pack_start (GTK_BOX(ui_widgets.statusbar), bar, FALSE, FALSE, 3);
2265
/* Set the progressbar's height to 1 to fit it in the statusbar */
2266
gtk_widget_set_size_request(bar, -1, 1);
2267
gtk_box_pack_start (GTK_BOX(ui_widgets.statusbar), bar, FALSE, FALSE, 3);
2364
2398
* @since 0.19 */
2365
2399
void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback callback)
2401
ui_menu_add_document_items_sorted(menu, active, callback, NULL);
2405
/** Adds a list of document items to @a menu.
2407
* @a compare_func might be NULL to not sort the documents in the menu. In this case,
2408
* the order of the document tabs is used.
2410
* See document_sort_by_display_name() for an example sort function.
2413
* @param active Which document to highlight, or @c NULL.
2414
* @param callback is used for each menu item's @c "activate" signal and will be passed
2415
* the corresponding document pointer as @c user_data.
2416
* @param compare_func is used to sort the list. Might be @c NULL to not sort the list.
2417
* @warning You should check @c doc->is_valid in the callback.
2419
void ui_menu_add_document_items_sorted(GtkMenu *menu, GeanyDocument *active,
2420
GCallback callback, GCompareFunc compare_func)
2367
2422
GtkWidget *menu_item, *menu_item_label, *image;
2368
2423
const GdkColor *color;
2369
2424
GeanyDocument *doc;
2371
2426
gchar *base_name, *label;
2427
GPtrArray *sorted_documents;
2373
2429
len = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
2374
for (i = 0; i < len; i++)
2376
doc = document_get_from_page(i);
2377
if (! DOC_VALID(doc))
2431
sorted_documents = g_ptr_array_sized_new(len);
2432
/* copy the documents_array into the new one */
2435
g_ptr_array_add(sorted_documents, documents[i]);
2437
if (compare_func == NULL)
2438
compare_func = document_compare_by_tab_order;
2440
/* and now sort it */
2441
g_ptr_array_sort(sorted_documents, compare_func);
2443
for (i = 0; i < sorted_documents->len; i++)
2445
doc = g_ptr_array_index(sorted_documents, i);
2380
2447
base_name = g_path_get_basename(DOC_FILENAME(doc));
2381
2448
menu_item = gtk_image_menu_item_new_with_label(base_name);
2461
2529
GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size)
2463
2531
GdkPixbuf *icon = NULL;
2464
#if defined(HAVE_GIO) && GLIB_CHECK_VERSION(2, 18, 0)
2532
#if GTK_CHECK_VERSION(2, 14, 0)
2467
2535
GtkIconInfo *info;
2491
/* fallback for builds without GIO or if icon lookup failed, like it might happen on Windows */
2559
/* fallback for builds with GIO < 2.18 or if icon lookup failed, like it might happen on Windows */
2492
2560
if (icon == NULL)
2494
2562
const gchar *stock_id = GTK_STOCK_FILE;