Commit e0f3bbf8 authored by Chema Celorio's avatar Chema Celorio Committed by Jose Maria Celorio
Browse files

add <popt.h>. implement : ./glade2 --dump {widget} to dump to the console

2001-08-01  Chema Celorio  <chema@celorio.com>

	* src/main.c: add <popt.h>.
	implement : ./glade2 --dump {widget} to dump to the console the
	properties of a widget.

	* src/glade.h: add _TAG_COMMON

	* src/glade-xml-utils.c (glade_xml_get_boolean): take a default value
	that should be used if the node is not found
	(glade_xml_property_get_boolean): ditto for properties.

	* src/glade-widget-class.c (glade_widget_class_dump_param_specs):
	improve. dump the type and the object the property belongs to.

	* src/glade-property-class.c (glade_widget_property_class_free):
	implement.
	(glade_property_class_load_from_param_spec): don't create the
	PropertyClass in here
	(glade_property_class_new_from_node): the query should be read
	before the ParamSpec, if we are loading with ParamSpec we want
	to be able to specify a query.

	* src/glade-project-window.c (glade_project_window_create): do not
	_show_all when creating a project_window
	(glade_project_window_show_all): implement

	* src/glade-placeholder.c (glade_placeholder_add): the properites
	for the GtkTable are n-rows and n-columns not rows-columns

	* src/glade-palette.c (glade_palette_create): implement.

	* src/glade-editor.h: add ->common for the common tab of the editor

	* src/glade-editor.c (glade_editor_table_append_items): add a common
	parameter for the common tab of the editor.
	(glade_editor_get_table_from_class): add a common parameter, when
	getting a table verify that common = table->common
	(glade_editor_load_common_page): implement.
	(glade_editor_load_class): load the common page too
	(glade_editor_create): do not show the editor when it is created

	* src/Makefile.am: remove empty variables.
	Add -lpopt. We are NOT checking in configure.in for popt yet.
