Commit 1baaef3b authored by Tristan Van Berkom's avatar Tristan Van Berkom

Set sizegroup_add action sensitive/insensitive depending on project format


	* plugins/gtk+/glade-gtk.c: Set sizegroup_add action sensitive/insensitive
	  depending on project format

	* plugins/gtk+/gtk+.xml.in: Set libglade-unsupported && create-type on alot of properties

	* gladeui/glade-editor-property.c: Set eprop insensitive also if its in an unsupported
	  format

	* gladeui/glade-xml-utils.h, gladeui/glade-property-class.c: Added "create-type"

	* gladeui/glade-property.[ch]: Now property states can be flagged and
	  also include format_disabled state.


svn path=/trunk/; revision=1948
parent 7aabb01a
2008-09-21 Tristan Van Berkom <tvb@gnome.org>
* plugins/gtk+/glade-gtk.c: Set sizegroup_add action sensitive/insensitive
depending on project format
* plugins/gtk+/gtk+.xml.in: Set libglade-unsupported && create-type on alot of properties
* gladeui/glade-editor-property.c: Set eprop insensitive also if its in an unsupported
format
* gladeui/glade-xml-utils.h, gladeui/glade-property-class.c: Added "create-type"
* gladeui/glade-property.[ch]: Now property states can be flagged and
also include format_disabled state.
2008-09-20 Tristan Van Berkom <tvb@gnome.org>
* TODO: Updated.
......
......@@ -2143,7 +2143,7 @@ glade_command_set_format_undo(GladeCommand *cmd)
static void
glade_command_set_format_finalize(GObject *obj)
{
GladeCommandSetFormat *me;
/* GladeCommandSetFormat *me; */
g_return_if_fail(GLADE_IS_COMMAND_SET_FORMAT(obj));
......@@ -2153,8 +2153,8 @@ glade_command_set_format_finalize(GObject *obj)
static gboolean
glade_command_set_format_unifies (GladeCommand *this_cmd, GladeCommand *other_cmd)
{
GladeCommandSetFormat *cmd1;
GladeCommandSetFormat *cmd2;
/* GladeCommandSetFormat *cmd1; */
/* GladeCommandSetFormat *cmd2; */
return FALSE;
}
......@@ -2163,10 +2163,10 @@ static void
glade_command_set_format_collapse (GladeCommand *this_cmd, GladeCommand *other_cmd)
{
/* this command is the one that will be used for an undo of the sequence of like commands */
GladeCommandSetFormat *this = GLADE_COMMAND_SET_FORMAT (this_cmd);
//GladeCommandSetFormat *this = GLADE_COMMAND_SET_FORMAT (this_cmd);
/* the other command contains the values that will be used for a redo */
GladeCommandSetFormat *other = GLADE_COMMAND_SET_FORMAT (other_cmd);
//GladeCommandSetFormat *other = GLADE_COMMAND_SET_FORMAT (other_cmd);
g_return_if_fail (GLADE_IS_COMMAND_SET_FORMAT (this_cmd) && GLADE_IS_COMMAND_SET_FORMAT (other_cmd));
......
......@@ -149,12 +149,13 @@ glade_editor_property_sensitivity_cb (GladeProperty *property,
GladeEditorProperty *eprop)
{
gboolean sensitive = glade_property_get_sensitive (eprop->property);
gboolean support_sensitive = (eprop->property->state & GLADE_STATE_SUPPORT_DISABLED) == 0;
gtk_widget_set_sensitive (eprop->item_label, sensitive);
gtk_widget_set_sensitive (eprop->input, sensitive &&
glade_property_get_enabled (property));
gtk_widget_set_sensitive (eprop->item_label, sensitive && support_sensitive);
gtk_widget_set_sensitive (eprop->input, sensitive && support_sensitive &&
glade_property_get_enabled (property));
if (eprop->check)
gtk_widget_set_sensitive (eprop->check, sensitive);
gtk_widget_set_sensitive (eprop->check, sensitive && support_sensitive);
}
static void
......@@ -176,37 +177,21 @@ glade_editor_property_fix_label (GladeEditorProperty *eprop)
return;
/* refresh label */
switch (eprop->property->state)
{
case GLADE_STATE_NORMAL:
case GLADE_STATE_UNSUPPORTED:
text = g_strdup_printf ("%s:", eprop->klass->name);
break;
case GLADE_STATE_CHANGED:
case GLADE_STATE_UNSUPPORTED_CHANGED:
if ((eprop->property->state & GLADE_STATE_CHANGED) != 0)
text = g_strdup_printf ("<b>%s:</b>", eprop->klass->name);
break;
default:
g_assert_not_reached ();
}
else
text = g_strdup_printf ("%s:", eprop->klass->name);
gtk_label_set_markup (GTK_LABEL (eprop->label), text);
g_free (text);
/* refresh icon */
switch (eprop->property->state)
{
case GLADE_STATE_NORMAL:
case GLADE_STATE_CHANGED:
gtk_widget_hide (eprop->warning);
break;
case GLADE_STATE_UNSUPPORTED:
case GLADE_STATE_UNSUPPORTED_CHANGED:
if ((eprop->property->state & GLADE_STATE_UNSUPPORTED) != 0)
gtk_widget_show (eprop->warning);
break;
default:
g_assert_not_reached ();
}
else
gtk_widget_hide (eprop->warning);
gtk_label_set_markup (GTK_LABEL (eprop->label), text);
g_free (text);
/* check sensitivity */
glade_editor_property_sensitivity_cb (eprop->property, NULL, eprop);
}
static void
......@@ -229,10 +214,11 @@ glade_editor_property_enabled_cb (GladeProperty *property,
{
enabled = glade_property_get_enabled (property);
/* sensitive = enabled && sensitive */
/* sensitive = enabled && support enabled && sensitive */
if (enabled == FALSE)
gtk_widget_set_sensitive (eprop->input, FALSE);
else if (glade_property_get_sensitive (property))
else if (glade_property_get_sensitive (property) ||
(property->state & GLADE_STATE_SUPPORT_DISABLED) != 0)
gtk_widget_set_sensitive (eprop->input, TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (eprop->check), enabled);
......@@ -2294,6 +2280,7 @@ enum {
};
#define GLADE_RESPONSE_CLEAR 42
#define GLADE_RESPONSE_CREATE 43
typedef struct {
GladeEditorProperty parent_instance;
......@@ -2610,7 +2597,7 @@ glade_eprop_object_dialog_title (GladeEditorProperty *eprop)
GladeWidgetAdaptor *adaptor;
const gchar *format =
GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec) ?
_("Choose %s implementors") : _("Choose a %s in this project");
_("Choose %s(s) in this project") : _("Choose a %s in this project");
if (GLADE_IS_PARAM_SPEC_OBJECTS (eprop->klass->pspec))
return g_strdup_printf (format, g_type_name
......@@ -2638,25 +2625,53 @@ glade_eprop_object_show_dialog (GtkWidget *dialog_button,
GladeProject *project;
gchar *title = glade_eprop_object_dialog_title (eprop);
gint res;
GladeWidgetAdaptor *create_adaptor = NULL;
project = glade_widget_get_project (eprop->property->widget);
parent = gtk_widget_get_toplevel (GTK_WIDGET (eprop));
dialog = gtk_dialog_new_with_buttons (title,
GTK_WINDOW (parent),
GTK_DIALOG_MODAL,
GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_free (title);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
GLADE_RESPONSE_CLEAR,
-1);
if (eprop->property->klass->create_type)
create_adaptor = glade_widget_adaptor_get_by_name (eprop->property->klass->create_type);
if (!create_adaptor)
create_adaptor = glade_widget_adaptor_get_by_type (eprop->klass->pspec->value_type);
if (create_adaptor)
{
dialog = gtk_dialog_new_with_buttons (title,
GTK_WINDOW (parent),
GTK_DIALOG_MODAL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
_("_New"), GLADE_RESPONSE_CREATE,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_free (title);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GLADE_RESPONSE_CREATE,
GTK_RESPONSE_CANCEL,
GLADE_RESPONSE_CLEAR,
-1);
}
else
{
dialog = gtk_dialog_new_with_buttons (title,
GTK_WINDOW (parent),
GTK_DIALOG_MODAL,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
g_free (title);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
GLADE_RESPONSE_CLEAR,
-1);
}
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
......@@ -2758,6 +2773,29 @@ glade_eprop_object_show_dialog (GtkWidget *dialog_button,
g_free (value);
}
}
else if (res == GLADE_RESPONSE_CREATE)
{
GValue *value;
GladeWidget *new_widget;
/* translators: Creating 'a widget' for 'a property' of 'a widget' */
gchar *desc = g_strdup_printf (_("Creating %s for %s of %s"),
create_adaptor->name,
eprop->property->klass->name,
eprop->property->widget->name);
glade_command_push_group (desc);
g_free (desc);
/* Dont bother if the user canceled the widget */
if ((new_widget = glade_command_create (create_adaptor, NULL, NULL, project)) != NULL)
{
value = glade_property_class_make_gvalue_from_string
(eprop->klass, new_widget->name, project);
glade_editor_property_commit (eprop, value);
}
glade_command_pop_group ();
}
else if (res == GLADE_RESPONSE_CLEAR)
{
GValue *value = glade_property_class_make_gvalue_from_string
......
......@@ -323,7 +323,7 @@ update_model (GladeInspector *inspector)
GladeWidget *gwidget = glade_widget_get_from_gobject (object);
g_assert (gwidget);
if (gwidget->parent == NULL && GTK_IS_WINDOW (object))
if (gwidget->parent == NULL && GTK_IS_WIDGET (object))
toplevels = g_list_prepend (toplevels, object);
}
toplevels = g_list_reverse (toplevels);
......@@ -342,7 +342,7 @@ update_model (GladeInspector *inspector)
GladeWidget *gwidget = glade_widget_get_from_gobject (object);
g_assert (gwidget);
if (gwidget->parent == NULL && !GTK_IS_WINDOW (object))
if (gwidget->parent == NULL && !GTK_IS_WIDGET (object))
toplevels = g_list_prepend (toplevels, object);
}
toplevels = g_list_reverse (toplevels);
......@@ -374,7 +374,7 @@ project_add_widget_cb (GladeProject *project,
if (!parent_iter)
{
if (GTK_IS_WINDOW (widget->object))
if (GTK_IS_WIDGET (widget->object))
parent_iter = &inspector->priv->widgets_iter;
else
parent_iter = &inspector->priv->objects_iter;
......
......@@ -1567,7 +1567,7 @@ glade_project_verify_property (GladeProject *project,
{
if (forwidget)
glade_property_set_support_warning
(property, _("This property is not supported in libglade format"));
(property, TRUE, _("This property is not supported in libglade format"));
else
/* translators: reffers to a property '%s' of widget '[%s]'
* introduced in toolkit version '%s %d.%d' */
......@@ -1587,7 +1587,7 @@ glade_project_verify_property (GladeProject *project,
{
if (forwidget)
glade_property_set_support_warning
(property, _("This property is only supported in libglade format"));
(property, TRUE, _("This property is only supported in libglade format"));
else
/* translators: reffers to a property '%s' of widget '[%s]'
* introduced in toolkit version '%s %d.%d' */
......@@ -1620,7 +1620,7 @@ glade_project_verify_property (GladeProject *project,
catalog,
target_major, target_minor);
glade_property_set_support_warning (property, tooltip);
glade_property_set_support_warning (property, FALSE, tooltip);
g_free (tooltip);
}
else
......@@ -1640,7 +1640,7 @@ glade_project_verify_property (GladeProject *project,
property->klass->version_since_minor);
}
else if (forwidget)
glade_property_set_support_warning (property, NULL);
glade_property_set_support_warning (property, FALSE, NULL);
g_free (catalog);
}
......
......@@ -1534,6 +1534,13 @@ glade_property_class_update_from_node (GladeXmlNode *node,
klass->factory_stock_id = buf;
}
if ((buf = glade_xml_get_property_string
(node, GLADE_TAG_CREATE_TYPE)) != NULL)
{
if (klass->create_type)
g_free (klass->create_type);
klass->create_type = buf;
}
/* If this property's value is an enumeration or flag then we try to get the displayable values */
if ((G_IS_PARAM_SPEC_ENUM(klass->pspec) || G_IS_PARAM_SPEC_FLAGS(klass->pspec)) &&
......
......@@ -169,6 +169,11 @@ struct _GladePropertyClass
gboolean parentless_widget; /* True if this property should point to a parentless widget
* in the project
*/
gchar *create_type; /* If this is an object property and you want the option to create
* one from the object selection dialog, then set the name of the
* concrete type here.
*/
};
......
......@@ -221,29 +221,15 @@ glade_property_fix_state (GladeProperty *property)
{
property->state = GLADE_STATE_NORMAL;
if (!property->sensitive)
property->state = GLADE_STATE_NORMAL;
else if (property->support_warning)
{
if (property->enabled)
{
if (glade_property_original_default (property))
property->state = GLADE_STATE_UNSUPPORTED;
else
property->state = GLADE_STATE_UNSUPPORTED_CHANGED;
}
}
else
{
if (property->enabled)
{
if (glade_property_original_default (property))
property->state = GLADE_STATE_NORMAL;
else
property->state = GLADE_STATE_CHANGED;
}
}
if (!glade_property_original_default (property))
property->state = GLADE_STATE_CHANGED;
if (property->support_warning)
property->state |= GLADE_STATE_UNSUPPORTED;
if (property->support_disabled)
property->state |= GLADE_STATE_SUPPORT_DISABLED;
g_object_notify (G_OBJECT (property), "state");
}
......@@ -576,7 +562,7 @@ glade_property_klass_init (GladePropertyKlass *prop_class)
("state", _("Visual State"),
_("Priority information for the property editor to act on"),
GLADE_STATE_NORMAL,
GLADE_N_STATES - 1,
G_MAXINT,
GLADE_STATE_NORMAL,
G_PARAM_READABLE));
......@@ -1418,6 +1404,7 @@ glade_property_get_sensitive (GladeProperty *property)
void
glade_property_set_support_warning (GladeProperty *property,
gboolean disable,
const gchar *reason)
{
g_return_if_fail (GLADE_IS_PROPERTY (property));
......@@ -1426,6 +1413,8 @@ glade_property_set_support_warning (GladeProperty *property,
g_free (property->support_warning);
property->support_warning = g_strdup (reason);
property->support_disabled = disable;
g_signal_emit (G_OBJECT (property),
glade_property_signals[TOOLTIP_CHANGED],
0,
......
......@@ -16,11 +16,10 @@ G_BEGIN_DECLS
typedef struct _GladePropertyKlass GladePropertyKlass;
typedef enum {
GLADE_STATE_NORMAL = 0,
GLADE_STATE_CHANGED,
GLADE_STATE_UNSUPPORTED,
GLADE_STATE_UNSUPPORTED_CHANGED,
GLADE_N_STATES
GLADE_STATE_NORMAL = 0,
GLADE_STATE_CHANGED = (1 << 0),
GLADE_STATE_UNSUPPORTED = (1 << 1),
GLADE_STATE_SUPPORT_DISABLED = (1 << 2)
} GladePropertyState;
/* A GladeProperty is an instance of a GladePropertyClass.
......@@ -57,6 +56,9 @@ struct _GladeProperty
* (used to explain why the property is
* insensitive)
*/
gboolean support_disabled; /* Whether this property is disabled due
* to format conflicts
*/
gboolean enabled; /* Enabled is a flag that is used for GladeProperties
* that have the optional flag set to let us know
......@@ -171,6 +173,7 @@ void glade_property_set_sensitive (GladeProperty
const gchar *reason);
void glade_property_set_support_warning (GladeProperty *property,
gboolean disable,
const gchar *reason);
gboolean glade_property_get_sensitive (GladeProperty *property);
......
......@@ -191,6 +191,7 @@ typedef enum
#define GLADE_TAG_ICON_PREFIX "icon-prefix"
#define GLADE_TAG_ICON_NAME "icon-name"
#define GLADE_TAG_IMPORTANT "important"
#define GLADE_TAG_CREATE_TYPE "create-type"
#define GLADE_ENUM_DATA_TAG "GladeEnumDataTag"
......
......@@ -1086,6 +1086,39 @@ widget_parent_changed (GtkWidget *widget,
glade_widget_set_action_sensitive (gwidget, "add_parent", FALSE);
}
static void
widget_format_changed (GladeProject *project,
GParamSpec *pspec,
GladeWidget *gwidget)
{
if (glade_project_get_format (project) == GLADE_PROJECT_FORMAT_LIBGLADE)
glade_widget_set_action_sensitive (gwidget, "sizegroup_add", FALSE);
else
glade_widget_set_action_sensitive (gwidget, "sizegroup_add", TRUE);
}
static void
widget_project_changed (GladeWidget *gwidget,
GParamSpec *pspec,
gpointer userdata)
{
GladeProject
*project = glade_widget_get_project (gwidget),
*old_project = g_object_get_data (G_OBJECT (gwidget), "notebook-project-ptr");
if (old_project)
g_signal_handlers_disconnect_by_func (G_OBJECT (old_project),
G_CALLBACK (widget_format_changed),
gwidget);
if (project)
g_signal_connect (G_OBJECT (project), "notify::format",
G_CALLBACK (widget_format_changed), gwidget);
g_object_set_data (G_OBJECT (gwidget), "notebook-project-ptr", project);
}
void
glade_gtk_widget_deep_post_create (GladeWidgetAdaptor *adaptor,
GObject *widget,
......@@ -1103,9 +1136,14 @@ glade_gtk_widget_deep_post_create (GladeWidgetAdaptor *adaptor,
if (GTK_IS_WINDOW (widget) || gwidget->internal)
glade_widget_set_action_sensitive (gwidget, "add_parent", FALSE);
/* Watch parents and set actions sensitive/insensitive */
/* Watch parents/projects and set actions sensitive/insensitive */
g_signal_connect (G_OBJECT (widget), "notify::parent",
G_CALLBACK (widget_parent_changed), adaptor);
g_signal_connect (G_OBJECT (gwidget), "notify::project",
G_CALLBACK (widget_project_changed), NULL);
widget_project_changed (gwidget, NULL, NULL);
}
......@@ -3772,6 +3810,7 @@ glade_gtk_notebook_selection_changed (GladeProject *project,
static void
glade_gtk_notebook_project_changed (GladeWidget *gwidget,
GParamSpec *pspec,
gpointer userdata)
{
GladeProject
......@@ -3802,7 +3841,7 @@ glade_gtk_notebook_post_create (GladeWidgetAdaptor *adaptor,
g_signal_connect (G_OBJECT (gwidget), "notify::project",
G_CALLBACK (glade_gtk_notebook_project_changed), NULL);
glade_gtk_notebook_project_changed (gwidget, NULL);
glade_gtk_notebook_project_changed (gwidget, NULL, NULL);
g_signal_connect (G_OBJECT (notebook), "switch-page",
G_CALLBACK (glade_gtk_notebook_switch_page), NULL);
......
......@@ -46,7 +46,6 @@
<action id="sizegroup_add" _name="Add to Size Group"/>
</actions>
<properties>
<property id="tooltip-text" since="2.12"/>
<property id="tooltip-markup" since="2.12"/>
......@@ -526,8 +525,8 @@ embedded in another object</_tooltip>
<set-property-function>glade_gtk_tool_button_set_property</set-property-function>
<properties>
<property id="icon-widget" parentless-widget="True"/>
<property id="label-widget" parentless-widget="True"/>
<property id="icon-widget" parentless-widget="True" libglade-unsupported="True"/>
<property id="label-widget" parentless-widget="True" libglade-unsupported="True"/>
<property id="glade-type" _name="Image Type" save="False">
<spec>glade_gtk_image_type_spec</spec>
<displayable-values>
......@@ -680,7 +679,7 @@ embedded in another object</_tooltip>
<value id="GTK_WRAP_WORD_CHAR" _name="Word Character"/>
</displayable-values>
</property>
x <property id="buffer"/>
<property id="buffer" libglade-unsupported="True"/>
</properties>
</glade-widget-class>
......@@ -692,7 +691,7 @@ x <property id="buffer"/>
<set-property-function>glade_gtk_button_set_property</set-property-function>
<properties>
<property id="image" parentless-widget="True"/>
<property id="image" parentless-widget="True" create-type="GtkImage" libglade-unsupported="True"/>
<property id="use-stock" visible="False"/>
<property id="label" default="button" translatable="True">
......@@ -813,7 +812,7 @@ x <property id="buffer"/>
<properties>
<property id="title" translatable="True"/>
<property id="size" disabled="True"/>
<property id="dialog" parentless-widget="True"/>
<property id="dialog" parentless-widget="True" create-type="GtkFileChooserDialog" libglade-unsupported="True"/>
<property id="focus-on-click" since="2.10"/>
<property id="action">
<displayable-values>
......@@ -823,9 +822,9 @@ x <property id="buffer"/>
<value id="GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER" _name="Create Folder"/>
</displayable-values>
</property>
<property id="extra-widget" parentless-widget="True"/>
<property id="preview-widget" parentless-widget="True"/>
<property id="filter"/>
<property id="extra-widget" parentless-widget="True" libglade-unsupported="True"/>
<property id="preview-widget" parentless-widget="True" libglade-unsupported="True"/>
<property id="filter" libglade-unsupported="True"/>
</properties>
</glade-widget-class>
......@@ -859,9 +858,9 @@ x <property id="buffer"/>
<value id="GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER" _name="Create Folder"/>
</displayable-values>
</property>
<property id="extra-widget" parentless-widget="True"/>
<property id="preview-widget" parentless-widget="True"/>
<property id="filter"/>
<property id="extra-widget" parentless-widget="True" libglade-unsupported="True"/>
<property id="preview-widget" parentless-widget="True" libglade-unsupported="True"/>
<property id="filter" libglade-unsupported="True"/>
</properties>
</glade-widget-class>
......@@ -936,8 +935,8 @@ x <property id="buffer"/>
<value id="GTK_TREE_VIEW_GRID_LINES_BOTH" _name="Horizontal and Vertical"/>
</displayable-values>
</property>
<property id="hadjustment"/>
<property id="vadjustment"/>
<property id="hadjustment" libglade-unsupported="True"/>
<property id="vadjustment" libglade-unsupported="True"/>
</properties>
</glade-widget-class>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment