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:
Sven Neumann 2004-05-31 20:44:18 +00:00 committed by Sven Neumann
parent dbc49d9a11
commit b2037adcdf
5 changed files with 179 additions and 52 deletions

View File

@ -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> 2004-05-31 Michael Natterer <mitch@gimp.org>
* app/widgets/Makefile.am * app/widgets/Makefile.am

View File

@ -32,6 +32,7 @@
#include "file/file-open.h" #include "file/file-open.h"
#include "file/file-utils.h" #include "file/file-utils.h"
#include "widgets/gimpcontainerentry.h"
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "file-open-location-dialog.h" #include "file-open-location-dialog.h"
@ -43,6 +44,11 @@ static void file_open_location_response (GtkWidget *dialog,
gint response_id, gint response_id,
Gimp *gimp); Gimp *gimp);
static gboolean file_open_location_completion (GtkEntryCompletion *completion,
const gchar *key,
GtkTreeIter *iter,
gpointer data);
/* public functions */ /* public functions */
@ -54,6 +60,7 @@ file_open_location_dialog_show (Gimp *gimp,
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *label; GtkWidget *label;
GtkWidget *entry; GtkWidget *entry;
GtkEntryCompletion *completion;
g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent)); 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_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label); 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_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
gtk_widget_show (entry); gtk_widget_show (entry);
@ -113,10 +128,21 @@ file_open_location_response (GtkWidget *dialog,
{ {
GimpImage *image; GimpImage *image;
gchar *uri; gchar *uri;
gchar *filename;
GError *error = NULL; GError *error = NULL;
GimpPDBStatusType status; GimpPDBStatusType status;
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); uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL);
}
image = file_open_with_proc_and_display (gimp, image = file_open_with_proc_and_display (gimp,
gimp_get_user_context (gimp), gimp_get_user_context (gimp),
@ -140,3 +166,39 @@ file_open_location_response (GtkWidget *dialog,
gtk_widget_destroy (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;
}

View File

@ -32,6 +32,7 @@
#include "file/file-open.h" #include "file/file-open.h"
#include "file/file-utils.h" #include "file/file-utils.h"
#include "widgets/gimpcontainerentry.h"
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "file-open-location-dialog.h" #include "file-open-location-dialog.h"
@ -43,6 +44,11 @@ static void file_open_location_response (GtkWidget *dialog,
gint response_id, gint response_id,
Gimp *gimp); Gimp *gimp);
static gboolean file_open_location_completion (GtkEntryCompletion *completion,
const gchar *key,
GtkTreeIter *iter,
gpointer data);
/* public functions */ /* public functions */
@ -54,6 +60,7 @@ file_open_location_dialog_show (Gimp *gimp,
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *label; GtkWidget *label;
GtkWidget *entry; GtkWidget *entry;
GtkEntryCompletion *completion;
g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent)); 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_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label); 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_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
gtk_widget_show (entry); gtk_widget_show (entry);
@ -113,10 +128,21 @@ file_open_location_response (GtkWidget *dialog,
{ {
GimpImage *image; GimpImage *image;
gchar *uri; gchar *uri;
gchar *filename;
GError *error = NULL; GError *error = NULL;
GimpPDBStatusType status; GimpPDBStatusType status;
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); uri = file_utils_filename_to_uri (gimp->load_procs, text, NULL);
}
image = file_open_with_proc_and_display (gimp, image = file_open_with_proc_and_display (gimp,
gimp_get_user_context (gimp), gimp_get_user_context (gimp),
@ -140,3 +166,39 @@ file_open_location_response (GtkWidget *dialog,
gtk_widget_destroy (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;
}

View File

@ -41,14 +41,6 @@
gtk_entry_completion_get_model (gtk_entry_get_completion (GTK_ENTRY (entry))) 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_class_init (GimpContainerEntryClass *klass);
static void gimp_container_entry_init (GimpContainerEntry *view); static void gimp_container_entry_init (GimpContainerEntry *view);
@ -151,31 +143,33 @@ gimp_container_entry_class_init (GimpContainerEntryClass *klass)
static void static void
gimp_container_entry_init (GimpContainerEntry *entry) gimp_container_entry_init (GimpContainerEntry *entry)
{ {
GtkEntryCompletion *comp; GtkEntryCompletion *completion;
GtkListStore *store; GtkListStore *store;
GtkCellRenderer *cell; 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, GIMP_TYPE_PREVIEW_RENDERER,
G_TYPE_STRING); 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); g_object_unref (store);
gtk_entry_set_completion (GTK_ENTRY (entry), comp); gtk_entry_set_completion (GTK_ENTRY (entry), completion);
g_object_unref (comp); g_object_unref (completion);
/* FIXME: This can be done better with GTK+ 2.6. */ /* FIXME: This can be done better with GTK+ 2.6. */
cell = gimp_cell_renderer_viewable_new (); cell = gimp_cell_renderer_viewable_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comp), cell, FALSE); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (comp), cell, gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell,
"renderer", COLUMN_RENDERER, "renderer",
GIMP_CONTAINER_ENTRY_COLUMN_RENDERER,
NULL); 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_signal_connect (entry, "changed",
G_CALLBACK (gimp_container_entry_changed), G_CALLBACK (gimp_container_entry_changed),
@ -239,14 +233,11 @@ gimp_container_entry_set (GimpContainerEntry *entry,
GimpContainerView *view = GIMP_CONTAINER_VIEW (entry); GimpContainerView *view = GIMP_CONTAINER_VIEW (entry);
GtkTreeModel *model = gimp_container_entry_get_model (entry); GtkTreeModel *model = gimp_container_entry_get_model (entry);
GimpPreviewRenderer *renderer; GimpPreviewRenderer *renderer;
gchar *name;
gint preview_size; gint preview_size;
gint border_width; gint border_width;
preview_size = gimp_container_view_get_preview_size (view, &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), renderer = gimp_preview_renderer_new (G_TYPE_FROM_INSTANCE (viewable),
preview_size, border_width, preview_size, border_width,
FALSE); FALSE);
@ -258,12 +249,13 @@ gimp_container_entry_set (GimpContainerEntry *entry,
view); view);
gtk_list_store_set (GTK_LIST_STORE (model), iter, gtk_list_store_set (GTK_LIST_STORE (model), iter,
COLUMN_RENDERER, renderer, GIMP_CONTAINER_ENTRY_COLUMN_RENDERER,
COLUMN_NAME, name, renderer,
GIMP_CONTAINER_ENTRY_COLUMN_NAME,
gimp_object_get_name (GIMP_OBJECT (viewable)),
-1); -1);
g_object_unref (renderer); g_object_unref (renderer);
g_free (name);
} }
/* GimpContainerView methods */ /* GimpContainerView methods */
@ -355,15 +347,10 @@ gimp_container_entry_rename_item (GimpContainerView *view,
GtkTreeIter *iter = insert_data; GtkTreeIter *iter = insert_data;
if (iter) if (iter)
{
gchar *name = gimp_viewable_get_description (viewable, NULL);
gtk_list_store_set (GTK_LIST_STORE (model), iter, gtk_list_store_set (GTK_LIST_STORE (model), iter,
COLUMN_NAME, name, GIMP_CONTAINER_ENTRY_COLUMN_NAME,
gimp_object_get_name (GIMP_OBJECT (viewable)),
-1); -1);
g_free (name);
}
} }
static gboolean static gboolean
@ -417,7 +404,7 @@ gimp_container_entry_set_preview_size (GimpContainerView *view)
GimpPreviewRenderer *renderer; GimpPreviewRenderer *renderer;
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter,
COLUMN_RENDERER, &renderer, GIMP_CONTAINER_ENTRY_COLUMN_RENDERER, &renderer,
-1); -1);
gimp_preview_renderer_set_size (renderer, preview_size, border_width); gimp_preview_renderer_set_size (renderer, preview_size, border_width);

View File

@ -26,6 +26,14 @@
#include <gtk/gtkentry.h> #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_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(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)) #define GIMP_CONTAINER_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTAINER_ENTRY, GimpContainerEntryClass))