summaryrefslogtreecommitdiff
path: root/gladeui
diff options
context:
space:
mode:
Diffstat (limited to 'gladeui')
-rw-r--r--gladeui/glade-command.c145
-rw-r--r--gladeui/glade-command.h5
-rw-r--r--gladeui/glade-widget-adaptor.c34
-rw-r--r--gladeui/glade-widget-adaptor.h23
-rw-r--r--gladeui/glade-widget.c19
-rw-r--r--gladeui/glade-widget.h3
-rw-r--r--gladeui/glade-xml-utils.h1
7 files changed, 228 insertions, 2 deletions
diff --git a/gladeui/glade-command.c b/gladeui/glade-command.c
index 617994cc..45fdd402 100644
--- a/gladeui/glade-command.c
+++ b/gladeui/glade-command.c
@@ -786,6 +786,151 @@ glade_command_set_property (GladeProperty * property, ...)
glade_command_set_property_value (property, value);
}
+/***********************************************************/
+/******* GLADE_COMMAND_SET_PROPERTY_SENSITIVE ******/
+/***********************************************************/
+
+/* create a new GladeCommandSetPropertySensitive class. Objects of this class will
+ * encapsulate a "set property (in)sensitive" operation */
+
+typedef struct
+{
+ GladeCommand parent;
+ GladeProperty *property;
+ gboolean sensitive;
+ gchar *new_reason;
+ gchar *old_reason;
+ gboolean undo;
+} GladeCommandSetPropertySensitive;
+
+/* standard macros */
+GLADE_MAKE_COMMAND (GladeCommandSetPropertySensitive, glade_command_set_property_sensitive);
+#define GLADE_COMMAND_SET_PROPERTY_SENSITIVE_TYPE (glade_command_set_property_sensitive_get_type ())
+#define GLADE_COMMAND_SET_PROPERTY_SENSITIVE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_SET_PROPERTY_SENSITIVE_TYPE, GladeCommandSetPropertySensitive))
+#define GLADE_COMMAND_SET_PROPERTY_SENSITIVE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_SET_PROPERTY_SENSITIVE_TYPE, GladeCommandSetPropertySensitiveClass))
+#define GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_SET_PROPERTY_SENSITIVE_TYPE))
+#define GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_SET_PROPERTY_SENSITIVE_TYPE))
+
+/* Undo the last "set property (in)sensitive" command" */
+static gboolean
+glade_command_set_property_sensitive_undo (GladeCommand * cmd)
+{
+ return glade_command_set_property_sensitive_execute (cmd);
+}
+
+/*
+ * Execute the set property command and revert it. IE, after the execution of
+ * this function cmd will point to the undo action
+ */
+static gboolean
+glade_command_set_property_sensitive_execute (GladeCommand * cmd)
+{
+ GladeCommandSetPropertySensitive *scmd;
+
+ g_return_val_if_fail (GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE (cmd), TRUE);
+
+ scmd = GLADE_COMMAND_SET_PROPERTY_SENSITIVE (cmd);
+ glade_property_set_sensitive (scmd->property,
+ scmd->undo ? !scmd->sensitive : scmd->sensitive,
+ scmd->undo ? scmd->old_reason : scmd->new_reason);
+
+ scmd->undo = !scmd->undo;
+ return TRUE;
+}
+
+static void
+glade_command_set_property_sensitive_finalize (GObject * obj)
+{
+ GladeCommandSetPropertySensitive *cmd;
+
+ cmd = GLADE_COMMAND_SET_PROPERTY_SENSITIVE (obj);
+ g_free (cmd->new_reason);
+ g_free (cmd->old_reason);
+
+ glade_command_finalize (obj);
+}
+
+static gboolean
+glade_command_set_property_sensitive_unifies (GladeCommand * this_cmd,
+ GladeCommand * other_cmd)
+{
+ GladeCommandSetPropertySensitive *cmd1, *cmd2;
+
+ if (GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE (this_cmd) &&
+ GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE (other_cmd))
+ {
+ cmd1 = GLADE_COMMAND_SET_PROPERTY_SENSITIVE (this_cmd);
+ cmd2 = GLADE_COMMAND_SET_PROPERTY_SENSITIVE (other_cmd);
+
+ return (cmd1->property == cmd2->property &&
+ cmd1->new_reason == cmd2->new_reason);
+ }
+
+ return FALSE;
+}
+
+static void
+glade_command_set_property_sensitive_collapse (GladeCommand * this_cmd,
+ GladeCommand * other_cmd)
+{
+ g_return_if_fail (GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE (this_cmd));
+ g_return_if_fail (GLADE_IS_COMMAND_SET_PROPERTY_SENSITIVE (other_cmd));
+
+ /* Nothing to do */
+}
+
+void
+glade_command_widget_set_property_sensitive (GladeWidget * widget,
+ const gchar * property_id,
+ gboolean sensitive,
+ const gchar * reason)
+{
+ GladeProperty *property;
+
+ g_return_if_fail (GLADE_IS_WIDGET (widget));
+ g_return_if_fail (property_id != NULL);
+
+ if ((property = glade_widget_get_property (widget, property_id)) != NULL)
+ glade_command_set_property_sensitive (property, sensitive, reason);
+}
+
+void
+glade_command_set_property_sensitive (GladeProperty * property,
+ gboolean sensitive,
+ const gchar * reason)
+{
+ GladeCommandSetPropertySensitive *me;
+ GladeCommand *cmd;
+
+ g_return_if_fail (GLADE_IS_PROPERTY (property));
+
+ me = g_object_new (GLADE_COMMAND_SET_PROPERTY_SENSITIVE_TYPE, NULL);
+ me->undo = FALSE;
+ me->property = property;
+ me->sensitive = sensitive;
+
+ me->new_reason = g_strdup (reason);
+ me->old_reason = g_strdup (glade_propert_get_insensitive_tooltip (me->property));
+ if (me->old_reason)
+ me->old_reason = g_strdup (me->old_reason);
+
+ cmd = GLADE_COMMAND (me);
+ cmd->priv->project =
+ glade_widget_get_project (glade_property_get_widget (me->property));
+
+ /* This command is always part of a group, thus its description should
+ * never be visible
+ */
+ cmd->priv->description = g_strdup ("dummy");
+
+ glade_command_check_group (GLADE_COMMAND (me));
+
+ if (glade_command_set_property_sensitive_execute (GLADE_COMMAND (me)))
+ glade_project_push_undo (cmd->priv->project, cmd);
+ else
+ g_object_unref (G_OBJECT (me));
+}
+
/**************************************************/
/******* GLADE_COMMAND_SET_NAME *******/
/**************************************************/
diff --git a/gladeui/glade-command.h b/gladeui/glade-command.h
index 0e7837d7..7bc0cf41 100644
--- a/gladeui/glade-command.h
+++ b/gladeui/glade-command.h
@@ -95,6 +95,11 @@ void glade_command_set_properties (GladeProperty *property,
void glade_command_set_properties_list (GladeProject *project,
GList *props); /* list of GCSetPropData */
+void glade_command_widget_set_property_sensitive (GladeWidget *widget,
+ const gchar *property_id,
+ gboolean sensitive,
+ const gchar *reason);
+
/************************** name ******************************/
void glade_command_set_name (GladeWidget *glade_widget, const gchar *name);
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index 87d31eea..eb266877 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -1325,6 +1325,13 @@ glade_widget_adaptor_object_get_children (GladeWidgetAdaptor *adaptor,
return children;
}
+static void
+glade_widget_adaptor_object_adjust_property_flags (GladeWidgetAdaptor * adaptor,
+ GladeWidget * widget,
+ gboolean use_command)
+{
+ /* Nothing to do */
+}
/*******************************************************************************
GladeWidgetAdaptor type registration and class initializer
@@ -1378,6 +1385,7 @@ glade_widget_adaptor_class_init (GladeWidgetAdaptorClass * adaptor_class)
adaptor_class->create_eprop = glade_widget_adaptor_object_create_eprop;
adaptor_class->string_from_value = glade_widget_adaptor_object_string_from_value;
adaptor_class->create_editable = glade_widget_adaptor_object_create_editable;
+ adaptor_class->adjust_property_flags = glade_widget_adaptor_object_adjust_property_flags;
/* Base defaults here */
adaptor_class->toplevel = FALSE;
@@ -1645,6 +1653,10 @@ gwa_extend_with_node_load_sym (GladeWidgetAdaptorClass * klass,
&symbol))
klass->create_editable = symbol;
+ if (glade_xml_load_sym_from_node (node, module,
+ GLADE_TAG_ADJUST_PROPERTY_FLAGS_FUNCTION,
+ &symbol))
+ klass->adjust_property_flags = symbol;
}
static void
@@ -4358,3 +4370,25 @@ glade_widget_adaptor_create_editable (GladeWidgetAdaptor * adaptor,
return GLADE_WIDGET_ADAPTOR_GET_CLASS
(adaptor)->create_editable (adaptor, type);
}
+
+/**
+ * glade_widget_adaptor_adjust_property_flags:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @widget: The #GladeWidget
+ * @use_command: whether to use the GladeCommand interface
+ *
+ * This is called after a widget is loaded or a widget's
+ * property value has changed. It allows the backend to keep the
+ * sensitive/enabled flags of all properties consistent with the
+ * property values.
+ */
+void
+glade_widget_adaptor_adjust_property_flags (GladeWidgetAdaptor * adaptor,
+ GladeWidget * widget,
+ gboolean use_command)
+{
+ g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));
+
+ GLADE_WIDGET_ADAPTOR_GET_CLASS
+ (adaptor)->adjust_property_flags (adaptor, widget, use_command);
+}
diff --git a/gladeui/glade-widget-adaptor.h b/gladeui/glade-widget-adaptor.h
index ab33a531..a1a2a29f 100644
--- a/gladeui/glade-widget-adaptor.h
+++ b/gladeui/glade-widget-adaptor.h
@@ -553,6 +553,21 @@ typedef GladeEditable *(* GladeCreateEditableFunc) (GladeWidgetAdaptor *adapto
GladeEditorPageType type);
+/**
+ * GladeAdjustPropertyFlagsFunc:
+ * @adaptor: A #GladeWidgetAdaptor
+ * @widget: The #GladeWidget
+ * @use_command: whether to use the GladeCommand interface
+ *
+ * This is called after a widget is loaded or a widget's
+ * property value has changed. It allows the backend to keep the
+ * sensitive/enabled flags of all properties consistent with the
+ * property values.
+ */
+typedef void (* GladeAdjustPropertyFlagsFunc) (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ gboolean use_command);
+
/* Note that everything that must be processed at the creation of
* every instance is managed on the instance structure, and everywhere
* that we want to take advantage of inheritance is handled in the class
@@ -659,7 +674,8 @@ struct _GladeWidgetAdaptorClass
GladeCreateEPropFunc create_eprop; /* Creates a GladeEditorProperty */
GladeStringFromValueFunc string_from_value; /* Creates a string for a value */
GladeCreateEditableFunc create_editable; /* Creates a page for the editor */
-
+ GladeAdjustPropertyFlagsFunc adjust_property_flags; /* Appropiately sets all properties' sensitive/enabled flags */
+
void (* glade_reserved1) (void);
void (* glade_reserved2) (void);
void (* glade_reserved3) (void);
@@ -667,7 +683,6 @@ struct _GladeWidgetAdaptorClass
void (* glade_reserved5) (void);
void (* glade_reserved6) (void);
void (* glade_reserved7) (void);
- void (* glade_reserved8) (void);
};
#define glade_widget_adaptor_create_widget(adaptor, query, ...) \
@@ -845,6 +860,10 @@ GladeWidgetAdaptor *glade_widget_adaptor_get_parent_adaptor (GladeWidgetAdapto
gboolean glade_widget_adaptor_has_internal_children (GladeWidgetAdaptor *adaptor);
+void glade_widget_adaptor_adjust_property_flags (GladeWidgetAdaptor *adaptor,
+ GladeWidget *widget,
+ gboolean use_command);
+
G_END_DECLS
#endif /* _GLADE_WIDGET_ADAPTOR_H_ */
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index 53226bda..b8eb1bac 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -3779,6 +3779,9 @@ glade_widget_read (GladeProject * project,
}
glade_widget_adaptor_read_widget (adaptor, widget, node);
+
+ /* Set initial property sensitivity */
+ glade_widget_adaptor_adjust_property_flags (adaptor, widget, FALSE);
}
else
{
@@ -3996,6 +3999,22 @@ glade_widget_is_ancestor (GladeWidget * widget, GladeWidget * ancestor)
return FALSE;
}
+/**
+ * glade_widget_adjust_property_flags:
+ * @widget: A #GladeWidget
+ * @use_command: whether to use the GladeCommand interface
+ *
+ * Adjusts the sensitive/enabled flags of all widget properties to match
+ * the widget's property values.
+ */
+void
+glade_widget_adjust_property_flags (GladeWidget * widget, gboolean use_command)
+{
+ g_return_if_fail (GLADE_IS_WIDGET (widget));
+
+ glade_widget_adaptor_adjust_property_flags (widget->priv->adaptor,
+ widget, use_command);
+}
static gint glade_widget_su_stack = 0;
diff --git a/gladeui/glade-widget.h b/gladeui/glade-widget.h
index aa0726f2..038c090c 100644
--- a/gladeui/glade-widget.h
+++ b/gladeui/glade-widget.h
@@ -216,6 +216,9 @@ gchar *glade_widget_generate_path_name (GladeWidget *w
gboolean glade_widget_is_ancestor (GladeWidget *widget,
GladeWidget *ancestor);
+void glade_widget_adjust_property_flags (GladeWidget *widget,
+ gboolean use_command);
+
/*******************************************************************************
Project, object property references
*******************************************************************************/
diff --git a/gladeui/glade-xml-utils.h b/gladeui/glade-xml-utils.h
index c7b116fa..8dcdc94a 100644
--- a/gladeui/glade-xml-utils.h
+++ b/gladeui/glade-xml-utils.h
@@ -113,6 +113,7 @@ typedef struct _GladeProject GladeProject;
#define GLADE_TAG_CREATE_EPROP_FUNCTION "create-editor-property-function"
#define GLADE_TAG_STRING_FROM_VALUE_FUNCTION "string-from-value-function"
#define GLADE_TAG_CREATE_EDITABLE_FUNCTION "create-editable-function"
+#define GLADE_TAG_ADJUST_PROPERTY_FLAGS_FUNCTION "adjust-property-flags-function"
#define GLADE_TAG_PROPERTIES "properties"
#define GLADE_TAG_PACKING_PROPERTIES "packing-properties"
#define GLADE_TAG_PROPERTY "property"