Commit 5a3db79a authored by Tristan Van Berkom's avatar Tristan Van Berkom

Now load insensitive when widgets are unsupported, and use a warning icon


	* gladeui/glade-palette-item.c, gladeui/glade-palette.c,
	gladeui/glade-palette-item.h, gladeui/glade-palette.h:
	Now load insensitive when widgets are unsupported, and use
	a warning icon when they are deprecated, use tooltips from
	glade_project_verify_adaptor ().

	* gladeui/glade-app.[ch]: Added glade_app_check_get_project ()

	* gladeui/glade-project.c, gladeui/glade-project.h: fix some mistakes


svn path=/trunk/; revision=1791
parent 3eb37dae
2008-04-10 Tristan Van Berkom <tvb@gnome.org>
* gladeui/glade-palette-item.c, gladeui/glade-palette.c,
gladeui/glade-palette-item.h, gladeui/glade-palette.h:
Now load insensitive when widgets are unsupported, and use
a warning icon when they are deprecated, use tooltips from
glade_project_verify_adaptor ().
* gladeui/glade-app.[ch]: Added glade_app_check_get_project ()
* gladeui/glade-project.c, gladeui/glade-project.h: fix some mistakes
* src/glade-window.c: Added padding on top of undocked tools, removed
custom label handling of widget name.
......
......@@ -792,6 +792,14 @@ glade_app_get_project (void)
return app->priv->active_project;
}
GladeProject *
glade_app_check_get_project (void)
{
if (singleton_app)
return glade_app_get_project ();
return NULL;
}
GList *
glade_app_get_projects (void)
{
......@@ -1061,6 +1069,9 @@ glade_app_set_project (GladeProject *project)
/* (XXX really ?) trigger the selection changed signal to update the editor */
glade_project_selection_changed (project);
/* refresh palette for active project */
glade_palette_refresh (glade_app_get_palette ());
/* Update UI */
glade_app_update_ui ();
......
......@@ -111,6 +111,8 @@ GladeClipboard* glade_app_get_clipboard (void);
GtkWidget* glade_app_get_clipboard_view (void);
GladeProject* glade_app_get_project (void);
GladeProject* glade_app_check_get_project (void);
void glade_app_set_project (GladeProject *project);
......
......@@ -33,6 +33,7 @@
#include "glade.h"
#include "glade-palette-item.h"
#define GLADE_PALETTE_ITEM_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object),\
GLADE_TYPE_PALETTE_ITEM, \
GladePaletteItemPrivate))
......@@ -131,6 +132,87 @@ glade_palette_item_set_appearance (GladePaletteItem *item, GladeItemAppearance a
}
}
#if 0
/* XXX Code doesnt work well, think they are not transperent ? */
static GdkPixbuf *
render_deprecated_pixbuf (GladeWidgetAdaptor *adaptor,
gint size)
{
GdkPixbuf *widget_icon, *deprecated_icon;
if ((widget_icon =
gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
adaptor->icon_name, size,
GTK_ICON_LOOKUP_USE_BUILTIN, NULL)) != NULL)
{
if ((deprecated_icon =
gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
"media-record", size,
GTK_ICON_LOOKUP_USE_BUILTIN, NULL)) != NULL)
{
g_print ("rendering deprecated\n");
gdk_pixbuf_composite (deprecated_icon, widget_icon,
0, 0,
gdk_pixbuf_get_width (widget_icon),
gdk_pixbuf_get_height (widget_icon),
0.0, 0.0, 1.0, 1.0, GDK_INTERP_HYPER, 0);
g_object_unref (G_OBJECT (deprecated_icon));
}
}
return widget_icon;
}
#endif
void
glade_palette_item_refresh (GladePaletteItem *item)
{
GladePaletteItemPrivate *priv;
GladeProject *project;
GladeSupportMask support;
gint size;
gchar *warning, *text;
priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item);
size = priv->use_small_icon ? GTK_ICON_SIZE_MENU : GTK_ICON_SIZE_BUTTON;
if ((project = glade_app_check_get_project ()) &&
(warning =
glade_project_verify_widget_adaptor (project, priv->adaptor, &support)) != NULL)
{
/* set sensitivity */
gtk_widget_set_sensitive (GTK_WIDGET (item),
!(support & (GLADE_SUPPORT_BUILDER_UNSUPPORTED |
GLADE_SUPPORT_MISMATCH)));
if (support & GLADE_SUPPORT_DEPRECATED)
/* XXX Todo, draw a cross overlaying the widget icon */
gtk_image_set_from_stock (GTK_IMAGE (priv->icon),
GTK_STOCK_DIALOG_WARNING,
size);
else
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
priv->adaptor->icon_name,
size);
/* prepend widget title */
text = g_strdup_printf ("%s: %s", priv->adaptor->title, warning);
gtk_widget_set_tooltip_text (priv->icon, text);
g_free (text);
g_free (warning);
}
else
{
gtk_widget_set_tooltip_text (GTK_WIDGET (item), priv->adaptor->title);
gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
priv->adaptor->icon_name,
size);
}
}
void
glade_palette_item_set_use_small_icon (GladePaletteItem *item, gboolean use_small_icon)
{
......@@ -143,11 +225,8 @@ glade_palette_item_set_use_small_icon (GladePaletteItem *item, gboolean use_smal
{
priv->use_small_icon = use_small_icon;
if (use_small_icon != FALSE)
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), priv->adaptor->icon_name, GTK_ICON_SIZE_MENU);
else
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), priv->adaptor->icon_name, GTK_ICON_SIZE_BUTTON);
glade_palette_item_refresh (item);
g_object_notify (G_OBJECT (item), "use-small-icon");
}
}
......@@ -163,7 +242,7 @@ glade_palette_set_adaptor (GladePaletteItem *item, GladeWidgetAdaptor *adaptor)
gtk_label_set_text (GTK_LABEL (priv->label), adaptor->title);
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), adaptor->icon_name, GTK_ICON_SIZE_BUTTON);
glade_palette_item_refresh (item);
}
static void
......
......@@ -78,6 +78,7 @@ gboolean glade_palette_item_get_use_small_icon (GladePaletteItem *i
void glade_palette_item_set_use_small_icon (GladePaletteItem *item,
gboolean use_small_icon);
void glade_palette_item_refresh (GladePaletteItem *item);
G_END_DECLS
......
......@@ -455,8 +455,6 @@ glade_palette_new_item (GladePalette *palette, GladeWidgetAdaptor *adaptor)
glade_palette_item_set_appearance (GLADE_PALETTE_ITEM (item), priv->item_appearance);
gtk_widget_set_tooltip_text (item, adaptor->title);
g_signal_connect (G_OBJECT (item), "toggled",
G_CALLBACK (glade_palette_on_button_toggled), palette);
......@@ -531,12 +529,9 @@ glade_palette_update_appearance (GladePalette *palette)
GtkWidget *viewport;
GSList *sections;
GList *items, *i;
gboolean show_tooltips;
priv = GLADE_PALETTE_GET_PRIVATE (palette);
show_tooltips = priv->item_appearance == GLADE_ITEM_ICON_ONLY;
for (sections = priv->sections; sections; sections = sections->next)
{
items = gtk_container_get_children (GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (sections->data))));
......@@ -545,8 +540,6 @@ glade_palette_update_appearance (GladePalette *palette)
{
glade_palette_item_set_appearance (GLADE_PALETTE_ITEM (i->data), priv->item_appearance);
glade_palette_item_set_use_small_icon (GLADE_PALETTE_ITEM (i->data), priv->use_small_item_icons);
g_object_set (i->data, "has-tooltip", show_tooltips, NULL);
}
g_list_free (items);
}
......@@ -765,3 +758,32 @@ glade_palette_get_show_selector_button (GladePalette *palette)
return GTK_WIDGET_VISIBLE (palette->priv->selector_hbox);
}
/**
* glade_palette_refresh:
* @palette: a #GladePalette
*
* Refreshes project dependant states of palette buttons
*/
void
glade_palette_refresh (GladePalette *palette)
{
GladePalettePrivate *priv;
GSList *sections;
GList *items, *i;
g_return_if_fail (GLADE_IS_PALETTE (palette));
priv = GLADE_PALETTE_GET_PRIVATE (palette);
for (sections = priv->sections; sections; sections = sections->next)
{
items = gtk_container_get_children
(GTK_CONTAINER (gtk_bin_get_child (GTK_BIN (sections->data))));
for (i = items; i; i = i->next)
glade_palette_item_refresh (GLADE_PALETTE_ITEM (i->data));
g_list_free (items);
}
}
......@@ -92,6 +92,8 @@ void glade_palette_set_show_selector_button (GladePalette *palette,
gboolean glade_palette_get_show_selector_button (GladePalette *palette);
void glade_palette_refresh (GladePalette *palette);
G_END_DECLS
#endif /* __GLADE_PALETTE_H__ */
......
......@@ -499,8 +499,10 @@ glade_project_verify_adaptor (GladeProject *project,
const gchar *path_name,
GString *string,
gboolean saving,
gboolean forwidget)
gboolean forwidget,
GladeSupportMask *mask)
{
GladeSupportMask support_mask = GLADE_SUPPORT_OK;
GladeWidgetAdaptor *adaptor_iter;
gint target_major, target_minor;
gchar *catalog = NULL;
......@@ -536,6 +538,8 @@ glade_project_verify_adaptor (GladeProject *project,
path_name, adaptor_iter->title, catalog,
GWA_VERSION_SINCE_MAJOR (adaptor_iter),
GWA_VERSION_SINCE_MINOR (adaptor_iter));
support_mask |= GLADE_SUPPORT_MISMATCH;
}
if (project->priv->format == GLADE_PROJECT_FORMAT_GTKBUILDER &&
......@@ -556,6 +560,8 @@ glade_project_verify_adaptor (GladeProject *project,
"is not supported by GtkBuilder\n"),
path_name, adaptor_iter->title, catalog,
target_major, target_minor);
support_mask |= GLADE_SUPPORT_BUILDER_UNSUPPORTED;
}
if (!saving && GWA_DEPRECATED (adaptor_iter))
......@@ -574,29 +580,48 @@ glade_project_verify_adaptor (GladeProject *project,
"is deprecated\n"),
path_name, adaptor_iter->title, catalog,
target_major, target_minor);
support_mask |= GLADE_SUPPORT_DEPRECATED;
}
g_free (catalog);
}
if (mask)
*mask = support_mask;
}
static void
glade_project_verify_widget_for_ui (GladeWidget *widget)
/**
* glade_project_verify_widget_adaptor:
* @project: A #GladeProject
* @adaptor: the #GladeWidgetAdaptor to verify
* @mask: a return location for a #GladeSupportMask
*
* Checks the supported state of this widget adaptor
* and generates a string to show in the UI describing why.
*
* Returns: A newly allocated string
*/
gchar *
glade_project_verify_widget_adaptor (GladeProject *project,
GladeWidgetAdaptor *adaptor,
GladeSupportMask *mask)
{
GString *string = g_string_new (NULL);
gchar *ret = NULL;
glade_project_verify_adaptor (widget->project,
widget->adaptor,
NULL,
string,
FALSE,
TRUE);
glade_project_verify_adaptor (project, adaptor, NULL,
string, FALSE, TRUE, mask);
/* there was a '\0' byte... */
if (string->len > 0)
glade_widget_set_support_warning (widget, string->str);
{
ret = string->str;
g_string_free (string, FALSE);
}
else
glade_widget_set_support_warning (widget, NULL);
g_string_free (string, TRUE);
g_string_free (string, TRUE);
return ret;
}
static void
......@@ -604,16 +629,25 @@ glade_project_verify_project_for_ui (GladeProject *project)
{
GList *list;
GladeWidget *widget;
gchar *warning;
/* Sync displayable info here */
for (list = project->priv->objects; list; list = list->next)
{
widget = glade_widget_get_from_gobject (list->data);
glade_project_verify_widget_for_ui (widget);
glade_project_verify_properties (widget);
warning = glade_project_verify_widget_adaptor (project, widget->adaptor, NULL);
glade_widget_set_support_warning (widget, warning);
if (warning)
g_free (warning);
glade_project_verify_properties (widget);
}
/* refresh palette if this is the active project */
if (project == glade_app_get_project ())
glade_palette_refresh (glade_app_get_palette ());
}
static void
......@@ -1397,7 +1431,7 @@ glade_project_verify (GladeProject *project,
path_name = glade_widget_generate_path_name (widget);
glade_project_verify_adaptor (project, widget->adaptor,
path_name, string, saving, FALSE);
path_name, string, saving, FALSE, NULL);
glade_project_verify_properties_internal (widget, path_name, string, FALSE);
glade_project_verify_signals (widget, path_name, string);
......
......@@ -25,6 +25,14 @@ typedef enum
GLADE_PROJECT_FORMAT_GTKBUILDER
} GladeProjectFormat;
typedef enum
{
GLADE_SUPPORT_OK = 0x00,
GLADE_SUPPORT_DEPRECATED = 0x01,
GLADE_SUPPORT_MISMATCH = 0x02,
GLADE_SUPPORT_BUILDER_UNSUPPORTED = 0x04
} GladeSupportMask;
struct _GladeProject
{
GObject parent_instance;
......@@ -174,6 +182,9 @@ void glade_project_preferences (GladeProject *project);
void glade_project_verify_properties (GladeWidget *widget);
gchar *glade_project_verify_widget_adaptor (GladeProject *project,
GladeWidgetAdaptor *adaptor,
GladeSupportMask *mask);
G_END_DECLS
......
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