[dia] [substitute] move Diagram::selection_changed signal to base class
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] [substitute] move Diagram::selection_changed signal to base class
- Date: Sun, 16 Sep 2012 18:11:29 +0000 (UTC)
commit 433627f16ddf2e9421202c40bb7c6a3daf12f516
Author: Hans Breuer <hans breuer org>
Date: Sun Sep 16 13:11:53 2012 +0200
[substitute] move Diagram::selection_changed signal to base class
For the new object_substitute() facility an object within the active
selection can change. While object-add and object-remove already were
signals on DiagramData selection-changed was not. But it should
because DiagramData::selected is also managed in the base class.
When objects are added/removed the Diagram react on the signal to
update it's content, i.e. calls object_add_updates(obj, dia);
app/diagram.c | 57 +++++++++++++++++++++++++++--------------------------
app/diagram.h | 1 -
lib/diagramdata.c | 19 +++++++++++++++++
lib/diagramdata.h | 1 +
4 files changed, 49 insertions(+), 29 deletions(-)
---
diff --git a/app/diagram.c b/app/diagram.c
index a074799..eca9c95 100644
--- a/app/diagram.c
+++ b/app/diagram.c
@@ -63,7 +63,6 @@ static gboolean diagram_init(Diagram *obj, const char *filename);
static void diagram_update_for_filename(Diagram *dia);
enum {
- SELECTION_CHANGED,
REMOVED,
LAST_SIGNAL
};
@@ -141,11 +140,6 @@ _diagram_removed (Diagram* dia)
}
static void
-_diagram_selection_changed (Diagram* dia, int n)
-{
-}
-
-static void
diagram_class_init (DiagramClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -161,18 +155,7 @@ diagram_class_init (DiagramClass *klass)
dia_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- diagram_signals[SELECTION_CHANGED] =
- g_signal_new ("selection_changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (DiagramClass, selection_changed),
- NULL, NULL,
- dia_marshal_VOID__INT,
- G_TYPE_NONE, 1,
- G_TYPE_INT);
-
klass->removed = _diagram_removed;
- klass->selection_changed = _diagram_selection_changed;
object_class->finalize = diagram_finalize;
object_class->dispose = diagram_dispose;
@@ -184,6 +167,25 @@ dia_open_diagrams(void)
return open_diagrams;
}
+static void
+_object_add (Diagram *dia,
+ Layer *layer,
+ DiaObject *obj,
+ gpointer user_data)
+{
+ if (obj)
+ object_add_updates(obj, dia);
+}
+static void
+_object_remove(Diagram *dia,
+ Layer *layer,
+ DiaObject *obj,
+ gpointer user_data)
+{
+ if (obj)
+ object_add_updates(obj, dia);
+}
+
/** Initializes a diagram with standard info and sets it to be called
* 'filename'.
* Returns TRUE if everything went ok, FALSE otherwise.
@@ -254,6 +256,10 @@ diagram_init(Diagram *dia, const char *filename)
layer_dialog_update_diagram_list();
g_free(newfilename);
+
+ g_signal_connect (G_OBJECT(dia), "object_add", G_CALLBACK(_object_add), dia);
+ g_signal_connect (G_OBJECT(dia), "object_remove", G_CALLBACK(_object_remove), dia);
+
return TRUE;
}
@@ -748,7 +754,6 @@ diagram_remove_all_selected(Diagram *diagram, int delete_empty)
object_add_updates_list(diagram->data->selected, diagram);
textedit_remove_focus_all(diagram);
data_remove_all_selected(diagram->data);
- g_signal_emit (diagram, diagram_signals[SELECTION_CHANGED], 0, g_list_length (diagram->data->selected));
}
void
@@ -757,8 +762,6 @@ diagram_unselect_object(Diagram *diagram, DiaObject *obj)
object_add_updates(obj, diagram);
textedit_remove_focus(obj, diagram);
data_unselect(DIA_DIAGRAM_DATA(diagram), obj);
- g_signal_emit (diagram, diagram_signals[SELECTION_CHANGED], 0,
- g_list_length (DIA_DIAGRAM_DATA(diagram)->selected));
}
void
@@ -768,7 +771,7 @@ diagram_unselect_objects(Diagram *dia, GList *obj_list)
DiaObject *obj;
/* otherwise we would signal objects step by step */
- g_signal_handlers_block_by_func (dia, _diagram_selection_changed, NULL);
+ g_signal_handlers_block_by_func (dia, DIA_DIAGRAM_DATA_GET_CLASS (dia)->selection_changed, NULL);
list = obj_list;
while (list != NULL) {
obj = (DiaObject *) list->data;
@@ -779,8 +782,8 @@ diagram_unselect_objects(Diagram *dia, GList *obj_list)
list = g_list_next(list);
}
- g_signal_handlers_unblock_by_func (dia, _diagram_selection_changed, NULL);
- g_signal_emit (dia, diagram_signals[SELECTION_CHANGED], 0, g_list_length (dia->data->selected));
+ g_signal_handlers_unblock_by_func (dia, DIA_DIAGRAM_DATA_GET_CLASS (dia)->selection_changed, NULL);
+ g_signal_emit_by_name (dia, "selection_changed", 0, g_list_length (dia->data->selected));
}
/** Make a single object selected.
@@ -796,8 +799,6 @@ diagram_select(Diagram *diagram, DiaObject *obj)
data_select(diagram->data, obj);
obj->ops->selectf(obj, NULL, NULL);
object_add_updates(obj, diagram);
- g_signal_emit (diagram, diagram_signals[SELECTION_CHANGED], 0,
- g_list_length (diagram->data->selected));
}
}
@@ -806,7 +807,7 @@ diagram_select_list(Diagram *dia, GList *list)
{
g_return_if_fail (dia && list);
/* otherwise we would signal objects step by step */
- g_signal_handlers_block_by_func (dia, _diagram_selection_changed, NULL);
+ g_signal_handlers_block_by_func (dia, DIA_DIAGRAM_DATA_GET_CLASS (dia)->selection_changed, NULL);
while (list != NULL) {
DiaObject *obj = (DiaObject *)list->data;
@@ -817,8 +818,8 @@ diagram_select_list(Diagram *dia, GList *list)
if (get_active_focus((DiagramData*) dia) == NULL) {
textedit_activate_first(ddisplay_active());
}
- g_signal_handlers_unblock_by_func (dia, _diagram_selection_changed, NULL);
- g_signal_emit (dia, diagram_signals[SELECTION_CHANGED], 0, g_list_length (dia->data->selected));
+ g_signal_handlers_unblock_by_func (dia, DIA_DIAGRAM_DATA_GET_CLASS (dia)->selection_changed, NULL);
+ g_signal_emit_by_name (dia, "selection_changed", 0, g_list_length (dia->data->selected));
}
int
diff --git a/app/diagram.h b/app/diagram.h
index 7bc2b51..b99e0d3 100644
--- a/app/diagram.h
+++ b/app/diagram.h
@@ -70,7 +70,6 @@ typedef struct _DiagramClass {
/* signals */
void (* removed) (Diagram*);
- void (* selection_changed) (Diagram*, int);
} DiagramClass;
diff --git a/lib/diagramdata.c b/lib/diagramdata.c
index c6ca0f4..34c2b5c 100644
--- a/lib/diagramdata.c
+++ b/lib/diagramdata.c
@@ -42,6 +42,7 @@ static void diagram_data_init (DiagramData *object);
enum {
OBJECT_ADD,
OBJECT_REMOVE,
+ SELECTION_CHANGED,
LAST_SIGNAL
};
@@ -95,6 +96,11 @@ _diagram_data_object_remove (DiagramData* dia,Layer* layer,DiaObject* obj)
{
}
+static void
+_diagram_data_selection_changed (DiagramData* dia, int n)
+{
+}
+
/** Initialize a new diagram data object.
* @param data A diagram data object to initialize.
*/
@@ -268,6 +274,16 @@ diagram_data_class_init(DiagramDataClass *klass)
G_TYPE_POINTER,
G_TYPE_POINTER);
+ diagram_data_signals[SELECTION_CHANGED] =
+ g_signal_new ("selection_changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (DiagramDataClass, selection_changed),
+ NULL, NULL,
+ dia_marshal_VOID__INT,
+ G_TYPE_NONE, 1,
+ G_TYPE_INT);
+
object_class->finalize = diagram_data_finalize;
klass->object_add = _diagram_data_object_add;
klass->object_remove = _diagram_data_object_remove;
@@ -476,6 +492,7 @@ data_select(DiagramData *data, DiaObject *obj)
return; /* should this be an error?`*/
data->selected = g_list_prepend(data->selected, obj);
data->selected_count_private++;
+ g_signal_emit (data, diagram_data_signals[SELECTION_CHANGED], 0, data->selected_count_private);
}
/** Deselect an object in a diagram. Note that other objects may still be
@@ -490,6 +507,7 @@ data_unselect(DiagramData *data, DiaObject *obj)
return; /* should this be an error?`*/
data->selected = g_list_remove(data->selected, obj);
data->selected_count_private--;
+ g_signal_emit (data, diagram_data_signals[SELECTION_CHANGED], 0, data->selected_count_private);
}
/** Clears the list of selected objects.
@@ -502,6 +520,7 @@ data_remove_all_selected(DiagramData *data)
g_list_free(data->selected); /* Remove previous selection */
data->selected = NULL;
data->selected_count_private = 0;
+ g_signal_emit (data, diagram_data_signals[SELECTION_CHANGED], 0, data->selected_count_private);
}
/** Return TRUE if the diagram has visible layers.
diff --git a/lib/diagramdata.h b/lib/diagramdata.h
index d00a756..3f59f2e 100644
--- a/lib/diagramdata.h
+++ b/lib/diagramdata.h
@@ -99,6 +99,7 @@ typedef struct _DiagramDataClass {
/* Signals */
void (* object_add) (DiagramData*, Layer*, DiaObject*);
void (* object_remove) (DiagramData*, Layer*, DiaObject*);
+ void (* selection_changed) (DiagramData*, int);
} DiagramDataClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]