Rember the user input that triggered the completion, add API to the
* gtk/gtkentry.c: * gtk/gtkentrycompletion.c: * gtk/gtkentrycompletion.h: * gtk/gtkentryprivate.h: Rember the user input that triggered the completion, add API to the retrieve it and reset the entry contents to it if the user cancels the tentative completion during the inline-selection. svn path=/trunk/; revision=17666
This commit is contained in:
parent
61de24aa9a
commit
c5ce76fda2
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2007-04-28 Xan Lopez <xan@gnome.org>
|
||||||
|
|
||||||
|
* gtk/gtkentry.c:
|
||||||
|
* gtk/gtkentrycompletion.c:
|
||||||
|
* gtk/gtkentrycompletion.h:
|
||||||
|
* gtk/gtkentryprivate.h:
|
||||||
|
|
||||||
|
Rember the user input that triggered the completion, add
|
||||||
|
API to the retrieve it and reset the entry contents to it
|
||||||
|
if the user cancels the tentative completion during
|
||||||
|
the inline-selection.
|
||||||
|
|
||||||
2007-04-27 Matthias Clasen <mclasen@redhat.com>
|
2007-04-27 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* gdk/x11/gdkgeometry-x11.c: Factor out window movement
|
* gdk/x11/gdkgeometry-x11.c: Factor out window movement
|
||||||
|
@ -5692,6 +5692,11 @@ gtk_entry_completion_key_press (GtkWidget *widget,
|
|||||||
if (!gtk_tree_selection_get_selected (sel, &model, &iter))
|
if (!gtk_tree_selection_get_selected (sel, &model, &iter))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
if (completion->priv->completion_prefix == NULL)
|
||||||
|
{
|
||||||
|
completion->priv->completion_prefix = g_strdup (gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
|
||||||
|
}
|
||||||
|
|
||||||
g_signal_emit_by_name (completion, "cursor_on_match", model,
|
g_signal_emit_by_name (completion, "cursor_on_match", model,
|
||||||
&iter, &entry_set);
|
&iter, &entry_set);
|
||||||
}
|
}
|
||||||
@ -5720,10 +5725,23 @@ gtk_entry_completion_key_press (GtkWidget *widget,
|
|||||||
|
|
||||||
if (completion->priv->inline_selection)
|
if (completion->priv->inline_selection)
|
||||||
{
|
{
|
||||||
|
/* Escape rejects the tentative completion */
|
||||||
if (event->keyval == GDK_Escape)
|
if (event->keyval == GDK_Escape)
|
||||||
gtk_editable_delete_selection (GTK_EDITABLE (widget));
|
{
|
||||||
/* Move the cursor to the end */
|
gtk_entry_set_text (GTK_ENTRY (completion->priv->entry), completion->priv->completion_prefix);
|
||||||
gtk_editable_set_position (GTK_EDITABLE (widget), -1);
|
}
|
||||||
|
|
||||||
|
/* Move the cursor to the end for Right/Esc, to the
|
||||||
|
beginning for Left */
|
||||||
|
if (event->keyval == GDK_Right ||
|
||||||
|
event->keyval == GDK_KP_Right ||
|
||||||
|
event->keyval == GDK_Escape)
|
||||||
|
gtk_editable_set_position (GTK_EDITABLE (widget), -1);
|
||||||
|
else
|
||||||
|
gtk_editable_set_position (GTK_EDITABLE (widget), 0);
|
||||||
|
|
||||||
|
g_free (completion->priv->completion_prefix);
|
||||||
|
completion->priv->completion_prefix = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -5738,6 +5756,12 @@ gtk_entry_completion_key_press (GtkWidget *widget,
|
|||||||
_gtk_entry_reset_im_context (GTK_ENTRY (widget));
|
_gtk_entry_reset_im_context (GTK_ENTRY (widget));
|
||||||
_gtk_entry_completion_popdown (completion);
|
_gtk_entry_completion_popdown (completion);
|
||||||
|
|
||||||
|
if (completion->priv->completion_prefix)
|
||||||
|
{
|
||||||
|
g_free (completion->priv->completion_prefix);
|
||||||
|
completion->priv->completion_prefix = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
|
gtk_widget_child_focus (gtk_widget_get_toplevel (widget), dir);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -67,71 +67,71 @@ enum
|
|||||||
|
|
||||||
#define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
|
#define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
|
||||||
|
|
||||||
static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
|
static void gtk_entry_completion_cell_layout_init (GtkCellLayoutIface *iface);
|
||||||
static void gtk_entry_completion_set_property (GObject *object,
|
static void gtk_entry_completion_set_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
const GValue *value,
|
const GValue *value,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
static void gtk_entry_completion_get_property (GObject *object,
|
static void gtk_entry_completion_get_property (GObject *object,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec);
|
GParamSpec *pspec);
|
||||||
static void gtk_entry_completion_finalize (GObject *object);
|
static void gtk_entry_completion_finalize (GObject *object);
|
||||||
|
|
||||||
static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
|
static void gtk_entry_completion_pack_start (GtkCellLayout *cell_layout,
|
||||||
GtkCellRenderer *cell,
|
GtkCellRenderer *cell,
|
||||||
gboolean expand);
|
gboolean expand);
|
||||||
static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
|
static void gtk_entry_completion_pack_end (GtkCellLayout *cell_layout,
|
||||||
GtkCellRenderer *cell,
|
GtkCellRenderer *cell,
|
||||||
gboolean expand);
|
gboolean expand);
|
||||||
static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
|
static void gtk_entry_completion_clear (GtkCellLayout *cell_layout);
|
||||||
static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
|
static void gtk_entry_completion_add_attribute (GtkCellLayout *cell_layout,
|
||||||
GtkCellRenderer *cell,
|
GtkCellRenderer *cell,
|
||||||
const char *attribute,
|
const char *attribute,
|
||||||
gint column);
|
gint column);
|
||||||
static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
|
static void gtk_entry_completion_set_cell_data_func (GtkCellLayout *cell_layout,
|
||||||
GtkCellRenderer *cell,
|
GtkCellRenderer *cell,
|
||||||
GtkCellLayoutDataFunc func,
|
GtkCellLayoutDataFunc func,
|
||||||
gpointer func_data,
|
gpointer func_data,
|
||||||
GDestroyNotify destroy);
|
GDestroyNotify destroy);
|
||||||
static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
|
static void gtk_entry_completion_clear_attributes (GtkCellLayout *cell_layout,
|
||||||
GtkCellRenderer *cell);
|
GtkCellRenderer *cell);
|
||||||
static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
|
static void gtk_entry_completion_reorder (GtkCellLayout *cell_layout,
|
||||||
GtkCellRenderer *cell,
|
GtkCellRenderer *cell,
|
||||||
gint position);
|
gint position);
|
||||||
|
|
||||||
static gboolean gtk_entry_completion_visible_func (GtkTreeModel *model,
|
static gboolean gtk_entry_completion_visible_func (GtkTreeModel *model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gboolean gtk_entry_completion_popup_key_event (GtkWidget *widget,
|
static gboolean gtk_entry_completion_popup_key_event (GtkWidget *widget,
|
||||||
GdkEventKey *event,
|
GdkEventKey *event,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static gboolean gtk_entry_completion_popup_button_press (GtkWidget *widget,
|
static gboolean gtk_entry_completion_popup_button_press (GtkWidget *widget,
|
||||||
GdkEventButton *event,
|
GdkEventButton *event,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static gboolean gtk_entry_completion_list_button_press (GtkWidget *widget,
|
static gboolean gtk_entry_completion_list_button_press (GtkWidget *widget,
|
||||||
GdkEventButton *event,
|
GdkEventButton *event,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget,
|
static gboolean gtk_entry_completion_action_button_press (GtkWidget *widget,
|
||||||
GdkEventButton *event,
|
GdkEventButton *event,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
|
static void gtk_entry_completion_selection_changed (GtkTreeSelection *selection,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gboolean gtk_entry_completion_list_enter_notify (GtkWidget *widget,
|
static gboolean gtk_entry_completion_list_enter_notify (GtkWidget *widget,
|
||||||
GdkEventCrossing *event,
|
GdkEventCrossing *event,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static gboolean gtk_entry_completion_list_motion_notify (GtkWidget *widget,
|
static gboolean gtk_entry_completion_list_motion_notify (GtkWidget *widget,
|
||||||
GdkEventMotion *event,
|
GdkEventMotion *event,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
|
static void gtk_entry_completion_insert_action (GtkEntryCompletion *completion,
|
||||||
gint index,
|
gint index,
|
||||||
const gchar *string,
|
const gchar *string,
|
||||||
gboolean markup);
|
gboolean markup);
|
||||||
static void gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
|
static void gtk_entry_completion_action_data_func (GtkTreeViewColumn *tree_column,
|
||||||
GtkCellRenderer *cell,
|
GtkCellRenderer *cell,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
static gboolean gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
|
static gboolean gtk_entry_completion_match_selected (GtkEntryCompletion *completion,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
@ -141,6 +141,11 @@ static gboolean gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *co
|
|||||||
static gboolean gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
|
static gboolean gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
GtkTreeIter *iter);
|
GtkTreeIter *iter);
|
||||||
|
static gboolean gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
|
||||||
|
GtkTreeModel *model,
|
||||||
|
GtkTreeIter *iter);
|
||||||
|
static void gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
|
||||||
|
const gchar *text);
|
||||||
|
|
||||||
static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
|
static guint entry_completion_signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
@ -1631,13 +1636,34 @@ gtk_entry_completion_real_insert_prefix (GtkEntryCompletion *completion,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
/**
|
||||||
|
* gtk_entry_completion_get_completion_prefix:
|
||||||
|
* @completion: a #GtkEntryCompletion
|
||||||
|
*
|
||||||
|
* Get the original text entered by the user that triggered
|
||||||
|
* the completion or NULL if there's no completion ongoing.
|
||||||
|
*
|
||||||
|
* Since: 2.12
|
||||||
|
**/
|
||||||
|
|
||||||
|
const gchar*
|
||||||
|
gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), NULL);
|
||||||
|
|
||||||
|
return completion->priv->completion_prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
|
gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
|
||||||
const gchar *text)
|
const gchar *text)
|
||||||
{
|
{
|
||||||
GtkEntryCompletionPrivate *priv = completion->priv;
|
GtkEntryCompletionPrivate *priv = completion->priv;
|
||||||
|
gchar *needle;
|
||||||
gint len;
|
gint len;
|
||||||
|
|
||||||
|
priv = completion->priv;
|
||||||
|
|
||||||
if (priv->changed_id > 0)
|
if (priv->changed_id > 0)
|
||||||
{
|
{
|
||||||
g_signal_handler_block (priv->entry,
|
g_signal_handler_block (priv->entry,
|
||||||
@ -1650,9 +1676,15 @@ gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
|
|||||||
completion->priv->insert_text_id);
|
completion->priv->insert_text_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_editable_get_selection_bounds (GTK_EDITABLE (priv->entry), &len, NULL);
|
|
||||||
gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
|
gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
|
||||||
gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
|
needle = g_strstr_len (text, -1, completion->priv->completion_prefix);
|
||||||
|
if (needle)
|
||||||
|
{
|
||||||
|
len = g_utf8_strlen (text, -1) - g_utf8_strlen (needle, -1)
|
||||||
|
+ g_utf8_strlen (priv->completion_prefix, -1);
|
||||||
|
gtk_editable_select_region (GTK_EDITABLE (priv->entry),
|
||||||
|
len, -1);
|
||||||
|
}
|
||||||
|
|
||||||
if (priv->changed_id > 0)
|
if (priv->changed_id > 0)
|
||||||
{
|
{
|
||||||
@ -1667,15 +1699,13 @@ gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
static gboolean
|
||||||
gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
|
gtk_entry_completion_insert_completion (GtkEntryCompletion *completion,
|
||||||
GtkTreeModel *model,
|
GtkTreeModel *model,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
gchar *str = NULL;
|
gchar *str = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE);
|
|
||||||
|
|
||||||
if (completion->priv->text_column < 0)
|
if (completion->priv->text_column < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -119,8 +119,7 @@ void gtk_entry_completion_set_popup_single_match (GtkEntryComplet
|
|||||||
gboolean popup_single_match);
|
gboolean popup_single_match);
|
||||||
gboolean gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion);
|
gboolean gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion);
|
||||||
|
|
||||||
void gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
|
const gchar *gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion);
|
||||||
const gchar *text);
|
|
||||||
/* convenience */
|
/* convenience */
|
||||||
void gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
|
void gtk_entry_completion_set_text_column (GtkEntryCompletion *completion,
|
||||||
gint column);
|
gint column);
|
||||||
|
@ -66,6 +66,8 @@ struct _GtkEntryCompletionPrivate
|
|||||||
guint popup_single_match : 1;
|
guint popup_single_match : 1;
|
||||||
guint inline_selection : 1;
|
guint inline_selection : 1;
|
||||||
|
|
||||||
|
gchar *completion_prefix;
|
||||||
|
|
||||||
GSource *check_completion_idle;
|
GSource *check_completion_idle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user