1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
30 #include <libgeda/libgeda.h>
32 #include "../include/i_vars.h"
33 #include "../include/globals.h"
34 #include "../include/prototype.h"
36 #ifdef HAVE_LIBDMALLOC
40 #include <gdk/gdkkeysyms.h>
41 #include "../include/gschem_dialog.h"
42 #include "../include/x_multiattrib.h"
44 /*! \brief Process the response returned by the multi-attribte dialog.
45 * \par Function Description
46 * This function handles the response <B>arg1</B> of the multi-attribute
47 * editor dialog <B>dialog</B>.
49 * \param [in] dialog The multi-attribute editor dialog.
50 * \param [in] arg1 The response ID.
51 * \param [in] user_data A pointer on the toplevel environment.
54 multiattrib_callback_response (GtkDialog
*dialog
,
58 TOPLEVEL
*toplevel
= (TOPLEVEL
*)user_data
;
61 case GTK_RESPONSE_CLOSE
:
62 case GTK_RESPONSE_DELETE_EVENT
:
63 gtk_widget_destroy (GTK_WIDGET (dialog
));
64 toplevel
->mawindow
= NULL
;
69 /*! \brief Open multiple attribute editor dialog.
70 * \par Function Description
71 * Opens the multiple attribute editor dialog for objects in this <B>toplevel</B>.
73 * \param [in] toplevel The TOPLEVEL object.
75 void x_multiattrib_open (TOPLEVEL
*toplevel
)
77 if ( toplevel
->mawindow
== NULL
) {
78 toplevel
->mawindow
= GTK_WIDGET (g_object_new (TYPE_MULTIATTRIB
,
79 "selection", toplevel
->page_current
->selection_list
,
81 "settings-name", "multiattrib",
85 g_signal_connect (toplevel
->mawindow
,
87 G_CALLBACK (multiattrib_callback_response
),
90 gtk_window_set_transient_for (GTK_WINDOW(toplevel
->mawindow
),
91 GTK_WINDOW(toplevel
->main_window
));
93 gtk_widget_show (toplevel
->mawindow
);
95 gtk_window_present (GTK_WINDOW(toplevel
->mawindow
));
100 /*! \brief Close the multiattrib dialog.
102 * \par Function Description
104 * Closes the multiattrib dialog associated with <B>toplevel</B>.
106 * \param [in] toplevel The TOPLEVEL object.
108 void x_multiattrib_close (TOPLEVEL
*toplevel
)
110 if (toplevel
->mawindow
!= NULL
) {
111 gtk_widget_destroy (toplevel
->mawindow
);
112 toplevel
->mawindow
= NULL
;
117 /*! \brief Update the multiattrib editor dialog for a TOPLEVEL.
119 * \par Function Description
121 * If the TOPLEVEL has an open multiattrib dialog, switch to
122 * watching the current page's SELECTION object for changes.
124 * \param [in] toplevel The TOPLEVEL object.
126 void x_multiattrib_update( TOPLEVEL
*toplevel
)
128 if (toplevel
->mawindow
!= NULL
) {
129 g_object_set (G_OBJECT (toplevel
->mawindow
), "selection",
130 toplevel
->page_current
->selection_list
, NULL
);
135 /*! \section celltextview-widget Cell TextView Widget Code.
136 * This widget makes a 'GtkTextView' widget implements the 'GtkCellEditable'
137 * interface. It can then be used to renderer multi-line texts inside
138 * tree views ('GtkTreeView').
140 static void celltextview_class_init (CellTextViewClass
*klass
);
141 static void celltextview_init (CellTextView
*self
);
142 static void celltextview_cell_editable_init (GtkCellEditableIface
*iface
);
144 /*! \todo Finish function documentation
146 * \par Function Description
149 static gboolean
celltextview_key_press_event (GtkWidget
*widget
,
150 GdkEventKey
*key_event
,
153 CellTextView
*celltextview
= (CellTextView
*)widget
;
155 /* If the Escape key is pressed, we flag the edit as canceled */
156 if (key_event
->keyval
== GDK_Escape
)
157 celltextview
->editing_canceled
= TRUE
;
159 /* ends editing of cell if one of these keys are pressed or editing is canceled */
160 if (celltextview
->editing_canceled
== TRUE
||
161 /* the Enter key without the Control modifier */
162 (!(key_event
->state
& GDK_CONTROL_MASK
) &&
163 (key_event
->keyval
== GDK_Return
||
164 key_event
->keyval
== GDK_KP_Enter
))) {
165 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (celltextview
));
166 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (celltextview
));
173 /*! \todo Finish function documentation
175 * \par Function Description
178 static void celltextview_start_editing (GtkCellEditable
*cell_editable
,
181 g_signal_connect (cell_editable
,
183 G_CALLBACK (celltextview_key_press_event
),
188 /*! \todo Finish function documentation
190 * \par Function Description
193 GType
celltextview_get_type()
195 static GType celltextview_type
= 0;
197 if (!celltextview_type
) {
198 static const GTypeInfo celltextview_info
= {
199 sizeof(CellTextViewClass
),
200 NULL
, /* base_init */
201 NULL
, /* base_finalize */
202 (GClassInitFunc
) celltextview_class_init
,
203 NULL
, /* class_finalize */
204 NULL
, /* class_data */
205 sizeof(CellTextView
),
207 (GInstanceInitFunc
) celltextview_init
,
210 static const GInterfaceInfo cell_editable_info
= {
211 (GInterfaceInitFunc
) celltextview_cell_editable_init
,
212 NULL
, /* interface_finalize */
213 NULL
/* interface_data */
216 celltextview_type
= g_type_register_static(GTK_TYPE_TEXT_VIEW
,
218 &celltextview_info
, 0);
219 g_type_add_interface_static(celltextview_type
,
220 GTK_TYPE_CELL_EDITABLE
,
221 &cell_editable_info
);
224 return celltextview_type
;
227 /*! \todo Finish function documentation
229 * \par Function Description
232 static void celltextview_class_init(CellTextViewClass
*klass
)
234 /* GObjectClass *gobject_class = G_OBJECT_CLASS (klass); */
237 /*! \todo Finish function documentation
239 * \par Function Description
242 static void celltextview_init(CellTextView
*celltextview
)
244 celltextview
->editing_canceled
= FALSE
;
247 /*! \todo Finish function documentation
249 * \par Function Description
252 static void celltextview_cell_editable_init(GtkCellEditableIface
*iface
)
254 iface
->start_editing
= celltextview_start_editing
;
257 /*! \section multi-line-text-cell-renderer Multi-line Text Cell Renderer
258 * GTK has no multi-line text cell renderer. This code adds one to be used
259 * in gschem code. It is inspired by the 'GtkCellRendererCombo' renderer
262 static void cellrenderermultilinetext_class_init(CellRendererMultiLineTextClass
*klass
);
263 static void cellrenderermultilinetext_init (CellRendererMultiLineText
*self
);
265 static void cellrenderermultilinetext_editing_done (GtkCellEditable
*cell_editable
,
267 static gboolean
cellrenderermultilinetext_focus_out_event (GtkWidget
*widget
,
272 #define CELL_RENDERER_MULTI_LINE_TEXT_PATH "cell-renderer-multi-line-text-path"
275 /*! \todo Finish function documentation
277 * \par Function Description
280 static GtkCellEditable
* cellrenderermultilinetext_start_editing(GtkCellRenderer
*cell
,
284 GdkRectangle
*background_area
,
285 GdkRectangle
*cell_area
,
286 GtkCellRendererState flags
)
288 GtkCellRendererText
*cell_text
;
289 CellRendererMultiLineText
*cell_mlt
;
291 GtkTextBuffer
*textbuffer
;
293 cell_text
= GTK_CELL_RENDERER_TEXT (cell
);
294 if (cell_text
->editable
== FALSE
) {
298 cell_mlt
= CELL_RENDERER_MULTI_LINE_TEXT (cell
);
300 textbuffer
= GTK_TEXT_BUFFER (g_object_new (GTK_TYPE_TEXT_BUFFER
,
302 gtk_text_buffer_set_text (textbuffer
,
304 strlen (cell_text
->text
));
306 textview
= GTK_WIDGET (g_object_new (TYPE_CELL_TEXT_VIEW
,
308 "buffer", textbuffer
,
311 "height-request", cell_area
->height
,
313 g_object_set_data_full (G_OBJECT (textview
),
314 CELL_RENDERER_MULTI_LINE_TEXT_PATH
,
315 g_strdup (path
), g_free
);
317 gtk_widget_show (textview
);
319 g_signal_connect (GTK_CELL_EDITABLE (textview
),
321 G_CALLBACK (cellrenderermultilinetext_editing_done
),
323 cell_mlt
->focus_out_id
=
324 g_signal_connect (textview
,
326 G_CALLBACK (cellrenderermultilinetext_focus_out_event
),
329 return GTK_CELL_EDITABLE (textview
);
332 /*! \todo Finish function documentation
334 * \par Function Description
337 static void cellrenderermultilinetext_editing_done(GtkCellEditable
*cell_editable
,
340 CellRendererMultiLineText
*cell
= CELL_RENDERER_MULTI_LINE_TEXT (user_data
);
341 GtkTextBuffer
*buffer
;
342 GtkTextIter start
, end
;
346 if (cell
->focus_out_id
> 0) {
347 g_signal_handler_disconnect (cell_editable
,
349 cell
->focus_out_id
= 0;
352 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (cell
),
353 CELL_TEXT_VIEW (cell_editable
)->editing_canceled
);
354 if (CELL_TEXT_VIEW (cell_editable
)->editing_canceled
)
357 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (cell_editable
));
358 gtk_text_buffer_get_start_iter (buffer
, &start
);
359 gtk_text_buffer_get_end_iter (buffer
, &end
);
360 new_text
= gtk_text_buffer_get_text (buffer
, &start
, &end
, TRUE
);
362 path
= g_object_get_data (G_OBJECT (cell_editable
),
363 CELL_RENDERER_MULTI_LINE_TEXT_PATH
);
364 g_signal_emit_by_name (cell
, "edited", path
, new_text
);
370 /*! \todo Finish function documentation
372 * \par Function Description
375 static gboolean
cellrenderermultilinetext_focus_out_event(GtkWidget
*widget
,
379 cellrenderermultilinetext_editing_done (GTK_CELL_EDITABLE (widget
),
385 /*! \todo Finish function documentation
387 * \par Function Description
390 GType
cellrenderermultilinetext_get_type()
392 static GType cellrenderermultilinetext_type
= 0;
394 if (!cellrenderermultilinetext_type
) {
395 static const GTypeInfo cellrenderermultilinetext_info
= {
396 sizeof(CellRendererMultiLineTextClass
),
397 NULL
, /* base_init */
398 NULL
, /* base_finalize */
399 (GClassInitFunc
) cellrenderermultilinetext_class_init
,
400 NULL
, /* class_finalize */
401 NULL
, /* class_data */
402 sizeof(CellRendererMultiLineText
),
404 (GInstanceInitFunc
) cellrenderermultilinetext_init
,
407 cellrenderermultilinetext_type
= g_type_register_static (
408 GTK_TYPE_CELL_RENDERER_TEXT
,
409 "CellRendererMultiLineText",
410 &cellrenderermultilinetext_info
, 0);
413 return cellrenderermultilinetext_type
;
416 /*! \todo Finish function documentation
418 * \par Function Description
421 static void cellrenderermultilinetext_class_init(CellRendererMultiLineTextClass
*klass
)
423 /* GObjectClass *gobject_class = G_OBJECT_CLASS (klass); */
424 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
426 cell_class
->start_editing
= cellrenderermultilinetext_start_editing
;
430 /*! \todo Finish function documentation
432 * \par Function Description
435 static void cellrenderermultilinetext_init(CellRendererMultiLineText
*self
)
449 static GObjectClass
*multiattrib_parent_class
= NULL
;
451 static void multiattrib_class_init (MultiattribClass
*class);
452 static void multiattrib_init (Multiattrib
*multiattrib
);
453 static void multiattrib_set_property (GObject
*object
,
457 static void multiattrib_get_property (GObject
*object
,
462 static void multiattrib_popup_menu (Multiattrib
*multiattrib
,
463 GdkEventButton
*event
);
466 /*! \todo Finish function documentation
468 * \par Function Description
471 static void multiattrib_action_add_attribute(TOPLEVEL
*toplevel
,
476 gint show_name_value
)
481 newtext
= g_strdup_printf ("%s=%s", name
, value
);
483 /* create a new attribute and link it */
484 o_attrib
= o_attrib_add_attrib (toplevel
, newtext
,
485 visible
, show_name_value
, object
);
487 toplevel
->page_current
->CHANGED
= 1;
488 o_undo_savestate (toplevel
, UNDO_ALL
);
494 /*! \todo Finish function documentation
496 * \par Function Description
499 static void multiattrib_action_duplicate_attribute(TOPLEVEL
*toplevel
,
505 o_new
= o_attrib_add_attrib (toplevel
,
506 o_attrib
->text
->string
,
507 o_attrib
->visibility
,
508 o_attrib
->show_name_value
,
510 toplevel
->page_current
->CHANGED
= 1;
511 o_undo_savestate (toplevel
, UNDO_ALL
);
515 /*! \todo Finish function documentation
517 * \par Function Description
520 static void multiattrib_action_delete_attribute(TOPLEVEL
*toplevel
,
523 /* actually deletes the attribute */
524 o_selection_remove ( toplevel
->page_current
->selection_list
, o_attrib
);
525 o_delete_text (toplevel
, o_attrib
);
526 toplevel
->page_current
->CHANGED
=1;
527 o_undo_savestate (toplevel
, UNDO_ALL
);
531 /*! \todo Finish function documentation
533 * \par Function Description
536 static void multiattrib_column_set_data_name(GtkTreeViewColumn
*tree_column
,
537 GtkCellRenderer
*cell
,
538 GtkTreeModel
*tree_model
,
545 gtk_tree_model_get (tree_model
, iter
,
546 COLUMN_ATTRIBUTE
, &o_attrib
,
548 g_assert (o_attrib
->type
== OBJ_TEXT
);
550 o_attrib_get_name_value (o_attrib
->text
->string
, &name
, &value
);
559 /*! \todo Finish function documentation
561 * \par Function Description
564 static void multiattrib_column_set_data_value(GtkTreeViewColumn
*tree_column
,
565 GtkCellRenderer
*cell
,
566 GtkTreeModel
*tree_model
,
573 gtk_tree_model_get (tree_model
, iter
,
574 COLUMN_ATTRIBUTE
, &o_attrib
,
576 g_assert (o_attrib
->type
== OBJ_TEXT
);
578 o_attrib_get_name_value (o_attrib
->text
->string
, &name
, &value
);
587 /*! \todo Finish function documentation
589 * \par Function Description
592 static void multiattrib_column_set_data_visible(GtkTreeViewColumn
*tree_column
,
593 GtkCellRenderer
*cell
,
594 GtkTreeModel
*tree_model
,
600 gtk_tree_model_get (tree_model
, iter
,
601 COLUMN_ATTRIBUTE
, &o_attrib
,
603 g_assert (o_attrib
->type
== OBJ_TEXT
);
606 "active", (o_attrib
->visibility
== VISIBLE
),
611 /*! \todo Finish function documentation
613 * \par Function Description
616 static void multiattrib_column_set_data_show_name(GtkTreeViewColumn
*tree_column
,
617 GtkCellRenderer
*cell
,
618 GtkTreeModel
*tree_model
,
624 gtk_tree_model_get (tree_model
, iter
,
625 COLUMN_ATTRIBUTE
, &o_attrib
,
627 g_assert (o_attrib
->type
== OBJ_TEXT
);
630 "active", (o_attrib
->show_name_value
== SHOW_NAME_VALUE
||
631 o_attrib
->show_name_value
== SHOW_NAME
),
636 /*! \todo Finish function documentation
638 * \par Function Description
641 static void multiattrib_column_set_data_show_value(GtkTreeViewColumn
*tree_column
,
642 GtkCellRenderer
*cell
,
643 GtkTreeModel
*tree_model
,
649 gtk_tree_model_get (tree_model
, iter
,
650 COLUMN_ATTRIBUTE
, &o_attrib
,
652 g_assert (o_attrib
->type
== OBJ_TEXT
);
655 "active", (o_attrib
->show_name_value
== SHOW_NAME_VALUE
||
656 o_attrib
->show_name_value
== SHOW_VALUE
),
661 /*! \brief Requests an update of the display of a row.
662 * \par Function Description
663 * This is an helper function to update the display of a row when
664 * data for this row have been modified in the model.
666 * It emits the 'row_changed' signal on the pointed row.
668 * \param [in] model A GtkTreeModel.
669 * \param [in] iter A valid GtkTreeIter pointing to the changed row.
672 update_row_display (GtkTreeModel
*model
, GtkTreeIter
*iter
)
676 path
= gtk_tree_model_get_path (model
, iter
);
677 gtk_tree_model_row_changed (model
, path
, iter
);
678 gtk_tree_path_free (path
);
682 /*! \todo Finish function documentation
684 * \par Function Description
687 static void multiattrib_callback_edited_name(GtkCellRendererText
*cellrenderertext
,
692 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
697 gchar
*name
, *value
, *newtext
;
699 model
= gtk_tree_view_get_model (multiattrib
->treeview
);
700 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
702 if (!gtk_tree_model_get_iter_from_string (model
, &iter
, arg1
)) {
706 if (g_ascii_strcasecmp (arg2
, "") == 0) {
707 GtkWidget
*dialog
= gtk_message_dialog_new (
708 GTK_WINDOW (multiattrib
),
712 _("Attributes with empty name are not allowed. Please set a name."));
714 gtk_dialog_run (GTK_DIALOG (dialog
));
715 gtk_widget_destroy (dialog
);
719 gtk_tree_model_get (model
, &iter
,
720 COLUMN_ATTRIBUTE
, &o_attrib
,
722 g_assert (o_attrib
->type
== OBJ_TEXT
);
724 o_attrib_get_name_value (o_attrib
->text
->string
, &name
, &value
);
725 newtext
= g_strdup_printf ("%s=%s", arg2
, value
);
727 /* actually modifies the attribute */
728 o_text_change (toplevel
, o_attrib
,
729 newtext
, o_attrib
->visibility
, o_attrib
->show_name_value
);
737 /*! \todo Finish function documentation
739 * \par Function Description
742 static void multiattrib_callback_edited_value(GtkCellRendererText
*cell_renderer
,
747 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
752 gchar
*name
, *value
, *newtext
;
754 model
= gtk_tree_view_get_model (multiattrib
->treeview
);
755 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
757 if (!gtk_tree_model_get_iter_from_string (model
, &iter
, arg1
)) {
761 gtk_tree_model_get (model
, &iter
,
762 COLUMN_ATTRIBUTE
, &o_attrib
,
764 g_assert (o_attrib
->type
== OBJ_TEXT
);
766 o_attrib_get_name_value (o_attrib
->text
->string
, &name
, &value
);
767 newtext
= g_strdup_printf ("%s=%s", name
, arg2
);
769 /* actually modifies the attribute */
770 o_text_change (toplevel
, o_attrib
,
771 newtext
, o_attrib
->visibility
, o_attrib
->show_name_value
);
773 /* request an update of display for this row */
774 update_row_display (model
, &iter
);
782 /*! \todo Finish function documentation
784 * \par Function Description
787 static void multiattrib_callback_toggled_visible(GtkCellRendererToggle
*cell_renderer
,
791 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
798 model
= gtk_tree_view_get_model (multiattrib
->treeview
);
799 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
801 if (!gtk_tree_model_get_iter_from_string (model
, &iter
, path
)) {
805 gtk_tree_model_get (model
, &iter
,
806 COLUMN_ATTRIBUTE
, &o_attrib
,
808 g_assert (o_attrib
->type
== OBJ_TEXT
);
809 o_text_erase (toplevel
, o_attrib
);
811 visibility
= o_attrib
->visibility
== VISIBLE
? INVISIBLE
: VISIBLE
;
813 /* actually modifies the attribute */
814 o_attrib
->visibility
= visibility
;
815 o_text_recreate (toplevel
, o_attrib
);
816 o_text_draw (toplevel
, o_attrib
);
817 o_undo_savestate (toplevel
, UNDO_ALL
);
819 /* request an update of display for this row */
820 update_row_display (model
, &iter
);
824 /*! \todo Finish function documentation
826 * \par Function Description
829 static void multiattrib_callback_toggled_show_name(GtkCellRendererToggle
*cell_renderer
,
833 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
840 model
= gtk_tree_view_get_model (multiattrib
->treeview
);
841 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
843 if (!gtk_tree_model_get_iter_from_string (model
, &iter
, path
)) {
847 gtk_tree_model_get (model
, &iter
,
848 COLUMN_ATTRIBUTE
, &o_attrib
,
850 g_assert (o_attrib
->type
== OBJ_TEXT
);
851 o_text_erase (toplevel
, o_attrib
);
853 switch (o_attrib
->show_name_value
) {
854 case SHOW_NAME_VALUE
: new_snv
= SHOW_VALUE
; break;
855 case SHOW_NAME
: new_snv
= SHOW_VALUE
; break;
856 case SHOW_VALUE
: new_snv
= SHOW_NAME_VALUE
; break;
858 g_assert_not_reached ();
859 new_snv
= SHOW_NAME_VALUE
;
862 /* actually modifies the attribute */
863 o_attrib
->show_name_value
= new_snv
;
864 o_text_recreate (toplevel
, o_attrib
);
865 o_text_draw (toplevel
, o_attrib
);
866 o_undo_savestate (toplevel
, UNDO_ALL
);
868 /* request an update of display for this row */
869 update_row_display (model
, &iter
);
873 /*! \todo Finish function documentation
875 * \par Function Description
878 static void multiattrib_callback_toggled_show_value(GtkCellRendererToggle
*cell_renderer
,
882 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
889 model
= gtk_tree_view_get_model (multiattrib
->treeview
);
890 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
892 if (!gtk_tree_model_get_iter_from_string (model
, &iter
, path
)) {
896 gtk_tree_model_get (model
, &iter
,
897 COLUMN_ATTRIBUTE
, &o_attrib
,
899 g_assert (o_attrib
->type
== OBJ_TEXT
);
900 o_text_erase (toplevel
, o_attrib
);
902 switch (o_attrib
->show_name_value
) {
903 case SHOW_NAME_VALUE
: new_snv
= SHOW_NAME
; break;
904 case SHOW_NAME
: new_snv
= SHOW_NAME_VALUE
; break;
905 case SHOW_VALUE
: new_snv
= SHOW_NAME
; break;
907 g_assert_not_reached ();
908 new_snv
= SHOW_NAME_VALUE
;
911 /* actually modifies the attribute */
912 o_attrib
->show_name_value
= new_snv
;
913 o_text_recreate (toplevel
, o_attrib
);
914 o_text_draw (toplevel
, o_attrib
);
915 o_undo_savestate (toplevel
, UNDO_ALL
);
917 /* request an update of display for this row */
918 update_row_display (model
, &iter
);
922 /*! \todo Finish function documentation
924 * \par Function Description
927 static gboolean
multiattrib_callback_key_pressed(GtkWidget
*widget
,
931 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
933 if (event
->state
== 0 &&
934 (event
->keyval
== GDK_Delete
|| event
->keyval
== GDK_KP_Delete
)) {
938 /* delete the currently selected attribute */
940 if (!gtk_tree_selection_get_selected (
941 gtk_tree_view_get_selection (multiattrib
->treeview
),
943 /* nothing selected, nothing to do */
947 gtk_tree_model_get (model
, &iter
,
948 COLUMN_ATTRIBUTE
, &o_attrib
,
950 g_assert (o_attrib
->type
== OBJ_TEXT
);
952 multiattrib_action_delete_attribute (GSCHEM_DIALOG (multiattrib
)->toplevel
,
955 /* update the treeview contents */
956 multiattrib_update (multiattrib
);
962 /*! \todo Finish function documentation
964 * \par Function Description
967 static gboolean
multiattrib_callback_button_pressed(GtkWidget
*widget
,
968 GdkEventButton
*event
,
971 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
972 gboolean ret
= FALSE
;
974 if (event
->type
== GDK_BUTTON_PRESS
&& event
->button
== 3) {
975 multiattrib_popup_menu (multiattrib
, event
);
982 /*! \todo Finish function documentation
984 * \par Function Description
987 static gboolean
multiattrib_callback_popup_menu(GtkWidget
*widget
,
990 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
992 multiattrib_popup_menu (multiattrib
, NULL
);
997 /*! \todo Finish function documentation
999 * \par Function Description
1002 static void multiattrib_callback_popup_duplicate(GtkMenuItem
*menuitem
,
1005 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
1006 GtkTreeModel
*model
;
1009 OBJECT
*object
, *o_attrib
;
1011 if (!gtk_tree_selection_get_selected (
1012 gtk_tree_view_get_selection (multiattrib
->treeview
),
1014 /* nothing selected, nothing to do */
1018 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
1019 object
= multiattrib
->object
;
1021 gtk_tree_model_get (model
, &iter
,
1022 COLUMN_ATTRIBUTE
, &o_attrib
,
1024 g_assert (o_attrib
->type
== OBJ_TEXT
);
1026 multiattrib_action_duplicate_attribute (toplevel
, object
, o_attrib
);
1028 /* update the treeview contents */
1029 multiattrib_update (multiattrib
);
1033 /*! \todo Finish function documentation
1035 * \par Function Description
1038 static void multiattrib_callback_popup_delete(GtkMenuItem
*menuitem
,
1041 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
1042 GtkTreeModel
*model
;
1047 if (!gtk_tree_selection_get_selected (
1048 gtk_tree_view_get_selection (multiattrib
->treeview
),
1050 /* nothing selected, nothing to do */
1054 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
1056 gtk_tree_model_get (model
, &iter
,
1057 COLUMN_ATTRIBUTE
, &o_attrib
,
1059 g_assert (o_attrib
->type
== OBJ_TEXT
);
1061 multiattrib_action_delete_attribute (toplevel
, o_attrib
);
1063 /* update the treeview contents */
1064 multiattrib_update (multiattrib
);
1068 /*! \todo Finish function documentation
1070 * \par Function Description
1073 static gboolean
multiattrib_callback_value_key_pressed(GtkWidget
*widget
,
1077 Multiattrib
*multiattrib
= (Multiattrib
*)widget
;
1078 gboolean retval
= FALSE
;
1080 /* ends editing of cell if one of these keys are pressed: */
1081 /* - the Return key without the Control modifier */
1082 /* - the Tab key without the Control modifier */
1083 if ((event
->keyval
== GDK_Return
|| event
->keyval
== GDK_KP_Enter
) ||
1084 (event
->keyval
== GDK_Tab
|| event
->keyval
== GDK_KP_Tab
)) {
1085 /* Control modifier activated? */
1086 if (event
->state
& GDK_CONTROL_MASK
) {
1087 /* yes the modifier in event structure and let event propagate */
1088 event
->state
^= GDK_CONTROL_MASK
;
1091 /* change focus and stop propagation */
1092 g_signal_emit_by_name (multiattrib
,
1094 (event
->state
& GDK_SHIFT_MASK
) ?
1095 GTK_DIR_TAB_BACKWARD
: GTK_DIR_TAB_FORWARD
);
1104 /*! \brief GtkWidget "grab-focus" signal handler
1106 * \par Function Description
1107 * Select the text in the GtkTextView so it may be over-typed quickly
1109 static void multiattrib_callback_value_grab_focus (GtkWidget
*widget
,
1112 GtkTextView
*textview
= GTK_TEXT_VIEW (widget
);
1113 GtkTextBuffer
*textbuffer
;
1114 GtkTextIter startiter
, enditer
;
1116 textbuffer
= gtk_text_view_get_buffer (textview
);
1117 gtk_text_buffer_get_iter_at_offset (textbuffer
, &startiter
, 0);
1118 gtk_text_buffer_get_iter_at_offset (textbuffer
, &enditer
, -1);
1119 gtk_text_buffer_select_range (textbuffer
, &enditer
, &startiter
);
1123 /*! \todo Finish function documentation
1125 * \par Function Description
1128 static void multiattrib_callback_button_add(GtkButton
*button
,
1131 Multiattrib
*multiattrib
= (Multiattrib
*)user_data
;
1132 GtkTextBuffer
*buffer
;
1133 GtkTextIter start
, end
;
1141 toplevel
= GSCHEM_DIALOG (multiattrib
)->toplevel
;
1142 object
= multiattrib
->object
;
1143 buffer
= gtk_text_view_get_buffer (multiattrib
->textview_value
);
1145 /* retrieve information from the Add/Edit frame */
1146 /* - attribute's name */
1147 name
= gtk_entry_get_text (
1148 GTK_ENTRY (GTK_COMBO (multiattrib
->combo_name
)->entry
));
1149 /* - attribute's value */
1150 gtk_text_buffer_get_bounds (buffer
, &start
, &end
);
1151 value
= gtk_text_buffer_get_text (buffer
, &start
, &end
, FALSE
);
1152 /* - attribute's visibility status */
1153 visible
= gtk_toggle_button_get_active (
1154 (GtkToggleButton
*)multiattrib
->button_visible
);
1155 /* - visibility type */
1156 shownv
= (gint
)gtk_option_menu_get_history (multiattrib
->optionmenu_shownv
);
1158 if (name
[0] == '\0' || name
[0] == ' ') {
1159 /* name not allowed for an attribute */
1164 multiattrib_action_add_attribute (toplevel
, object
,
1169 multiattrib_update (multiattrib
);
1172 /*! \todo Finish function documentation
1174 * \par Function Description
1177 static void multiattrib_init_attrib_names(GtkCombo
*combo
)
1179 GList
*items
= NULL
;
1180 const gchar
*string
;
1183 for (i
= 0, string
= s_attrib_get (i
);
1185 i
++, string
= s_attrib_get (i
)) {
1186 items
= g_list_append (items
, (gpointer
)string
);
1189 gtk_combo_set_popdown_strings (GTK_COMBO (combo
), items
);
1191 g_list_free (items
);
1195 /*! \todo Finish function documentation
1197 * \par Function Description
1200 static void multiattrib_init_visible_types(GtkOptionMenu
*optionmenu
)
1202 GtkWidget
*menu
, *item
;
1204 menu
= gtk_menu_new ();
1205 item
= gtk_menu_item_new_with_label (_("Show Name & Value"));
1206 gtk_menu_append (menu
, item
);
1207 item
= gtk_menu_item_new_with_label (_("Show Value only"));
1208 gtk_menu_append (menu
, item
);
1209 item
= gtk_menu_item_new_with_label (_("Show Name only"));
1210 gtk_menu_append (menu
, item
);
1212 gtk_option_menu_set_menu (optionmenu
, menu
);
1217 /*! \brief Popup a context-sensitive menu.
1218 * \par Function Description
1219 * Pops up a context-sensitive menu.
1220 * <B>event</B> can be NULL if the popup is triggered by a key binding
1221 * instead of a mouse click.
1223 * \param [in] multiattrib The Multiattrib object.
1224 * \param [in] event Mouse event.
1226 static void multiattrib_popup_menu(Multiattrib
*multiattrib
,
1227 GdkEventButton
*event
)
1235 struct menuitem_t menuitems
[] = {
1236 { N_("Duplicate"), G_CALLBACK (multiattrib_callback_popup_duplicate
) },
1237 { N_("Delete"), G_CALLBACK (multiattrib_callback_popup_delete
) },
1239 struct menuitem_t
*tmp
;
1241 if (event
!= NULL
&&
1242 gtk_tree_view_get_path_at_pos (multiattrib
->treeview
,
1245 &path
, NULL
, NULL
, NULL
)) {
1246 GtkTreeSelection
*selection
;
1247 selection
= gtk_tree_view_get_selection (multiattrib
->treeview
);
1248 gtk_tree_selection_unselect_all (selection
);
1249 gtk_tree_selection_select_path (selection
, path
);
1250 gtk_tree_path_free (path
);
1253 /* create the context menu */
1254 menu
= gtk_menu_new();
1255 for (tmp
= menuitems
; tmp
->label
!= NULL
; tmp
++) {
1256 GtkWidget
*menuitem
;
1257 if (g_strcasecmp (tmp
->label
, "-") == 0) {
1258 menuitem
= gtk_separator_menu_item_new ();
1260 menuitem
= gtk_menu_item_new_with_label (_(tmp
->label
));
1261 g_signal_connect (menuitem
,
1266 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), menuitem
);
1268 gtk_widget_show_all (menu
);
1269 /* make menu a popup menu */
1270 gtk_menu_popup (GTK_MENU (menu
), NULL
, NULL
, NULL
, NULL
,
1271 (event
!= NULL
) ? event
->button
: 0,
1272 gdk_event_get_time ((GdkEvent
*)event
));
1277 /*! \brief Function to retrieve Multiattrib's GType identifier.
1279 * \par Function Description
1281 * Function to retrieve Multiattrib's GType identifier.
1282 * Upon first call, this registers Multiattrib in the GType system.
1283 * Subsequently it returns the saved value from its first execution.
1285 * \return the GType identifier associated with Multiattrib.
1287 GType
multiattrib_get_type()
1289 static GType multiattrib_type
= 0;
1291 if (!multiattrib_type
) {
1292 static const GTypeInfo multiattrib_info
= {
1293 sizeof(MultiattribClass
),
1294 NULL
, /* base_init */
1295 NULL
, /* base_finalize */
1296 (GClassInitFunc
) multiattrib_class_init
,
1297 NULL
, /* class_finalize */
1298 NULL
, /* class_data */
1299 sizeof(Multiattrib
),
1300 0, /* n_preallocs */
1301 (GInstanceInitFunc
) multiattrib_init
,
1304 multiattrib_type
= g_type_register_static (GSCHEM_TYPE_DIALOG
,
1306 &multiattrib_info
, 0);
1309 return multiattrib_type
;
1313 /*! \brief Update the multiattrib editor dialog when the page's selection changes.
1315 * \par Function Description
1317 * When the page's selection changes this function identifies how many objects
1318 * which can have attributes are currently selected. If this number is 1, the
1319 * dialog is set to edit its attributes.
1321 * \todo The dialog doesn't currently support editing multiple objects at once
1323 * \param [in] selection The SELECTION object of page being edited.
1324 * \param [in] multiattrib The multi-attribute editor dialog.
1326 static void selection_changed_cb (SELECTION
*selection
, Multiattrib
*multiattrib
)
1328 int object_count
= 0;
1329 GList
*selection_glist
;
1333 selection_glist
= geda_list_get_glist (selection
);
1335 for ( iter
= selection_glist
;
1337 iter
= g_list_next (iter
) ) {
1338 object
= (OBJECT
*)iter
->data
;
1339 g_assert( object
!= NULL
);
1341 if (object
->type
== OBJ_COMPLEX
||
1342 object
->type
== OBJ_PLACEHOLDER
||
1343 object
->type
== OBJ_NET
||
1344 object
->type
== OBJ_BUS
||
1345 object
->type
== OBJ_PIN
) {
1350 if (object_count
== 0) {
1351 /* TODO: If the user selects a single attribute which is
1352 * not floating, should we find its parent object and
1353 * display the multi-attribute editor for that?
1354 * Bonus marks for making it jump to the correct attrib.
1356 multiattrib
->object
= NULL
;
1357 } else if (object_count
== 1) {
1358 multiattrib
->object
= (OBJECT
*)selection_glist
->data
;
1360 /* TODO: Something clever with multiple objects selected */
1361 multiattrib
->object
= NULL
;
1364 multiattrib_update (multiattrib
);
1368 /*! \brief Update the dialog when the current page's SELECTION object is destroyed
1370 * \par Function Description
1372 * This handler is called when the g_object_weak_ref() on the SELECTION object
1373 * we're watching expires. We reset our multiattrib->selection pointer to NULL
1374 * to avoid attempting to access the destroyed object. NB: Our signal handlers
1375 * were automatically disconnected during the destruction process.
1377 * \param [in] data Pointer to the multi-attrib dialog
1378 * \param [in] where_the_object_was Pointer to where the object was just destroyed
1380 static void selection_weak_ref_cb (gpointer data
, GObject
*where_the_object_was
)
1382 Multiattrib
*multiattrib
= (Multiattrib
*)data
;
1384 multiattrib
->selection
= NULL
;
1385 multiattrib_update (multiattrib
);
1389 /*! \brief Connect signal handler and weak_ref on the SELECTION object
1391 * \par Function Description
1393 * Connect the "changed" signal and add a weak reference
1394 * on the SELECTION object we are going to watch.
1396 * \param [in] multiattrib The Multiattrib dialog.
1397 * \param [in] selection The SELECTION object to watch.
1399 static void connect_selection( Multiattrib
*multiattrib
, SELECTION
*selection
)
1401 multiattrib
->selection
= selection
;
1402 if (multiattrib
->selection
!= NULL
) {
1403 g_object_weak_ref (G_OBJECT (multiattrib
->selection
),
1404 selection_weak_ref_cb
,
1406 multiattrib
->selection_changed_id
=
1407 g_signal_connect (G_OBJECT (multiattrib
->selection
),
1409 G_CALLBACK (selection_changed_cb
),
1411 /* Synthesise a selection changed update to refresh the view */
1412 selection_changed_cb (multiattrib
->selection
, multiattrib
);
1414 /* Call an update to set the sensitivities */
1415 multiattrib_update (multiattrib
);
1420 /*! \brief Disconnect signal handler and weak_ref on the SELECTION object
1422 * \par Function Description
1424 * If the dialog is watching a SELECTION object, disconnect the
1425 * "changed" signal and remove our weak reference on the object.
1427 * \param [in] multiattrib The Multiattrib dialog.
1429 static void disconnect_selection( Multiattrib
*multiattrib
)
1431 if (multiattrib
->selection
!= NULL
) {
1432 g_signal_handler_disconnect (multiattrib
->selection
,
1433 multiattrib
->selection_changed_id
);
1434 g_object_weak_unref(G_OBJECT( multiattrib
->selection
),
1435 selection_weak_ref_cb
,
1441 /*! \brief GObject finalise handler
1443 * \par Function Description
1445 * Just before the Multiattrib GObject is finalized, disconnect from
1446 * the SELECTION object being watched and then chain up to the parent
1447 * class's finalize handler.
1449 * \param [in] object The GObject being finalized.
1451 static void multiattrib_finalize (GObject
*object
)
1453 Multiattrib
*multiattrib
= MULTIATTRIB(object
);
1455 disconnect_selection( multiattrib
);
1456 G_OBJECT_CLASS (multiattrib_parent_class
)->finalize (object
);
1460 /*! \brief GType class initialiser for Multiattrib
1462 * \par Function Description
1464 * GType class initialiser for Multiattrib. We override our parent
1465 * virtual class methods as needed and register our GObject properties.
1467 * \param [in] klass The MultiattribClass we are initialising
1469 static void multiattrib_class_init(MultiattribClass
*klass
)
1471 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
1473 multiattrib_parent_class
= g_type_class_peek_parent (klass
);
1475 gobject_class
->set_property
= multiattrib_set_property
;
1476 gobject_class
->get_property
= multiattrib_get_property
;
1477 gobject_class
->finalize
= multiattrib_finalize
;
1479 g_object_class_install_property (
1480 gobject_class
, PROP_SELECTION
,
1481 g_param_spec_pointer ("selection",
1484 G_PARAM_READWRITE
));
1488 /*! \brief GType instance initialiser for Multiattrib
1490 * \par Function Description
1492 * GType instance initialiser for Multiattrib. Create
1493 * and setup the widgets which make up the dialog.
1495 * \param [in] dialog The Multiattrib we are initialising
1497 static void multiattrib_init(Multiattrib
*multiattrib
)
1499 GtkWidget
*frame
, *label
, *scrolled_win
, *treeview
;
1500 GtkWidget
*table
, *textview
, *combo
, *optionm
, *button
;
1501 GtkTreeModel
*store
;
1502 GtkCellRenderer
*renderer
;
1503 GtkTreeViewColumn
*column
;
1504 GtkTreeSelection
*selection
;
1507 /* dialog initialization */
1508 g_object_set (G_OBJECT (multiattrib
),
1512 "type", GTK_WINDOW_TOPLEVEL
,
1513 "title", _("Edit Attributes"),
1514 "default-width", 320,
1515 "default-height", 350,
1516 "window-position", GTK_WIN_POS_MOUSE
,
1518 "allow-shrink", FALSE
,
1520 "has-separator", TRUE
,
1523 multiattrib
->object
= NULL
;
1525 /* create the attribute list frame */
1526 frame
= GTK_WIDGET (g_object_new (GTK_TYPE_FRAME
,
1528 "label", _("Attributes"),
1530 multiattrib
->frame_add
= frame
;
1531 /* - create the model for the treeview */
1532 store
= (GtkTreeModel
*)gtk_list_store_new (NUM_COLUMNS
,
1533 G_TYPE_POINTER
); /* attribute */
1534 /* - create a scrolled window for the treeview */
1535 scrolled_win
= GTK_WIDGET (
1536 g_object_new (GTK_TYPE_SCROLLED_WINDOW
,
1539 /* GtkScrolledWindow */
1540 "hscrollbar-policy",
1541 GTK_POLICY_AUTOMATIC
,
1542 "vscrollbar-policy",
1543 GTK_POLICY_AUTOMATIC
,
1545 GTK_SHADOW_ETCHED_IN
,
1547 /* - create the treeview */
1548 treeview
= GTK_WIDGET (g_object_new (GTK_TYPE_TREE_VIEW
,
1553 g_signal_connect (treeview
,
1555 G_CALLBACK (multiattrib_callback_key_pressed
),
1557 g_signal_connect (treeview
,
1558 "button-press-event",
1559 G_CALLBACK (multiattrib_callback_button_pressed
),
1561 g_signal_connect (treeview
,
1563 G_CALLBACK (multiattrib_callback_popup_menu
),
1565 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview
));
1566 gtk_tree_selection_set_mode (selection
,
1567 GTK_SELECTION_SINGLE
);
1569 /* - and now the columns of the treeview */
1570 /* - column 1: attribute name */
1571 renderer
= GTK_CELL_RENDERER (
1572 g_object_new (GTK_TYPE_CELL_RENDERER_TEXT
,
1573 /* GtkCellRendererText */
1575 /* unknown in GTK 2.4 */
1577 * PANGO_ELLIPSIZE_END, */
1579 g_signal_connect (renderer
,
1581 G_CALLBACK (multiattrib_callback_edited_name
),
1583 column
= GTK_TREE_VIEW_COLUMN (
1584 g_object_new (GTK_TYPE_TREE_VIEW_COLUMN
,
1585 /* GtkTreeViewColumn */
1590 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
1591 gtk_tree_view_column_set_cell_data_func (column
, renderer
,
1592 multiattrib_column_set_data_name
,
1594 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
1595 /* - column 2: attribute value */
1596 renderer
= GTK_CELL_RENDERER (
1597 g_object_new (TYPE_CELL_RENDERER_MULTI_LINE_TEXT
,
1598 /* GtkCellRendererText */
1600 /* unknown in GTK 2.4 */
1602 PANGO_ELLIPSIZE_END, */
1604 g_signal_connect (renderer
,
1606 G_CALLBACK (multiattrib_callback_edited_value
),
1608 column
= GTK_TREE_VIEW_COLUMN (
1609 g_object_new (GTK_TYPE_TREE_VIEW_COLUMN
,
1610 /* GtkTreeViewColumn */
1611 "title", _("Value"),
1615 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
1616 gtk_tree_view_column_set_cell_data_func (column
, renderer
,
1617 multiattrib_column_set_data_value
,
1619 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
1620 /* - column 3: visibility */
1621 renderer
= GTK_CELL_RENDERER (
1622 g_object_new (GTK_TYPE_CELL_RENDERER_TOGGLE
,
1623 /* GtkCellRendererToggle */
1624 "activatable", TRUE
,
1626 g_signal_connect (renderer
,
1628 G_CALLBACK (multiattrib_callback_toggled_visible
),
1630 column
= GTK_TREE_VIEW_COLUMN (
1631 g_object_new (GTK_TYPE_TREE_VIEW_COLUMN
,
1632 /* GtkTreeViewColumn */
1635 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
1636 gtk_tree_view_column_set_cell_data_func (column
, renderer
,
1637 multiattrib_column_set_data_visible
,
1639 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
1640 /* - column 4: show name */
1641 renderer
= GTK_CELL_RENDERER (
1642 g_object_new (GTK_TYPE_CELL_RENDERER_TOGGLE
,
1643 /* GtkCellRendererToggle */
1644 "activatable", TRUE
,
1646 g_signal_connect (renderer
,
1648 G_CALLBACK (multiattrib_callback_toggled_show_name
),
1650 column
= GTK_TREE_VIEW_COLUMN (
1651 g_object_new (GTK_TYPE_TREE_VIEW_COLUMN
,
1652 /* GtkTreeViewColumn */
1655 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
1656 gtk_tree_view_column_set_cell_data_func (column
, renderer
,
1657 multiattrib_column_set_data_show_name
,
1659 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
1660 /* - column 5: show value */
1661 renderer
= GTK_CELL_RENDERER (
1662 g_object_new (GTK_TYPE_CELL_RENDERER_TOGGLE
,
1663 /* GtkCellRendererToggle */
1664 "activatable", TRUE
,
1666 g_signal_connect (renderer
,
1668 G_CALLBACK (multiattrib_callback_toggled_show_value
),
1670 column
= GTK_TREE_VIEW_COLUMN (
1671 g_object_new (GTK_TYPE_TREE_VIEW_COLUMN
,
1672 /* GtkTreeViewColumn */
1675 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
1676 gtk_tree_view_column_set_cell_data_func (column
, renderer
,
1677 multiattrib_column_set_data_show_value
,
1679 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview
), column
);
1681 /* add the treeview to the scrolled window */
1682 gtk_container_add (GTK_CONTAINER (scrolled_win
), treeview
);
1683 /* set treeview of multiattrib */
1684 multiattrib
->treeview
= GTK_TREE_VIEW (treeview
);
1685 /* add the scrolled window to frame */
1686 gtk_container_add (GTK_CONTAINER (frame
), scrolled_win
);
1687 /* pack the frame */
1688 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (multiattrib
)->vbox
), frame
,
1690 gtk_widget_show_all (frame
);
1692 /* create the add/edit frame */
1693 frame
= GTK_WIDGET (g_object_new (GTK_TYPE_FRAME
,
1694 "label", _("Add Attribute"),
1696 multiattrib
->frame_attributes
= frame
;
1697 table
= GTK_WIDGET (g_object_new (GTK_TYPE_TABLE
,
1701 "homogeneous", FALSE
,
1704 /* - the name entry: a GtkComboBoxEntry */
1705 label
= GTK_WIDGET (g_object_new (GTK_TYPE_LABEL
,
1710 "label", _("Name:"),
1712 combo
= GTK_WIDGET (g_object_new (GTK_TYPE_COMBO
,
1714 "value-in-list", FALSE
,
1716 multiattrib_init_attrib_names (GTK_COMBO (combo
));
1717 multiattrib
->combo_name
= GTK_COMBO (combo
);
1718 gtk_table_attach (GTK_TABLE (table
), label
,
1719 0, 1, 0, 1, 0, 0, 0, 0);
1720 gtk_table_attach (GTK_TABLE (table
), combo
,
1721 1, 2, 0, 1, GTK_EXPAND
| GTK_FILL
, 0, 6, 3);
1723 /* - the value entry: a GtkEntry */
1724 label
= GTK_WIDGET (g_object_new (GTK_TYPE_LABEL
,
1729 "label", _("Value:"),
1731 scrolled_win
= GTK_WIDGET (
1732 g_object_new (GTK_TYPE_SCROLLED_WINDOW
,
1733 /* GtkScrolledWindow */
1734 "hscrollbar-policy",
1736 "vscrollbar-policy",
1737 GTK_POLICY_AUTOMATIC
,
1741 textview
= GTK_WIDGET (g_object_new (GTK_TYPE_TEXT_VIEW
,
1743 g_signal_connect (textview
,
1745 G_CALLBACK (multiattrib_callback_value_key_pressed
),
1747 g_signal_connect (textview
,
1749 G_CALLBACK (multiattrib_callback_value_grab_focus
),
1751 /* Save the GTK_STATE_NORMAL color so we can work around GtkTextView's
1752 * stubborn refusal to draw with GTK_STATE_INSENSITIVE later on */
1753 style
= gtk_widget_get_style (textview
);
1754 multiattrib
->value_normal_text_color
= style
->text
[ GTK_STATE_NORMAL
];
1756 gtk_container_add (GTK_CONTAINER (scrolled_win
), textview
);
1757 multiattrib
->textview_value
= GTK_TEXT_VIEW (textview
);
1758 gtk_table_attach (GTK_TABLE (table
), label
,
1759 0, 1, 1, 2, 0, 0, 0, 0);
1760 gtk_table_attach (GTK_TABLE (table
), scrolled_win
,
1761 1, 2, 1, 2, GTK_EXPAND
| GTK_FILL
, 0, 6, 3);
1763 /* - the visible status */
1764 button
= GTK_WIDGET (g_object_new (GTK_TYPE_CHECK_BUTTON
,
1766 "label", _("Visible"),
1769 multiattrib
->button_visible
= GTK_CHECK_BUTTON (button
);
1770 gtk_table_attach (GTK_TABLE (table
), button
,
1771 0, 1, 2, 3, GTK_FILL
, 0, 3, 0);
1773 /* - the visibility type */
1774 optionm
= GTK_WIDGET (g_object_new (GTK_TYPE_OPTION_MENU
,
1776 multiattrib_init_visible_types (GTK_OPTION_MENU (optionm
));
1777 multiattrib
->optionmenu_shownv
= GTK_OPTION_MENU (optionm
);
1778 gtk_table_attach (GTK_TABLE (table
), optionm
,
1779 1, 2, 2, 3, GTK_EXPAND
| GTK_FILL
, 0, 6, 3);
1780 gtk_widget_show_all (table
);
1782 /* create the add button */
1783 button
= gtk_button_new_from_stock (GTK_STOCK_ADD
);
1784 g_signal_connect (button
,
1786 G_CALLBACK (multiattrib_callback_button_add
),
1788 gtk_table_attach (GTK_TABLE (table
), button
,
1789 2, 3, 0, 3, 0, 0, 6, 3);
1791 /* add the table to the frame */
1792 gtk_container_add (GTK_CONTAINER (frame
), table
);
1793 /* pack the frame in the dialog */
1794 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (multiattrib
)->vbox
), frame
,
1796 gtk_widget_show_all (frame
);
1799 /* now add the close button to the action area */
1800 gtk_dialog_add_button (GTK_DIALOG (multiattrib
),
1801 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
);
1806 /*! \brief GObject property setter function
1808 * \par Function Description
1809 * Setter function for Multiattrib's GObject property, "selection".
1811 * \param [in] object The GObject whose properties we are setting
1812 * \param [in] property_id The numeric id. under which the property was
1813 * registered with g_object_class_install_property()
1814 * \param [in] value The GValue the property is being set from
1815 * \param [in] pspec A GParamSpec describing the property being set
1818 static void multiattrib_set_property (GObject
*object
,
1820 const GValue
*value
,
1823 Multiattrib
*multiattrib
= MULTIATTRIB (object
);
1825 switch(property_id
) {
1826 case PROP_SELECTION
:
1827 disconnect_selection (multiattrib
);
1828 connect_selection (multiattrib
, g_value_get_pointer (value
));
1831 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
1836 /*! \brief GObject property getter function
1838 * \par Function Description
1839 * Getter function for Multiattrib's GObject property, "selection".
1841 * \param [in] object The GObject whose properties we are getting
1842 * \param [in] property_id The numeric id. under which the property was
1843 * registered with g_object_class_install_property()
1844 * \param [out] value The GValue in which to return the value of the property
1845 * \param [in] pspec A GParamSpec describing the property being got
1847 static void multiattrib_get_property (GObject
*object
,
1852 Multiattrib
*multiattrib
= MULTIATTRIB (object
);
1854 switch(property_id
) {
1855 case PROP_SELECTION
:
1856 g_value_set_pointer (value
, (gpointer
)multiattrib
->selection
);
1859 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
1865 /*! \brief Update the multiattrib editor dialog's interface
1867 * \par Function Description
1869 * Update the dialog to reflect the attributes of the currently selected
1870 * object. If no (or multiple) objects are selected, the dialog's controls
1871 * are set insensitive.
1873 * \todo The dialog doesn't currently support editing multiple objects at once
1875 * \param [in] multiattrib The multi-attribute editor dialog.
1877 void multiattrib_update (Multiattrib
*multiattrib
)
1879 GtkListStore
*liststore
;
1881 OBJECT
**object_attribs
, *o_current
;
1886 g_assert (GSCHEM_DIALOG (multiattrib
)->toplevel
!= NULL
);
1888 /* clear the list of attributes */
1889 liststore
= (GtkListStore
*)gtk_tree_view_get_model (multiattrib
->treeview
);
1890 gtk_list_store_clear (liststore
);
1892 /* Update sensitivities */
1893 sensitive
= (multiattrib
->selection
!= NULL
&& multiattrib
->object
!= NULL
);
1894 gtk_widget_set_sensitive (GTK_WIDGET (multiattrib
->frame_attributes
), sensitive
);
1895 gtk_widget_set_sensitive (GTK_WIDGET (multiattrib
->frame_add
), sensitive
);
1897 /* Work around GtkTextView's stubborn indifference
1898 * to GTK_STATE_INSENSITIVE when rendering its text. */
1899 style
= gtk_widget_get_style (GTK_WIDGET (multiattrib
->textview_value
));
1900 gtk_widget_modify_text (GTK_WIDGET (multiattrib
->textview_value
),
1902 sensitive
? &multiattrib
->value_normal_text_color
1903 : &style
->text
[GTK_STATE_INSENSITIVE
]);
1905 /* If we aren't sensitive, there is nothing more to do */
1909 /* get list of attributes */
1910 object_attribs
= o_attrib_return_attribs (
1911 GSCHEM_DIALOG (multiattrib
)->toplevel
->page_current
->object_head
,
1912 multiattrib
->object
);
1913 /* populate the store with attributes */
1914 if (object_attribs
) {
1915 for (i
= 0, o_current
= object_attribs
[i
];
1917 i
++, o_current
= object_attribs
[i
]) {
1918 gtk_list_store_append (liststore
, &iter
);
1919 gtk_list_store_set (liststore
, &iter
,
1920 COLUMN_ATTRIBUTE
, o_current
,
1924 /* delete the list of attribute objects */
1925 o_attrib_free_returned (object_attribs
);