app: update GimpContainerEntry when the selected item's name changes
Keep track of the selected viewable of a GimpContainerEntry, and update the entry text when the viewable's name changes, if the text hasn't changed since the viewable was selected.
This commit is contained in:
@ -40,6 +40,8 @@
|
|||||||
|
|
||||||
static void gimp_container_entry_view_iface_init (GimpContainerViewInterface *iface);
|
static void gimp_container_entry_view_iface_init (GimpContainerViewInterface *iface);
|
||||||
|
|
||||||
|
static void gimp_container_entry_finalize (GObject *object);
|
||||||
|
|
||||||
static void gimp_container_entry_set_context (GimpContainerView *view,
|
static void gimp_container_entry_set_context (GimpContainerView *view,
|
||||||
GimpContext *context);
|
GimpContext *context);
|
||||||
static gpointer gimp_container_entry_insert_item (GimpContainerView *view,
|
static gpointer gimp_container_entry_insert_item (GimpContainerView *view,
|
||||||
@ -87,6 +89,7 @@ gimp_container_entry_class_init (GimpContainerEntryClass *klass)
|
|||||||
|
|
||||||
object_class->set_property = gimp_container_view_set_property;
|
object_class->set_property = gimp_container_view_set_property;
|
||||||
object_class->get_property = gimp_container_view_get_property;
|
object_class->get_property = gimp_container_view_get_property;
|
||||||
|
object_class->finalize = gimp_container_entry_finalize;
|
||||||
|
|
||||||
gimp_container_view_install_properties (object_class);
|
gimp_container_view_install_properties (object_class);
|
||||||
}
|
}
|
||||||
@ -120,6 +123,8 @@ gimp_container_entry_init (GimpContainerEntry *entry)
|
|||||||
GType types[GIMP_CONTAINER_TREE_STORE_N_COLUMNS];
|
GType types[GIMP_CONTAINER_TREE_STORE_N_COLUMNS];
|
||||||
gint n_types = 0;
|
gint n_types = 0;
|
||||||
|
|
||||||
|
entry->viewable = NULL;
|
||||||
|
|
||||||
completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION,
|
completion = g_object_new (GTK_TYPE_ENTRY_COMPLETION,
|
||||||
"inline-completion", TRUE,
|
"inline-completion", TRUE,
|
||||||
"popup-single-match", FALSE,
|
"popup-single-match", FALSE,
|
||||||
@ -208,6 +213,21 @@ gimp_container_entry_get_model (GimpContainerView *view)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gimp_container_entry_finalize (GObject *object)
|
||||||
|
{
|
||||||
|
GimpContainerEntry *entry = GIMP_CONTAINER_ENTRY (object);
|
||||||
|
|
||||||
|
if (entry->viewable)
|
||||||
|
{
|
||||||
|
g_object_remove_weak_pointer (G_OBJECT (entry->viewable),
|
||||||
|
(gpointer) &entry->viewable);
|
||||||
|
entry->viewable = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_container_entry_set_context (GimpContainerView *view,
|
gimp_container_entry_set_context (GimpContainerView *view,
|
||||||
GimpContext *context)
|
GimpContext *context)
|
||||||
@ -266,7 +286,22 @@ gimp_container_entry_rename_item (GimpContainerView *view,
|
|||||||
GimpViewable *viewable,
|
GimpViewable *viewable,
|
||||||
gpointer insert_data)
|
gpointer insert_data)
|
||||||
{
|
{
|
||||||
GtkTreeModel *model = gimp_container_entry_get_model (view);
|
GimpContainerEntry *container_entry = GIMP_CONTAINER_ENTRY (view);
|
||||||
|
GtkEntry *entry = GTK_ENTRY (view);
|
||||||
|
GtkTreeModel *model = gimp_container_entry_get_model (view);
|
||||||
|
|
||||||
|
if (viewable == container_entry->viewable)
|
||||||
|
{
|
||||||
|
g_signal_handlers_block_by_func (entry,
|
||||||
|
gimp_container_entry_changed,
|
||||||
|
view);
|
||||||
|
|
||||||
|
gtk_entry_set_text (entry, gimp_object_get_name (viewable));
|
||||||
|
|
||||||
|
g_signal_handlers_unblock_by_func (entry,
|
||||||
|
gimp_container_entry_changed,
|
||||||
|
view);
|
||||||
|
}
|
||||||
|
|
||||||
gimp_container_tree_store_rename_item (GIMP_CONTAINER_TREE_STORE (model),
|
gimp_container_tree_store_rename_item (GIMP_CONTAINER_TREE_STORE (model),
|
||||||
viewable,
|
viewable,
|
||||||
@ -278,15 +313,27 @@ gimp_container_entry_select_item (GimpContainerView *view,
|
|||||||
GimpViewable *viewable,
|
GimpViewable *viewable,
|
||||||
gpointer insert_data)
|
gpointer insert_data)
|
||||||
{
|
{
|
||||||
GtkEntry *entry = GTK_ENTRY (view);
|
GimpContainerEntry *container_entry = GIMP_CONTAINER_ENTRY (view);
|
||||||
GtkTreeIter *iter = insert_data;
|
GtkEntry *entry = GTK_ENTRY (view);
|
||||||
|
GtkTreeIter *iter = insert_data;
|
||||||
|
|
||||||
g_signal_handlers_block_by_func (entry,
|
g_signal_handlers_block_by_func (entry,
|
||||||
gimp_container_entry_changed,
|
gimp_container_entry_changed,
|
||||||
view);
|
view);
|
||||||
|
|
||||||
|
if (container_entry->viewable)
|
||||||
|
{
|
||||||
|
g_object_remove_weak_pointer (G_OBJECT (container_entry->viewable),
|
||||||
|
(gpointer) &container_entry->viewable);
|
||||||
|
container_entry->viewable = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (iter)
|
if (iter)
|
||||||
{
|
{
|
||||||
|
container_entry->viewable = viewable;
|
||||||
|
g_object_add_weak_pointer (G_OBJECT (container_entry->viewable),
|
||||||
|
(gpointer) &container_entry->viewable);
|
||||||
|
|
||||||
gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
|
gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -333,19 +380,31 @@ static void
|
|||||||
gimp_container_entry_changed (GtkEntry *entry,
|
gimp_container_entry_changed (GtkEntry *entry,
|
||||||
GimpContainerView *view)
|
GimpContainerView *view)
|
||||||
{
|
{
|
||||||
GimpContainer *container = gimp_container_view_get_container (view);
|
GimpContainerEntry *container_entry = GIMP_CONTAINER_ENTRY (entry);
|
||||||
GimpObject *object;
|
GimpContainer *container = gimp_container_view_get_container (view);
|
||||||
const gchar *text;
|
GimpObject *object;
|
||||||
|
const gchar *text;
|
||||||
|
|
||||||
if (! container)
|
if (! container)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (container_entry->viewable)
|
||||||
|
{
|
||||||
|
g_object_remove_weak_pointer (G_OBJECT (container_entry->viewable),
|
||||||
|
(gpointer) &container_entry->viewable);
|
||||||
|
container_entry->viewable = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
text = gtk_entry_get_text (entry);
|
text = gtk_entry_get_text (entry);
|
||||||
|
|
||||||
object = gimp_container_get_child_by_name (container, text);
|
object = gimp_container_get_child_by_name (container, text);
|
||||||
|
|
||||||
if (object)
|
if (object)
|
||||||
{
|
{
|
||||||
|
container_entry->viewable = GIMP_VIEWABLE (object);
|
||||||
|
g_object_add_weak_pointer (G_OBJECT (container_entry->viewable),
|
||||||
|
(gpointer) &container_entry->viewable);
|
||||||
|
|
||||||
gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
|
gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL);
|
||||||
gimp_container_view_item_selected (view, GIMP_VIEWABLE (object));
|
gimp_container_view_item_selected (view, GIMP_VIEWABLE (object));
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ typedef struct _GimpContainerEntryClass GimpContainerEntryClass;
|
|||||||
struct _GimpContainerEntry
|
struct _GimpContainerEntry
|
||||||
{
|
{
|
||||||
GtkEntry parent_instance;
|
GtkEntry parent_instance;
|
||||||
|
|
||||||
|
GimpViewable *viewable;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpContainerEntryClass
|
struct _GimpContainerEntryClass
|
||||||
|
Reference in New Issue
Block a user