parent 54bb92c3
2001-08-01 Chema Celorio <chema@celorio.com>
* src/main.c: add <popt.h>.
implement : ./glade2 --dump {widget} to dump to the console the
properties of a widget.
* src/glade.h: add _TAG_COMMON
* src/glade-xml-utils.c (glade_xml_get_boolean): take a default value
that should be used if the node is not found
(glade_xml_property_get_boolean): ditto for properties.
* src/glade-widget-class.c (glade_widget_class_dump_param_specs):
improve. dump the type and the object the property belongs to.
* src/glade-property-class.c (glade_widget_property_class_free):
implement.
(glade_property_class_load_from_param_spec): don't create the
PropertyClass in here
(glade_property_class_new_from_node): the query should be read
before the ParamSpec, if we are loading with ParamSpec we want
to be able to specify a query.
* src/glade-project-window.c (glade_project_window_create): do not
_show_all when creating a project_window
(glade_project_window_show_all): implement
* src/glade-placeholder.c (glade_placeholder_add): the properites
for the GtkTable are n-rows and n-columns not rows-columns
* src/glade-palette.c (glade_palette_create): implement.
* src/glade-editor.h: add ->common for the common tab of the editor
* src/glade-editor.c (glade_editor_table_append_items): add a common
parameter for the common tab of the editor.
(glade_editor_get_table_from_class): add a common parameter, when
getting a table verify that common = table->common
(glade_editor_load_common_page): implement.
(glade_editor_load_class): load the common page too
(glade_editor_create): do not show the editor when it is created
* src/Makefile.am: remove empty variables.
Add -lpopt. We are NOT checking in configure.in for popt yet.
2001-07-23 Chema Celorio <chema@celorio.com>
* src/glade-xml-utils.c (glade_xml_doc_save): when saving a .xml file indent
......
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = glade2
bin_PROGRAMS = glade2
INCLUDES = \
$(GLADE_CFLAGS) \
-I$(top_srcdir)/intl \
-I$(top_builddir)/intl
DIST_SUBDIRS =
CFLAGS = -g -O2 -Wall
SUBDIRS =
glade2_LDADD = \
$(GLADE_LIBS) \
$(INTLLIBS)
$(INTLLIBS) \
-lpopt
## FIXME popt should be added in configure.in and checked for
glade2_DEPENDENCIES = \
$(INTLLIBS)
......
......@@ -55,8 +55,10 @@ static void glade_editor_select_item_real (GladeEditor *editor, GladeWidget *wid
/* We use this function recursively so we need to declare it */
static gboolean glade_editor_table_append_items (GladeEditorTable *table, GladeWidgetClass *class,
GList **list);
static gboolean glade_editor_table_append_items (GladeEditorTable *table,
GladeWidgetClass *class,
GList **list,
gboolean common);
guint
glade_editor_get_type (void)
......@@ -592,7 +594,7 @@ glade_editor_create_input_object (GladeEditorProperty *property, GladeEditorTabl
g_return_val_if_fail (GLADE_IS_EDITOR_TABLE (table), NULL);
g_return_val_if_fail (GLADE_IS_EDITOR_PROPERTY (property), NULL);
glade_editor_table_append_items (table, property->class->child, &property->children);
glade_editor_table_append_items (table, property->class->child, &property->children, FALSE);
return NULL;
}
......@@ -673,7 +675,7 @@ glade_editor_table_append_item (GladeEditorTable *table,
}
static void
glade_editor_table_append_common (GladeEditorTable *table)
glade_editor_table_append_standard_fields (GladeEditorTable *table)
{
GtkWidget *gtk_table;
GtkWidget *label;
......@@ -710,7 +712,8 @@ glade_editor_table_append_common (GladeEditorTable *table)
static gboolean
glade_editor_table_append_items (GladeEditorTable *table,
GladeWidgetClass *class,
GList **list_)
GList **list_,
gboolean common)
{
GladeEditorProperty *property;
GladePropertyClass *property_class;
......@@ -723,6 +726,8 @@ glade_editor_table_append_items (GladeEditorTable *table,
for (; list != NULL; list = list->next) {
property_class = (GladePropertyClass *) list->data;
if (common != property_class->common)
continue;
property = glade_editor_table_append_item (table, property_class);
if (property != NULL)
new_list = g_list_prepend (new_list,
......@@ -735,7 +740,7 @@ glade_editor_table_append_items (GladeEditorTable *table,
}
static GladeEditorTable *
glade_editor_table_create (GladeEditor *editor, GladeWidgetClass *class)
glade_editor_table_create (GladeEditor *editor, GladeWidgetClass *class, gboolean common)
{
GladeEditorTable *table;
......@@ -744,8 +749,10 @@ glade_editor_table_create (GladeEditor *editor, GladeWidgetClass *class)
table = glade_editor_table_new (class);
table->editor = editor;
glade_editor_table_append_common (table);
if (!glade_editor_table_append_items (table, class, &table->properties))
table->common = common;
if (!common)
glade_editor_table_append_standard_fields (table);
if (!glade_editor_table_append_items (table, class, &table->properties, common))
return NULL;
gtk_widget_show_all (table->table_widget);
editor->widget_tables = g_list_prepend (editor->widget_tables,
......@@ -755,7 +762,7 @@ glade_editor_table_create (GladeEditor *editor, GladeWidgetClass *class)
}
static GladeEditorTable *
glade_editor_get_table_from_class (GladeEditor *editor, GladeWidgetClass *class)
glade_editor_get_table_from_class (GladeEditor *editor, GladeWidgetClass *class, gboolean common)
{
GladeEditorTable *table;
GList *list;
......@@ -763,6 +770,8 @@ glade_editor_get_table_from_class (GladeEditor *editor, GladeWidgetClass *class)
list = editor->widget_tables;
for (; list != NULL; list = list->next) {
table = list->data;
if (common != table->common)
continue;
if (table->glade_widget_class == class)
return table;
}
......@@ -777,9 +786,9 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class)
GtkContainer *container;
GList *list;
table = glade_editor_get_table_from_class (editor, class);
table = glade_editor_get_table_from_class (editor, class, FALSE);
if (table == NULL)
table = glade_editor_table_create (editor, class);
table = glade_editor_table_create (editor, class, FALSE);
g_return_if_fail (table != NULL);
......@@ -799,13 +808,41 @@ glade_editor_load_widget_page (GladeEditor *editor, GladeWidgetClass *class)
}
static void
glade_editor_load_signal_page (GladeEditor *editor, GladeWidgetClass *class)
glade_editor_load_common_page (GladeEditor *editor, GladeWidgetClass *class)
{
GladeEditorTable *table;
GtkContainer *container;
GList *list;
table = glade_editor_get_table_from_class (editor, class, TRUE);
if (table == NULL)
table = glade_editor_table_create (editor, class, TRUE);
g_return_if_fail (table != NULL);
/* Remove the old table that was in this container */
container = GTK_CONTAINER (editor->vbox_common);
list = gtk_container_children (container);
for (; list; list = list->next) {
GtkWidget *widget = list->data;
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_widget_ref (widget);
gtk_container_remove (container, widget);
}
/* Attach the new table */
gtk_box_pack_start (GTK_BOX (editor->vbox_common), table->table_widget,
TRUE, TRUE, 0);
}
static void
glade_editor_load_signal_page (GladeEditor *editor, GladeWidgetClass *class)
{
if (editor->signal_editor == NULL) {
editor->signal_editor = glade_signal_editor_new ();
gtk_box_pack_start (GTK_BOX (editor->vbox_signals), glade_signal_editor_get_widget (editor->signal_editor),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (editor->vbox_signals),
glade_signal_editor_get_widget (editor->signal_editor),
TRUE, TRUE, 0);
}
}
......@@ -813,6 +850,7 @@ static void
glade_editor_load_class (GladeEditor *editor, GladeWidgetClass *class)
{
glade_editor_load_widget_page (editor, class);
glade_editor_load_common_page (editor, class);
glade_editor_load_signal_page (editor, class);
editor->loaded_class = class;
......@@ -1110,12 +1148,19 @@ glade_editor_load_item (GladeEditor *editor, GladeWidget *item)
class = item->class;
if (editor->loaded_class != class)
glade_editor_load_class (editor, class);
editor->loaded_widget = item;
/* Load each GladeEditorProperty */
table = glade_editor_get_table_from_class (editor, class);
table = glade_editor_get_table_from_class (editor, class, FALSE);
list = table->properties;
for (; list != NULL; list = list->next) {
property = list->data;
glade_editor_property_load (property, item);
}
/* Load each GladeEditorProperty for the common tab*/
table = glade_editor_get_table_from_class (editor, class, TRUE);
list = table->properties;
for (; list != NULL; list = list->next) {
property = list->data;
......@@ -1149,7 +1194,7 @@ glade_editor_select_item_real (GladeEditor *editor, GladeWidget *widget)
glade_editor_load_item (editor, widget);
editor->loading = TRUE;
table = glade_editor_get_table_from_class (editor, widget->class);
table = glade_editor_get_table_from_class (editor, widget->class, FALSE);
g_return_if_fail (table != NULL);
gtk_entry_set_text (GTK_ENTRY (table->name_entry), widget->name);
editor->loading = FALSE;
......@@ -1171,29 +1216,17 @@ glade_editor_show (GladeProjectWindow *gpw)
{
g_return_if_fail (gpw != NULL);
if (gpw->editor == NULL) {
gpw->editor = GLADE_EDITOR (glade_editor_new ());
gpw->editor->project_window = gpw;
}
if (gpw->editor == NULL)
glade_editor_create (gpw);
gtk_widget_show_all (GTK_WIDGET (gpw->editor));
}
void
glade_editor_create (GladeProjectWindow *gpw)
{
glade_editor_show (gpw);
if (gpw->editor == NULL) {
gpw->editor = GLADE_EDITOR (glade_editor_new ());
gpw->editor->project_window = gpw;
}
}
......@@ -134,6 +134,9 @@ struct _GladeEditorTable
* corrsponding GladeEditorProperty struct.
*/
gboolean common; /* Is this table to be used in the common tab ?
* or the general tab ?
*/
gint rows;
};
......
......@@ -311,10 +311,19 @@ glade_palette_new ()
void
glade_palette_show (GladeProjectWindow *gpw)
{
GtkWidget *widget;
g_return_if_fail (gpw != NULL);
if (gpw->palette == NULL)
glade_palette_create (gpw);
gtk_widget_show_all (GTK_WIDGET (gpw->palette));
}
void
glade_palette_create (GladeProjectWindow *gpw)
{
GtkWidget *widget;
if (gpw->palette == NULL) {
GladePalette *palette;
......@@ -331,11 +340,4 @@ glade_palette_show (GladeProjectWindow *gpw)
gtk_box_pack_start (GTK_BOX (gpw->palette->vbox), widget, FALSE, TRUE, 3);
}
gtk_widget_show_all (GTK_WIDGET (gpw->palette));
}
void
glade_palette_create (GladeProjectWindow *gpw)
{
glade_palette_show (gpw);
}
......@@ -346,8 +346,8 @@ glade_placeholder_add (GladeWidgetClass *class,
gint row, col;
gint rows = 6, cols = 6;
glade_property_query_result_get_int (result, "rows", &rows);
glade_property_query_result_get_int (result, "columns", &cols);
glade_property_query_result_get_int (result, "n-rows", &rows);
glade_property_query_result_get_int (result, "n-columns", &cols);
for (row = 0; row < rows; row++) {
for (col = 0; col < cols; col++) {
......
......@@ -243,8 +243,6 @@ glade_project_window_create (GladeProjectWindow *gpw, GladeProjectView *view)
gtk_signal_connect (GTK_OBJECT (app), "delete_event",
GTK_SIGNAL_FUNC (gpw_delete_event), NULL);
gtk_widget_show_all (app);
return app;
}
......@@ -586,3 +584,13 @@ glade_project_window_get_project (void)
return gpw->project;
}
void
glade_project_window_show_all (GladeProjectWindow *gpw)
{
gtk_widget_show_all (gpw->window);
glade_palette_show (gpw);
glade_editor_show (gpw);
}
......@@ -46,6 +46,7 @@ struct _GladeProjectWindow
GladeProjectWindow * glade_project_window_new (GladeCatalog *catalog);
GladeProjectWindow * glade_project_window_get ();
GladeProject * glade_project_window_get_project ();
void glade_project_window_show_all (GladeProjectWindow *gpw);
void glade_project_window_set_add_class (GladeProjectWindow *gpw, GladeWidgetClass *class);
void glade_project_window_set_project (GladeProjectWindow *project_window,
......
......@@ -130,12 +130,25 @@ glade_property_class_new (void)
property_class->parameters = NULL;
property_class->choices = NULL;
property_class->optional = FALSE;
property_class->common = FALSE;
property_class->query = NULL;
property_class->set_function = NULL;
return property_class;
}
#define MY_FREE(foo) if(foo) g_free(foo); foo = NULL
static void
glade_widget_property_class_free (GladePropertyClass *class)
{
g_return_if_fail (GLADE_IS_PROPERTY_CLASS (class));
MY_FREE (class->name);
MY_FREE (class->tooltip);
MY_FREE (class);
}
#undef MY_FREE
static GladePropertyType
glade_property_class_get_type_from_spec (GParamSpec *spec)
......@@ -418,12 +431,23 @@ glade_property_class_get_parameters_from_spec (GParamSpec *spec,
}
static GladePropertyClass *
glade_property_class_new_from_param_spec (const gchar *name,
GladeWidgetClass *widget_class,
GladeXmlNode *node)
/**
* glade_property_class_load_from_param_spec:
* @name:
* @class:
* @widget_class:
* @node:
*
* Loads the members of @class that we get from gtk's ParamSpec
*
* Return Value:
**/
static gboolean
glade_property_class_load_from_param_spec (const gchar *name,
GladePropertyClass *class,
GladeWidgetClass *widget_class,
GladeXmlNode *node)
{
GladePropertyClass *class;
GParamSpec *spec;
spec = glade_widget_class_find_spec (widget_class, name);
......@@ -431,10 +455,9 @@ glade_property_class_new_from_param_spec (const gchar *name,
if (spec == NULL) {
g_warning ("Could not create a property class from a param spec for *%s* with name *%s*\n",
widget_class->name, name);
return NULL;
return FALSE;
}
class = glade_property_class_new ();
class->id = g_strdup (spec->name);
class->name = g_strdup (spec->nick);
class->tooltip = g_strdup (spec->blurb);
......@@ -443,7 +466,7 @@ glade_property_class_new_from_param_spec (const gchar *name,
if (class->type == GLADE_PROPERTY_TYPE_ERROR) {
g_warning ("Could not create the \"%s\" property for the \"%s\" class\n",
name, widget_class->name);
return NULL;
return FALSE;
}
if (class->type == GLADE_PROPERTY_TYPE_CHOICE)
......@@ -451,7 +474,7 @@ glade_property_class_new_from_param_spec (const gchar *name,
class->parameters = glade_property_class_get_parameters_from_spec (spec, class, node);
return class;
return TRUE;
}
static gboolean
......@@ -530,26 +553,41 @@ glade_property_class_new_from_node (GladeXmlNode *node, GladeWidgetClass *widget
if (id == NULL)
return NULL;
property_class = glade_property_class_new ();
/* We first load the members that can be present in a property defined by a ParamSpec */
/* Get the Query */
child = glade_xml_search_child (node, GLADE_TAG_QUERY);
if (child != NULL)
property_class->query = glade_query_new_from_node (child);
/* Will this property go in the common tab ? */
property_class->common = glade_xml_property_get_boolean (node, GLADE_TAG_COMMON, FALSE);
/* Should we load this property from the ParamSpec ?
* We can have a property like ... ParamSpec="TRUE">
* Or a child like <ParamSpec/>, but this will be deprecated
*/
if (glade_xml_property_get_boolean (node, GLADE_TAG_PARAM_SPEC)) {
property_class = glade_property_class_new_from_param_spec (id, widget_class, node);
if (glade_xml_property_get_boolean (node, GLADE_TAG_PARAM_SPEC, TRUE)) {
gboolean retval;
retval = glade_property_class_load_from_param_spec (id, property_class, widget_class, node);
g_free (id);
if (property_class == NULL)
if (retval == FALSE) {
glade_widget_class_dump_param_specs (widget_class);
glade_widget_property_class_free (property_class);
property_class = NULL;
}
return property_class;
}
name = glade_xml_get_property_string_required (node, GLADE_TAG_NAME, widget_class->name);
if (name == NULL)
return NULL;
/* Ok, this property should not be loaded with ParamSpec */
property_class = glade_property_class_new ();
property_class->id = id;
property_class->name = name;
property_class->tooltip = glade_xml_get_value_string (node, GLADE_TAG_TOOLTIP);
......@@ -569,11 +607,6 @@ glade_property_class_new_from_node (GladeXmlNode *node, GladeWidgetClass *widget
property_class->parameters = glade_parameter_list_new_from_node (NULL, child);
glade_parameter_get_boolean (property_class->parameters, "Optional", &property_class->optional);
/* Get the Query */
child = glade_xml_search_child (node, GLADE_TAG_QUERY);
if (child != NULL)
property_class->query = glade_query_new_from_node (child);
/* Get the choices */
if (property_class->type == GLADE_PROPERTY_TYPE_CHOICE) {
child = glade_xml_search_child_required (node, GLADE_TAG_CHOICES);
......
......@@ -153,6 +153,8 @@ struct _GladePropertyClass {
* from the real widget
*/
gboolean common; /* Common properties go in the common tab */
void (*set_function) (GObject *object,
const gchar *value);
/* If this property can't be set with g_object_set then
......
......@@ -85,14 +85,15 @@ glade_widget_class_compose_get_type_func (GladeWidgetClass *class)
static GladeWidgetClass *
glade_widget_class_new (void)
{
GladeWidgetClass *widget;
GladeWidgetClass *class;
widget = g_new0 (GladeWidgetClass, 1);
widget->flags = 0;
widget->placeholder_replace = NULL;
widget->type = 0;
class = g_new0 (GladeWidgetClass, 1);
class->flags = 0;
class->placeholder_replace = NULL;
class->type = 0;
class->properties = NULL;
return widget;
return class;
}
static void
......@@ -207,16 +208,18 @@ glade_widget_class_new_from_node (GladeXmlNode *node)
if (!glade_xml_node_verify (node, GLADE_TAG_GLADE_WIDGET_CLASS))
return NULL;
child = glade_xml_search_child_required (node, GLADE_TAG_PROPERTIES);
if (child == NULL)
return FALSE;
class = glade_widget_class_new ();
class->name = glade_xml_get_value_string_required (node, GLADE_TAG_NAME, NULL);
class->generic_name = glade_xml_get_value_string_required (node, GLADE_TAG_GENERIC_NAME, NULL);
init_function_name = glade_xml_get_value_string (node, GLADE_TAG_GET_TYPE_FUNCTION);
if (!class->name ||
!class->generic_name) {
g_warning ("Invalid XML file. Widget Class %s\n", class->name);
return NULL;
}
init_function_name = glade_xml_get_value_string (node, GLADE_TAG_GET_TYPE_FUNCTION);
if (!init_function_name) {
init_function_name = glade_widget_class_compose_get_type_func (class);
if (!init_function_name)
......@@ -227,21 +230,22 @@ glade_widget_class_new_from_node (GladeXmlNode *node)
return NULL;
g_free (init_function_name);
class->properties = glade_property_class_list_new_from_node (child, class);
class->signals = glade_widget_class_list_signals (class);
if (!class->name ||
!class->generic_name) {
g_warning ("Invalid XML file. Widget Class %s\n", class->name);
return NULL;
}
/* <Properties> */
child = glade_xml_search_child_required (node, GLADE_TAG_PROPERTIES);
if (child == NULL)
return FALSE;
class->properties = glade_property_class_list_new_from_node (child, class);
class->signals = glade_widget_class_list_signals (class);
/* Get the flags */
if (glade_xml_get_boolean (node, GLADE_TAG_TOPLEVEL))
if (glade_xml_get_boolean (node, GLADE_TAG_TOPLEVEL, FALSE))
GLADE_WIDGET_CLASS_SET_FLAGS (class, GLADE_TOPLEVEL);
else
GLADE_WIDGET_CLASS_UNSET_FLAGS (class, GLADE_TOPLEVEL);
if (glade_xml_get_boolean (node, GLADE_TAG_PLACEHOLDER))
if (glade_xml_get_boolean (node, GLADE_TAG_PLACEHOLDER, FALSE))
GLADE_WIDGET_CLASS_SET_FLAGS (class, GLADE_ADD_PLACEHOLDER);
else
GLADE_WIDGET_CLASS_UNSET_FLAGS (class, GLADE_ADD_PLACEHOLDER);
......@@ -391,23 +395,42 @@ glade_widget_class_find_spec (GladeWidgetClass *class, const gchar *name)
return NULL;
}
/**
* glade_widget_class_dump_param_specs:
* @class:
*
* Dump to the console the properties of the Widget as specified
* by gtk+. You can also run glade2 with : "glade2 --dump GtkWindow" to
* get the widget properties.
*
* Return Value:
**/
void
glade_widget_class_dump_param_specs (GladeWidgetClass *class)
{
GParamSpec **specs = NULL;
GParamSpec *spec;