2005-05-19 07:48:47 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
2005-05-19 06:21:07 +08:00
|
|
|
*
|
|
|
|
* gimpbrowser.c
|
|
|
|
* Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2005-05-19 07:48:47 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2005-05-19 06:21:07 +08:00
|
|
|
*
|
2005-05-19 07:48:47 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2005-05-19 06:21:07 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-05-19 07:48:47 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2005-05-19 06:21:07 +08:00
|
|
|
*
|
2005-05-19 07:48:47 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2005-05-19 06:21:07 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-11-02 05:32:06 +08:00
|
|
|
#include <gegl.h>
|
2005-05-19 06:21:07 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2005-05-19 07:48:47 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2005-07-06 09:51:17 +08:00
|
|
|
#include "gimpwidgets.h"
|
2005-05-19 07:48:47 +08:00
|
|
|
#include "gimpwidgetsmarshal.h"
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2005-05-19 07:48:47 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpbrowser
|
|
|
|
* @title: GimpBrowser
|
|
|
|
* @short_description: A base class for a documentation browser.
|
|
|
|
*
|
|
|
|
* A base class for a documentation browser.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2005-05-19 06:21:07 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SEARCH,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
typedef struct _GimpBrowserPrivate
|
2011-01-01 01:19:37 +08:00
|
|
|
{
|
|
|
|
GtkWidget *left_vbox;
|
|
|
|
|
|
|
|
GtkWidget *search_entry;
|
|
|
|
guint search_timeout_id;
|
|
|
|
|
|
|
|
GtkWidget *search_type_combo;
|
|
|
|
gint search_type;
|
|
|
|
|
|
|
|
GtkWidget *count_label;
|
|
|
|
|
|
|
|
GtkWidget *right_vbox;
|
|
|
|
GtkWidget *right_widget;
|
2024-08-01 11:55:31 +08:00
|
|
|
} GimpBrowserPrivate;
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
|
2010-10-14 23:47:48 +08:00
|
|
|
static void gimp_browser_dispose (GObject *object);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2009-05-24 23:24:28 +08:00
|
|
|
static void gimp_browser_combo_changed (GtkComboBox *combo,
|
|
|
|
GimpBrowser *browser);
|
|
|
|
static void gimp_browser_entry_changed (GtkEntry *entry,
|
2009-05-24 23:02:55 +08:00
|
|
|
GimpBrowser *browser);
|
|
|
|
static void gimp_browser_entry_icon_press (GtkEntry *entry,
|
|
|
|
GtkEntryIconPosition icon_pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpBrowser *browser);
|
|
|
|
static gboolean gimp_browser_search_timeout (gpointer data);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-19 00:09:39 +08:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpBrowser, gimp_browser, GTK_TYPE_PANED)
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_browser_parent_class
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
static guint browser_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_browser_class_init (GimpBrowserClass *klass)
|
|
|
|
{
|
2010-10-14 23:47:48 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
browser_signals[SEARCH] =
|
|
|
|
g_signal_new ("search",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GimpBrowserClass, search),
|
|
|
|
NULL, NULL,
|
2005-05-19 07:48:47 +08:00
|
|
|
_gimp_widgets_marshal_VOID__STRING_INT,
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
G_TYPE_STRING,
|
2005-05-19 06:21:07 +08:00
|
|
|
G_TYPE_INT);
|
|
|
|
|
2010-10-14 23:47:48 +08:00
|
|
|
object_class->dispose = gimp_browser_dispose;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2010-10-14 23:47:48 +08:00
|
|
|
klass->search = NULL;
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_browser_init (GimpBrowser *browser)
|
|
|
|
{
|
2018-05-03 18:51:36 +08:00
|
|
|
GimpBrowserPrivate *priv;
|
2011-01-01 01:19:37 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *viewport;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2018-05-03 18:51:36 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (browser),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->search_type = -1;
|
|
|
|
|
|
|
|
priv->left_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2024-06-11 11:10:55 +08:00
|
|
|
gtk_paned_pack1 (GTK_PANED (browser), priv->left_vbox, TRUE, FALSE);
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_widget_show (priv->left_vbox);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
/* search entry */
|
|
|
|
|
2011-09-30 16:50:50 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (priv->left_vbox), hbox, FALSE, FALSE, 0);
|
2005-05-19 06:21:07 +08:00
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (_("_Search:"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->search_entry = gtk_entry_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), priv->search_entry, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (priv->search_entry);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->search_entry);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
g_signal_connect (priv->search_entry, "changed",
|
2005-05-19 06:21:07 +08:00
|
|
|
G_CALLBACK (gimp_browser_entry_changed),
|
|
|
|
browser);
|
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->search_entry),
|
2014-05-12 04:49:22 +08:00
|
|
|
GTK_ENTRY_ICON_SECONDARY, "edit-clear");
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_entry_set_icon_activatable (GTK_ENTRY (priv->search_entry),
|
2009-05-24 23:24:28 +08:00
|
|
|
GTK_ENTRY_ICON_SECONDARY, TRUE);
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->search_entry),
|
2009-05-24 23:24:28 +08:00
|
|
|
GTK_ENTRY_ICON_SECONDARY, FALSE);
|
2009-05-24 23:02:55 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
g_signal_connect (priv->search_entry, "icon-press",
|
2009-05-24 23:02:55 +08:00
|
|
|
G_CALLBACK (gimp_browser_entry_icon_press),
|
|
|
|
browser);
|
|
|
|
|
2005-05-19 06:21:07 +08:00
|
|
|
/* count label */
|
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->count_label = gtk_label_new (_("No matches"));
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (priv->count_label), 0.0);
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (priv->count_label),
|
2005-07-06 09:51:17 +08:00
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (priv->left_vbox), priv->count_label,
|
2005-05-19 06:21:07 +08:00
|
|
|
FALSE, FALSE, 0);
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_widget_show (priv->count_label);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
/* scrolled window */
|
|
|
|
|
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
2024-06-11 11:10:55 +08:00
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_paned_pack2 (GTK_PANED (browser), scrolled_window, TRUE, FALSE);
|
2005-05-19 06:21:07 +08:00
|
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
|
2016-09-08 02:09:46 +08:00
|
|
|
viewport = gtk_viewport_new (NULL, NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), viewport);
|
|
|
|
gtk_widget_show (viewport);
|
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->right_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (priv->right_vbox), 12);
|
|
|
|
gtk_container_add (GTK_CONTAINER (viewport), priv->right_vbox);
|
|
|
|
gtk_widget_show (priv->right_vbox);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_widget_grab_focus (priv->search_entry);
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-14 23:47:48 +08:00
|
|
|
gimp_browser_dispose (GObject *object)
|
2005-05-19 06:21:07 +08:00
|
|
|
{
|
2024-08-01 11:55:31 +08:00
|
|
|
GimpBrowser *browser = GIMP_BROWSER (object);
|
|
|
|
GimpBrowserPrivate *priv = gimp_browser_get_instance_private (browser);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
if (priv->search_timeout_id)
|
2005-05-19 06:21:07 +08:00
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
g_source_remove (priv->search_timeout_id);
|
|
|
|
priv->search_timeout_id = 0;
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
|
2010-10-14 23:47:48 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2005-09-28 01:11:01 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_browser_new:
|
|
|
|
*
|
|
|
|
* Create a new #GimpBrowser widget.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: a newly created #GimpBrowser.
|
2005-09-28 01:11:01 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-28 01:11:01 +08:00
|
|
|
**/
|
2005-05-19 06:21:07 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_browser_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_BROWSER, NULL);
|
|
|
|
}
|
|
|
|
|
2005-09-28 01:11:01 +08:00
|
|
|
/**
|
2020-05-21 19:43:47 +08:00
|
|
|
* gimp_browser_add_search_types: (skip)
|
2005-09-28 01:11:01 +08:00
|
|
|
* @browser: a #GimpBrowser widget
|
|
|
|
* @first_type_label: the label of the first search type
|
|
|
|
* @first_type_id: an integer that identifies the first search type
|
|
|
|
* @...: a %NULL-terminated list of more labels and ids.
|
|
|
|
*
|
|
|
|
* Populates the #GtkComboBox with search types.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-28 01:11:01 +08:00
|
|
|
**/
|
2005-05-19 06:21:07 +08:00
|
|
|
void
|
|
|
|
gimp_browser_add_search_types (GimpBrowser *browser,
|
|
|
|
const gchar *first_type_label,
|
|
|
|
gint first_type_id,
|
|
|
|
...)
|
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
GimpBrowserPrivate *priv;
|
|
|
|
|
2005-05-19 06:21:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_BROWSER (browser));
|
|
|
|
g_return_if_fail (first_type_label != NULL);
|
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
if (! priv->search_type_combo)
|
2005-05-19 06:21:07 +08:00
|
|
|
{
|
|
|
|
GtkWidget *combo;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start (args, first_type_id);
|
|
|
|
combo = gimp_int_combo_box_new_valist (first_type_label,
|
|
|
|
first_type_id,
|
|
|
|
args);
|
|
|
|
va_end (args);
|
|
|
|
|
2018-04-29 23:35:33 +08:00
|
|
|
gtk_widget_set_focus_on_click (combo, FALSE);
|
2005-07-06 08:31:59 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->search_type_combo = combo;
|
|
|
|
priv->search_type = first_type_id;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (gtk_widget_get_parent (priv->search_entry)),
|
2008-06-28 23:09:46 +08:00
|
|
|
combo, FALSE, FALSE, 0);
|
2005-05-19 06:21:07 +08:00
|
|
|
gtk_widget_show (combo);
|
|
|
|
|
|
|
|
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->search_type,
|
2005-05-19 06:21:07 +08:00
|
|
|
G_CALLBACK (gimp_int_combo_box_get_active),
|
2019-08-08 06:22:15 +08:00
|
|
|
&priv->search_type, NULL);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
g_signal_connect (combo, "changed",
|
2009-05-24 23:24:28 +08:00
|
|
|
G_CALLBACK (gimp_browser_combo_changed),
|
2005-05-19 06:21:07 +08:00
|
|
|
browser);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (priv->search_type_combo),
|
2005-05-19 06:21:07 +08:00
|
|
|
first_type_label, first_type_id,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
/**
|
|
|
|
* gimp_browser_get_left_vbox:
|
|
|
|
* @browser: a #GimpBrowser widget
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Returns: (transfer none) (type GtkBox): The left vbox.
|
2011-01-01 01:19:37 +08:00
|
|
|
*
|
2019-07-24 07:18:30 +08:00
|
|
|
* Since: 3.0
|
2011-01-01 01:19:37 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_browser_get_left_vbox (GimpBrowser *browser)
|
|
|
|
{
|
|
|
|
GimpBrowserPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_BROWSER (browser), NULL);
|
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
return priv->left_vbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_browser_get_right_vbox:
|
|
|
|
* @browser: a #GimpBrowser widget
|
|
|
|
*
|
GIR: Try to return more specific GtkWidget subclass
In GTK, a common scheme is to let a function creating a specific widget
to return a `GtkWidget *`, rather than the specific subtype, since you
often need to call API of GtkWidget, avoiding some useless casts.
For bindings however (and especially bindings to compiled languages),
this is a bit annoying, as you have to explicitly change the type of the
return value (downcast), which is not trivial (or at least desirable) in
each language.
Luckily, we can use `(type ...)` annotation for this use case, leaving
the C API unchanged, while improving the experience for bindings.
2020-12-25 22:05:16 +08:00
|
|
|
* Returns: (transfer none) (type GtkBox): The right vbox.
|
2011-01-01 01:19:37 +08:00
|
|
|
*
|
2019-07-24 07:18:30 +08:00
|
|
|
* Since: 3.0
|
2011-01-01 01:19:37 +08:00
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_browser_get_right_vbox (GimpBrowser *browser)
|
|
|
|
{
|
|
|
|
GimpBrowserPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_BROWSER (browser), NULL);
|
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
return priv->right_vbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_browser_set_search_summary:
|
|
|
|
* @browser: a #GimpBrowser widget
|
|
|
|
* @summary: a string describing the search result
|
|
|
|
*
|
|
|
|
* Sets the search summary text.
|
|
|
|
*
|
2019-07-24 07:18:30 +08:00
|
|
|
* Since: 3.0
|
2011-01-01 01:19:37 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_browser_set_search_summary (GimpBrowser *browser,
|
|
|
|
const gchar *summary)
|
|
|
|
{
|
|
|
|
GimpBrowserPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_BROWSER (browser));
|
|
|
|
g_return_if_fail (summary != NULL);
|
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->count_label), summary);
|
|
|
|
}
|
|
|
|
|
2005-09-28 01:11:01 +08:00
|
|
|
/**
|
|
|
|
* gimp_browser_set_widget:
|
|
|
|
* @browser: a #GimpBrowser widget
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
*
|
|
|
|
* Sets the widget to appear on the right side of the @browser.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-28 01:11:01 +08:00
|
|
|
**/
|
2005-05-19 06:21:07 +08:00
|
|
|
void
|
|
|
|
gimp_browser_set_widget (GimpBrowser *browser,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
GimpBrowserPrivate *priv;
|
|
|
|
|
2005-05-19 06:21:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_BROWSER (browser));
|
2005-06-23 19:28:15 +08:00
|
|
|
g_return_if_fail (widget == NULL || GTK_IS_WIDGET (widget));
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
if (widget == priv->right_widget)
|
2005-06-23 19:28:15 +08:00
|
|
|
return;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
if (priv->right_widget)
|
|
|
|
gtk_container_remove (GTK_CONTAINER (priv->right_vbox),
|
|
|
|
priv->right_widget);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->right_widget = widget;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2005-06-23 19:28:15 +08:00
|
|
|
if (widget)
|
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (priv->right_vbox), widget,
|
2005-06-23 19:28:15 +08:00
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
}
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
|
2005-09-28 01:11:01 +08:00
|
|
|
/**
|
|
|
|
* gimp_browser_show_message:
|
|
|
|
* @browser: a #GimpBrowser widget
|
|
|
|
* @message: text message
|
|
|
|
*
|
|
|
|
* Displays @message in the right side of the @browser. Unless the right
|
|
|
|
* side already contains a #GtkLabel, the widget previously added with
|
|
|
|
* gimp_browser_set_widget() is removed and replaced by a #GtkLabel.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-28 01:11:01 +08:00
|
|
|
**/
|
2005-05-19 06:21:07 +08:00
|
|
|
void
|
|
|
|
gimp_browser_show_message (GimpBrowser *browser,
|
|
|
|
const gchar *message)
|
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
GimpBrowserPrivate *priv;
|
|
|
|
|
2005-05-19 06:21:07 +08:00
|
|
|
g_return_if_fail (GIMP_IS_BROWSER (browser));
|
|
|
|
g_return_if_fail (message != NULL);
|
|
|
|
|
2024-08-01 11:55:31 +08:00
|
|
|
priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
if (GTK_IS_LABEL (priv->right_widget))
|
2005-05-19 06:21:07 +08:00
|
|
|
{
|
2011-01-01 01:19:37 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (priv->right_widget), message);
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-06 07:31:49 +08:00
|
|
|
GtkWidget *label = gtk_label_new (message);
|
|
|
|
|
|
|
|
gimp_label_set_attributes (GTK_LABEL (label),
|
|
|
|
PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
|
|
|
|
-1);
|
|
|
|
gimp_browser_set_widget (browser, label);
|
2005-05-19 06:21:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2009-05-24 23:24:28 +08:00
|
|
|
gimp_browser_queue_search (GimpBrowser *browser)
|
2005-05-19 06:21:07 +08:00
|
|
|
{
|
2024-08-01 11:55:31 +08:00
|
|
|
GimpBrowserPrivate *priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
|
|
|
|
if (priv->search_timeout_id)
|
|
|
|
g_source_remove (priv->search_timeout_id);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->search_timeout_id =
|
2005-05-19 06:21:07 +08:00
|
|
|
g_timeout_add (100, gimp_browser_search_timeout, browser);
|
|
|
|
}
|
|
|
|
|
2009-05-24 23:24:28 +08:00
|
|
|
static void
|
|
|
|
gimp_browser_combo_changed (GtkComboBox *combo,
|
|
|
|
GimpBrowser *browser)
|
|
|
|
{
|
|
|
|
gimp_browser_queue_search (browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_browser_entry_changed (GtkEntry *entry,
|
|
|
|
GimpBrowser *browser)
|
|
|
|
{
|
|
|
|
gimp_browser_queue_search (browser);
|
|
|
|
|
|
|
|
gtk_entry_set_icon_sensitive (entry,
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
gtk_entry_get_text_length (entry) > 0);
|
|
|
|
}
|
|
|
|
|
2009-05-24 23:02:55 +08:00
|
|
|
static void
|
|
|
|
gimp_browser_entry_icon_press (GtkEntry *entry,
|
|
|
|
GtkEntryIconPosition icon_pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpBrowser *browser)
|
|
|
|
{
|
2009-05-24 23:06:17 +08:00
|
|
|
GdkEventButton *bevent = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
if (icon_pos == GTK_ENTRY_ICON_SECONDARY && bevent->button == 1)
|
2009-05-24 23:02:55 +08:00
|
|
|
{
|
|
|
|
gtk_entry_set_text (entry, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-19 06:21:07 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_browser_search_timeout (gpointer data)
|
|
|
|
{
|
2024-08-01 11:55:31 +08:00
|
|
|
GimpBrowser *browser = GIMP_BROWSER (data);
|
|
|
|
GimpBrowserPrivate *priv = gimp_browser_get_instance_private (browser);
|
2011-01-01 01:19:37 +08:00
|
|
|
const gchar *search_string;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
search_string = gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
|
2005-05-19 07:48:47 +08:00
|
|
|
|
|
|
|
if (! search_string)
|
|
|
|
search_string = "";
|
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
g_signal_emit (data, browser_signals[SEARCH], 0,
|
|
|
|
search_string, priv->search_type);
|
2005-05-19 06:21:07 +08:00
|
|
|
|
2011-01-01 01:19:37 +08:00
|
|
|
priv->search_timeout_id = 0;
|
2005-05-19 06:21:07 +08:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|