mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-21 03:52:33 +00:00
Migrate entry completion code and put responsability on clients to set
2007-08-08 Martin Nordholts <martinn@svn.gnome.org> * libgimpwidgets/gimpratioentry.[ch]: Migrate entry completion code and put responsability on clients to set that up when needed. * app/tools/gimprectangleoptions.[ch]: Setup entry completion code manually for the GimpRatioEntry widgets by using (gimp_rectangle_options_setup_ratio_completion) (gimp_ratio_entry_history_select, gimp_ratio_entry_history_add): these new functions. svn path=/trunk/; revision=23149
This commit is contained in:
parent
4ab3e92782
commit
17020f29b2
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2007-08-08 Martin Nordholts <martinn@svn.gnome.org>
|
||||
|
||||
* libgimpwidgets/gimpratioentry.[ch]: Migrate entry completion
|
||||
code and put responsability on clients to set that up when needed.
|
||||
|
||||
* app/tools/gimprectangleoptions.[ch]: Setup entry completion code
|
||||
manually for the GimpRatioEntry widgets by using
|
||||
(gimp_rectangle_options_setup_ratio_completion)
|
||||
(gimp_ratio_entry_history_select, gimp_ratio_entry_history_add):
|
||||
these new functions.
|
||||
|
||||
2007-08-08 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* modules/cdisplay_lcms.c
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
@ -36,11 +38,33 @@
|
|||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static void gimp_rectangle_options_iface_base_init (GimpRectangleOptionsInterface *rectangle_options_iface);
|
||||
enum
|
||||
{
|
||||
COLUMN_NUMERATOR,
|
||||
COLUMN_DENOMINATOR,
|
||||
COLUMN_TEXT,
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
|
||||
static void gimp_rectangle_options_iface_base_init (GimpRectangleOptionsInterface *rectangle_options_iface);
|
||||
|
||||
static void gimp_rectangle_options_unparent_fixed_rule_widgets (GimpRectangleOptionsPrivate *private);
|
||||
static void gimp_rectangle_options_fixed_rule_changed (GtkWidget *combo_box,
|
||||
GimpRectangleOptionsPrivate *private);
|
||||
|
||||
static void gimp_rectangle_options_setup_ratio_completion (GimpRectangleOptions *rectangle_options,
|
||||
GtkWidget *entry,
|
||||
GtkListStore *history);
|
||||
|
||||
static gboolean gimp_ratio_entry_history_select (GtkEntryCompletion *completion,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
GimpRatioEntry *entry);
|
||||
|
||||
static void gimp_ratio_entry_history_add (GtkWidget *entry,
|
||||
GtkTreeModel *model);
|
||||
|
||||
static void gimp_rectangle_options_unparent_fixed_rule_widgets (GimpRectangleOptionsPrivate *private);
|
||||
static void gimp_rectangle_options_fixed_rule_changed (GtkWidget *combo_box,
|
||||
GimpRectangleOptionsPrivate *private);
|
||||
|
||||
|
||||
/* TODO: Calculate this dynamically so that the GtkEntry:s are always
|
||||
|
@ -255,6 +279,9 @@ gimp_rectangle_options_private_finalize (GimpRectangleOptionsPrivate *private)
|
|||
g_object_unref (private->size_button_box);
|
||||
g_object_unref (private->aspect_button_box);
|
||||
|
||||
g_object_unref (private->aspect_history);
|
||||
g_object_unref (private->size_history);
|
||||
|
||||
g_slice_free (GimpRectangleOptionsPrivate, private);
|
||||
}
|
||||
|
||||
|
@ -276,6 +303,16 @@ gimp_rectangle_options_get_private (GimpRectangleOptions *options)
|
|||
{
|
||||
private = g_slice_new0 (GimpRectangleOptionsPrivate);
|
||||
|
||||
private->aspect_history = gtk_list_store_new (NUM_COLUMNS,
|
||||
G_TYPE_DOUBLE,
|
||||
G_TYPE_DOUBLE,
|
||||
G_TYPE_STRING);
|
||||
|
||||
private->size_history = gtk_list_store_new (NUM_COLUMNS,
|
||||
G_TYPE_DOUBLE,
|
||||
G_TYPE_DOUBLE,
|
||||
G_TYPE_STRING);
|
||||
|
||||
g_object_set_qdata_full (G_OBJECT (options), private_key, private,
|
||||
(GDestroyNotify) gimp_rectangle_options_private_finalize);
|
||||
}
|
||||
|
@ -726,6 +763,9 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
|
|||
"aspect-numerator",
|
||||
"aspect-denominator");
|
||||
g_object_ref_sink (private->fixed_aspect_entry);
|
||||
gimp_rectangle_options_setup_ratio_completion (GIMP_RECTANGLE_OPTIONS (tool_options),
|
||||
private->fixed_aspect_entry,
|
||||
private->aspect_history);
|
||||
gtk_widget_show (private->fixed_aspect_entry);
|
||||
|
||||
private->aspect_button_box =
|
||||
|
@ -768,6 +808,9 @@ gimp_rectangle_options_gui (GimpToolOptions *tool_options)
|
|||
gimp_prop_aspect_ratio_new (config,
|
||||
"desired-fixed-size-width",
|
||||
"desired-fixed-size-height");
|
||||
gimp_rectangle_options_setup_ratio_completion (GIMP_RECTANGLE_OPTIONS (tool_options),
|
||||
private->fixed_size_entry,
|
||||
private->size_history);
|
||||
g_object_ref_sink (private->fixed_size_entry);
|
||||
gtk_widget_show (private->fixed_size_entry);
|
||||
|
||||
|
@ -888,3 +931,100 @@ gimp_rectangle_options_fixed_rule_active (GimpRectangleOptions *rectangle_
|
|||
return private->fixed_rule_active &&
|
||||
private->fixed_rule == fixed_rule;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_rectangle_options_setup_ratio_completion (GimpRectangleOptions *rectangle_options,
|
||||
GtkWidget *entry,
|
||||
GtkListStore *history)
|
||||
{
|
||||
GtkEntryCompletion *completion;
|
||||
GimpRectangleOptionsPrivate *private;
|
||||
|
||||
private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (rectangle_options);
|
||||
|
||||
completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION,
|
||||
"model", history,
|
||||
"inline-completion", TRUE,
|
||||
NULL);
|
||||
|
||||
gtk_entry_completion_set_text_column (completion, COLUMN_TEXT);
|
||||
gtk_entry_set_completion (GTK_ENTRY (entry), completion);
|
||||
g_object_unref (completion);
|
||||
|
||||
g_signal_connect (entry, "ratio-changed",
|
||||
G_CALLBACK (gimp_ratio_entry_history_add),
|
||||
history);
|
||||
|
||||
g_signal_connect (completion, "match-selected",
|
||||
G_CALLBACK (gimp_ratio_entry_history_select),
|
||||
entry);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_ratio_entry_history_select (GtkEntryCompletion *completion,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
GimpRatioEntry *entry)
|
||||
{
|
||||
gdouble numerator;
|
||||
gdouble denominator;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
COLUMN_NUMERATOR, &numerator,
|
||||
COLUMN_DENOMINATOR, &denominator,
|
||||
-1);
|
||||
|
||||
gimp_ratio_entry_set_fraction (entry, numerator, denominator);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_ratio_entry_history_add (GtkWidget *entry,
|
||||
GtkTreeModel *model)
|
||||
{
|
||||
GValue value = { 0, };
|
||||
GtkTreeIter iter;
|
||||
gboolean iter_valid;
|
||||
gdouble numerator;
|
||||
gdouble denominator;
|
||||
const gchar *text;
|
||||
|
||||
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||
gimp_ratio_entry_get_fraction (GIMP_RATIO_ENTRY (entry),
|
||||
&numerator,
|
||||
&denominator);
|
||||
|
||||
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
|
||||
iter_valid;
|
||||
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
||||
{
|
||||
gtk_tree_model_get_value (model, &iter, COLUMN_TEXT, &value);
|
||||
|
||||
if (strcmp (text, g_value_get_string (&value)) == 0)
|
||||
{
|
||||
g_value_unset (&value);
|
||||
break;
|
||||
}
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
if (iter_valid)
|
||||
{
|
||||
gtk_list_store_move_after (GTK_LIST_STORE (model), &iter, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
COLUMN_NUMERATOR, numerator,
|
||||
COLUMN_DENOMINATOR, denominator,
|
||||
COLUMN_TEXT, text,
|
||||
-1);
|
||||
|
||||
/* FIXME: limit the size of the history */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,9 +108,11 @@ struct _GimpRectangleOptionsPrivate
|
|||
|
||||
GtkWidget *fixed_aspect_entry;
|
||||
GtkWidget *aspect_button_box;
|
||||
GtkListStore *aspect_history;
|
||||
|
||||
GtkWidget *fixed_size_entry;
|
||||
GtkWidget *size_button_box;
|
||||
GtkListStore *size_history;
|
||||
|
||||
GtkWidget *width_entry;
|
||||
GtkWidget *height_entry;
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
|
@ -53,14 +51,6 @@ enum
|
|||
PROP_ASPECT
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
COLUMN_NUMERATOR,
|
||||
COLUMN_DENOMINATOR,
|
||||
COLUMN_TEXT,
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
|
||||
static void gimp_ratio_entry_set_property (GObject *object,
|
||||
guint property_id,
|
||||
|
@ -76,15 +66,6 @@ static void gimp_ratio_entry_format_text (GimpRatioEntry *entry);
|
|||
static void gimp_ratio_entry_parse_text (GimpRatioEntry *entry,
|
||||
const gchar *text);
|
||||
|
||||
static gboolean gimp_ratio_entry_history_select (GtkEntryCompletion *completion,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
GimpRatioEntry *entry);
|
||||
|
||||
static void gimp_ratio_entry_history_add (GimpRatioEntry *entry,
|
||||
gdouble numerator,
|
||||
gdouble denominator,
|
||||
const gchar *text);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpRatioEntry, gimp_ratio_entry, GTK_TYPE_ENTRY)
|
||||
|
@ -137,11 +118,6 @@ gimp_ratio_entry_class_init (GimpRatioEntryClass *klass)
|
|||
GIMP_TYPE_ASPECT_TYPE,
|
||||
GIMP_ASPECT_SQUARE,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
|
||||
klass->history = gtk_list_store_new (NUM_COLUMNS,
|
||||
G_TYPE_DOUBLE, G_TYPE_DOUBLE,
|
||||
G_TYPE_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -215,8 +191,6 @@ gimp_ratio_entry_get_property (GObject *object,
|
|||
static void
|
||||
gimp_ratio_entry_init (GimpRatioEntry *entry)
|
||||
{
|
||||
GtkEntryCompletion *completion;
|
||||
|
||||
entry->numerator = 1;
|
||||
entry->denominator = 1;
|
||||
|
||||
|
@ -228,19 +202,6 @@ gimp_ratio_entry_init (GimpRatioEntry *entry)
|
|||
g_signal_connect (entry, "key-press-event",
|
||||
G_CALLBACK (gimp_ratio_entry_events),
|
||||
NULL);
|
||||
|
||||
completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION,
|
||||
"model",
|
||||
GIMP_RATIO_ENTRY_GET_CLASS (entry)->history,
|
||||
"inline-completion", TRUE,
|
||||
NULL);
|
||||
gtk_entry_completion_set_text_column (completion, COLUMN_TEXT);
|
||||
gtk_entry_set_completion (GTK_ENTRY (entry), completion);
|
||||
g_object_unref (completion);
|
||||
|
||||
g_signal_connect (completion, "match-selected",
|
||||
G_CALLBACK (gimp_ratio_entry_history_select),
|
||||
entry);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -518,8 +479,6 @@ gimp_ratio_entry_format_text (GimpRatioEntry *entry)
|
|||
buffer = g_strdup_printf ("%g:%g", entry->numerator, entry->denominator);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (entry), buffer);
|
||||
gimp_ratio_entry_history_add (entry,
|
||||
entry->numerator, entry->denominator, buffer);
|
||||
|
||||
g_free (buffer);
|
||||
}
|
||||
|
@ -578,67 +537,3 @@ gimp_ratio_entry_parse_text (GimpRatioEntry *entry,
|
|||
|
||||
gtk_editable_set_position (GTK_EDITABLE (entry), -1);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_ratio_entry_history_select (GtkEntryCompletion *completion,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
GimpRatioEntry *entry)
|
||||
{
|
||||
gdouble numerator;
|
||||
gdouble denominator;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
COLUMN_NUMERATOR, &numerator,
|
||||
COLUMN_DENOMINATOR, &denominator,
|
||||
-1);
|
||||
|
||||
gimp_ratio_entry_set_fraction (entry, numerator, denominator);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_ratio_entry_history_add (GimpRatioEntry *entry,
|
||||
gdouble numerator,
|
||||
gdouble denominator,
|
||||
const gchar *text)
|
||||
{
|
||||
GimpRatioEntryClass *klass = GIMP_RATIO_ENTRY_GET_CLASS (entry);
|
||||
GtkTreeModel *model = GTK_TREE_MODEL (klass->history);
|
||||
GValue value = { 0, };
|
||||
GtkTreeIter iter;
|
||||
gboolean iter_valid;
|
||||
|
||||
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
|
||||
iter_valid;
|
||||
iter_valid = gtk_tree_model_iter_next (model, &iter))
|
||||
{
|
||||
gtk_tree_model_get_value (model, &iter, COLUMN_TEXT, &value);
|
||||
|
||||
if (strcmp (text, g_value_get_string (&value)) == 0)
|
||||
{
|
||||
g_value_unset (&value);
|
||||
break;
|
||||
}
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
if (iter_valid)
|
||||
{
|
||||
gtk_list_store_move_after (GTK_LIST_STORE (model), &iter, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
COLUMN_NUMERATOR, numerator,
|
||||
COLUMN_DENOMINATOR, denominator,
|
||||
COLUMN_TEXT, text,
|
||||
-1);
|
||||
|
||||
/* FIXME: limit the size of the history */
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,6 @@ struct _GimpRatioEntryClass
|
|||
{
|
||||
GtkEntryClass parent_class;
|
||||
|
||||
GtkListStore *history;
|
||||
|
||||
void (* ratio_changed) (GimpRatioEntry *entry);
|
||||
|
||||
/* Padding for future expansion */
|
||||
|
|
Loading…
Reference in a new issue