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
33 #include <gdk/gdkkeysyms.h>
37 #ifdef HAVE_LIBDMALLOC
41 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
42 g_object_set_data_full (G_OBJECT (component), name, \
43 gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
45 /** @brief How many entries to keep in the "Search text" combo box. */
46 #define HISTORY_LENGTH 15
48 /* autonumber text structs and enums */
50 AUTONUMBER_SORT_DIAGONAL
,
52 AUTONUMBER_SORT_YX_REV
,
54 AUTONUMBER_SORT_XY_REV
,
70 typedef struct autonumber_text_t AUTONUMBER_TEXT
;
72 /** @brief Stored state of the autonumber text dialog */
73 struct autonumber_text_t
{
74 /** @brief Search text history */
77 /** @brief Scope for searching existing numbers */
80 /** @brief Scope for autonumbering text */
83 /** @brief Overwrite existing numbers in scope */
84 gboolean scope_overwrite
;
86 /** @brief Sort order */
89 /** @brief Starting number for automatic numbering */
92 /** @brief Remove numbers instead of automatic numbering */
95 /** @brief Automatic assignments of slots */
98 /** @brief Pointer to the dialog */
101 /** @brief Pointer to the GSCHEM_TOPLEVEL struct */
102 GSCHEM_TOPLEVEL
*w_current
;
104 /* variables used while autonumbering */
105 gchar
* current_searchtext
;
106 gint root_page
; /* flag whether its the root page or not */
107 GList
*used_numbers
; /* list of used numbers */
108 GList
*free_slots
; /* list of FREE_SLOT objects */
109 GList
*used_slots
; /* list of USED_SLOT objects */
112 typedef struct autonumber_slot_t AUTONUMBER_SLOT
;
114 struct autonumber_slot_t
{
115 gchar
*symbolname
; /* or should I use the device name? (Werner) */
116 gint number
; /* usually this is the refdes number */
117 gint slotnr
; /* just the number of the free slot */
122 /* ***** BACK-END CODE ***************************************************** */
124 /********** compare functions for g_list_sort, ... ***********************/
125 /*! \brief GCompareFunc function to sort a list with g_list_sort().
126 * \par Function Description
127 * Compares the integer values of the gconstpointers a and b.
128 * \return -1 if a<b, 1 if a>b, 0 if a==b
130 gint
autonumber_sort_numbers(gconstpointer a
, gconstpointer b
) {
131 if (GPOINTER_TO_INT(a
) < GPOINTER_TO_INT(b
))
133 if (GPOINTER_TO_INT(a
) > GPOINTER_TO_INT(b
))
138 /*! \brief GCompareFunc function to sort text objects by there location
139 * \par Function Description
140 * This Function takes two <B>OBJECT*</B> arguments and compares the
141 * location of the two text objects. The first sort criteria is the x location,
142 * the second sort criteria is the y location.
143 * The Function is used as GCompareFunc by g_list_sort().
145 gint
autonumber_sort_xy(gconstpointer a
, gconstpointer b
) {
146 OBJECT
const *aa
, *bb
;
148 if (aa
->text
->x
< bb
->text
->x
)
150 if (aa
->text
->x
> bb
->text
->x
)
153 if (aa
->text
->y
> bb
->text
->y
)
155 if (aa
->text
->y
< bb
->text
->y
)
160 /*! \brief GCompareFunc function to sort text objects by there location
161 * \par Function Description
162 * This function takes two <B>OBJECT*</B> arguments and compares the
163 * location of the two text objects. The first sort criteria is the x location,
164 * the second sort criteria is the y location.
165 * This function sorts the objects in reverse order.
166 * The function is used as GCompareFunc by g_list_sort().
168 gint
autonumber_sort_xy_rev(gconstpointer a
, gconstpointer b
) {
169 OBJECT
const *aa
, *bb
;
171 if (aa
->text
->x
< bb
->text
->x
)
173 if (aa
->text
->x
> bb
->text
->x
)
176 if (aa
->text
->y
< bb
->text
->y
)
178 if (aa
->text
->y
> bb
->text
->y
)
183 /*! \brief GCompareFunc function to sort text objects by there location
184 * \par Function Description
185 * This function takes two <B>OBJECT*</B> arguments and compares the
186 * location of the two text objects. The first sort criteria is the y location,
187 * the second sort criteria is the x location.
188 * The function is used as GCompareFunc by g_list_sort().
190 int autonumber_sort_yx(gconstpointer a
, gconstpointer b
) {
191 OBJECT
const *aa
, *bb
;
193 if (aa
->text
->y
> bb
->text
->y
)
195 if (aa
->text
->y
< bb
->text
->y
)
198 if (aa
->text
->x
< bb
->text
->x
)
200 if (aa
->text
->x
> bb
->text
->x
)
205 /*! \brief GCompareFunc function to sort text objects by there location
206 * \par Function Description
207 * This Function takes two <B>OBJECT*</B> arguments and compares the
208 * location of the two text objects. The first sort criteria is the y location,
209 * the second sort criteria is the x location.
210 * This function sorts the objects in reverse order.
211 * The function is used as GCompareFunc by g_list_sort().
213 int autonumber_sort_yx_rev(gconstpointer a
, gconstpointer b
) {
214 OBJECT
const *aa
, *bb
;
216 if (aa
->text
->y
> bb
->text
->y
)
218 if (aa
->text
->y
< bb
->text
->y
)
221 if (aa
->text
->x
> bb
->text
->x
)
223 if (aa
->text
->x
< bb
->text
->x
)
228 /*! \brief GCompareFunc function to sort text objects by there location
229 * \par Function Description
230 * This Function takes two <B>OBJECT*</B> arguments and compares the
231 * location of the two text objects. The sort criteria is the combined x- and the
232 * y-location. The function sorts from top left to bottom right.
233 * The function is used as GCompareFunc by g_list_sort().
235 int autonumber_sort_diagonal(gconstpointer a
, gconstpointer b
) {
236 OBJECT
const *aa
, *bb
;
238 if (aa
->text
->x
- aa
->text
->y
< bb
->text
->x
- bb
->text
->y
)
240 if (aa
->text
->x
- aa
->text
->y
> bb
->text
->x
- bb
->text
->y
)
245 /*! \brief GCompareFunc function to access <B>AUTONUMBER_SLOT</B> object in a GList
246 * \par Function Description
247 * This Function takes two <B>AUTONUMBER_SLOT*</B> arguments and compares them.
248 * Sorting criteria is are the AUTONUMBER_SLOT members: first the symbolname, than the
249 * number and last the slotnr.
250 * If the number or the slotnr is set to zero it acts as a wildcard.
251 * The function is used as GCompareFunc by GList functions.
253 gint
freeslot_compare(gconstpointer a
, gconstpointer b
)
255 AUTONUMBER_SLOT
const *aa
, *bb
;
259 if ((res
= strcmp(aa
->symbolname
, bb
->symbolname
)) != 0)
262 /* aa->symbolname == bb->symbolname */
263 if (aa
->number
== 0 || bb
->number
== 0)
265 if (aa
->number
> bb
->number
)
267 if (aa
->number
< bb
->number
)
270 /* aa->number == bb->number */
271 if (aa
->slotnr
== 0 || bb
->slotnr
== 0)
273 if (aa
->slotnr
> bb
->slotnr
)
275 if (aa
->slotnr
< bb
->slotnr
)
281 /*! \brief Prints a <B>GList</B> of <B>AUTONUMBER_SLOT</B> elements
282 * \par Function Description
283 * This function prints the elements of a GList that contains <B>AUTONUMBER_SLOT</B> elements
284 * It is only used for debugging purposes.
286 void freeslot_print(GList
*list
) {
290 printf("freeslot_print(): symname, number, slot\n");
291 for (item
= list
; item
!= NULL
; item
= g_list_next(item
)) {
293 printf(" %s, %d, %d\n",fs
->symbolname
, fs
->number
, fs
->slotnr
);
298 /*! \brief Function to clear the databases of used parts
299 * \par Function Descriptions
300 * Just remove the list of used numbers, used slots and free slots.
302 void autonumber_clear_database (AUTONUMBER_TEXT
*autotext
)
304 /* cleanup everything for the next searchtext */
305 if (autotext
->used_numbers
!= NULL
) {
306 g_list_free(autotext
->used_numbers
);
307 autotext
->used_numbers
= NULL
;
309 if (autotext
->free_slots
!= NULL
) {
310 g_list_foreach(autotext
->free_slots
, (GFunc
) g_free
, NULL
);
311 g_list_free(autotext
->free_slots
);
312 autotext
->free_slots
= NULL
;
314 if (autotext
->used_slots
!= NULL
) {
315 g_list_foreach(autotext
->used_slots
, (GFunc
) g_free
, NULL
);
316 g_list_free(autotext
->used_slots
);
317 autotext
->used_slots
= NULL
;
321 /*! \brief Function to test, whether the OBJECT matches the autotext criteria
322 * \par Function Description
323 * The criteria are those of the autonumber text dialog. The function decides
324 * whether the <B>OBJECT</B> has to be renumberd, ignored or taken care of when
325 * renumbering all other objects.
326 * \return one of these integer values: <B>AUTONUMBER_IGNORE</B>,
327 * <B>AUTONUMBER_RESPECT</B> or <B>AUTONUMBER_RENUMBER</B> and the current number
328 * of the text object in <B>*number</B>.
330 gint
autonumber_match(AUTONUMBER_TEXT
*autotext
, OBJECT
*o_current
, gint
*number
)
332 gint i
, len
, isnumbered
=1;
333 const gchar
*str
= NULL
;
335 len
= strlen(autotext
->current_searchtext
);
336 /* first find out whether we can ignore that object */
337 if (o_current
->type
!= OBJ_TEXT
) /* text object */
338 return AUTONUMBER_IGNORE
;
340 str
= o_text_get_string(o_current
);
342 if (!(strlen(str
) - len
> 0)
343 || !g_str_has_prefix(str
, autotext
->current_searchtext
))
344 return AUTONUMBER_IGNORE
;
346 /* the string object matches with its leading characters to the searchtext */
347 /* now look for the extension, either a number or the "?" */
348 if (g_str_has_suffix (str
,"?")) {
350 /* There must not be any character between the "?" and the searchtext */
351 if (strlen(str
) != len
+1)
352 return AUTONUMBER_IGNORE
;
355 if (!isdigit( (int) (str
[len
]) )) /* has at least one digit */
356 return AUTONUMBER_IGNORE
;
358 for (i
=len
+1; str
[i
]; i
++) /* and only digits */
359 if (!isdigit( (int) (str
[i
]) ))
360 return AUTONUMBER_IGNORE
;
363 /* we have six cases, 3 from focus multiplied by 2 selection cases */
364 if ((autotext
->root_page
|| autotext
->scope_number
== SCOPE_HIERARCHY
)
365 && (o_current
->selected
366 || autotext
->scope_number
== SCOPE_HIERARCHY
|| autotext
->scope_number
== SCOPE_PAGE
)
367 && (!isnumbered
|| (autotext
->scope_overwrite
)))
368 return AUTONUMBER_RENUMBER
;
371 && !(autotext
->scope_skip
== SCOPE_SELECTED
372 && !(o_current
->selected
) && autotext
->root_page
)) {
373 sscanf(&(str
[len
])," %d", number
);
374 return AUTONUMBER_RESPECT
; /* numbered objects which we don't renumber */
377 return AUTONUMBER_IGNORE
; /* unnumbered objects outside the focus */
381 /*! \brief Creates a list of already numbered objects and slots
382 * \par Function Description
383 * This function collects the used numbers of a single schematic page.
384 * The used element numbers are stored in a GList container
385 * inside the <B>AUTONUMBER_TEXT</B> struct.
386 * The slotting container is a little bit different. It stores free slots of
387 * multislotted symbols, that were used only partially.
388 * The criteria are derived from the autonumber dialog entries.
390 void autonumber_get_used(GSCHEM_TOPLEVEL
*w_current
, AUTONUMBER_TEXT
*autotext
)
392 gint number
, numslots
, slotnr
, i
;
393 OBJECT
*o_current
, *o_parent
, *o_numslots
;
394 AUTONUMBER_SLOT
*slot
;
396 char *numslot_str
, *slot_str
;
398 for (o_current
= w_current
->toplevel
->page_current
->object_head
; o_current
!= NULL
;
399 o_current
= o_current
->next
) {
400 if (autonumber_match(autotext
, o_current
, &number
) == AUTONUMBER_RESPECT
) {
401 /* check slot and maybe add it to the lists */
402 o_parent
= o_current
->attached_to
;
403 if (autotext
->slotting
&& o_parent
!= NULL
) {
404 /* check for slotted symbol */
405 if ((numslot_str
= o_attrib_search_numslots(o_parent
, &o_numslots
)) != NULL
) {
406 sscanf(numslot_str
," %d",&numslots
);
410 slot_str
=o_attrib_search_attrib_name(o_parent
->attribs
,"slot",0);
411 if (slot_str
== NULL
) {
412 s_log_message(_("slotted object without slot attribute may cause "
413 "problems when autonumbering slots\n"));
416 sscanf(slot_str
, " %d", &slotnr
);
417 slot
= g_new(AUTONUMBER_SLOT
,1);
418 slot
->number
= number
;
419 slot
->slotnr
= slotnr
;
420 slot
->symbolname
= o_parent
->complex_basename
;
423 slot_item
= g_list_find_custom(autotext
->used_slots
,
425 (GCompareFunc
) freeslot_compare
);
426 if (slot_item
!= NULL
) { /* duplicate slot in used_slots */
427 s_log_message(_("duplicate slot may cause problems: "
428 "[symbolname=%s, number=%d, slot=%d]\n"),
429 slot
->symbolname
, slot
->number
, slot
->slotnr
);
433 autotext
->used_slots
= g_list_insert_sorted(autotext
->used_slots
,
435 (GCompareFunc
) freeslot_compare
);
437 slot_item
= g_list_find_custom(autotext
->free_slots
,
439 (GCompareFunc
) freeslot_compare
);
440 if (slot_item
== NULL
) {
441 /* insert all slots to the list, except of the current one */
442 for (i
=1; i
<= numslots
; i
++) {
444 slot
= g_memdup(slot
, sizeof(AUTONUMBER_SLOT
));
446 autotext
->free_slots
= g_list_insert_sorted(autotext
->free_slots
,
448 (GCompareFunc
) freeslot_compare
);
453 g_free(slot_item
->data
);
454 autotext
->free_slots
= g_list_delete_link(autotext
->free_slots
, slot_item
);
461 /* put number into the used list */
462 autotext
->used_numbers
= g_list_insert_sorted(autotext
->used_numbers
,
463 GINT_TO_POINTER(number
),
464 (GCompareFunc
) autonumber_sort_numbers
);
470 /*! \brief Gets or generates free numbers for the autonumbering process.
471 * \par Function Description
472 * This function gets or generates new numbers for the <B>OBJECT o_current</B>.
473 * It uses the element numbers <B>used_numbers</B> and the list of the free slots
474 * <B>free_slots</B> of the <B>AUTONUMBER_TEXT</B> struct.
476 * The new number is returned into the <B>number</B> parameter.
477 * <B>slot</B> is set if autoslotting is active, else it is set to zero.
479 void autonumber_get_new_numbers(AUTONUMBER_TEXT
*autotext
, OBJECT
*o_current
,
480 gint
*number
, gint
*slot
)
483 gint new_number
, numslots
, i
;
484 AUTONUMBER_SLOT
*freeslot
;
485 OBJECT
*o_parent
= NULL
, *o_numslots
;
486 GList
*freeslot_item
;
489 new_number
= autotext
->startnum
;
491 /* Check for slots first */
492 /* 1. are there any unused slots in the database? */
493 o_parent
= o_current
->attached_to
;
494 if (autotext
->slotting
&& o_parent
!= NULL
) {
495 freeslot
= g_new(AUTONUMBER_SLOT
,1);
496 freeslot
->symbolname
= o_parent
->complex_basename
;
497 freeslot
->number
= 0;
498 freeslot
->slotnr
= 0;
499 freeslot_item
= g_list_find_custom(autotext
->free_slots
,
501 (GCompareFunc
) freeslot_compare
);
503 /* Yes! -> remove from database, apply it */
504 if (freeslot_item
!= NULL
) {
505 freeslot
= freeslot_item
->data
;
506 *number
= freeslot
->number
;
507 *slot
= freeslot
->slotnr
;
509 autotext
->free_slots
= g_list_delete_link(autotext
->free_slots
, freeslot_item
);
515 /* get a new number */
516 item
= autotext
->used_numbers
;
518 while (item
!= NULL
&& GPOINTER_TO_INT(item
->data
) < new_number
)
519 item
= g_list_next(item
);
521 if (item
== NULL
|| GPOINTER_TO_INT(item
->data
) > new_number
)
523 else /* new_number == item->data */
526 *number
= new_number
;
529 /* insert the new number to the used list */
530 autotext
->used_numbers
= g_list_insert_sorted(autotext
->used_numbers
,
531 GINT_TO_POINTER(new_number
),
532 (GCompareFunc
) autonumber_sort_numbers
);
534 /* 3. is o_current a slotted object ? */
535 if ((autotext
->slotting
) && o_parent
!= NULL
) {
536 if ((numslot_str
= o_attrib_search_numslots(o_parent
, &o_numslots
)) != NULL
) {
537 sscanf(numslot_str
," %d",&numslots
);
540 /* Yes! -> new number and slot=1; add the other slots to the database */
542 for (i
=2; i
<=numslots
; i
++) {
543 freeslot
= g_new(AUTONUMBER_SLOT
,1);
544 freeslot
->symbolname
= o_parent
->complex_basename
;
545 freeslot
->number
= new_number
;
546 freeslot
->slotnr
= i
;
547 autotext
->free_slots
= g_list_insert_sorted(autotext
->free_slots
,
549 (GCompareFunc
) freeslot_compare
);
556 /** @brief Removes the number from the element.
558 * This function updates the text content of the \a o_current object.
560 * @param autotext Pointer to the state structure
561 * @param o_current Pointer to the object from which to remove the number
564 void autonumber_remove_number(AUTONUMBER_TEXT
* autotext
, OBJECT
*o_current
)
566 OBJECT
*o_parent
, *o_slot
;
570 /* replace old text */
571 str
= g_strdup_printf("%s?", autotext
->current_searchtext
);
572 o_text_set_string(o_current
, str
);
575 /* redraw the text */
576 o_erase_single(autotext
->w_current
, o_current
);
577 o_text_recreate(o_current
);
578 o_text_draw(autotext
->w_current
, o_current
);
580 /* remove the slot attribute if slotting is active */
581 if (autotext
->slotting
) {
582 /* get the slot attribute */
583 o_parent
= o_current
->attached_to
;
584 if (o_parent
!= NULL
) {
585 slot_str
= o_attrib_search_slot(o_parent
, &o_slot
);
586 if (slot_str
!= NULL
&& o_slot
!= NULL
) {
588 /* delete the slot attribute */
589 o_selection_remove (autotext
->w_current
->toplevel
->page_current
->selection_list
, o_slot
);
590 o_delete (autotext
->w_current
, o_slot
);
594 autotext
->w_current
->toplevel
->page_current
->CHANGED
= 1;
597 /*! \brief Changes the number <B>OBJECT</B> element. Changes the slot attribute.
598 * \par Function Description
599 * This function updates the text content of the <B>o_current</B> object.
600 * If the <B>slot</B> value is not zero. It updates the slot attribute of the
601 * complex element that is also the parent object of the o_current element.
603 void autonumber_apply_new_text(AUTONUMBER_TEXT
* autotext
, OBJECT
*o_current
,
604 gint number
, gint slot
)
606 OBJECT
*o_parent
, *o_slot
;
610 /* add the slot as attribute to the object */
611 o_parent
= o_current
->attached_to
;
612 if (slot
!= 0 && o_parent
!= NULL
) {
613 slot_str
= o_attrib_search_slot(o_parent
, &o_slot
);
614 if (slot_str
!= NULL
) {
615 /* update the slot attribute */
617 slot_str
= g_strdup_printf("slot=%d",slot
);
618 o_text_set_string(o_slot
, slot_str
);
620 o_erase_single(autotext
->w_current
, o_slot
);
621 o_text_recreate(o_slot
);
622 o_text_draw(autotext
->w_current
, o_slot
);
625 /* create a new attribute and attach it */
626 o_attrib_add_attrib(autotext
->w_current
,
627 g_strdup_printf("slot=%d",slot
),
628 INVISIBLE
, SHOW_NAME_VALUE
,
631 o_attrib_slot_update(autotext
->w_current
->toplevel
, o_parent
);
634 /* replace old text */
635 str
= g_strdup_printf("%s%d", autotext
->current_searchtext
, number
);
636 o_text_set_string(o_current
, str
);
639 /* redraw the text */
640 o_erase_single(autotext
->w_current
, o_current
);
641 o_text_recreate(o_current
);
642 o_text_draw(autotext
->w_current
, o_current
);
643 autotext
->w_current
->toplevel
->page_current
->CHANGED
= 1;
647 /*! \brief Handles all the options of the autonumber text dialog
648 * \par Function Description
649 * This function is the master of all autonumber code. It receives the options of
650 * the the autonumber text dialog in an <B>AUTONUMBER_TEXT</B> structure.
651 * First it collects all pages of a hierarchical schematic.
652 * Second it gets all matching text elements for the searchtext.
653 * Then it renumbers all text elements of all schematic pages. The renumbering
654 * follows the rules of the parameters given in the autonumber text dialog.
656 void autonumber_text_autonumber(AUTONUMBER_TEXT
*autotext
)
659 GList
*searchtext_list
=NULL
;
660 GList
*text_item
, *obj_item
, *page_item
;
662 GSCHEM_TOPLEVEL
*w_current
;
665 gchar
*new_searchtext
;
666 gint i
, number
, slot
;
667 GList
*o_list
= NULL
;
669 w_current
= autotext
->w_current
;
670 autotext
->current_searchtext
= NULL
;
671 autotext
->root_page
= 1;
672 autotext
->used_numbers
= NULL
;
673 autotext
->free_slots
= NULL
;
674 autotext
->used_slots
= NULL
;
676 scope_text
= g_list_first(autotext
->scope_text
)->data
;
678 /* Step1: get all pages of the hierarchy */
679 pages
= s_hierarchy_traversepages(w_current
->toplevel
,
680 w_current
->toplevel
->page_current
,
683 /* g_list_foreach(pages, (GFunc) s_hierarchy_print_page, NULL); */
685 /* Step2: if searchtext has an asterisk at the end we have to find
686 all matching searchtextes.
688 Example: "refdes=*" will match each text that starts with "refdes="
689 and has a trailing "?" or a trailing number if the "all"-option is set.
690 We get a list of possible prefixes: refdes=R, refdes=C.
692 If there is only one search pattern, it becomes a single item
693 in the searchtext list */
695 if (strlen(scope_text
) == 0) {
696 s_log_message(_("No searchstring given in autonumber text.\n"));
699 else if (g_str_has_suffix(scope_text
,"?") == TRUE
) {
700 /* single searchtext, strip of the "?" */
701 searchtext
= g_strndup(scope_text
, strlen(scope_text
)-1);
702 searchtext_list
=g_list_append (searchtext_list
, searchtext
);
704 else if (g_str_has_suffix(scope_text
,"*") == TRUE
) {
705 /* strip of the "*" */
706 searchtext
= g_strndup(scope_text
, strlen(scope_text
)-1);
707 /* collect all the possible searchtexts in all pages of the hierarchy */
708 for (page_item
= pages
; page_item
!= NULL
; page_item
= g_list_next(page_item
)) {
709 s_toplevel_goto_page(w_current
->toplevel
, page_item
->data
);
710 /* iterate over all objects an look for matching searchtext's */
711 for (o_current
= w_current
->toplevel
->page_current
->object_head
; o_current
!= NULL
;
712 o_current
= o_current
->next
) {
713 if (o_current
->type
== OBJ_TEXT
) {
714 if (autotext
->scope_number
== SCOPE_HIERARCHY
715 || autotext
->scope_number
== SCOPE_PAGE
716 || ((autotext
->scope_number
== SCOPE_SELECTED
) && (o_current
->selected
))) {
717 const gchar
*str
= o_text_get_string(o_current
);
718 if (g_str_has_prefix (str
, searchtext
)) {
719 /* the beginnig of the current text matches with the searchtext now */
720 /* strip of the trailing [0-9?] chars and add it too the searchtext */
721 for (i
= strlen (str
)-1;
722 (i
>= strlen(searchtext
))
724 || isdigit( (int) (str
[i
]) ));
728 new_searchtext
= g_strndup (str
, i
+1);
729 if (g_list_find_custom(searchtext_list
, new_searchtext
,
730 (GCompareFunc
) strcmp
) == NULL
) {
731 searchtext_list
= g_list_append(searchtext_list
, new_searchtext
);
734 g_free(new_searchtext
);
740 if (autotext
->scope_number
== SCOPE_SELECTED
|| autotext
->scope_number
== SCOPE_PAGE
)
741 break; /* search only in the first page */
746 s_log_message(_("No '*' or '?' given at the end of the autonumber text.\n"));
750 /* Step3: iterate over the search items in the list */
751 for (text_item
=searchtext_list
; text_item
!=NULL
; text_item
=g_list_next(text_item
)) {
752 autotext
->current_searchtext
= text_item
->data
;
753 /* printf("autonumber_text_autonumber: searchtext %s\n", autotext->current_searchtext); */
754 /* decide whether to renumber page by page or get a global used-list */
755 if (autotext
->scope_skip
== SCOPE_HIERARCHY
) { /* whole hierarchy database */
756 /* renumbering all means that no db is required */
757 if (!(autotext
->scope_number
== SCOPE_HIERARCHY
758 && autotext
->scope_overwrite
)) {
759 for (page_item
= pages
; page_item
!= NULL
; page_item
= g_list_next(page_item
)) {
760 autotext
->root_page
= (pages
->data
== page_item
->data
);
761 s_toplevel_goto_page(w_current
->toplevel
, page_item
->data
);
762 autonumber_get_used(w_current
, autotext
);
767 /* renumber the elements */
768 for (page_item
= pages
; page_item
!= NULL
; page_item
= g_list_next(page_item
)) {
769 s_toplevel_goto_page(w_current
->toplevel
, page_item
->data
);
770 autotext
->root_page
= (pages
->data
== page_item
->data
);
771 /* build a page database if we're numbering pagebypage or selection only*/
772 if (autotext
->scope_skip
== SCOPE_PAGE
|| autotext
->scope_skip
== SCOPE_SELECTED
) {
773 autonumber_get_used(w_current
, autotext
);
776 /* RENUMBER CODE FOR ONE PAGE AND ONE SEARCHTEXT*/
777 /* 1. get objects to renumber */
778 for (o_current
= w_current
->toplevel
->page_current
->object_head
; o_current
!= NULL
;
779 o_current
= o_current
->next
) {
780 if (autonumber_match(autotext
, o_current
, &number
) == AUTONUMBER_RENUMBER
) {
781 /* put number into the used list */
782 o_list
= g_list_append(o_list
, o_current
);
786 /* 2. sort object list */
787 switch (autotext
->order
) {
788 case AUTONUMBER_SORT_YX
:
789 o_list
=g_list_sort(o_list
, autonumber_sort_yx
);
791 case AUTONUMBER_SORT_YX_REV
:
792 o_list
=g_list_sort(o_list
, autonumber_sort_yx_rev
);
794 case AUTONUMBER_SORT_XY
:
795 o_list
=g_list_sort(o_list
, autonumber_sort_xy
);
797 case AUTONUMBER_SORT_XY_REV
:
798 o_list
=g_list_sort(o_list
, autonumber_sort_xy_rev
);
800 case AUTONUMBER_SORT_DIAGONAL
:
801 o_list
=g_list_sort(o_list
, autonumber_sort_diagonal
);
804 ; /* unsorted file order */
807 /* 3. renumber/reslot the objects */
808 for(obj_item
=o_list
; obj_item
!= NULL
; obj_item
=g_list_next(obj_item
)) {
809 o_current
= obj_item
->data
;
810 if(autotext
->removenum
) {
811 autonumber_remove_number(autotext
, o_current
);
813 /* get valid numbers from the database */
814 autonumber_get_new_numbers(autotext
, o_current
, &number
, &slot
);
815 /* and apply it. TODO: join these two functions */
816 autonumber_apply_new_text(autotext
, o_current
, number
, slot
);
822 /* destroy the page database */
823 if (autotext
->scope_skip
== SCOPE_PAGE
824 || autotext
->scope_skip
== SCOPE_SELECTED
)
825 autonumber_clear_database(autotext
);
827 if (autotext
->scope_number
== SCOPE_SELECTED
828 || autotext
->scope_number
== SCOPE_PAGE
)
829 break; /* only renumber the parent page (the first page) */
831 autonumber_clear_database(autotext
); /* cleanup */
834 /* cleanup and redraw all*/
835 g_list_foreach(searchtext_list
, (GFunc
) g_free
, NULL
);
836 g_list_free(searchtext_list
);
837 /* go back to the root page */
838 s_toplevel_goto_page(w_current
->toplevel
, pages
->data
);
839 o_redraw_all(w_current
);
841 o_undo_savestate(w_current
, UNDO_ALL
);
844 /* ***** UTILITY GUI FUNCTIONS (move to a separate file in the future?) **** */
846 /*! \brief Put the icons and the text into the sortorder combobox
847 * \par Function Description
848 * Load all bitmaps for the combobox and store them together with the label
851 void autonumber_sortorder_create(GSCHEM_TOPLEVEL
*w_current
, GtkWidget
*sort_order
)
855 GtkCellRenderer
*renderer
;
860 gchar
*filenames
[] = {"gschem-diagonal.png",
861 "gschem-top2bottom.png", "gschem-bottom2top.png",
862 "gschem-left2right.png", "gschem-right2left.png",
863 "gschem-fileorder.png",
865 gchar
*names
[] = {N_("Diagonal"),
866 N_("Top to bottom"), N_("Bottom to top"),
867 N_("Left to right"), N_("Right to left"),
872 store
= gtk_list_store_new(2, G_TYPE_STRING
, GDK_TYPE_PIXBUF
);
874 for (i
=0; filenames
[i
] != NULL
; i
++) {
875 path
=g_build_filename(w_current
->toplevel
->bitmap_directory
,
877 pixbuf
= gdk_pixbuf_new_from_file(path
, &error
);
879 gtk_list_store_append(store
, &iter
);
880 gtk_list_store_set(store
, &iter
,
886 gtk_combo_box_set_model(GTK_COMBO_BOX(sort_order
), GTK_TREE_MODEL(store
));
887 renderer
= gtk_cell_renderer_text_new ();
889 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (sort_order
),
891 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (sort_order
),
892 renderer
, "text", 0, NULL
);
893 renderer
= gtk_cell_renderer_pixbuf_new();
894 g_object_set(G_OBJECT(renderer
), "xpad", 5, "ypad", 5, NULL
);
896 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (sort_order
),
898 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (sort_order
),
899 renderer
, "pixbuf", 1, NULL
);
902 /* ***** STATE STRUCT HANDLING (interface between GUI and backend code) **** */
904 /** @brief Adds a line to the search text history list
906 * Function makes sure that: 1) There are no duplicates in the list and 2) the
907 * last search text is always at the top of the list.
909 GList
*autonumber_history_add(GList
*history
, gchar
*text
)
911 /* Search for this text in history and delete it (so we don't have
912 * duplicate entries) */
918 if(!strcmp(text
, cur
->data
)) {
919 history
=g_list_remove_link(history
, cur
);
925 cur
=g_list_next(cur
);
928 /* Add the new text at the beginning of the list */
930 history
=g_list_prepend(history
, text
);
932 /* Truncate history */
933 while(g_list_length(history
) > HISTORY_LENGTH
) {
934 GList
*last
= g_list_last(history
);
936 history
= g_list_remove_link(history
, last
);
945 /** @brief Allocate and initialize the state structure
947 * @return Pointer to the allocated structure or NULL on error.
949 AUTONUMBER_TEXT
*autonumber_init_state()
951 AUTONUMBER_TEXT
*autotext
;
953 /* Default contents of the combo box history */
954 gchar
*default_text
[] = {
972 autotext
= g_new(AUTONUMBER_TEXT
, 1);
974 if(autotext
==NULL
) return NULL
;
976 autotext
->scope_text
= NULL
;
979 autotext
->scope_text
=g_list_append(autotext
->scope_text
,
984 autotext
->scope_skip
= SCOPE_PAGE
;
985 autotext
->scope_number
= SCOPE_SELECTED
;
987 autotext
->scope_overwrite
= 0;
988 autotext
->order
= AUTONUMBER_SORT_DIAGONAL
;
990 autotext
->startnum
=1;
992 autotext
->removenum
=0;
993 autotext
->slotting
=0;
995 autotext
->dialog
= NULL
;
1000 /** @brief Restore the settings for the autonumber text dialog
1002 * @param autotext Pointer to the state struct.
1004 void autonumber_set_state(AUTONUMBER_TEXT
*autotext
)
1007 GtkTreeModel
*model
;
1011 /* Search text history */
1012 widget
= lookup_widget(autotext
->dialog
, "scope_text");
1014 /* Simple way to clear the ComboBox. Owen from #gtk+ says:
1016 * Yeah, it's just slightly "shady" ... if you want to stick to fully
1017 * advertised API, you need to remember how many rows you added and
1018 * use gtk_combo_box_remove_text() */
1020 model
= gtk_combo_box_get_model(GTK_COMBO_BOX(widget
));
1021 gtk_list_store_clear(GTK_LIST_STORE(model
));
1023 for (el
= autotext
->scope_text
; el
!= NULL
; el
=g_list_next(el
)) {
1024 gtk_combo_box_append_text(GTK_COMBO_BOX(widget
), el
->data
);
1027 widget
= gtk_bin_get_child(GTK_BIN(widget
));
1028 gtk_entry_set_text(GTK_ENTRY(widget
), g_list_first(autotext
->scope_text
)->data
);
1030 widget
= lookup_widget(autotext
->dialog
, "scope_skip");
1031 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
),
1032 autotext
->scope_skip
);
1034 widget
= lookup_widget(autotext
->dialog
, "scope_number");
1035 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
),
1036 autotext
->scope_number
);
1038 widget
= lookup_widget(autotext
->dialog
, "scope_overwrite");
1039 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
1040 autotext
->scope_overwrite
);
1043 widget
= lookup_widget(autotext
->dialog
, "opt_startnum");
1044 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget
),
1045 autotext
->startnum
);
1047 widget
= lookup_widget(autotext
->dialog
, "sort_order");
1048 gtk_combo_box_set_active(GTK_COMBO_BOX(widget
), autotext
->order
);
1050 widget
= lookup_widget(autotext
->dialog
, "opt_removenum");
1051 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
1052 autotext
->removenum
);
1054 widget
= lookup_widget(autotext
->dialog
, "opt_slotting");
1055 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
1056 autotext
->slotting
);
1059 /** @brief Get the settings from the autonumber text dialog
1061 * Get the settings from the autonumber text dialog and store it in the
1062 * <B>AUTONUMBER_TEXT</B> structure.
1064 * @param autotext Pointer to the state struct.
1066 void autonumber_get_state(AUTONUMBER_TEXT
*autotext
)
1073 /* Search text history */
1074 widget
= lookup_widget(autotext
->dialog
, "scope_text");
1075 widget
= gtk_bin_get_child(GTK_BIN(widget
));
1076 text
= g_strdup(gtk_entry_get_text( GTK_ENTRY(widget
)));
1078 autotext
->scope_text
=autonumber_history_add(autotext
->scope_text
, text
);
1080 widget
= lookup_widget(autotext
->dialog
, "scope_skip");
1081 autotext
->scope_skip
= gtk_combo_box_get_active( GTK_COMBO_BOX(widget
) );
1083 widget
= lookup_widget(autotext
->dialog
, "scope_number");
1084 autotext
->scope_number
= gtk_combo_box_get_active(GTK_COMBO_BOX(widget
) );
1086 widget
= lookup_widget(autotext
->dialog
, "scope_overwrite");
1087 autotext
->scope_overwrite
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1090 widget
= lookup_widget(autotext
->dialog
, "sort_order");
1091 autotext
->order
= gtk_combo_box_get_active(GTK_COMBO_BOX(widget
));
1094 widget
= lookup_widget(autotext
->dialog
, "opt_startnum");
1095 autotext
->startnum
=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget
));
1097 widget
= lookup_widget(autotext
->dialog
, "opt_removenum");
1098 autotext
->removenum
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1100 widget
= lookup_widget(autotext
->dialog
, "opt_slotting");
1101 autotext
->slotting
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget
));
1104 /* ***** CALLBACKS (functions that get called directly from the GTK) ******* */
1106 /*! \brief response callback for the autonumber text dialog
1107 * \par Function Description
1108 * The function just closes the dialog if the close button is pressed or the
1109 * user closes the dialog window.
1110 * Triggering the apply button will call the autonumber action functions.
1112 void autonumber_text_response(GtkWidget
* widget
, gint response
,
1113 AUTONUMBER_TEXT
*autotext
)
1116 case GTK_RESPONSE_ACCEPT
:
1117 autonumber_get_state(autotext
);
1118 if (autotext
->removenum
== TRUE
&& autotext
->scope_overwrite
== FALSE
) {
1119 /* temporarly set the overwrite flag */
1120 autotext
->scope_overwrite
= TRUE
;
1121 autonumber_text_autonumber(autotext
);
1122 autotext
->scope_overwrite
= FALSE
;
1125 autonumber_text_autonumber(autotext
);
1128 case GTK_RESPONSE_REJECT
:
1129 case GTK_RESPONSE_DELETE_EVENT
:
1130 gtk_widget_destroy(autotext
->dialog
);
1131 autotext
->dialog
= NULL
;
1134 printf("ERROR: autonumber_text_response(): strange signal %d\n",response
);
1139 /** @brief Callback that activates or deactivates "overwrite existing numbers"
1142 * This gets called each time "remove numbers" check box gets clicked.
1144 void autonumber_removenum_toggled(GtkWidget
* opt_removenum
,
1145 AUTONUMBER_TEXT
*autotext
)
1147 GtkWidget
*scope_overwrite
;
1149 scope_overwrite
=lookup_widget(autotext
->dialog
, "scope_overwrite");
1151 /* toggle activity of scope overwrite with respect to removenum */
1152 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(opt_removenum
))) {
1153 gtk_widget_set_sensitive(scope_overwrite
, 0);
1155 gtk_widget_set_sensitive(scope_overwrite
, 1);
1160 /* ***** DIALOG SET-UP ***************************************************** */
1162 /** @brief Creates the autonumber text dialog.
1164 * Dialog is not shown. No callbacks are registered. This is basically
1165 * unmodified code returned by Glade.
1167 * Only modification was the following substitution:
1169 * %s/create_pixmap (autonumber_text, "\(.*\)")/autonumber_create_pixmap("gschem-\1", w_current)/
1171 * and addition of the "w_current" parameter.
1173 * @param w_current Pointer to the top level struct.
1174 * @return Pointer to the dialog window.
1176 GtkWidget
* autonumber_create_dialog(GSCHEM_TOPLEVEL
*w_current
)
1178 GtkWidget
*autonumber_text
;
1180 GtkWidget
*alignment1
;
1184 GtkWidget
*scope_text
;
1187 GtkWidget
*scope_number
;
1188 GtkWidget
*scope_skip
;
1189 GtkWidget
*scope_overwrite
;
1191 GtkWidget
*alignment3
;
1196 GtkObject
*opt_startnum_adj
;
1197 GtkWidget
*opt_startnum
;
1198 GtkWidget
*sort_order
;
1199 GtkWidget
*opt_removenum
;
1200 GtkWidget
*opt_slotting
;
1204 autonumber_text
= gschem_dialog_new_with_buttons(_("Autonumber text"),
1205 GTK_WINDOW(w_current
->main_window
),
1207 "autonumber", w_current
,
1209 GTK_RESPONSE_REJECT
,
1211 GTK_RESPONSE_ACCEPT
,
1213 /* Set the alternative button order (ok, cancel, help) for other systems */
1214 gtk_dialog_set_alternative_button_order(GTK_DIALOG(autonumber_text
),
1215 GTK_RESPONSE_ACCEPT
,
1216 GTK_RESPONSE_REJECT
,
1219 gtk_window_position (GTK_WINDOW (autonumber_text
),
1222 gtk_container_border_width(GTK_CONTAINER(autonumber_text
),
1223 DIALOG_BORDER_SPACING
);
1224 vbox1
= GTK_DIALOG(autonumber_text
)->vbox
;
1225 gtk_box_set_spacing(GTK_BOX(vbox1
), DIALOG_V_SPACING
);
1228 label1
= gtk_label_new (_("<b>Scope</b>"));
1229 gtk_label_set_use_markup (GTK_LABEL (label1
), TRUE
);
1230 gtk_misc_set_alignment (GTK_MISC(label1
), 0, 0);
1231 gtk_box_pack_start (GTK_BOX(vbox1
), label1
, TRUE
, TRUE
, 0);
1232 gtk_widget_show (label1
);
1234 alignment1
= gtk_alignment_new (0, 0, 1, 1);
1235 gtk_widget_show (alignment1
);
1236 gtk_box_pack_start (GTK_BOX (vbox1
), alignment1
, TRUE
, TRUE
, 0);
1237 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment1
),
1238 0, 0, DIALOG_INDENTATION
, 0);
1240 vbox3
= gtk_vbox_new (FALSE
, 0);
1241 gtk_widget_show (vbox3
);
1242 gtk_container_add (GTK_CONTAINER (alignment1
), vbox3
);
1244 table1
= gtk_table_new (3, 2, FALSE
);
1245 gtk_widget_show (table1
);
1246 gtk_box_pack_start (GTK_BOX (vbox3
), table1
, TRUE
, TRUE
, 0);
1247 gtk_table_set_row_spacings (GTK_TABLE (table1
), DIALOG_V_SPACING
);
1248 gtk_table_set_col_spacings (GTK_TABLE (table1
), DIALOG_H_SPACING
);
1250 label4
= gtk_label_new (_("Search for:"));
1251 gtk_widget_show (label4
);
1252 gtk_table_attach (GTK_TABLE (table1
), label4
, 0, 1, 0, 1,
1253 (GtkAttachOptions
) (GTK_FILL
),
1254 (GtkAttachOptions
) (0), 0, 0);
1255 gtk_misc_set_alignment (GTK_MISC (label4
), 0, 0.5);
1257 scope_text
= gtk_combo_box_entry_new_text ();
1258 gtk_entry_set_activates_default(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(scope_text
))), TRUE
);
1259 gtk_widget_show (scope_text
);
1260 gtk_table_attach (GTK_TABLE (table1
), scope_text
, 1, 2, 0, 1,
1261 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
1262 (GtkAttachOptions
) (GTK_FILL
), 0, 0);
1264 label8
= gtk_label_new (_("Autonumber text in:"));
1265 gtk_widget_show (label8
);
1266 gtk_table_attach (GTK_TABLE (table1
), label8
, 0, 1, 1, 2,
1267 (GtkAttachOptions
) (GTK_FILL
),
1268 (GtkAttachOptions
) (0), 0, 0);
1269 gtk_misc_set_alignment (GTK_MISC (label8
), 0, 0.5);
1271 label6
= gtk_label_new (_("Skip numbers found in:"));
1272 gtk_widget_show (label6
);
1273 gtk_table_attach (GTK_TABLE (table1
), label6
, 0, 1, 2, 3,
1274 (GtkAttachOptions
) (GTK_FILL
),
1275 (GtkAttachOptions
) (0), 0, 0);
1276 gtk_misc_set_alignment (GTK_MISC (label6
), 0, 0.5);
1278 scope_number
= gtk_combo_box_new_text ();
1279 gtk_widget_show (scope_number
);
1280 gtk_table_attach (GTK_TABLE (table1
), scope_number
, 1, 2, 1, 2,
1281 (GtkAttachOptions
) (GTK_FILL
),
1282 (GtkAttachOptions
) (GTK_FILL
), 0, 0);
1283 gtk_combo_box_append_text (GTK_COMBO_BOX (scope_number
), _("Selected objects"));
1284 gtk_combo_box_append_text (GTK_COMBO_BOX (scope_number
), _("Current page"));
1285 gtk_combo_box_append_text (GTK_COMBO_BOX (scope_number
), _("Whole hierarchy"));
1287 scope_skip
= gtk_combo_box_new_text ();
1288 gtk_widget_show (scope_skip
);
1289 gtk_table_attach (GTK_TABLE (table1
), scope_skip
, 1, 2, 2, 3,
1290 (GtkAttachOptions
) (GTK_FILL
),
1291 (GtkAttachOptions
) (GTK_FILL
), 0, 0);
1292 gtk_combo_box_append_text (GTK_COMBO_BOX (scope_skip
), _("Selected objects"));
1293 gtk_combo_box_append_text (GTK_COMBO_BOX (scope_skip
), _("Current page"));
1294 gtk_combo_box_append_text (GTK_COMBO_BOX (scope_skip
), _("Whole hierarchy"));
1296 scope_overwrite
= gtk_check_button_new_with_mnemonic (_("Overwrite existing numbers"));
1297 gtk_widget_show (scope_overwrite
);
1298 gtk_box_pack_start (GTK_BOX (vbox3
), scope_overwrite
, FALSE
, FALSE
, 6);
1300 /* Options section */
1301 label3
= gtk_label_new (_("<b>Options</b>"));
1302 gtk_label_set_use_markup (GTK_LABEL (label3
), TRUE
);
1303 gtk_misc_set_alignment(GTK_MISC(label3
), 0, 0);
1304 gtk_widget_show (label3
);
1305 gtk_box_pack_start(GTK_BOX(vbox1
), label3
, TRUE
, TRUE
, 0);
1307 alignment3
= gtk_alignment_new (0, 0, 1, 1);
1308 gtk_widget_show (alignment3
);
1309 gtk_box_pack_start(GTK_BOX(vbox1
), alignment3
, TRUE
, TRUE
, 0);
1310 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment3
),
1311 0, 0, DIALOG_INDENTATION
, 0);
1313 vbox4
= gtk_vbox_new (FALSE
, 3);
1314 gtk_widget_show (vbox4
);
1315 gtk_container_add (GTK_CONTAINER (alignment3
), vbox4
);
1317 table3
= gtk_table_new (2, 2, FALSE
);
1318 gtk_widget_show (table3
);
1319 gtk_box_pack_start (GTK_BOX (vbox4
), table3
, TRUE
, TRUE
, 0);
1320 gtk_table_set_row_spacings (GTK_TABLE (table3
), DIALOG_V_SPACING
);
1321 gtk_table_set_col_spacings (GTK_TABLE (table3
), DIALOG_H_SPACING
);
1323 label12
= gtk_label_new (_("Starting number:"));
1324 gtk_widget_show (label12
);
1325 gtk_table_attach (GTK_TABLE (table3
), label12
, 0, 1, 0, 1,
1326 (GtkAttachOptions
) (GTK_FILL
),
1327 (GtkAttachOptions
) (0), 0, 0);
1328 gtk_misc_set_alignment (GTK_MISC (label12
), 0, 0.5);
1330 label13
= gtk_label_new (_("Sort order:"));
1331 gtk_widget_show (label13
);
1332 gtk_table_attach (GTK_TABLE (table3
), label13
, 0, 1, 1, 2,
1333 (GtkAttachOptions
) (GTK_FILL
),
1334 (GtkAttachOptions
) (0), 0, 0);
1335 gtk_misc_set_alignment (GTK_MISC (label13
), 0, 0.5);
1337 opt_startnum_adj
= gtk_adjustment_new (1, 0, 10000, 1, 10, 10);
1338 opt_startnum
= gtk_spin_button_new (GTK_ADJUSTMENT (opt_startnum_adj
), 1, 0);
1339 gtk_entry_set_activates_default(GTK_ENTRY(opt_startnum
), TRUE
);
1340 gtk_widget_show (opt_startnum
);
1341 gtk_table_attach (GTK_TABLE (table3
), opt_startnum
, 1, 2, 0, 1,
1342 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
1343 (GtkAttachOptions
) (0), 0, 0);
1345 sort_order
= gtk_combo_box_new();
1346 gtk_widget_show (sort_order
);
1347 gtk_table_attach (GTK_TABLE (table3
), sort_order
, 1, 2, 1, 2,
1348 (GtkAttachOptions
) (GTK_FILL
),
1349 (GtkAttachOptions
) (GTK_FILL
), 0, 0);
1351 opt_removenum
= gtk_check_button_new_with_mnemonic (_("Remove numbers"));
1352 gtk_widget_show (opt_removenum
);
1353 gtk_box_pack_start (GTK_BOX (vbox4
), opt_removenum
, FALSE
, FALSE
, 0);
1355 opt_slotting
= gtk_check_button_new_with_mnemonic (_("Automatic slotting"));
1356 gtk_widget_show (opt_slotting
);
1357 gtk_box_pack_start (GTK_BOX (vbox4
), opt_slotting
, FALSE
, FALSE
, 0);
1359 /* Store pointers to all widgets, for use by lookup_widget(). */
1360 GLADE_HOOKUP_OBJECT (autonumber_text
, scope_text
, "scope_text");
1361 GLADE_HOOKUP_OBJECT (autonumber_text
, scope_number
, "scope_number");
1362 GLADE_HOOKUP_OBJECT (autonumber_text
, scope_skip
, "scope_skip");
1363 GLADE_HOOKUP_OBJECT (autonumber_text
, scope_overwrite
, "scope_overwrite");
1364 GLADE_HOOKUP_OBJECT (autonumber_text
, opt_startnum
, "opt_startnum");
1365 GLADE_HOOKUP_OBJECT (autonumber_text
, sort_order
, "sort_order");
1366 GLADE_HOOKUP_OBJECT (autonumber_text
, opt_removenum
, "opt_removenum");
1367 GLADE_HOOKUP_OBJECT (autonumber_text
, opt_slotting
, "opt_slotting");
1369 return autonumber_text
;
1372 /*! \brief Create or restore the autonumber text dialog
1374 * If the function is called the first time the dialog is created.
1375 * If the dialog is only in background it is moved to the foreground.
1377 * @param w_current Pointer to the top level struct
1379 void autonumber_text_dialog(GSCHEM_TOPLEVEL
*w_current
)
1381 static AUTONUMBER_TEXT
*autotext
= NULL
;
1383 GtkWidget
*opt_removenum
= NULL
;
1384 GtkWidget
*sort_order
= NULL
;
1386 if(autotext
== NULL
) {
1387 /* first call of this function, init dialog structure */
1388 autotext
=autonumber_init_state();
1391 /* set the GSCHEM_TOPLEVEL always. Can it be changed between the calls??? */
1392 autotext
->w_current
= w_current
;
1394 if(autotext
->dialog
== NULL
) {
1395 /* Dialog is not currently displayed - create it */
1397 autotext
->dialog
= autonumber_create_dialog(w_current
);
1399 opt_removenum
= lookup_widget(autotext
->dialog
, "opt_removenum");
1400 sort_order
= lookup_widget(autotext
->dialog
, "sort_order");
1402 autonumber_sortorder_create(w_current
, sort_order
);
1404 gtk_dialog_set_default_response (GTK_DIALOG (autotext
->dialog
),
1405 GTK_RESPONSE_ACCEPT
);
1407 gtk_signal_connect(GTK_OBJECT(autotext
->dialog
), "response",
1408 GTK_SIGNAL_FUNC(autonumber_text_response
),
1411 gtk_signal_connect(GTK_OBJECT(opt_removenum
),
1413 GTK_SIGNAL_FUNC(autonumber_removenum_toggled
),
1416 autonumber_set_state(autotext
);
1418 gtk_widget_show_all(autotext
->dialog
);
1421 /* if the dialog is in the background or minimized: show it */
1422 gtk_window_present(GTK_WINDOW(autotext
->dialog
));