dia r4307 - in trunk: . app lib
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4307 - in trunk: . app lib
- Date: Sat, 7 Mar 2009 21:35:20 +0000 (UTC)
Author: hans
Date: Sat Mar 7 21:35:20 2009
New Revision: 4307
URL: http://svn.gnome.org/viewvc/dia?rev=4307&view=rev
Log:
2009-03-07 Hans Breuer <hans breuer org>
* app/menus.c(create_or_ref_display_actions) : only create the action
group once, not per display, so the right actions are sensitive for the
"Use menu bar", too. Fixes bug #574472
* app/layer_dialog.[ch] : implement "Add Layer" and "Rename Layer" also
without the indirection Layer dialog
* app/menus.c : activate both commands
* lib/diagramdata.[ch] lib/libdia.def : implement and export
data_layer_get_index() used for the above
Modified:
trunk/ChangeLog
trunk/app/commands.c
trunk/app/layer_dialog.c
trunk/app/layer_dialog.h
trunk/app/makefile.msc
trunk/app/menus.c
trunk/lib/diagramdata.c
trunk/lib/diagramdata.h
trunk/lib/libdia.def
Modified: trunk/app/commands.c
==============================================================================
--- trunk/app/commands.c (original)
+++ trunk/app/commands.c Sat Mar 7 21:35:20 2009
@@ -1021,11 +1021,23 @@
void
layers_add_layer_callback (GtkAction *action)
{
+ Diagram *dia;
+
+ dia = ddisplay_active_diagram();
+ if (!dia) return;
+
+ diagram_edit_layer (dia, NULL);
}
void
layers_rename_layer_callback (GtkAction *action)
{
+ Diagram *dia;
+
+ dia = ddisplay_active_diagram();
+ if (!dia) return;
+
+ diagram_edit_layer (dia, dia->data->active_layer);
}
void
Modified: trunk/app/layer_dialog.c
==============================================================================
--- trunk/app/layer_dialog.c (original)
+++ trunk/app/layer_dialog.c Sat Mar 7 21:35:20 2009
@@ -153,7 +153,7 @@
static void layer_dialog_raise_callback(GtkWidget *widget, gpointer gdata);
static void layer_dialog_lower_callback(GtkWidget *widget, gpointer gdata);
static void layer_dialog_delete_callback(GtkWidget *widget, gpointer gdata);
-static void layer_dialog_edit_layer(DiaLayerWidget *layer_widget);
+static void layer_dialog_edit_layer(DiaLayerWidget *layer_widget, Diagram *dia, Layer *layer);
static ButtonData buttons[] = {
{ GTK_STOCK_ADD, layer_dialog_new_callback, N_("New Layer") },
@@ -240,7 +240,7 @@
case GDK_2BUTTON_PRESS:
bevent = (GdkEventButton *) event;
- layer_dialog_edit_layer(layer_widget);
+ layer_dialog_edit_layer(layer_widget, NULL, NULL);
return TRUE;
case GDK_KEY_PRESS:
@@ -1088,14 +1088,15 @@
/*
* The edit layer attributes dialog
*/
-
+/* called from the layer widget for rename */
static void
edit_layer_ok_callback (GtkWidget *w, gpointer client_data)
{
- EditLayerDialog *dialog;
+ EditLayerDialog *dialog = (EditLayerDialog *) client_data;
Layer *layer;
- dialog = (EditLayerDialog *) client_data;
+ g_return_if_fail (dialog->layer_widget != NULL);
+
layer = dialog->layer_widget->layer;
g_free (layer->name);
@@ -1112,6 +1113,45 @@
}
static void
+edit_layer_add_ok_callback (GtkWidget *w, gpointer client_data)
+{
+ EditLayerDialog *dialog = (EditLayerDialog *) client_data;
+ Diagram *dia = ddisplay_active_diagram();
+ Layer *layer;
+ int pos = data_layer_get_index (dia->data, dia->data->active_layer) + 1;
+
+ layer = new_layer(g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry))), dia->data);
+ data_add_layer_at(dia->data, layer, pos);
+ data_set_active_layer(dia->data, layer);
+
+ diagram_add_update_all(dia);
+ diagram_flush(dia);
+
+ undo_layer(dia, layer, TYPE_ADD_LAYER, pos);
+ undo_set_transactionpoint(dia->undo);
+
+ gtk_widget_destroy (dialog->dialog);
+ g_free (dialog);
+}
+
+static void
+edit_layer_rename_ok_callback (GtkWidget *w, gpointer client_data)
+{
+ EditLayerDialog *dialog = (EditLayerDialog *) client_data;
+ Diagram *dia = ddisplay_active_diagram();
+ Layer *layer = dia->data->active_layer;
+
+ g_free (layer->name);
+ layer->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
+
+ diagram_add_update_all(dia);
+ diagram_flush(dia);
+ /* FIXME: undo handling */
+
+ gtk_widget_destroy (dialog->dialog);
+ g_free (dialog);
+}
+static void
edit_layer_cancel_callback (GtkWidget *w,
gpointer client_data)
{
@@ -1119,7 +1159,8 @@
dialog = (EditLayerDialog *) client_data;
- dialog->layer_widget->edit_dialog = NULL;
+ if (dialog->layer_widget)
+ dialog->layer_widget->edit_dialog = NULL;
if (dialog->dialog != NULL)
gtk_widget_destroy (dialog->dialog);
g_free (dialog);
@@ -1136,7 +1177,7 @@
}
static void
-layer_dialog_edit_layer (DiaLayerWidget *layer_widget)
+layer_dialog_edit_layer (DiaLayerWidget *layer_widget, Diagram *dia, Layer *layer)
{
EditLayerDialog *dialog;
GtkWidget *vbox;
@@ -1151,7 +1192,8 @@
/* the dialog */
dialog->dialog = gtk_dialog_new ();
gtk_window_set_role (GTK_WINDOW (dialog->dialog), "edit_layer_attrributes");
- gtk_window_set_title (GTK_WINDOW (dialog->dialog), _("Edit Layer Attributes"));
+ gtk_window_set_title (GTK_WINDOW (dialog->dialog),
+ (layer_widget || layer) ? _("Edit Layer") : _("Add Layer"));
gtk_window_set_position (GTK_WINDOW (dialog->dialog), GTK_WIN_POS_MOUSE);
/* handle the wm close signal */
@@ -1175,7 +1217,16 @@
gtk_widget_show (label);
dialog->name_entry = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (hbox), dialog->name_entry, TRUE, TRUE, 0);
- gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), layer_widget->layer->name);
+ if (layer_widget)
+ gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), layer_widget->layer->name);
+ else if (layer)
+ gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), layer->name);
+ else if (dia) {
+ gchar *name = g_strdup_printf (_("New layer %d"), dia->data->layers->len);
+ gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), name);
+ g_free (name);
+ }
+
gtk_widget_show (dialog->name_entry);
gtk_widget_show (hbox);
@@ -1183,9 +1234,16 @@
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog->dialog)->action_area),
button, TRUE, TRUE, 0);
- g_signal_connect (GTK_OBJECT (button), "clicked",
- G_CALLBACK(edit_layer_ok_callback),
- dialog);
+ if (layer_widget)
+ g_signal_connect (GTK_OBJECT (button), "clicked",
+ G_CALLBACK(edit_layer_ok_callback), dialog);
+ else if (layer)
+ g_signal_connect (GTK_OBJECT (button), "clicked",
+ G_CALLBACK(edit_layer_rename_ok_callback), dialog);
+ else if (dia)
+ g_signal_connect (GTK_OBJECT (button), "clicked",
+ G_CALLBACK(edit_layer_add_ok_callback), dialog);
+
gtk_widget_grab_default (button);
gtk_widget_show (button);
@@ -1201,7 +1259,8 @@
gtk_widget_show (vbox);
gtk_widget_show (dialog->dialog);
- layer_widget->edit_dialog = dialog;
+ if (layer_widget)
+ layer_widget->edit_dialog = dialog;
}
@@ -1400,3 +1459,14 @@
undo_push_change(dia->undo, (Change *) change);
return change;
}
+
+/*!
+ * \brief edit a layers name, possibly also creating the layer
+ */
+void
+diagram_edit_layer(Diagram *dia, Layer *layer)
+{
+ g_return_if_fail(dia != NULL);
+
+ layer_dialog_edit_layer (NULL, layer ? NULL : dia, layer);
+}
Modified: trunk/app/layer_dialog.h
==============================================================================
--- trunk/app/layer_dialog.h (original)
+++ trunk/app/layer_dialog.h Sat Mar 7 21:35:20 2009
@@ -36,6 +36,8 @@
void dia_layer_set_layer(DiaLayerWidget *widget, Diagram *dia, Layer *layer);
void dia_layer_update_from_layer(DiaLayerWidget *widget);
+void diagram_edit_layer(Diagram *dia, Layer *layer);
+
#endif /* LAYER_DIALOG_H */
Modified: trunk/app/makefile.msc
==============================================================================
--- trunk/app/makefile.msc (original)
+++ trunk/app/makefile.msc Sat Mar 7 21:35:20 2009
@@ -97,11 +97,11 @@
dia_diagram_icon pixmaps\dia-diagram.png \
dia_app_icon pixmaps\dia-app.png \
\
- dia_objects_layer_above $(srcdir)/pixmaps/objects-layer-above.png \
- dia_objects_layer_below $(srcdir)/pixmaps/objects-layer-below.png \
- dia_layers $(srcdir)/pixmaps/layers.png \
- dia_layer_add $(srcdir)/pixmaps/layer-add.png \
- dia_layer_rename $(srcdir)/pixmaps/layer-rename.png
+ dia_objects_layer_above pixmaps\objects-layer-above.png \
+ dia_objects_layer_below pixmaps\objects-layer-below.png \
+ dia_layers pixmaps\layers.png \
+ dia_layer_add pixmaps\layer-add.png \
+ dia_layer_rename pixmaps\layer-rename.png
dia-app-icons.h : makefile.msc pixmaps\*.png
gdk-pixbuf-csource --build-list \
Modified: trunk/app/menus.c
==============================================================================
--- trunk/app/menus.c (original)
+++ trunk/app/menus.c Sat Mar 7 21:35:20 2009
@@ -140,10 +140,8 @@
{ "EditPastetext", NULL, N_("Paste _Text"), "<control><shift>V", NULL, G_CALLBACK (edit_paste_text_callback) },
{ "Layers", NULL, N_("_Layers"), NULL, NULL, NULL },
-#if 0 /* TODO: implement the callbacks */
{ "LayerAdd", DIA_STOCK_LAYER_ADD, N_("Add Layer..."), NULL, NULL, G_CALLBACK (layers_add_layer_callback) },
{ "LayerRename", DIA_STOCK_LAYER_RENAME, N_("Rename Layer..."), NULL, NULL, G_CALLBACK (layers_rename_layer_callback) },
-#endif
{ "ObjectsLayerAbove", DIA_STOCK_OBJECTS_LAYER_ABOVE, N_("Move selection to layer above"), NULL, NULL, G_CALLBACK (objects_move_up_layer) },
{ "ObjectsLayerBelow", DIA_STOCK_OBJECTS_LAYER_BELOW, N_("Move selection to layer below"), NULL, NULL, G_CALLBACK (objects_move_down_layer) },
{ "DiagramLayers", DIA_STOCK_LAYERS, N_("_Layers..."), "<control>L", NULL, G_CALLBACK (dialogs_layers_callback) },
@@ -820,6 +818,31 @@
}
}
+GtkActionGroup *
+create_or_ref_display_actions (void)
+{
+ if (display_actions)
+ return g_object_ref (display_actions);
+ display_actions = gtk_action_group_new ("display-actions");
+ gtk_action_group_set_translation_domain (display_actions, NULL);
+ gtk_action_group_set_translate_func (display_actions, _dia_translate, NULL, NULL);
+ gtk_action_group_add_actions (display_actions, common_entries,
+ G_N_ELEMENTS (common_entries), NULL);
+ gtk_action_group_add_actions (display_actions, display_entries,
+ G_N_ELEMENTS (display_entries), NULL);
+ gtk_action_group_add_toggle_actions (display_actions, display_toggle_entries,
+ G_N_ELEMENTS (display_toggle_entries),
+ NULL);
+ gtk_action_group_add_radio_actions (display_actions,
+ display_select_radio_entries,
+ G_N_ELEMENTS (display_select_radio_entries),
+ 1,
+ G_CALLBACK (select_style_callback),
+ NULL);
+ /* the initial reference */
+ return display_actions;
+}
+
/* Very minimal fallback menu info for ui-files missing
* as well as to register the InvisibleMenu */
static const gchar *ui_info =
@@ -877,23 +900,7 @@
toolbox_menubar = gtk_ui_manager_get_widget (toolbox_ui_manager, TOOLBOX_MENU);
/* the display menu */
- display_actions = gtk_action_group_new ("display-actions");
- gtk_action_group_set_translation_domain (display_actions, NULL);
- gtk_action_group_set_translate_func (display_actions, _dia_translate, NULL, NULL);
- gtk_action_group_add_actions (display_actions, common_entries,
- G_N_ELEMENTS (common_entries), NULL);
- gtk_action_group_add_actions (display_actions, display_entries,
- G_N_ELEMENTS (display_entries), NULL);
- gtk_action_group_add_toggle_actions (display_actions, display_toggle_entries,
- G_N_ELEMENTS (display_toggle_entries),
- NULL);
- gtk_action_group_add_radio_actions (display_actions,
- display_select_radio_entries,
- G_N_ELEMENTS (display_select_radio_entries),
- 1,
- G_CALLBACK (select_style_callback),
- NULL);
-
+ display_actions = create_or_ref_display_actions ();
display_tool_actions = create_tool_actions ();
display_ui_manager = gtk_ui_manager_new ();
@@ -1051,24 +1058,8 @@
GError *error = NULL;
gchar *uifile;
- *actions = gtk_action_group_new ("display-actions");
- gtk_action_group_set_translation_domain (*actions, NULL);
- gtk_action_group_set_translate_func (*actions, _dia_translate, NULL, NULL);
-
- gtk_action_group_add_actions (*actions, common_entries,
- G_N_ELEMENTS (common_entries), NULL);
- gtk_action_group_add_actions (*actions, display_entries,
- G_N_ELEMENTS (display_entries), NULL);
- gtk_action_group_add_toggle_actions (*actions, display_toggle_entries,
- G_N_ELEMENTS (display_toggle_entries),
- NULL);
- gtk_action_group_add_radio_actions (*actions,
- display_select_radio_entries,
- G_N_ELEMENTS (display_select_radio_entries),
- 1,
- G_CALLBACK (select_style_callback),
- NULL);
-
+
+ *actions = create_or_ref_display_actions ();
tool_actions = create_tool_actions ();
*ui_manager = gtk_ui_manager_new ();
Modified: trunk/lib/diagramdata.c
==============================================================================
--- trunk/lib/diagramdata.c (original)
+++ trunk/lib/diagramdata.c Sat Mar 7 21:35:20 2009
@@ -285,7 +285,6 @@
/** Add a layer object to a diagram.
* @param data The diagram to add the layer to.
* @param layer The layer to add.
- * @bug Should just call data_add_layer_at().
*/
void
data_add_layer(DiagramData *data, Layer *layer)
@@ -317,6 +316,20 @@
data_update_extents(data);
}
+int
+data_layer_get_index (const DiagramData *data, const Layer *layer)
+{
+ int len;
+ int i;
+
+ len = data->layers->len;
+ for (i=0;i<len;++i) {
+ if (layer == g_ptr_array_index(data->layers, i))
+ return i;
+ }
+ return -1;
+}
+
/** Set which layer is the active layer in a diagram.
* @param data The diagram in which to set the active layer.
* @param layer The layer that should be active.
Modified: trunk/lib/diagramdata.h
==============================================================================
--- trunk/lib/diagramdata.h (original)
+++ trunk/lib/diagramdata.h Sat Mar 7 21:35:20 2009
@@ -130,6 +130,8 @@
void data_add_layer_at(DiagramData *data, Layer *layer, int pos);
void data_set_active_layer(DiagramData *data, Layer *layer);
void data_delete_layer(DiagramData *data, Layer *layer);
+int data_layer_get_index (const DiagramData *data, const Layer *layer);
+
void data_select(DiagramData *data, DiaObject *obj);
void data_unselect(DiagramData *data, DiaObject *obj);
void data_remove_all_selected(DiagramData *data);
Modified: trunk/lib/libdia.def
==============================================================================
--- trunk/lib/libdia.def (original)
+++ trunk/lib/libdia.def Sat Mar 7 21:35:20 2009
@@ -151,6 +151,7 @@
data_get_sorted_selected
data_get_sorted_selected_remove
data_int
+ data_layer_get_index
data_lower_layer
data_next
data_point
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]