~ubuntu-branches/ubuntu/utopic/geany/utopic

« back to all changes in this revision

Viewing changes to src/ui_utils.c

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-12-10 07:43:26 UTC
  • mfrom: (3.3.7 sid)
  • Revision ID: package-import@ubuntu.com-20111210074326-s8yqbew5i20h33tf
Tags: 0.21-1ubuntu1
* Merge from Debian Unstable, remaining changes:
  - debian/patches/20_use_evince_viewer.patch:
     + use evince as viewer for pdf and dvi files
  - debian/patches/20_use_x_terminal_emulator.patch:
     + use x-terminal-emulator as terminal
  - debian/control
     + Add breaks on geany-plugins-common << 0.20
* Also fixes bugs:
  - Filter for MATLAB/Octave files filters everythign (LP: 885505)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *      ui_utils.c - this file is part of Geany, a fast and lightweight IDE
3
3
 *
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>
6
6
 *
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.
20
20
 *
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 $
22
22
 */
23
23
 
24
24
/** @file ui_utils.h
661
661
        gboolean dirty_tabs = FALSE;
662
662
 
663
663
        if (ui_prefs.allow_always_save)
664
 
                return;
 
664
                enable = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)) > 0 ? TRUE : FALSE;
665
665
 
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");
1435
1441
}
1436
1442
 
1437
1443
 
 
1444
/* Adds a :activate-backwards signal emitted by default when <Shift>Return is pressed */
 
1445
void ui_entry_add_activate_backward_signal(GtkEntry *entry)
 
1446
{
 
1447
        static gboolean installed = FALSE;
 
1448
 
 
1449
        g_return_if_fail(GTK_IS_ENTRY(entry));
 
1450
 
 
1451
        if (G_UNLIKELY(! installed))
 
1452
        {
 
1453
                GtkBindingSet *binding_set;
 
1454
 
 
1455
                installed = TRUE;
 
1456
 
 
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)))
 
1459
                {
 
1460
                        g_warning("Signal GtkEntry:activate-backward is unexpectedly already installed");
 
1461
                        return;
 
1462
                }
 
1463
 
 
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);
 
1469
        }
 
1470
}
 
1471
 
 
1472
 
1438
1473
static void add_to_size_group(GtkWidget *widget, gpointer size_group)
1439
1474
{
1440
1475
        g_return_if_fail(GTK_IS_SIZE_GROUP(size_group));
1589
1624
        while (TRUE)
1590
1625
        {
1591
1626
                gtk_tree_selection_select_iter(treesel, &iter);
1592
 
                if (cb(0))
 
1627
                if (cb(FALSE))
1593
1628
                        break;  /* found next message */
1594
1629
 
1595
1630
                if (! tree_model_iter_get_next(model, &iter, down))
1907
1942
        gsize i, len;
1908
1943
        GtkStockItem items[] =
1909
1944
        {
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 }
1913
1948
        };
1914
1949
 
1915
1950
        len = G_N_ELEMENTS(items);
1985
2020
 
1986
2021
typedef struct GeanySharedMenu
1987
2022
{
1988
 
        gchar *menu;
1989
 
        gchar *menubar_item;
1990
 
        gchar *popup_item;
 
2023
        const gchar *menu;
 
2024
        const gchar *menubar_item;
 
2025
        const gchar *popup_item;
1991
2026
}
1992
2027
GeanySharedMenu;
1993
2028
 
2030
2065
{
2031
2066
        StashGroup *group = stash_group_new(PACKAGE);
2032
2067
 
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);
 
2068
        /* various prefs */
 
2069
        configuration_add_various_pref_group(group);
2036
2070
 
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);
2047
2089
}
2048
2090
 
2049
2091
 
2160
2202
 
2161
2203
 
2162
2204
/**
2163
 
 *  Sets @a text as the contents of the tooltip for @a widget.
2164
 
 *
2165
 
 *  @param widget The widget the tooltip should be set for.
2166
 
 *  @param text The text for the tooltip.
2167
 
 *
2168
 
 *  @since 0.16
 
2205
 * Sets @a text as the contents of the tooltip for @a widget.
 
2206
 *
 
2207
 * @param widget The widget the tooltip should be set for.
 
2208
 * @param text The text for the tooltip.
 
2209
 *
 
2210
 * @since 0.16
 
2211
 * @deprecated 0.21 use gtk_widget_set_tooltip_text() instead
2169
2212
 */
