[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-user: gschem AutoNumber/AutoText with Replace capabilities (test patch)



Hi,
	As I said in a previous post, I find useful to be able to
search/replace in the way the autonumer text tool does autonumbering in
gschem. 
	I took the freedom to modify the code in gschem in order to achieve
this. The functionality seems to be working just like I wanted and would
be great if someone interested test it for feedback. I think it would be
very useful to have this patch added to mainstream gschem if the patch
seems to work without problems and the developers agree.

Now it's possible to do tasks such as:

1. search: pinlabel=unknown   >>  replace: pinlabel=PC?

2. search: pintype=unknown   >>  replace: pintype=io

3. search: pinlabel=EBI0_D?   >>  replace: pinlabel=PC?

4. search: refdes=*   	>>  replace: refdes=U?

5. search: refdes=J?   >>  replace: CONN?

and so on... Of course if you left the "Replace with" entry empty, it
behaves just like before.

Hope you find it useful!

Best Regards, Felipe.

PS: Also fixed the Warning regarding adjustment size in the autonumber
dialog constructor(when the user launches the dialog)
	

-- 
Felipe De la Puente Christen
Mobile Phone    : +56 9 93199807
MSN/GTalk       : fdelapuente@xxxxxxxxx


On Fri, 2010-04-02 at 20:12 +0200, kai-martin knaak wrote:
> Felipe De la Puente Christen wrote:
> 
> > Hi,
> > Not a big issue, but I think that would be great if the Autonumber text
> > dialog has a separate TextEntry for the EXPRESSION to search for and a
> > different one for the Text Pattern to replace with.
> 
> +1
> Search and replace in protel works like this. And yes, it is powerful and 
> very useful in the context of larger schematics. In my humble opinion, 
> gschem might benefit a lot from more powerful search (and replace) 
> utilities.
> 
> ---<)kaimartin(>---
From 47ecf9946bc1d900325910b463439b65bbdee798 Mon Sep 17 00:00:00 2001
From: Felipe De la Puente <fdelapuente@xxxxxxxxx>
Date: Fri, 9 Apr 2010 22:06:39 -0400
Subject: [PATCH] Added search/replace capabilities to tue autonumber text tool. A new combobox_entry is added to the dialog to input the "replace with" field.

Signed-off-by: Felipe De la Puente Christen <felipe@fdelapuente@gmail.com>
---
 gschem/src/x_autonumber.c |  361 +++++++++++++++++++++++++++++++++------------
 1 files changed, 263 insertions(+), 98 deletions(-)

diff --git a/gschem/src/x_autonumber.c b/gschem/src/x_autonumber.c
index 073f916..0af193c 100644
--- a/gschem/src/x_autonumber.c
+++ b/gschem/src/x_autonumber.c
@@ -72,6 +72,9 @@ struct autonumber_text_t {
   /** @brief Search text history */
   GList *scope_text;
 
+  /** @brief Replace text history */
+  GList *replace_scope_text;
+
   /** @brief Scope for searching existing numbers */
   gint scope_skip;
 
@@ -90,6 +93,9 @@ struct autonumber_text_t {
   /** @brief Remove numbers instead of automatic numbering */
   gboolean removenum;
 
+  /** @brief Replace text instead of automatic numbering */
+  gboolean replace;
+
   /** @brief Automatic assignments of slots */
   gboolean slotting;
 
@@ -101,6 +107,7 @@ struct autonumber_text_t {
 
   /* variables used while autonumbering */
   gchar * current_searchtext;
+  gchar * current_replacetext;
   gint root_page;      /* flag whether its the root page or not */
   GList *used_numbers; /* list of used numbers */ 
   GList *free_slots;   /* list of FREE_SLOT objects */
@@ -243,7 +250,7 @@ int autonumber_sort_diagonal(gconstpointer a, gconstpointer b) {
 /*! \brief GCompareFunc function to acces <B>AUTONUMBER_SLOT</B> object in a GList
  *  \par Function Description
  *  This Funcion takes two <B>AUTONUMBER_SLOT*</B> arguments and compares them.
- *  Sorting criteria is are the AUTONUMBER_SLOT members: first the symbolname, than the 
+ *  Sorting criteria is are the AUTONUMBER_SLOT members: first the symbolname, then the 
  *  number and last the slotnr.
  *  If the number or the slotnr is set to zero it acts as a wildcard. 
  *  The function is used as GCompareFunc by GList functions.
@@ -319,7 +326,7 @@ void autonumber_clear_database (AUTONUMBER_TEXT *autotext)
 /*! \brief Function to test, whether the OBJECT matches the autotext criterias
  *  \par Function Description
  *  The criterias are those of the autonumber text dialog. The function decides
- *  whether the <B>OBJECT</B> has to be renumberd, ignored or taken care of when
+ *  whether the <B>OBJECT</B> has to be renumbered, ignored or taken care of when
  *  renumbering all other objects.  
  *  \return one of these integer values: <B>AUTONUMBER_IGNORE</B>, 
  *  <B>AUTONUMBER_RESPECT</B> or <B>AUTONUMBER_RENUMBER</B> and the current number
@@ -329,20 +336,29 @@ gint autonumber_match(AUTONUMBER_TEXT *autotext, OBJECT *o_current, gint *number
 {
   gint i, len, isnumbered=1; 
   const gchar *str = NULL;
-
-  len = strlen(autotext->current_searchtext);
+  
   /* first find out whether we can ignore that object */
   if (o_current->type != OBJ_TEXT)  /* text object */
     return AUTONUMBER_IGNORE;
 
   str = o_text_get_string (autotext->w_current->toplevel, o_current);
 
-  if (!(strlen(str) - len > 0)
-      || !g_str_has_prefix(str, autotext->current_searchtext))
+  if(g_str_has_prefix(str, autotext->current_searchtext))
+      len = strlen(autotext->current_searchtext);
+  else if(g_str_has_prefix(str, autotext->current_replacetext))
+      len = strlen(autotext->current_replacetext);
+  else
+      return AUTONUMBER_IGNORE;
+
+  if(autotext->replace && g_strcmp0(autotext->current_searchtext, str) == 0)
+      return AUTONUMBER_RENUMBER;
+
+  if (!(strlen(str) - len > 0))
     return AUTONUMBER_IGNORE;
 
   /* the string object matches with its leading characters to the searchtext */
   /* now look for the extension, either a number or the "?" */
+
   if (g_str_has_suffix (str,"?")) {
     isnumbered = 0;
     /* There must not be any character between the "?" and the searchtext */
@@ -367,7 +383,8 @@ gint autonumber_match(AUTONUMBER_TEXT *autotext, OBJECT *o_current, gint *number
   
   if (isnumbered
       && !(autotext->scope_skip == SCOPE_SELECTED 
-	   && !(o_current->selected)  && autotext->root_page)) {
+	   && !(o_current->selected)  && autotext->root_page)
+      && g_str_has_prefix(str, autotext->current_replacetext)) {
     sscanf(&(str[len])," %d", number);
     return AUTONUMBER_RESPECT; /* numbered objects which we don't renumber */
   }
@@ -573,7 +590,7 @@ void autonumber_remove_number(AUTONUMBER_TEXT * autotext, OBJECT *o_current)
   gchar *str = NULL;
 
   /* replace old text */
-  str = g_strdup_printf("%s?", autotext->current_searchtext);
+  str = g_strdup_printf("%s?", autotext->current_replacetext);
   o_text_set_string (autotext->w_current->toplevel, o_current, str);
   g_free (str);
 
@@ -614,7 +631,25 @@ void autonumber_apply_new_text(AUTONUMBER_TEXT * autotext, OBJECT *o_current,
   g_free (str);
 
   /* replace old text */
-  str = g_strdup_printf("%s%d", autotext->current_searchtext, number);
+  str = g_strdup_printf("%s%d", autotext->current_replacetext, number);
+  o_text_set_string (autotext->w_current->toplevel, o_current, str);
+  g_free (str);
+
+  autotext->w_current->toplevel->page_current->CHANGED = 1;
+}
+
+/*! \brief Just Replaces text in the <B>OBJECT</B> element. Changes the slot attribute.
+ *  \par Function Description
+ *  This function updates the text content of the <B>o_current</B> object.
+ *  If the <B>slot</B> value is not zero. It updates the slot attribut of the
+ *  complex element that is also the parent object of the o_current element.
+ */
+void autonumber_replace_text(AUTONUMBER_TEXT * autotext, OBJECT *o_current)
+{
+  char *str;
+
+  /* replace old text */
+  str = g_strdup_printf("%s", autotext->current_replacetext);
   o_text_set_string (autotext->w_current->toplevel, o_current, str);
   g_free (str);
 
@@ -635,24 +670,33 @@ void autonumber_text_autonumber(AUTONUMBER_TEXT *autotext)
 {
   GList *pages;
   GList *searchtext_list=NULL;
-  GList *text_item, *obj_item, *page_item;
+  GList *replacetext_list=NULL;
+  GList *text_item, *text_item2, *obj_item, *page_item;
   OBJECT *o_current;
   GSCHEM_TOPLEVEL *w_current;
   gchar *searchtext;
+  gchar *replacetext;
   gchar *scope_text;
+  gchar *replace_scope_text;
   gchar *new_searchtext;
+  gchar *new_replacetext;
   gint i, number, slot;
   GList *o_list = NULL;
   const GList *iter;
   
   w_current = autotext->w_current;
   autotext->current_searchtext = NULL;
+  autotext->current_replacetext = NULL;
   autotext->root_page = 1;
   autotext->used_numbers = NULL;
   autotext->free_slots = NULL;
   autotext->used_slots = NULL;
+  autotext->replace=FALSE;
 
+  /* This is the "search for:" dialog text input */
   scope_text = g_list_first(autotext->scope_text)->data;
+  /* This is the "replace with:" dialog text input */
+  replace_scope_text = g_list_first(autotext->replace_scope_text)->data;
 
   /* Step1: get all pages of the hierarchy */
   pages = s_hierarchy_traversepages(w_current->toplevel, HIERARCHY_NODUPS);
@@ -668,67 +712,133 @@ void autonumber_text_autonumber(AUTONUMBER_TEXT *autotext)
 
      If there is only one search pattern, it becomes a single item
      in the searchtext list */
-  
+
   if (strlen(scope_text) == 0) {
     s_log_message(_("No searchstring given in autonumber text.\n"));
     return; /* error */
   }
-  else if (g_str_has_suffix(scope_text,"?") == TRUE) {
-    /* single searchtext, strip of the "?" */
+
+  if(!g_str_has_suffix(replace_scope_text, "*") && !g_str_has_suffix(replace_scope_text, "?")){
+      autotext->replace=TRUE;
+  }
+
+  if (g_str_has_suffix(scope_text,"?") == TRUE) {
+    /* single searchtext, strip off the "?" */
     searchtext = g_strndup(scope_text, strlen(scope_text)-1);
     searchtext_list=g_list_append (searchtext_list, searchtext);
+    
+    if(!autotext->replace){
+	replacetext = g_strndup(replace_scope_text, strlen(replace_scope_text)-1);
+    }
+    else{
+	replacetext = g_strndup(replace_scope_text, strlen(replace_scope_text));
+    }
+
+    replacetext_list=g_list_append (replacetext_list, replacetext);
   }
   else if (g_str_has_suffix(scope_text,"*") == TRUE) {
-    /* strip of the "*" */
+    /* strip off the "*" */
     searchtext = g_strndup(scope_text, strlen(scope_text)-1);
+
+    if(!autotext->replace){
+	replacetext = g_strndup(replace_scope_text, strlen(replace_scope_text)-1);
+    }
+    else{
+	replacetext = g_strndup(replace_scope_text, strlen(replace_scope_text));
+    }
+
     /* collect all the possible searchtexts in all pages of the hierarchy */
     for (page_item = pages; page_item != NULL; page_item = g_list_next(page_item)) {
       s_page_goto(w_current->toplevel, page_item->data);
-      /* iterate over all objects an look for matching searchtext's */
+      /* iterate over all objects and look for matching searchtext's */
       for (iter = s_page_objects (w_current->toplevel->page_current);
-           iter != NULL;
-           iter = g_list_next (iter)) {
-	o_current = iter->data;
-	if (o_current->type == OBJ_TEXT) {
-	  if (autotext->scope_number == SCOPE_HIERARCHY
-	      || autotext->scope_number == SCOPE_PAGE
-	      || ((autotext->scope_number == SCOPE_SELECTED) && (o_current->selected))) {
-            const gchar *str = o_text_get_string (w_current->toplevel, o_current);
-	    if (g_str_has_prefix (str, searchtext)) {
-	      /* the beginnig of the current text matches with the searchtext now */
-	      /* strip of the trailing [0-9?] chars and add it too the searchtext */
-	      for (i = strlen (str)-1;
-		   (i >= strlen(searchtext))
-		     && (str[i] == '?'
-			 || isdigit( (int) (str[i]) ));
-		   i--)
-		; /* void */
-		
-	      new_searchtext = g_strndup (str, i+1);
-	      if (g_list_find_custom(searchtext_list, new_searchtext,
-				     (GCompareFunc) strcmp) == NULL ) {
-		searchtext_list = g_list_append(searchtext_list, new_searchtext);
-	      }
-	      else {
-		g_free(new_searchtext);
-	      }
-	    }
+	      iter != NULL;
+	      iter = g_list_next (iter)) {
+	  o_current = iter->data;
+	  if (o_current->type == OBJ_TEXT) {
+	      if (autotext->scope_number == SCOPE_HIERARCHY
+		      || autotext->scope_number == SCOPE_PAGE
+		      || ((autotext->scope_number == SCOPE_SELECTED) && (o_current->selected))) {
+		  const gchar *str = o_text_get_string (w_current->toplevel, o_current);
+		  if (g_str_has_prefix (str, searchtext)) {
+		      /* the beginnig of the current text matches with the searchtext now */
+		      /* strip off the trailing [0-9?] chars and add it too the searchtext */
+		      for (i = strlen (str)-1;
+			      (i >= strlen(searchtext))
+			      && (str[i] == '?'
+				  || isdigit( (int) (str[i]) ));
+			      i--)
+			  ; /* void */
+		      new_searchtext = g_strndup (str, i+1);
+
+		      if(autotext->replace || g_str_has_suffix(replace_scope_text, "?")){
+			  new_replacetext=g_strndup(replacetext, strlen(replacetext));
+		      }
+		      else {
+			  int nmbr = strlen(searchtext);
+			  gchar* str2 = g_strndup((str+nmbr),(i-nmbr+1)); 
+			  new_replacetext = g_strconcat(replacetext, str2, NULL);
+			  g_free(str2);
+		      }
+
+		      if (g_list_find_custom(searchtext_list, new_searchtext,
+				  (GCompareFunc) strcmp) == NULL ) {
+			  searchtext_list = g_list_append(searchtext_list, new_searchtext);
+		      }
+		      else {
+			  /* new_searchtext already in the list */
+			  g_free(new_searchtext);
+		      }
+		      
+		      /* new need an entry for each entry in searchtext_list, 
+		       * no matter if it's duplicated. Not the most efficient way, but it just works */
+		      replacetext_list= g_list_append(replacetext_list, new_replacetext);
+		  }
 	  }
 	}
       }
       if (autotext->scope_number == SCOPE_SELECTED || autotext->scope_number == SCOPE_PAGE)
-	break; /* search only in the first page */
+	  break; /* search only in the first page */
     }
     g_free(searchtext);
+    g_free(replacetext);
   }
   else {
-    s_log_message(_("No '*' or '?' given at the end of the autonumber text.\n"));
-    return;
+      if(g_strcmp0(replace_scope_text, scope_text) != 0) {
+	  /* We are definitely not doing AutoNumber tasks, may be just search and replace? */
+	  s_log_message(_("No '*' or '?' given, just Replacing\n"));
+	  autotext->replace=TRUE;
+
+	  /* single searchtext, no "?" to strip off */
+	  searchtext = g_strndup(scope_text, strlen(scope_text));
+	  searchtext_list=g_list_append (searchtext_list, searchtext);
+
+	  if (g_str_has_suffix(replace_scope_text,"?") == TRUE) {
+	      /* single replacetext, strip off the "?" */
+	      replacetext = g_strndup(replace_scope_text, strlen(replace_scope_text)-1);
+	      replacetext_list=g_list_append (replacetext_list, replacetext);
+	  }
+	  else{
+	      /* single replacetext, no "?" to strip off */
+	      replacetext = g_strndup(replace_scope_text, strlen(replace_scope_text));
+	      replacetext_list=g_list_append (replacetext_list, replacetext);
+	  }
+      }
+      else{
+	  /* Ok, just nothing to do */
+	  s_log_message(_("No '*' or '?' given at the end of the autonumber text.\n"));
+	  return;
+      }
   }
 
   /* Step3: iterate over the search items in the list */
-  for (text_item=searchtext_list; text_item !=NULL; text_item=g_list_next(text_item)) {
-    autotext->current_searchtext = text_item->data;
+  for (text_item=searchtext_list, text_item2=replacetext_list; 
+	  text_item !=NULL && text_item2 != NULL; 
+	  text_item=g_list_next(text_item), text_item2 = g_list_next(text_item2)) {
+
+      autotext->current_searchtext = text_item->data;
+      autotext->current_replacetext = text_item2->data;
+
     /* printf("autonumber_text_autonumber: searchtext %s\n", autotext->current_searchtext); */
     /* decide whether to renumber page by page or get a global used-list */
     if (autotext->scope_skip == SCOPE_HIERARCHY) {  /* whole hierarchy database */
@@ -790,7 +900,11 @@ void autonumber_text_autonumber(AUTONUMBER_TEXT *autotext)
 	o_current= obj_item->data;
       	if(autotext->removenum) {
 	  autonumber_remove_number(autotext, o_current);		
-	} else {
+	} 
+	else if(autotext->replace && !g_str_has_suffix(replace_scope_text, "?")){
+	    autonumber_replace_text(autotext, o_current);
+	}
+	else{
 	  /* get valid numbers from the database */
 	  autonumber_get_new_numbers(autotext, o_current, &number, &slot);
 	  /* and apply it. TODO: join these two functions */
@@ -845,53 +959,53 @@ GtkWidget* lookup_widget(GtkWidget *widget, const gchar *widget_name)
  */
 void autonumber_sortorder_create(GSCHEM_TOPLEVEL *w_current, GtkWidget *sort_order)
 {
-  GtkListStore *store;
-  GtkTreeIter iter;
-  GtkCellRenderer *renderer;
-  GdkPixbuf *pixbuf;
-  gchar *path;
-  GError *error=NULL;
-
-  gchar *filenames[] = {"gschem-diagonal.png", 
-			"gschem-top2bottom.png", "gschem-bottom2top.png",
-			"gschem-left2right.png", "gschem-right2left.png",
-			"gschem-fileorder.png",
-			NULL};
-  gchar *names[] = {N_("Diagonal"),
-		    N_("Top to bottom"), N_("Bottom to top"),
-		    N_("Left to right"), N_("Right to left"),
-		    N_("File order"),
-		    NULL};
-  gint i;
-
-  store = gtk_list_store_new(2, G_TYPE_STRING, GDK_TYPE_PIXBUF); 
-
-  for (i=0; filenames[i] != NULL; i++) {
-    path=g_build_filename(w_current->toplevel->bitmap_directory,
-		     filenames[i], NULL);
-    pixbuf = gdk_pixbuf_new_from_file(path, &error);
-    g_free(path);
-    gtk_list_store_append(store, &iter);
-    gtk_list_store_set(store, &iter, 
-		       0, _(names[i]),
-		       1, pixbuf,
-		       -1);
-  }
+    GtkListStore *store;
+    GtkTreeIter iter;
+    GtkCellRenderer *renderer;
+    GdkPixbuf *pixbuf;
+    gchar *path;
+    GError *error=NULL;
+
+    gchar *filenames[] = {"gschem-diagonal.png", 
+	"gschem-top2bottom.png", "gschem-bottom2top.png",
+	"gschem-left2right.png", "gschem-right2left.png",
+	"gschem-fileorder.png",
+	NULL};
+    gchar *names[] = {N_("Diagonal"),
+	N_("Top to bottom"), N_("Bottom to top"),
+	N_("Left to right"), N_("Right to left"),
+	N_("File order"),
+	NULL};
+    gint i;
+
+    store = gtk_list_store_new(2, G_TYPE_STRING, GDK_TYPE_PIXBUF); 
+
+    for (i=0; filenames[i] != NULL; i++) {
+	path=g_build_filename(w_current->toplevel->bitmap_directory,
+		filenames[i], NULL);
+	pixbuf = gdk_pixbuf_new_from_file(path, &error);
+	g_free(path);
+	gtk_list_store_append(store, &iter);
+	gtk_list_store_set(store, &iter, 
+		0, _(names[i]),
+		1, pixbuf,
+		-1);
+    }
 
-  gtk_combo_box_set_model(GTK_COMBO_BOX(sort_order), GTK_TREE_MODEL(store));
-  renderer = gtk_cell_renderer_text_new ();
+    gtk_combo_box_set_model(GTK_COMBO_BOX(sort_order), GTK_TREE_MODEL(store));
+    renderer = gtk_cell_renderer_text_new ();
 
-  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (sort_order),
-			      renderer, TRUE);
-  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (sort_order),
-				  renderer, "text", 0, NULL);
-  renderer = gtk_cell_renderer_pixbuf_new();
-  g_object_set(G_OBJECT(renderer), "xpad", 5, "ypad", 5, NULL);
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (sort_order),
+	    renderer, TRUE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (sort_order),
+	    renderer, "text", 0, NULL);
+    renderer = gtk_cell_renderer_pixbuf_new();
+    g_object_set(G_OBJECT(renderer), "xpad", 5, "ypad", 5, NULL);
 
-  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (sort_order),
-			      renderer, FALSE);
-  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (sort_order),
-				  renderer, "pixbuf", 1, NULL);
+    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (sort_order),
+	    renderer, FALSE);
+    gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (sort_order),
+	    renderer, "pixbuf", 1, NULL);
 }
 
 /* ***** STATE STRUCT HANDLING (interface between GUI and backend code) **** */
@@ -960,6 +1074,8 @@ AUTONUMBER_TEXT *autonumber_init_state()
     "netname=*", 
     "netname=A?",
     "netname=D?", 
+    "pinnumber=*",
+    "pinseq=*",
     NULL
   };
   gchar **t;
@@ -969,10 +1085,14 @@ AUTONUMBER_TEXT *autonumber_init_state()
   if(autotext==NULL) return NULL;
 
   autotext->scope_text = NULL;
+  autotext->replace_scope_text = NULL;
+
   t=default_text;
   while(*t!=NULL) {
     autotext->scope_text=g_list_append(autotext->scope_text, 
 				       g_strdup(*t));
+    autotext->replace_scope_text=g_list_append(autotext->replace_scope_text, 
+				       g_strdup(*t));
     t++;
   }
 
@@ -1022,6 +1142,22 @@ void autonumber_set_state(AUTONUMBER_TEXT *autotext)
   widget = gtk_bin_get_child(GTK_BIN(widget));
   gtk_entry_set_text(GTK_ENTRY(widget), g_list_first(autotext->scope_text)->data);
 
+  /* Replace text history */
+  widget = lookup_widget(autotext->dialog, "replace_scope_text");
+
+  /* Simple way to clear the ComboBox. Owen from #gtk+ says: 
+   *
+   * Yeah, it's just slightly "shady" ... if you want to stick to fully 
+   * advertised API, you need to remember how many rows you added and 
+   * use gtk_combo_box_remove_text() */
+
+  model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
+  gtk_list_store_clear(GTK_LIST_STORE(model));
+
+  for (el= autotext->replace_scope_text; el != NULL; el=g_list_next(el)) {
+    gtk_combo_box_append_text(GTK_COMBO_BOX(widget), el->data);
+  }
+
   widget = lookup_widget(autotext->dialog, "scope_skip");
   gtk_combo_box_set_active(GTK_COMBO_BOX(widget),
 			   autotext->scope_skip);
@@ -1061,7 +1197,7 @@ void autonumber_set_state(AUTONUMBER_TEXT *autotext)
 void autonumber_get_state(AUTONUMBER_TEXT *autotext)
 {
   GtkWidget *widget;
-  gchar *text;
+  gchar *text, *replace_text;
 
   /* Scope */
 
@@ -1071,6 +1207,18 @@ void autonumber_get_state(AUTONUMBER_TEXT *autotext)
   text = g_strdup(gtk_entry_get_text( GTK_ENTRY(widget)));
 
   autotext->scope_text=autonumber_history_add(autotext->scope_text, text);
+  
+  /* Replace text history */
+  widget = lookup_widget(autotext->dialog, "replace_scope_text");
+  widget = gtk_bin_get_child(GTK_BIN(widget));
+  replace_text = g_strdup(gtk_entry_get_text( GTK_ENTRY(widget)));
+
+  if(strlen(replace_text) > 0){
+      autotext->replace_scope_text=autonumber_history_add(autotext->replace_scope_text, replace_text);
+  }
+  else{
+      autotext->replace_scope_text=autonumber_history_add(autotext->replace_scope_text, text);
+  }
 
   widget = lookup_widget(autotext->dialog, "scope_skip");
   autotext->scope_skip = gtk_combo_box_get_active( GTK_COMBO_BOX(widget) );
@@ -1176,7 +1324,9 @@ GtkWidget* autonumber_create_dialog(GSCHEM_TOPLEVEL *w_current)
   GtkWidget *vbox3;
   GtkWidget *table1;
   GtkWidget *label4;
+  GtkWidget *label44;
   GtkWidget *scope_text;
+  GtkWidget *replace_scope_text;
   GtkWidget *label8;
   GtkWidget *label6;
   GtkWidget *scope_number;
@@ -1256,23 +1406,37 @@ GtkWidget* autonumber_create_dialog(GSCHEM_TOPLEVEL *w_current)
                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                     (GtkAttachOptions) (GTK_FILL), 0, 0);
 
+  label44 = gtk_label_new (_("Replace with:"));
+  gtk_widget_show (label44);
+  gtk_table_attach (GTK_TABLE (table1), label44, 0, 1, 1, 2,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (0), 0, 0);
+  gtk_misc_set_alignment (GTK_MISC (label44), 0, 0.5);
+
+  replace_scope_text = gtk_combo_box_entry_new_text ();
+  gtk_entry_set_activates_default(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(replace_scope_text))), TRUE);
+  gtk_widget_show (replace_scope_text);
+  gtk_table_attach (GTK_TABLE (table1), replace_scope_text, 1, 2, 1, 2,
+                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                    (GtkAttachOptions) (GTK_FILL), 0, 0);
+
   label8 = gtk_label_new (_("Autonumber text in:"));
   gtk_widget_show (label8);
-  gtk_table_attach (GTK_TABLE (table1), label8, 0, 1, 1, 2,
+  gtk_table_attach (GTK_TABLE (table1), label8, 0, 1, 2, 3,
                     (GtkAttachOptions) (GTK_FILL),
                     (GtkAttachOptions) (0), 0, 0);
   gtk_misc_set_alignment (GTK_MISC (label8), 0, 0.5);
 
   label6 = gtk_label_new (_("Skip numbers found in:"));
   gtk_widget_show (label6);
-  gtk_table_attach (GTK_TABLE (table1), label6, 0, 1, 2, 3,
+  gtk_table_attach (GTK_TABLE (table1), label6, 0, 1, 3, 4,
                     (GtkAttachOptions) (GTK_FILL),
                     (GtkAttachOptions) (0), 0, 0);
   gtk_misc_set_alignment (GTK_MISC (label6), 0, 0.5);
 
   scope_number = gtk_combo_box_new_text ();
   gtk_widget_show (scope_number);
-  gtk_table_attach (GTK_TABLE (table1), scope_number, 1, 2, 1, 2,
+  gtk_table_attach (GTK_TABLE (table1), scope_number, 1, 2, 2, 3,
                     (GtkAttachOptions) (GTK_FILL),
                     (GtkAttachOptions) (GTK_FILL), 0, 0);
   gtk_combo_box_append_text (GTK_COMBO_BOX (scope_number), _("Selected objects"));
@@ -1281,7 +1445,7 @@ GtkWidget* autonumber_create_dialog(GSCHEM_TOPLEVEL *w_current)
 
   scope_skip = gtk_combo_box_new_text ();
   gtk_widget_show (scope_skip);
-  gtk_table_attach (GTK_TABLE (table1), scope_skip, 1, 2, 2, 3,
+  gtk_table_attach (GTK_TABLE (table1), scope_skip, 1, 2, 3, 4,
                     (GtkAttachOptions) (GTK_FILL),
                     (GtkAttachOptions) (GTK_FILL), 0, 0);
   gtk_combo_box_append_text (GTK_COMBO_BOX (scope_skip), _("Selected objects"));
@@ -1329,7 +1493,7 @@ GtkWidget* autonumber_create_dialog(GSCHEM_TOPLEVEL *w_current)
                     (GtkAttachOptions) (0), 0, 0);
   gtk_misc_set_alignment (GTK_MISC (label13), 0, 0.5);
 
-  opt_startnum_adj = gtk_adjustment_new (1, 0, 10000, 1, 10, 10);
+  opt_startnum_adj = gtk_adjustment_new (1, 0, 10000, 1, 10, 0);
   opt_startnum = gtk_spin_button_new (GTK_ADJUSTMENT (opt_startnum_adj), 1, 0);
   gtk_entry_set_activates_default(GTK_ENTRY(opt_startnum), TRUE);
   gtk_widget_show (opt_startnum);
@@ -1353,6 +1517,7 @@ GtkWidget* autonumber_create_dialog(GSCHEM_TOPLEVEL *w_current)
 
   /* Store pointers to all widgets, for use by lookup_widget(). */
   GLADE_HOOKUP_OBJECT (autonumber_text, scope_text, "scope_text");
+  GLADE_HOOKUP_OBJECT (autonumber_text, replace_scope_text, "replace_scope_text");
   GLADE_HOOKUP_OBJECT (autonumber_text, scope_number, "scope_number");
   GLADE_HOOKUP_OBJECT (autonumber_text, scope_skip, "scope_skip");
   GLADE_HOOKUP_OBJECT (autonumber_text, scope_overwrite, "scope_overwrite");
-- 
1.6.3.3


_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user