summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <juanpablougarte@gmail.com>2014-05-12 15:02:04 -0300
committerJuan Pablo Ugarte <juanpablougarte@gmail.com>2014-05-12 15:07:19 -0300
commit73b1137903a7acc32c0faa83f7e93fe049e03256 (patch)
tree823d4822ce6d77853a180e06982c12b77c6aba99
parentfd791c4cd7a4097482d4f8c467cc37272ef113fe (diff)
downloadglade-73b1137903a7acc32c0faa83f7e93fe049e03256.tar.gz
GladeEditorProperty: re grab focus on load_common() if property is construct-only.
If the property is construct-only, then glade_widget_rebuild() will be called which means the object will be removed from the project/selection and a new one will be added, which makes the eprop loose its focus.
-rw-r--r--gladeui/glade-editor-property.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/gladeui/glade-editor-property.c b/gladeui/glade-editor-property.c
index 2ee292c9..26d4fca1 100644
--- a/gladeui/glade-editor-property.c
+++ b/gladeui/glade-editor-property.c
@@ -151,6 +151,26 @@ glade_editor_property_editable_init (GladeEditableIface *iface)
GladeEditorPropertyClass
*******************************************************************************/
+static void
+deepest_child_grab_focus (GtkWidget *widget, gpointer data)
+{
+ gboolean *focus_set = data;
+
+ if (*focus_set)
+ return;
+
+ if (GTK_IS_CONTAINER (widget))
+ gtk_container_foreach (GTK_CONTAINER (widget),
+ deepest_child_grab_focus,
+ data);
+
+ if (gtk_widget_get_can_focus (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ *focus_set = TRUE;
+ }
+}
+
/* declare this forwardly for the finalize routine */
static void glade_editor_property_load_common (GladeEditorProperty *eprop,
GladeProperty *property);
@@ -169,6 +189,22 @@ glade_editor_property_commit_common (GladeEditorProperty *eprop,
*/
if (!glade_property_equals_value (eprop->priv->property, value))
glade_editor_property_load (eprop, eprop->priv->property);
+
+ /* Restore input focus. If the property is construct-only, then
+ * glade_widget_rebuild() will be called which means the object will be
+ * removed from the project/selection and a new one will be added, which makes
+ * the eprop loose its focus.
+ *
+ * FIXME: find a better way to set focus?
+ * make gtk_widget_grab_focus(eprop->priv->input) work?
+ */
+ if (glade_property_class_get_construct_only (eprop->priv->klass))
+ {
+ gboolean focus_set = FALSE;
+ gtk_container_foreach (GTK_CONTAINER (eprop->priv->input),
+ deepest_child_grab_focus,
+ &focus_set);
+ }
}
void