2170
2213
void ui_widget_set_tooltip_text(GtkWidget *widget, const gchar *text)
2171
2214
{
2172
 
#if GTK_CHECK_VERSION(2, 12, 0)
2173
2215
        gtk_widget_set_tooltip_text(widget, text);
2174
 
#else
2175
 
        static GtkTooltips *tooltips = NULL;
2176
 
 
2177
 
        if (G_UNLIKELY(tooltips == NULL))
2178
 
                tooltips = GTK_TOOLTIPS(ui_lookup_widget(main_widgets.window, "tooltips"));
2179
 
 
2180
 
        gtk_tooltips_set_tip(tooltips, widget, text, NULL);
2181
 
#endif
2182
2216
}
2183
2217
 
2184
2218
 
2228
2262
{
2229
2263
        GtkWidget *bar = gtk_progress_bar_new();
2230
2264
 
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);
2234
2268
 
2235
2269
        return bar;
2236
2270
}
2364
2398
 * @since 0.19 */
2365
2399
void ui_menu_add_document_items(GtkMenu *menu, GeanyDocument *active, GCallback callback)
2366
2400
{
 
2401
        ui_menu_add_document_items_sorted(menu, active, callback, NULL);
 
2402
}
 
2403
 
 
2404
 
 
2405
/** Adds a list of document items to @a menu.
 
2406
 *
 
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.
 
2409
 *
 
2410
 * See document_sort_by_display_name() for an example sort function.
 
2411
 *
 
2412
 * @param menu Menu.
 
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.
 
2418
 * @since 0.21 */
 
2419
void ui_menu_add_document_items_sorted(GtkMenu *menu, GeanyDocument *active,
 
2420
        GCallback callback, GCompareFunc compare_func)
 
2421
{
2367
2422
        GtkWidget *menu_item, *menu_item_label, *image;
2368
2423
        const GdkColor *color;
2369
2424
        GeanyDocument *doc;
2370
2425
        guint i, len;
2371
2426
        gchar *base_name, *label;
 
2427
        GPtrArray *sorted_documents;
2372
2428
 
2373
2429
        len = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
2374
 
        for (i = 0; i < len; i++)
2375
 
        {
2376
 
                doc = document_get_from_page(i);
2377
 
                if (! DOC_VALID(doc))
2378
 
                        continue;
 
2430
 
 
2431
        sorted_documents = g_ptr_array_sized_new(len);
 
2432
        /* copy the documents_array into the new one */
 
2433
        foreach_document(i)
 
2434
        {
 
2435
                g_ptr_array_add(sorted_documents, documents[i]);
 
2436
        }
 
2437
        if (compare_func == NULL)
 
2438
                compare_func = document_compare_by_tab_order;
 
2439
 
 
2440
        /* and now sort it */
 
2441
        g_ptr_array_sort(sorted_documents, compare_func);
 
2442
 
 
2443
        for (i = 0; i < sorted_documents->len; i++)
 
2444
        {
 
2445
                doc = g_ptr_array_index(sorted_documents, i);
2379
2446
 
2380
2447
                base_name = g_path_get_basename(DOC_FILENAME(doc));
2381
2448
                menu_item = gtk_image_menu_item_new_with_label(base_name);
2400
2467
 
2401
2468
                g_free(base_name);
2402
2469
        }
 
2470
        g_ptr_array_free(sorted_documents, TRUE);
2403
2471
}
2404
2472
 
2405
2473
 
2461
2529
GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size)
2462
2530
{
2463
2531
        GdkPixbuf *icon = NULL;
2464
 
#if defined(HAVE_GIO) && GLIB_CHECK_VERSION(2, 18, 0)
 
2532
#if GTK_CHECK_VERSION(2, 14, 0)
2465
2533
        gchar *ctype;
2466
2534
        GIcon *gicon;
2467
2535
        GtkIconInfo *info;
2488
2556
                }
2489
2557
        }
2490
2558
#endif
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)
2493
2561
        {
2494
2562
                const gchar *stock_id = GTK_STOCK_FILE;
2508
2576
        return icon;
2509
2577
}
2510
2578
 
 
2579
 
 
2580
void ui_focus_current_document(void)
 
2581
{
 
2582
        GeanyDocument *doc = document_get_current();
 
2583
 
 
2584
        if (doc != NULL)
 
2585
                document_grab_focus(doc);
 
2586
}