mirror of https://github.com/GNOME/gimp.git
export the column enum.
2004-05-31 Sven Neumann <sven@gimp.org> * app/widgets/gimpcontainerentry.[ch]: export the column enum. * app/gui/file-open-location-dialog.c: use a GimpContainerEntry on the documents list.
This commit is contained in:
parent
dbc49d9a11
commit
b2037adcdf
|
@ -1,3 +1,11 @@
|
|||
2004-05-31 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/widgets/gimpcontainerentry.[ch]: export the column enum.
|
||||
|
||||
* app/gui/file-open-location-dialog.c: use a GimpContainerEntry
|
||||
on the documents list. Use a custom match function that matches
|
||||
without the leading protocol part.
|
||||
|
||||
2004-05-31 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/widgets/Makefile.am
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "file/file-open.h"
|
||||
#include "file/file-utils.h"
|
||||
|
||||
#include "widgets/gimpcontainerentry.h"
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
|
||||
#include "file-open-location-dialog.h"
|
||||
|
@ -39,9 +40,14 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void file_open_location_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
Gimp *gimp);
|
||||
static void file_open_location_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
Gimp *gimp);
|
||||
|
||||
static gboolean file_open_location_completion (GtkEntryCompletion *completion,
|
||||
const gchar *key,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -50,10 +56,11 @@ void
|
|||
file_open_location_dialog_show (Gimp *gimp,
|
||||
GtkWidget *parent)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkEntryCompletion *completion;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
|
||||
|
@ -84,7 +91,15 @@ file_open_location_dialog_show (Gimp *gimp,
|
|||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
gtk_widget_show (label);
|
||||
|
||||
entry = gtk_entry_new ();
|
||||
entry = gimp_container_entry_new (gimp->documents, NULL,
|
||||
GIMP_PREVIEW_SIZE_SMALL, 1);
|
||||
|
||||
completion = gtk_entry_get_completion (GTK_ENTRY (entry));
|
||||
gtk_entry_completion_set_match_func (completion,
|
||||
file_open_location_completion,
|
||||
NULL, NULL);
|
||||
|
||||
gtk_widget_set_size_request (entry, 300, -1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
|
||||
gtk_widget_show (entry);
|
||||
|
||||
|
@ -113,10 +128,21 @@ file_open_location_response (GtkWidget *dialog,
|
|||
{
|
||||
GimpImage *image;
|
||||
gchar *uri;
|
||||
gchar *filename;
|
||||
GError *error = NULL;
|
||||
GimpPDBStatusType status;
|
||||
|
||||
uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL);
|
||||
filename = g_filename_from_uri (text, NULL, NULL);
|
||||
|
||||
if (filename)
|
||||
{
|
||||
uri = g_filename_to_uri (filename, NULL, NULL);
|
||||
g_free (filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL);
|
||||
}
|
||||
|
||||
image = file_open_with_proc_and_display (gimp,
|
||||
gimp_get_user_context (gimp),
|
||||
|
@ -140,3 +166,39 @@ file_open_location_response (GtkWidget *dialog,
|
|||
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
file_open_location_completion (GtkEntryCompletion *completion,
|
||||
const gchar *key,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = gtk_entry_completion_get_model (completion);
|
||||
gchar *name;
|
||||
gchar *normalized;
|
||||
gchar *case_normalized;
|
||||
gboolean match;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
1, &name,
|
||||
-1);
|
||||
|
||||
normalized = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
|
||||
case_normalized = g_utf8_casefold (normalized, -1);
|
||||
|
||||
match = (strncmp (key, case_normalized, strlen (key)) == 0);
|
||||
|
||||
if (! match)
|
||||
{
|
||||
const gchar *colon = strchr (case_normalized, ':');
|
||||
|
||||
if (colon && strlen (colon) > 2 && colon[1] == '/' && colon[2] == '/')
|
||||
match = (strncmp (key, colon + 3, strlen (key)) == 0);
|
||||
}
|
||||
|
||||
g_free (normalized);
|
||||
g_free (case_normalized);
|
||||
g_free (name);
|
||||
|
||||
return match;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "file/file-open.h"
|
||||
#include "file/file-utils.h"
|
||||
|
||||
#include "widgets/gimpcontainerentry.h"
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
|
||||
#include "file-open-location-dialog.h"
|
||||
|
@ -39,9 +40,14 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void file_open_location_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
Gimp *gimp);
|
||||
static void file_open_location_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
Gimp *gimp);
|
||||
|
||||
static gboolean file_open_location_completion (GtkEntryCompletion *completion,
|
||||
const gchar *key,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
@ -50,10 +56,11 @@ void
|
|||
file_open_location_dialog_show (Gimp *gimp,
|
||||
GtkWidget *parent)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *label;
|
||||
GtkWidget *entry;
|
||||
GtkEntryCompletion *completion;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
|
||||
|
@ -84,7 +91,15 @@ file_open_location_dialog_show (Gimp *gimp,
|
|||
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
||||
gtk_widget_show (label);
|
||||
|
||||
entry = gtk_entry_new ();
|
||||
entry = gimp_container_entry_new (gimp->documents, NULL,
|
||||
GIMP_PREVIEW_SIZE_SMALL, 1);
|
||||
|
||||
completion = gtk_entry_get_completion (GTK_ENTRY (entry));
|
||||
gtk_entry_completion_set_match_func (completion,
|
||||
file_open_location_completion,
|
||||
NULL, NULL);
|
||||
|
||||
gtk_widget_set_size_request (entry, 300, -1);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
|
||||
gtk_widget_show (entry);
|
||||
|
||||
|
@ -113,10 +128,21 @@ file_open_location_response (GtkWidget *dialog,
|
|||
{
|
||||
GimpImage *image;
|
||||
gchar *uri;
|
||||
gchar *filename;
|
||||
GError *error = NULL;
|
||||
GimpPDBStatusType status;
|
||||
|
||||
uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL);
|
||||
filename = g_filename_from_uri (text, NULL, NULL);
|
||||
|
||||
if (filename)
|
||||
{
|
||||
uri = g_filename_to_uri (filename, NULL, NULL);
|
||||
g_free (filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL);
|
||||
}
|
||||
|
||||
image = file_open_with_proc_and_display (gimp,
|
||||
gimp_get_user_context (gimp),
|
||||
|
@ -140,3 +166,39 @@ file_open_location_response (GtkWidget *dialog,
|
|||
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
file_open_location_completion (GtkEntryCompletion *completion,
|
||||
const gchar *key,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = gtk_entry_completion_get_model (completion);
|
||||
gchar *name;
|
||||
gchar *normalized;
|
||||
gchar *case_normalized;
|
||||
gboolean match;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
1, &name,
|
||||
-1);
|
||||
|
||||
normalized = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
|
||||
case_normalized = g_utf8_casefold (normalized, -1);
|
||||
|
||||
match = (strncmp (key, case_normalized, strlen (key)) == 0);
|
||||
|
||||
if (! match)
|
||||
{
|
||||
const gchar *colon = strchr (case_normalized, ':');
|
||||
|
||||
if (colon && strlen (colon) > 2 && colon[1] == '/' && colon[2] == '/')
|
||||
match = (strncmp (key, colon + 3, strlen (key)) == 0);
|
||||
}
|
||||
|
||||
g_free (normalized);
|
||||
g_free (case_normalized);
|
||||
g_free (name);
|
||||
|
||||
return match;
|
||||
}
|
||||
|
|
|
@ -41,14 +41,6 @@
|
|||
gtk_entry_completion_get_model (gtk_entry_get_completion (GTK_ENTRY (entry)))
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
COLUMN_RENDERER,
|
||||
COLUMN_NAME,
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
|
||||
static void gimp_container_entry_class_init (GimpContainerEntryClass *klass);
|
||||
static void gimp_container_entry_init (GimpContainerEntry *view);
|
||||
|
||||
|
@ -151,31 +143,33 @@ gimp_container_entry_class_init (GimpContainerEntryClass *klass)
|
|||
static void
|
||||
gimp_container_entry_init (GimpContainerEntry *entry)
|
||||
{
|
||||
GtkEntryCompletion *comp;
|
||||
GtkEntryCompletion *completion;
|
||||
GtkListStore *store;
|
||||
GtkCellRenderer *cell;
|
||||
|
||||
comp = gtk_entry_completion_new ();
|
||||
completion = gtk_entry_completion_new ();
|
||||
|
||||
store = gtk_list_store_new (NUM_COLUMNS,
|
||||
store = gtk_list_store_new (GIMP_CONTAINER_ENTRY_NUM_COLUMNS,
|
||||
GIMP_TYPE_PREVIEW_RENDERER,
|
||||
G_TYPE_STRING);
|
||||
|
||||
gtk_entry_completion_set_model (comp, GTK_TREE_MODEL (store));
|
||||
gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store));
|
||||
g_object_unref (store);
|
||||
|
||||
gtk_entry_set_completion (GTK_ENTRY (entry), comp);
|
||||
g_object_unref (comp);
|
||||
gtk_entry_set_completion (GTK_ENTRY (entry), completion);
|
||||
g_object_unref (completion);
|
||||
|
||||
/* FIXME: This can be done better with GTK+ 2.6. */
|
||||
|
||||
cell = gimp_cell_renderer_viewable_new ();
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp), cell, FALSE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (comp), cell,
|
||||
"renderer", COLUMN_RENDERER,
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE);
|
||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell,
|
||||
"renderer",
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_RENDERER,
|
||||
NULL);
|
||||
|
||||
gtk_entry_completion_set_text_column (comp, COLUMN_NAME);
|
||||
gtk_entry_completion_set_text_column (completion,
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_NAME);
|
||||
|
||||
g_signal_connect (entry, "changed",
|
||||
G_CALLBACK (gimp_container_entry_changed),
|
||||
|
@ -239,14 +233,11 @@ gimp_container_entry_set (GimpContainerEntry *entry,
|
|||
GimpContainerView *view = GIMP_CONTAINER_VIEW (entry);
|
||||
GtkTreeModel *model = gimp_container_entry_get_model (entry);
|
||||
GimpPreviewRenderer *renderer;
|
||||
gchar *name;
|
||||
gint preview_size;
|
||||
gint border_width;
|
||||
|
||||
preview_size = gimp_container_view_get_preview_size (view, &border_width);
|
||||
|
||||
name = gimp_viewable_get_description (viewable, NULL);
|
||||
|
||||
renderer = gimp_preview_renderer_new (G_TYPE_FROM_INSTANCE (viewable),
|
||||
preview_size, border_width,
|
||||
FALSE);
|
||||
|
@ -258,12 +249,13 @@ gimp_container_entry_set (GimpContainerEntry *entry,
|
|||
view);
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), iter,
|
||||
COLUMN_RENDERER, renderer,
|
||||
COLUMN_NAME, name,
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_RENDERER,
|
||||
renderer,
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_NAME,
|
||||
gimp_object_get_name (GIMP_OBJECT (viewable)),
|
||||
-1);
|
||||
|
||||
g_object_unref (renderer);
|
||||
g_free (name);
|
||||
}
|
||||
|
||||
/* GimpContainerView methods */
|
||||
|
@ -355,15 +347,10 @@ gimp_container_entry_rename_item (GimpContainerView *view,
|
|||
GtkTreeIter *iter = insert_data;
|
||||
|
||||
if (iter)
|
||||
{
|
||||
gchar *name = gimp_viewable_get_description (viewable, NULL);
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), iter,
|
||||
COLUMN_NAME, name,
|
||||
-1);
|
||||
|
||||
g_free (name);
|
||||
}
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), iter,
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_NAME,
|
||||
gimp_object_get_name (GIMP_OBJECT (viewable)),
|
||||
-1);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -417,7 +404,7 @@ gimp_container_entry_set_preview_size (GimpContainerView *view)
|
|||
GimpPreviewRenderer *renderer;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
COLUMN_RENDERER, &renderer,
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_RENDERER, &renderer,
|
||||
-1);
|
||||
|
||||
gimp_preview_renderer_set_size (renderer, preview_size, border_width);
|
||||
|
|
|
@ -26,6 +26,14 @@
|
|||
#include <gtk/gtkentry.h>
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_RENDERER,
|
||||
GIMP_CONTAINER_ENTRY_COLUMN_NAME,
|
||||
GIMP_CONTAINER_ENTRY_NUM_COLUMNS
|
||||
};
|
||||
|
||||
|
||||
#define GIMP_TYPE_CONTAINER_ENTRY (gimp_container_entry_get_type ())
|
||||
#define GIMP_CONTAINER_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTAINER_ENTRY, GimpContainerEntry))
|
||||
#define GIMP_CONTAINER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTAINER_ENTRY, GimpContainerEntryClass))
|
||||
|
|
Loading…
Reference in New Issue