[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gEDA-dev: gschem: Moving component selector into a new file (PATCH)



Hi,

Sourceforge is down at the moment, so I've attached my patch to this
email..

This patch against CVS HEAD, splits the functionality in
gschem/src/x_fileselect.c between file-selectors, and
component-selectors in the new file gschem/src/x_compselect.c

Some un-necessary code was removed (see patch, but IIRC just some GTK
1.2 stuff, and a few functions which were #if 0'd out already).

The patch also tidies up some unused ( and unused since this patch ),
members of the FILEDIALOG structure, also introducing a near duplicate
COMPDIALOG structure so they may part company as necessary in the
future.

This required a few minor changes in gattrib, which zero'd / NULL'd the
otherwise unused members.

As I have a late GTK version, I've not fully tested the behaviour of the
"old" style file-open etc... dialogs, and someone will need to verify
that they aren't affected by the changes.

Note that as I can't "CVS add" the new file, the patch file contains a
hacked header, pretending there is that file in CVS with version 1.00

Regards

Peter Clifton

Index: gaf/gattrib/src/x_fileselect.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/x_fileselect.c,v
retrieving revision 1.10
diff -U3 -p -r1.10 x_fileselect.c
--- gaf/gattrib/src/x_fileselect.c	17 Jul 2006 01:50:10 -0000	1.10
+++ gaf/gattrib/src/x_fileselect.c	24 Jul 2006 18:48:20 -0000
@@ -1141,9 +1141,6 @@ void x_fileselect_close(GtkWidget * w, F
   if(f_current->preview_checkbox)
     gtk_widget_destroy(GTK_WIDGET(f_current->preview_checkbox));
 
-  if(f_current->component_pulldown)
-    gtk_widget_destroy(GTK_WIDGET(f_current->component_pulldown));
-
   /* Finally kill main widget */
   gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
   return;
@@ -1186,7 +1183,6 @@ void x_fileselect_setup(TOPLEVEL *pr_cur
 
   f_current->xfwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   f_current->toplevel = pr_current;  /* This points back to toplevel for reading in files. */
-  f_current->type = 0;  /* used to be type */
   f_current->filesel_type = filesel_type;
   f_current->last_search = -1;
   f_current->filename = NULL;
@@ -1204,7 +1200,6 @@ void x_fileselect_setup(TOPLEVEL *pr_cur
   f_current->filename_entry = NULL;
   f_current->preview = NULL;
   f_current->preview_checkbox = NULL;
-  f_current->component_pulldown = NULL;
 
 #ifdef DEBUG
   printf("We have just entered x_fileselect_setup.\n");
Index: gaf/gschem/include/prototype.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/include/prototype.h,v
retrieving revision 1.132
diff -U3 -p -r1.132 prototype.h
--- gaf/gschem/include/prototype.h	24 Jul 2006 03:29:21 -0000	1.132
+++ gaf/gschem/include/prototype.h	24 Jul 2006 18:48:20 -0000
@@ -880,21 +880,33 @@ void x_fileselect_file_button(GtkWidget 
 void x_fileselect_update_dirfile_saveas(FILEDIALOG *f_current, char *new_filename);
 void x_fileselect_close(GtkWidget *w, FILEDIALOG *f_current);
 void x_fileselect_search(GtkWidget *w, FILEDIALOG *f_current);
+void x_fileselect_setup(TOPLEVEL *w_current, int filesel_type);
+int x_fileselect_load_backup(TOPLEVEL *toplevel, GString *message);
+/* x_compselect.c */
+void x_compselect_destroy_window(GtkWidget *widget, COMPDIALOG *f_current);
+int x_compselect_keypress(GtkWidget *widget, GdkEventKey *event, COMPDIALOG *f_current);
+void x_compselect_init_list_buffers(COMPDIALOG *f_current);
+void x_compselect_free_list_buffers(COMPDIALOG *f_current);
+void x_compselect_update_dirfile(COMPDIALOG *f_current, char *filename);
+void x_compselect_setup_list_buffers(COMPDIALOG *f_current, int num_files, int num_directories);
+int x_compselect_include_file(char *filename, int filter_type);
+void x_compselect_fill_lists(COMPDIALOG *f_current);
+void x_compselect_close(GtkWidget *w, COMPDIALOG *f_current);
+void x_compselect_search(GtkWidget *w, COMPDIALOG *f_current);
 gint default_components(GtkWidget *w, TOPLEVEL *w_current);
 gint embed_components(GtkWidget *w, TOPLEVEL *w_current);
 gint include_components(GtkWidget *w, TOPLEVEL *w_current);
-void x_fileselect_comp_fill_libs(TOPLEVEL *w_current, FILEDIALOG *f_current);
-void x_fileselect_comp_fill_components(FILEDIALOG *f_current, int row);
-void x_fileselect_comp_update_current(FILEDIALOG *f_current, char *library, char *component);
-void x_fileselect_change_clib(FILEDIALOG *f_current, char *new_clib, int row);
-void x_fileselect_lib_select(GtkWidget *widget, gint row, gint column, GdkEventButton *bevent, FILEDIALOG *f_current);
-void x_fileselect_comp_select(GtkWidget *widget, gint row, gint column, GdkEventButton *bevent, FILEDIALOG *f_current);
-void x_fileselect_comp_apply(GtkWidget *w, FILEDIALOG *f_current);
-void x_fileselect_comp_close(GtkWidget *w, FILEDIALOG *f_current);
-int x_fileselect_search_library(FILEDIALOG *f_current, char *library, const char *string);
-void x_fileselect_comp_search(GtkWidget *w, FILEDIALOG *f_current);
-void x_fileselect_setup(TOPLEVEL *w_current, int type, int filesel_type);
-int x_fileselect_load_backup(TOPLEVEL *toplevel, GString *message);
+void x_compselect_comp_fill_libs(TOPLEVEL *w_current, COMPDIALOG *f_current);
+void x_compselect_comp_fill_components(COMPDIALOG *f_current, int row);
+void x_compselect_comp_update_current(COMPDIALOG *f_current, char *library, char *component);
+void x_compselect_change_clib(COMPDIALOG *f_current, char *new_clib, int row);
+void x_compselect_lib_select(GtkWidget *widget, gint row, gint column, GdkEventButton *bevent, COMPDIALOG *f_current);
+void x_compselect_comp_select(GtkWidget *widget, gint row, gint column, GdkEventButton *bevent, COMPDIALOG *f_current);
+void x_compselect_comp_apply(GtkWidget *w, COMPDIALOG *f_current);
+void x_compselect_comp_close(GtkWidget *w, COMPDIALOG *f_current);
+int x_compselect_search_library(COMPDIALOG *f_current, char *library, const char *string);
+void x_compselect_comp_search(GtkWidget *w, COMPDIALOG *f_current);
+void x_compselect_setup(TOPLEVEL *w_current);
 /* x_grid.c */
 void x_grid_draw(TOPLEVEL *w_current);
 void x_draw_tiles(TOPLEVEL *w_current);
Index: gaf/gschem/src/Makefile.am
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/Makefile.am,v
retrieving revision 1.44
diff -U3 -p -r1.44 Makefile.am
--- gaf/gschem/src/Makefile.am	20 Jul 2006 02:15:28 -0000	1.44
+++ gaf/gschem/src/Makefile.am	24 Jul 2006 18:48:20 -0000
@@ -21,7 +21,7 @@ gschem_SOURCES = \
 	x_basic.c x_dialog.c \
 	x_event.c x_grid.c x_log.c x_menus.c x_script.c \
 	x_pagesel.c x_print.c x_window.c x_stroke.c x_image.c x_color.c \
-	x_fileselect.c x_preview.c x_attribedit.c \
+	x_fileselect.c x_compselect.c x_preview.c x_attribedit.c \
 	x_multiattrib.c \
 	parsecmd.c o_cue.c
 
Index: gaf/gschem/src/i_callbacks.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/i_callbacks.c,v
retrieving revision 1.58
diff -U3 -p -r1.58 i_callbacks.c
--- gaf/gschem/src/i_callbacks.c	15 Jul 2006 18:51:41 -0000	1.58
+++ gaf/gschem/src/i_callbacks.c	24 Jul 2006 18:48:20 -0000
@@ -283,7 +283,7 @@ DEFINE_I_CALLBACK(file_open)
 
   exit_if_null(w_current);
 
-  x_fileselect_setup(w_current, FILESELECT, OPEN);
+  x_fileselect_setup(w_current, OPEN);
 
 #if 0 /* replaced by above */
   setup_open_file_selector(w_current);
@@ -344,7 +344,7 @@ DEFINE_I_CALLBACK(file_save)
    */
   if (strstr(w_current->page_current->page_filename,
              w_current->untitled_name)) {
-    x_fileselect_setup(w_current, FILESELECT, SAVEAS_NONE);
+    x_fileselect_setup(w_current, SAVEAS_NONE);
 #if 0 /* replaced with x_fileselect_setup */
     setup_saveas_file_selector(
                                w_current,
@@ -425,7 +425,7 @@ DEFINE_I_CALLBACK(file_save_as)
   TOPLEVEL *w_current = (TOPLEVEL *) data;
 
   exit_if_null(w_current);
-  x_fileselect_setup(w_current, FILESELECT, SAVEAS_NONE);
+  x_fileselect_setup(w_current, SAVEAS_NONE);
 
 #if 0 /* replaced with above */
   setup_saveas_file_selector(w_current,
@@ -1743,7 +1743,7 @@ DEFINE_I_CALLBACK(page_close)
   exit_if_null(w_current);
 
   if (w_current->page_current->CHANGED) {
-    x_fileselect_setup(w_current, FILESELECT, SAVEAS_CLOSE);
+    x_fileselect_setup(w_current, SAVEAS_CLOSE);
     return;
   }
 
@@ -2442,7 +2442,7 @@ DEFINE_I_CALLBACK(add_component)
 
   exit_if_null(w_current);
 
-  x_fileselect_setup(w_current, COMPSELECT, -1);
+  x_compselect_setup(w_current);
 
 #if 0 /* replaced by above */
   setup_place_file_selector(w_current);
Index: gaf/gschem/src/x_dialog.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_dialog.c,v
retrieving revision 1.57
diff -U3 -p -r1.57 x_dialog.c
--- gaf/gschem/src/x_dialog.c	15 Jul 2006 18:51:41 -0000	1.57
+++ gaf/gschem/src/x_dialog.c	24 Jul 2006 18:48:21 -0000
@@ -3393,11 +3393,11 @@ void x_dialog_raise_all(TOPLEVEL *w_curr
   }
 
 #if 0 /* don't raise these windows ever */ 
-  if(w_current->fileselect[FILESELECT].xfwindow) {
-    gdk_window_raise(w_current->fileselect[FILESELECT].xfwindow->window);
+  if(w_current->fileselect.xfwindow) {
+    gdk_window_raise(w_current->fileselect.xfwindow->window);
   }
-  if(w_current->fileselect[COMPSELECT].xfwindow) {
-    gdk_window_raise(w_current->fileselect[COMPSELECT].xfwindow->window);
+  if(w_current->compselect.xfwindow) {
+    gdk_window_raise(w_current->compselect.xfwindow->window);
   }
 #endif
 
Index: gaf/gschem/src/x_fileselect.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_fileselect.c,v
retrieving revision 1.21
diff -U3 -p -r1.21 x_fileselect.c
--- gaf/gschem/src/x_fileselect.c	15 Jul 2006 18:51:41 -0000	1.21
+++ gaf/gschem/src/x_fileselect.c	24 Jul 2006 18:48:21 -0000
@@ -660,23 +660,6 @@ void x_fileselect_saveas_close (GtkWidge
   gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
   f_current->xfwindow = NULL;
 
-#if 0 /* this isn't relavent anymore */
-  w_current = f_current->toplevel;
-
-  if (f_current->filesel_type == SAVEAS_QUIT) {
-    exit_dialog(w_current);
-  }
-
-  if (f_current->filesel_type == SAVEAS_OPEN) {
-    x_fileselect_setup (w_current, FILESELECT, SAVEAS_OPEN);
-  }
-
-  if (f_current->filesel_type == SAVEAS_NEW) {
-    w_current->page_current->CHANGED = 0;
-    i_callback_file_new(w_current, 0, NULL);
-  }
-#endif
-
   /* do nothing if close is pressed for SAVEAS_CLOSE case */
 }
 
@@ -1149,652 +1132,18 @@ void x_fileselect_search(GtkWidget *w, F
 }
 /*********** File Open/Save As... specific code ends here ***********/
 
-/*********** Component Place specific code starts here **************/
-/*! \section component-place-specific-code Component Place Specific Code.
- *  \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-gint default_components(GtkWidget *w, TOPLEVEL *w_current)
-{
-  w_current->embed_complex = 0;
-  w_current->include_complex = 0;
-  return(0);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-gint embed_components(GtkWidget *w, TOPLEVEL *w_current)
-{
-  w_current->embed_complex = 1;
-  w_current->include_complex = 0;
-  return(0);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-gint include_components(GtkWidget *w, TOPLEVEL *w_current)
-{
-  w_current->include_complex = 1;
-  w_current->embed_complex = 0;
-  return(0);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- *  \note
- *  this is from gtktest.c
- */
-static GtkWidget *create_menu (TOPLEVEL *w_current)
-{
-  GtkWidget *menu;
-  GtkWidget *menuitem;
-  GSList *group;
-  char *buf;
-
-  menu = gtk_menu_new ();
-  group = NULL;
-
-  buf = g_strdup_printf(_("Default behavior - reference component"));
-  menuitem = gtk_radio_menu_item_new_with_label (group, buf);
-  g_free(buf);
-  group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
-  gtk_menu_append (GTK_MENU (menu), menuitem);
-  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
-                     (GtkSignalFunc) default_components,
-                     w_current);
-
-  gtk_widget_show(menuitem);
-
-  buf = g_strdup_printf(_("Embed component in schematic"));
-  menuitem = gtk_radio_menu_item_new_with_label (group, buf);
-  g_free(buf);
-  group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
-  gtk_menu_append (GTK_MENU (menu), menuitem);
-  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
-                     (GtkSignalFunc) embed_components,
-                     w_current);
-  gtk_widget_show(menuitem);
-
-  buf = g_strdup_printf(_("Include component as individual objects"));
-  menuitem = gtk_radio_menu_item_new_with_label (group, buf);
-  g_free(buf);
-  group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
-  gtk_menu_append (GTK_MENU (menu), menuitem);
-  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
-                     (GtkSignalFunc) include_components,
-                     w_current);
-  gtk_widget_show(menuitem);
-
-  if (w_current->embed_complex) {
-    gtk_menu_set_active(GTK_MENU (menu),1);
-    embed_components(NULL, w_current);
-  } else {
-    default_components(NULL, w_current);
-  }
-
-  return menu;
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_comp_fill_libs(TOPLEVEL *w_current, FILEDIALOG *f_current)
-{
-  char *text[2];
-  char *temp;
-  int i;
-  int max_width=0;
-  int width;
-  int first,last,done,j;		/* variables for the sort */
-  const GSList *dirs, *dir;
-
-  gtk_clist_freeze (GTK_CLIST (f_current->dir_list));
-  gtk_clist_clear (GTK_CLIST (f_current->dir_list));
-
-  i = 0;
-  text[0] = NULL;
-  text[1] = NULL;
-  max_width = 0;
-
-  /* populate the directory list */
-  dirs = s_clib_get_directories ();
-  for (dir = dirs; dir != NULL; dir = g_slist_next (dir)) {
-    gchar *string = (gchar*)dir->data;
-
-    temp = strrchr(string, G_DIR_SEPARATOR);
-    if (temp) {
-      temp++; /* get past last '/' */
-      text[0] = temp;
-    } else {
-      text[0] = string;
-    }
-
-    f_current->directory_entries[i++] = g_strdup (string);
-    
-    gtk_clist_append (GTK_CLIST (f_current->dir_list), text);
-
-#ifdef HAS_GTK22
-    width = gdk_string_width(gtk_style_get_font(f_current->dir_list->style), 
-                             text[0]);
-#else
-    width = gdk_string_width(f_current->dir_list->style->font,
-                             text[0]);
-#endif
-
-    if (width > max_width) {
-      gtk_clist_set_column_width(GTK_CLIST(f_current->
-                                           dir_list), 0, width);
-      max_width = width;
-    }
-  }
-
-  gtk_clist_thaw (GTK_CLIST (f_current->dir_list));
-  f_current->last_search_lib = -1;
-
-  /* added sort for the directory list so it would match the 
-     automatically sorted clist of directories
-     Chris Ellec - May 2001                           */
-  if (w_current->sort_component_library == TRUE) {
-    done = 0;
-    first = 0;
-    last = i;
-    while(!done) {
-      done = 1;
-      for (j = first ; j < last-1; j++) {
-        /*printf ("%i:",j);*/
-        if (strcmp(f_current->directory_entries[j], 
-                   f_current->directory_entries[j+1]) > 0) {
-          temp = f_current->directory_entries[j];
-          f_current->directory_entries[j] = 
-            f_current->directory_entries[j+1];
-          f_current->directory_entries[j+1] = temp;
-          done = 0;
-        }
-      }
-      last = last - 1;
-
-#if DEBUG 
-      pass_count++;
-#endif
-    }
-  }
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_comp_fill_components(FILEDIALOG *f_current, int row)
-{
-  GSList *filenames, *filename;
-  gint width = 0, max_width = 0;
-	
-  gtk_clist_freeze (GTK_CLIST (f_current->file_list));
-  gtk_clist_clear (GTK_CLIST (f_current->file_list));
-
-  /* update current_clib in toplevel with new directory name */
-  if (f_current->toplevel->current_clib) {
-    g_free (f_current->toplevel->current_clib);
-  }
-  f_current->toplevel->current_clib = g_strdup (
-    f_current->directory_entries[row]);
-
-  /* get the list of filenames in directory */
-  filenames = s_clib_get_files (f_current->directory_entries[row], ".sym");
-
-  filename = filenames;
-  while (filename != NULL) {
-    gchar *text[2];
-
-    text[0] = (gchar*) filename->data;
-    text[1] = NULL;
-    
-    /* add filename to the clist */
-    gtk_clist_append (GTK_CLIST (f_current->file_list), text);
-    
-#ifdef HAS_GTK22
-    width = gdk_string_width (gtk_style_get_font (
-                                f_current->file_list->style),
-                              (gchar*) filename->data);
-#else
-    width = gdk_string_width (f_current->file_list->style->font,
-                              (gchar*) filename->data);
-#endif
-    if (width > max_width) {
-      /* increase the width of the column */
-      gtk_clist_set_column_width (GTK_CLIST (f_current->file_list),
-                                  0, width);
-      max_width = width;
-    }
-    
-    /* continue with the next filename */
-    filename = g_slist_next (filename);
-  }
-
-  /* get ride of the list of filenames */
-  g_slist_foreach (filenames, (GFunc)g_free, NULL);
-  g_slist_free (filenames);
-
-  /* allow visual updates to clist */
-  gtk_clist_thaw (GTK_CLIST (f_current->file_list));
-      
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- *  \note
- *  don't pass in f_current->filename or f_current->directory for component
- *  or library
- */
-void x_fileselect_comp_update_current(FILEDIALOG *f_current, 
-				      char *library, char *component)
-{
-  char *temp=NULL;
-
-  /* component */
-  if (f_current->filename) {
-    g_free(f_current->filename);
-    f_current->filename = NULL;
-  }
-
-  /* library */
-  if (f_current->directory) {
-    g_free(f_current->directory);
-    f_current->directory = NULL;
-  }
-
-  if (library) {
-    f_current->directory = g_strdup(library);
-  } else {
-    f_current->directory = NULL;
-  }
-
-  if (component) {
-    f_current->filename = g_strdup(component);
-  } else {
-    f_current->filename = NULL;
-  }
-
-  if (f_current->directory && f_current->filename) {
-#ifdef __MINGW32__
-    if (u_basic_has_trailing(f_current->directory, G_DIR_SEPARATOR)) {
-    	temp = g_strconcat (f_current->directory, 
-                            f_current->filename, NULL);
-    } else {
-#endif
-    	temp = g_strconcat (f_current->directory, 
-                            G_DIR_SEPARATOR_S,
-                            f_current->filename, NULL);
-#ifdef __MINGW32__
-    }
-#endif
-    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), temp);
-    g_free(temp);
-  } else if (f_current->directory && !f_current->filename) {
-    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), 
-                       f_current->directory);
-  } else if (!f_current->directory) {
-    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), 
-                       "NONE");
-  }
-
-#if 0 /* old code */
-  if (f_current->directory && f_current->filename) {
-    temp = g_strconcat (f_current->directory, 
-                        f_current->filename, NULL);
-    gtk_label_set(GTK_LABEL(f_current->filename_entry), temp);
-  } else if (f_current->directory && !f_current->filename) {
-    gtk_label_set(GTK_LABEL(f_current->filename_entry), 
-                  f_current->directory);
-  } else if (!f_current->directory) {
-    gtk_label_set(GTK_LABEL(f_current->filename_entry), 
-                  " ");
-  }
-#endif
-
-#if DEBUG 
-  printf("directory: %s\n", f_current->directory);
-  printf("filename: %s\n", f_current->filename);
-#endif
-
-}
-
 /*! \todo Finish function documentation!!!
  *  \brief
  *  \par Function Description
  *
  */
-void x_fileselect_change_clib(FILEDIALOG *f_current, char *new_clib,
-			      int row)
-{
-  x_fileselect_comp_update_current(f_current, new_clib, NULL);
-  x_fileselect_comp_fill_components(f_current, row);
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_lib_select (GtkWidget *widget, gint row, gint column,
-			      GdkEventButton *bevent, FILEDIALOG *f_current)
-{
-  char *temp = NULL;
-
-  gtk_clist_get_text (GTK_CLIST (f_current->dir_list), row, 0, &temp);
-
-  if (temp) {	
-#if DEBUG 
-    printf("selected: %d _%s_ _%s_\n", row, temp, 
-           f_current->directory_entries[row]);
-#endif
-    if (bevent) {
-      switch (bevent->type) {
-        /*	case(GDK_2BUTTON_PRESS): */
-        default:
-          x_fileselect_change_clib(f_current, 
-                                   f_current->directory_entries[row],
-                                   row);
-          break;
-
-      }
-    }
-  }
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_comp_select (GtkWidget *widget, gint row, gint column,
-			       GdkEventButton *bevent, FILEDIALOG *f_current)
-{
-  char *comp = NULL;
-  int diff_x, diff_y;
-  TOPLEVEL *w_current;
-
-  w_current = f_current->toplevel;
-
-  gtk_clist_get_text (GTK_CLIST (f_current->file_list), row, 0, &comp);
-
-  if (comp) {	
-    strcpy(w_current->current_basename, comp);
-
-    if (f_current->preview_control && w_current->current_clib && comp) { 
-      x_preview_update(f_current->preview, 
-                       w_current->current_clib,
-                       comp);
-    }
-
-    x_fileselect_comp_update_current(f_current, 
-                                     w_current->current_clib, comp);
-
-    if (w_current->event_state == ENDCOMP) {
-      diff_x = w_current->last_x - w_current->start_x;
-      diff_y = w_current->last_y - w_current->start_y;
-
-      o_complex_translate_display(w_current,
-                                  diff_x, diff_y,
-                                  w_current->page_current->complex_place_head);
-    }
-
-    o_list_delete_rest(w_current,
-                       w_current->page_current->complex_place_head);
-    o_complex_set_filename(w_current, w_current->current_clib,
-                           w_current->current_basename);
-
-    w_current->event_state = DRAWCOMP;
-  }
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_comp_apply(GtkWidget *w, FILEDIALOG *f_current)
-{
-  TOPLEVEL *w_current;
-  int diff_x, diff_y;
-	
-  w_current = f_current->toplevel;
-
-  if (w_current->current_basename && w_current->current_clib) {
-    if (w_current->event_state == ENDCOMP) {
-      diff_x = w_current->last_x - w_current->start_x;
-      diff_y = w_current->last_y - w_current->start_y;
-
-      o_complex_translate_display(w_current,
-                                  diff_x, diff_y,
-                                  w_current->page_current->complex_place_head);
-    }
-
-    o_list_delete_rest(w_current,
-                       w_current->page_current->complex_place_head);
-    o_complex_set_filename(w_current, w_current->current_clib,
-                           w_current->current_basename);
-
-    w_current->event_state = DRAWCOMP;
-  }
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_comp_close (GtkWidget *w, FILEDIALOG *f_current)
-{
-  TOPLEVEL *w_current;
-
-  w_current = f_current->toplevel;
-
-  /* erase any existing component while it's being placed */
-  /* do this instead of the below o_redraw_all */
-  if (w_current->inside_action &&
-      (w_current->event_state == ENDCOMP ||
-       w_current->event_state == DRAWCOMP)) {
-    o_complex_rubbercomplex(w_current);
-  }
-
-  o_list_delete_rest(w_current, w_current->page_current->
-                     complex_place_head);
-
-  i_set_state(w_current, SELECT);
-  i_update_toolbar(w_current);
-
-  gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
-  f_current->xfwindow = NULL;
-  /* do nothing if close is pressed for SAVEAS_CLOSE case */
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-int x_fileselect_search_library(FILEDIALOG *f_current,
-				char *library, const char *string) 
-{
-  GSList *filenames, *filename;
-  int ret;
-
-  /* get the filenames with '.sym' in library */
-  filenames = s_clib_get_files(library, ".sym");
-
-  if (f_current->last_search == -1) {
-    /* last search failed: start over */
-    f_current->last_search = 0;
-  }
-
-  /* start search from last known position */
-  filename = g_slist_nth (filenames, (guint)f_current->last_search);
-  while (filename != NULL) {
-    /* increase position in search */
-    f_current->last_search++;
-
-    /* does filename match the query? */
-    if (strstr ((gchar*) filename->data, string)) {
-      /* yes, stop the search, prepare to return last_search */
-#if DEBUG
-      printf("found: %s %s %s %d\n", library, filename->data, string, f_current->last_search - 1);
-#endif
-      break;
-    }
-    
-    filename = g_slist_next (filename);
-  }
-
-  /* free the list of filenames */
-  g_slist_foreach (filenames, (GFunc)g_free, NULL);
-  g_slist_free (filenames);
-
-  /* nothing found? */
-  if (filename == NULL) {
-    /* no, reset for next search */
-    f_current->last_search = -1;
-    ret = -1;
-  } else {
-    /* yes, return the position in the list of the filename found */
-    ret = f_current->last_search - 1;
-  }
-
-  return ret;
-}
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- *  \note
- *  don't use widget, since it can be NULL
- */
-void x_fileselect_comp_search(GtkWidget *w, FILEDIALOG *f_current)
-{
-  TOPLEVEL *w_current;
-  const char *string;
-  int lib_count;
-  int flag;
-
-  w_current = f_current->toplevel;
-
-  string = gtk_entry_get_text(GTK_ENTRY(f_current->search_entry));
-	
-  if (!string) {
-    return;
-  }
-
-  gtk_entry_select_region(GTK_ENTRY(f_current->search_entry), 0, -1);
-
-  if (f_current->last_search_lib != -1) {
-    lib_count = f_current->last_search_lib;	
-    gtk_label_set(GTK_LABEL(f_current->search_label),
-                  _("Search in Components")); 
-  } else {
-    lib_count = 0;
-    gtk_label_set(GTK_LABEL(f_current->search_label),
-                  _("Search in Components")); 
-  }
-
-  while(f_current->directory_entries[lib_count] != NULL) {
-    flag = x_fileselect_search_library(f_current, 
-                                       f_current->directory_entries[lib_count], 
-                                       string);
-    if (flag != -1) {
-      gtk_clist_select_row(GTK_CLIST(f_current->dir_list), 
-                           lib_count, 0);
-
-      gtk_clist_moveto(GTK_CLIST(
-                                 f_current->dir_list), 
-                       lib_count, 0, -1, -1);
-
-      x_fileselect_change_clib(f_current, 
-                               f_current->
-                               directory_entries[lib_count],
-                               lib_count);
-
-      gtk_clist_select_row(GTK_CLIST(f_current->file_list), 
-                           flag, 0);
-
-      gtk_clist_moveto(GTK_CLIST(
-                                 f_current->file_list), 
-                       flag, 0, -1, -1);
-
-      f_current->last_search_lib = lib_count; 
-      return;
-    } else {
-      lib_count++;
-    }
-  }
-
-
-  f_current->last_search_lib = -1;
-  f_current->last_search = -1;
-
-#if 0 /* I'm not sure this is worth the effort and the confusion it causes */
-  /* now search the library names */
-  lib_count = 0;
-  while(f_current->directory_entries[lib_count] != NULL) {
-    if (strstr(f_current->directory_entries[lib_count], string)) {
-
-      printf("%s %s\n", f_current->directory_entries[lib_count], string);
-
-      gtk_clist_select_row(GTK_CLIST(f_current->dir_list), 
-                           lib_count, 0);
-
-      gtk_clist_moveto(GTK_CLIST(
-                                 f_current->dir_list), 
-                       lib_count, 0, -1, -1);
-
-      x_fileselect_change_clib(f_current, 
-                               f_current->
-                               directory_entries[lib_count],
-                               lib_count);
-
-      gtk_label_set(GTK_LABEL(f_current->search_label),
-                    _("Search in Components - Found library only")); 
-      return;
-    }
-    lib_count++;
-  }
-  f_current->last_search_lib = -1;
-#endif
-
-  gtk_label_set(GTK_LABEL(f_current->search_label),
-                _("Search in Components - End of list")); 
-
-}
-/*********** Component Place specific code ends here **************/
-
-/*! \todo Finish function documentation!!!
- *  \brief
- *  \par Function Description
- *
- */
-void x_fileselect_setup_old (TOPLEVEL *w_current, int type, int filesel_type)
+void x_fileselect_setup_old (TOPLEVEL *w_current, int filesel_type)
 {
   GtkWidget *buttonapply = NULL;
   GtkWidget *buttonclose = NULL;
   GtkWidget *scrolled_win;
   GtkWidget *action_area;
   GtkWidget *separator;
-  GtkWidget *optionmenu;
   GtkWidget *drawbox;
   GtkWidget *label;
   GtkWidget *searchbox;
@@ -1806,46 +1155,33 @@ void x_fileselect_setup_old (TOPLEVEL *w
   char *dir_title [2];
   char *file_title [2];
 
-
-  if (type < 0 || type > 2) {
-    return;
-  }
-
-  f_current = &w_current->fileselect[type];
+  f_current = &w_current->fileselect;
 
   if (!f_current->xfwindow) {
 
     f_current->xfwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     f_current->toplevel = w_current;
-    f_current->type = type;
     f_current->filesel_type = filesel_type;
     f_current->last_search = -1;
     f_current->filename = NULL;
     f_current->directory = NULL;
 
-    if (type == FILESELECT) {
 
-      gtk_window_position(GTK_WINDOW(f_current->xfwindow),
-                          GTK_WIN_POS_MOUSE);
+    gtk_window_position(GTK_WINDOW(f_current->xfwindow),
+                        GTK_WIN_POS_MOUSE);
 
-      if (filesel_type == OPEN) {
-        gtk_window_set_title(GTK_WINDOW(
-                                        f_current->xfwindow),
-                             _("Open..."));
-      } else if (filesel_type == SAVEAS) {
-        gtk_window_set_title(GTK_WINDOW(
-                                        f_current->xfwindow),
-                             _("Save As..."));
-      } else if (filesel_type == SAVEAS_CLOSE) {
-        gtk_window_set_title(GTK_WINDOW(
-                                        f_current->xfwindow),
-                             _("Save As..."));
-      }
-    } else {
-      gtk_window_position(GTK_WINDOW(f_current->xfwindow),
-                          GTK_WIN_POS_NONE);
-      gtk_window_set_title(GTK_WINDOW(f_current->xfwindow),
-                           _("Select Component..."));
+    if (filesel_type == OPEN) {
+      gtk_window_set_title(GTK_WINDOW(
+                                      f_current->xfwindow),
+                           _("Open..."));
+    } else if (filesel_type == SAVEAS) {
+      gtk_window_set_title(GTK_WINDOW(
+                                      f_current->xfwindow),
+                           _("Save As..."));
+    } else if (filesel_type == SAVEAS_CLOSE) {
+      gtk_window_set_title(GTK_WINDOW(
+                                      f_current->xfwindow),
+                           _("Save As..."));
     }
 
     gtk_signal_connect(GTK_OBJECT(f_current->xfwindow),
@@ -1880,28 +1216,22 @@ void x_fileselect_setup_old (TOPLEVEL *w
 
 
     /*  ----- Create the filter selection area -----  */
-    if (type == FILESELECT) {
-      f_current->filter_type = FILEDIALOG_SCH_ONLY;
-    } else {
-      f_current->filter_type = FILEDIALOG_SYM_ONLY;
-    }
+    f_current->filter_type = FILEDIALOG_SCH_ONLY;
 
-    if (type == FILESELECT) {
-      label=gtk_label_new(_("Filter"));
-      gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
-      gtk_box_pack_start(GTK_BOX(vbox), label, 
-                         FALSE, FALSE, 0);
-      gtk_widget_show(label);
-
-      f_current->filter = gtk_option_menu_new ();
-      gtk_option_menu_set_menu(GTK_OPTION_MENU(f_current->filter),
-                               x_fileselect_filter_menu(f_current));
-      /* gtk_option_menu_set_history(GTK_OPTION_MENU(f_current->filter),
-         4);*/
-      gtk_box_pack_start(GTK_BOX(vbox), f_current->filter, 
-                         FALSE, FALSE, 0);
-      gtk_widget_show (f_current->filter);
-    }
+    label=gtk_label_new(_("Filter"));
+    gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+    gtk_box_pack_start(GTK_BOX(vbox), label, 
+                       FALSE, FALSE, 0);
+    gtk_widget_show(label);
+
+    f_current->filter = gtk_option_menu_new ();
+    gtk_option_menu_set_menu(GTK_OPTION_MENU(f_current->filter),
+                             x_fileselect_filter_menu(f_current));
+    /* gtk_option_menu_set_history(GTK_OPTION_MENU(f_current->filter),
+       4);*/
+    gtk_box_pack_start(GTK_BOX(vbox), f_current->filter, 
+                       FALSE, FALSE, 0);
+    gtk_widget_show (f_current->filter);
 
     list_hbox = gtk_hbox_new (FALSE, 5);
     gtk_box_pack_start (GTK_BOX (vbox), list_hbox, TRUE, TRUE, 0);
@@ -1928,25 +1258,15 @@ void x_fileselect_setup_old (TOPLEVEL *w
 
     
     /*  -----  Create the "directories"/"libraries" clist widgets -----  */
-    if (type == FILESELECT) {
-      dir_title[0] = g_strdup(_("Directories"));
-    } else {
-      dir_title[0] = g_strdup(_("Libraries"));
-    }
+    dir_title[0] = g_strdup(_("Directories"));
     dir_title[1] = NULL;
     f_current->dir_list = gtk_clist_new_with_titles(1, 
                                                     (char**) dir_title);
     gtk_widget_set_usize(f_current->dir_list, 
                          DIR_LIST_WIDTH, DIR_LIST_HEIGHT);
-    if (type == FILESELECT) {
-      gtk_signal_connect (GTK_OBJECT (f_current->dir_list), 
-                          "select_row", (GtkSignalFunc) 
-                          x_fileselect_dir_button, f_current);
-    } else {
-      gtk_signal_connect (GTK_OBJECT (f_current->dir_list), 
-                          "select_row", (GtkSignalFunc) 
-                          x_fileselect_lib_select, f_current);
-    } 
+    gtk_signal_connect (GTK_OBJECT (f_current->dir_list), 
+                        "select_row", (GtkSignalFunc) 
+                        x_fileselect_dir_button, f_current);
     gtk_clist_column_titles_passive(GTK_CLIST(f_current->dir_list));
 
     scrolled_win = gtk_scrolled_window_new(NULL, NULL);
@@ -1967,11 +1287,7 @@ void x_fileselect_setup_old (TOPLEVEL *w
     g_free(dir_title[0]);
     
     /*  ----- Create the files clist -----  */
-    if (type == FILESELECT) {
-      file_title[0] = g_strdup (_("Files"));
-    } else {
-      file_title[0] = g_strdup (_("Components"));
-    }
+    file_title[0] = g_strdup (_("Files"));
     file_title[1] = NULL;
     f_current->file_list = gtk_clist_new_with_titles(1, 
                                                      (gchar**) file_title);
@@ -1979,23 +1295,14 @@ void x_fileselect_setup_old (TOPLEVEL *w
                          FILE_LIST_WIDTH, FILE_LIST_HEIGHT);
     
     /*  Stuff added by SDB to enable opening multiple files at once   */
-    if (type == FILESELECT) {
-      gtk_clist_set_selection_mode(GTK_CLIST(f_current->file_list),
-                                   GTK_SELECTION_EXTENDED);
-    }	
-
-    if (type == FILESELECT) {
-      gtk_signal_connect(GTK_OBJECT (f_current->file_list), 
-                         "select_row", 
-                         /* This is file opening callback */
-                         (GtkSignalFunc) x_fileselect_file_button, 
-                         f_current);
-    } else {
-      gtk_signal_connect(GTK_OBJECT (f_current->file_list), 
-                         "select_row",
-                         (GtkSignalFunc) x_fileselect_comp_select,
-                         f_current);
-    }
+    gtk_clist_set_selection_mode(GTK_CLIST(f_current->file_list),
+                                 GTK_SELECTION_EXTENDED);
+
+    gtk_signal_connect(GTK_OBJECT (f_current->file_list), 
+                       "select_row", 
+                       /* This is file opening callback */
+                       (GtkSignalFunc) x_fileselect_file_button, 
+                       f_current);
     gtk_clist_column_titles_passive(GTK_CLIST(f_current->file_list));
 
     scrolled_win = gtk_scrolled_window_new (NULL, NULL);
@@ -2028,11 +1335,7 @@ void x_fileselect_setup_old (TOPLEVEL *w
     gtk_widget_show(f_current->preview_checkbox);
 
     /* -----  Create the search input text box -----  */
-    if (f_current->type == FILESELECT) {
-      f_current->search_label=gtk_label_new(_("Search in Files"));
-    } else {
-      f_current->search_label=gtk_label_new(_("Search in Components"));
-    }
+    f_current->search_label=gtk_label_new(_("Search in Files"));
     gtk_misc_set_alignment(GTK_MISC(f_current->search_label), 0, 0);
     gtk_box_pack_start(GTK_BOX(searchbox), f_current->search_label,
                        FALSE, FALSE, 5);
@@ -2044,30 +1347,13 @@ void x_fileselect_setup_old (TOPLEVEL *w
                                             f_current->search_entry), 0, -1);
     gtk_box_pack_start(GTK_BOX (searchbox), 
                        f_current->search_entry, FALSE, FALSE, 0);
-    if (type == FILESELECT) { 
-      gtk_signal_connect(GTK_OBJECT(f_current->search_entry), 
-                         "activate", 
-                         GTK_SIGNAL_FUNC(x_fileselect_search),
-                         f_current);
-    } else {
-      gtk_signal_connect(GTK_OBJECT(f_current->search_entry), 
-                         "activate", 
-                         GTK_SIGNAL_FUNC(x_fileselect_comp_search),
-                         f_current);
-    }
+    gtk_signal_connect(GTK_OBJECT(f_current->search_entry), 
+                       "activate", 
+                       GTK_SIGNAL_FUNC(x_fileselect_search),
+                       f_current);
     gtk_widget_grab_focus(f_current->search_entry);
     gtk_widget_show(f_current->search_entry);
 
-    /*  ----- Create the "Filename" text entry area -----  */
-    if (type == COMPSELECT) {
-      optionmenu = gtk_option_menu_new ();
-      gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu),
-                               create_menu (w_current));
-      gtk_box_pack_start(GTK_BOX(vbox), optionmenu, 
-                         FALSE, FALSE, 10);
-      gtk_widget_show (optionmenu);
-    }
-
     label=gtk_label_new(_("Filename"));
     gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
@@ -2080,43 +1366,34 @@ void x_fileselect_setup_old (TOPLEVEL *w
     gtk_box_pack_start(GTK_BOX (vbox), 
                        f_current->filename_entry, FALSE, FALSE, 0);
 
-    if (type == FILESELECT) {
-      if (filesel_type == OPEN) {
-        gtk_signal_connect(GTK_OBJECT(f_current->filename_entry),
-                           /* Here we connect the callback to
-                              fileselect_open_file to the filename in
-                              the filename text entry field..  */
-                           "activate", 
-                           GTK_SIGNAL_FUNC(
-					   x_fileselect_open_file),
-                           f_current);
-      } else if ((filesel_type == SAVEAS_NONE) ||
-                 (filesel_type == SAVEAS_QUIT) ||
-                 (filesel_type == SAVEAS_OPEN) ||
-                 (filesel_type == SAVEAS_CLOSE) ||
-                 (filesel_type == SAVEAS_NEW)) { 
-        gtk_signal_connect(GTK_OBJECT(
-                                      f_current->filename_entry), 
-                           "activate", 
-                           GTK_SIGNAL_FUNC(x_fileselect_saveas),
-                           f_current);
-      }
-      gtk_editable_select_region(GTK_EDITABLE(
-                                              f_current->filename_entry), 0, -1);
-    } else {
-      gtk_entry_set_editable(GTK_ENTRY(
-                                       f_current->filename_entry), FALSE);
+    if (filesel_type == OPEN) {
+      gtk_signal_connect(GTK_OBJECT(f_current->filename_entry),
+                         /* Here we connect the callback to
+                            fileselect_open_file to the filename in
+                            the filename text entry field..  */
+                         "activate", 
+                         GTK_SIGNAL_FUNC(
+			   x_fileselect_open_file),
+                         f_current);
+    } else if ((filesel_type == SAVEAS_NONE) ||
+               (filesel_type == SAVEAS_QUIT) ||
+               (filesel_type == SAVEAS_OPEN) ||
+               (filesel_type == SAVEAS_CLOSE) ||
+               (filesel_type == SAVEAS_NEW)) { 
+      gtk_signal_connect(GTK_OBJECT(
+                                    f_current->filename_entry), 
+                         "activate", 
+                         GTK_SIGNAL_FUNC(x_fileselect_saveas),
+                         f_current);
     }
+    gtk_editable_select_region(GTK_EDITABLE(
+                                            f_current->filename_entry), 0, -1);
 	
     gtk_widget_show(f_current->filename_entry);
 
     /*  ----- Here we create the "open"/"save as"/"apply" buttons -----  */
     if (filesel_type == OPEN) {
-#ifdef HAS_GTK12
-      buttonapply = gtk_button_new_with_label (_("Open"));
-#else
       buttonapply = gtk_button_new_from_stock (GTK_STOCK_OPEN);
-#endif
       gtk_signal_connect(GTK_OBJECT(buttonapply),
                          /* Here we attach callback fileselect_open_file to
                             the "Open" button */
@@ -2129,27 +1406,13 @@ void x_fileselect_setup_old (TOPLEVEL *w
                (filesel_type == SAVEAS_OPEN) ||
                (filesel_type == SAVEAS_CLOSE) ||
                (filesel_type == SAVEAS_NEW)) { 
-#ifdef HAS_GTK12
-      buttonapply = gtk_button_new_with_label (_("SaveAs"));
-#else
       buttonapply = gtk_button_new_from_stock (GTK_STOCK_SAVE_AS);
-#endif
       gtk_signal_connect(GTK_OBJECT(buttonapply),
                          "clicked",
                          GTK_SIGNAL_FUNC(x_fileselect_saveas),
                          f_current);
-    } else if (type == COMPSELECT) {
-#ifdef HAS_GTK12
-      buttonapply = gtk_button_new_with_label (_("Apply"));
-#else
-      buttonapply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
-#endif
-      gtk_signal_connect(GTK_OBJECT(buttonapply),
-                         "clicked",
-                         GTK_SIGNAL_FUNC(x_fileselect_comp_apply),
-                         f_current);
     }
-
+    
     GTK_WIDGET_SET_FLAGS(buttonapply, GTK_CAN_DEFAULT);
     gtk_box_pack_start(GTK_BOX(action_area),
                        buttonapply, TRUE, TRUE, 0);
@@ -2158,73 +1421,41 @@ void x_fileselect_setup_old (TOPLEVEL *w
     gtk_widget_show(buttonapply);
 
     /*  ----- Here we create the "cancel"/"close" buttons -----  */
-    if (type == FILESELECT) {
-      if (filesel_type == OPEN) {
-#ifdef HAS_GTK12
-        buttonclose = gtk_button_new_with_label (
-                                                 _("Cancel"));
-#else
-	buttonclose = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
-#endif
-        GTK_WIDGET_SET_FLAGS(buttonclose, 
-                             GTK_CAN_DEFAULT);
-        gtk_box_pack_start(GTK_BOX(action_area),
-                           buttonclose, TRUE, TRUE, 0);
-        gtk_signal_connect(GTK_OBJECT(buttonclose),
-                           "clicked",
-                           GTK_SIGNAL_FUNC(x_fileselect_close),
-                           f_current);
-        gtk_widget_show(buttonclose);
-
-        x_fileselect_update_dirfile(f_current, NULL);
-        x_fileselect_fill_lists(f_current);
-      } else if ((filesel_type == SAVEAS_NONE) ||
-                 (filesel_type == SAVEAS_QUIT) ||
-                 (filesel_type == SAVEAS_OPEN) ||
-                 (filesel_type == SAVEAS_CLOSE) ||
-                 (filesel_type == SAVEAS_NEW)) { 
-#ifdef HAS_GTK12
-        buttonclose = gtk_button_new_with_label (
-                                                 _("Cancel"));
-#else
-	buttonclose = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
-#endif
-        GTK_WIDGET_SET_FLAGS(buttonclose, 
-                             GTK_CAN_DEFAULT);
-        gtk_box_pack_start(GTK_BOX(action_area),
-                           buttonclose, TRUE, TRUE, 0);
-        gtk_signal_connect(GTK_OBJECT(buttonclose),
-                           "clicked",
-                           GTK_SIGNAL_FUNC(
-                                           x_fileselect_saveas_close),
-                           f_current);
-        gtk_widget_show(buttonclose);
-
-        x_fileselect_update_dirfile_saveas(f_current, 
-                                           w_current->page_current->page_filename);
-        x_fileselect_fill_lists(f_current);
-      }
-    } else {
-#ifdef HAS_GTK12
-      buttonclose = gtk_button_new_with_label (_("Close"));
-#else
-      buttonclose = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
-#endif
-      GTK_WIDGET_SET_FLAGS(buttonclose, GTK_CAN_DEFAULT);
+    if (filesel_type == OPEN) {
+      buttonclose = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+      GTK_WIDGET_SET_FLAGS(buttonclose, 
+                         GTK_CAN_DEFAULT);
+      gtk_box_pack_start(GTK_BOX(action_area),
+                         buttonclose, TRUE, TRUE, 0);
+      gtk_signal_connect(GTK_OBJECT(buttonclose),
+                         "clicked",
+                         GTK_SIGNAL_FUNC(x_fileselect_close),
+                         f_current);
+      gtk_widget_show(buttonclose);
+
+      x_fileselect_update_dirfile(f_current, NULL);
+      x_fileselect_fill_lists(f_current);
+    } else if ((filesel_type == SAVEAS_NONE) ||
+               (filesel_type == SAVEAS_QUIT) ||
+               (filesel_type == SAVEAS_OPEN) ||
+               (filesel_type == SAVEAS_CLOSE) ||
+               (filesel_type == SAVEAS_NEW)) { 
+      buttonclose = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+      GTK_WIDGET_SET_FLAGS(buttonclose, 
+                           GTK_CAN_DEFAULT);
       gtk_box_pack_start(GTK_BOX(action_area),
                          buttonclose, TRUE, TRUE, 0);
       gtk_signal_connect(GTK_OBJECT(buttonclose),
                          "clicked",
-                         GTK_SIGNAL_FUNC(x_fileselect_comp_close),
+                         GTK_SIGNAL_FUNC(
+                                         x_fileselect_saveas_close),
                          f_current);
       gtk_widget_show(buttonclose);
 
-      /* files data structure is not used for components */
-      x_fileselect_setup_list_buffers(f_current,
-                                      g_slist_length ((GSList *) s_clib_get_directories()), 0);
-      x_fileselect_comp_update_current(f_current, NULL, NULL);
-      x_fileselect_comp_fill_libs(w_current, f_current);
-    }	
+      x_fileselect_update_dirfile_saveas(f_current, 
+                                         w_current->page_current->page_filename);
+      x_fileselect_fill_lists(f_current);
+    }
   }
 
   if (!GTK_WIDGET_VISIBLE(f_current->xfwindow)) {
@@ -2232,9 +1463,7 @@ void x_fileselect_setup_old (TOPLEVEL *w
     gdk_window_raise(f_current->xfwindow->window);
     x_preview_setup_rest(f_current->preview);
 
-    if (type == FILESELECT) {
-      gtk_grab_add (f_current->xfwindow);
-    }
+    gtk_grab_add (f_current->xfwindow);
 
     /* need to delay this till the drawing area is created and
      * is showing */
@@ -2267,10 +1496,9 @@ void x_fileselect_setup_old (TOPLEVEL *w
  *  This function creates the "open/save file" dialog box.
  *
  *  \param [in] w_current     The TOPLEVEL object.
- *  \param [in] type          \todo What is do?
  *  \param [in] filesel_type  \todo What to do?
  */
-void x_fileselect_setup (TOPLEVEL *w_current, int type, int filesel_type)
+void x_fileselect_setup (TOPLEVEL *w_current, int filesel_type)
 {
 #if ((GTK_MAJOR_VERSION > 2) || \
      ((GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION >= 4)) )
@@ -2278,24 +1506,20 @@ void x_fileselect_setup (TOPLEVEL *w_cur
   GtkImage *preview_widget;
   gchar *title;
   FILEDIALOG *f_current;
-  if (type < 0 || type > 2) {
-    return;
-  }
 
   if ( (filesel_type != OPEN) &&
        (filesel_type != SAVEAS) &&
        (filesel_type != SAVEAS_CLOSE) ) {
-    x_fileselect_setup_old(w_current, type, filesel_type);
+    x_fileselect_setup_old(w_current, filesel_type);
   }
 
-  f_current = &w_current->fileselect[type];
+  f_current = &w_current->fileselect;
 
   if (!f_current->xfwindow) {
     GtkFileFilter *sch_filefilter, *sym_filefilter, 
       *sch_sym_filefilter, *all_filefilter;
 
     f_current->toplevel = w_current;
-    f_current->type = type;
     f_current->filesel_type = filesel_type;
     f_current->last_search = -1;
     f_current->filename = NULL;
@@ -2431,7 +1655,7 @@ void x_fileselect_setup (TOPLEVEL *w_cur
     else {
       /* If it's not file load/save, then it's component library selection.
 	 Use the old interface */
-      x_fileselect_setup_old(w_current, type, filesel_type);
+      x_fileselect_setup_old(w_current, filesel_type);
     }
     /* This is not the way to free filefilters. Really do they need to be freed?  */
     /*
@@ -2446,7 +1670,7 @@ void x_fileselect_setup (TOPLEVEL *w_cur
     gdk_window_raise(f_current->xfwindow->window);
   }
 #else
-  x_fileselect_setup_old(w_current, type, filesel_type);
+  x_fileselect_setup_old(w_current, filesel_type);
 #endif
 }
 
Index: gaf/gschem/src/x_window.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_window.c,v
retrieving revision 1.30
diff -U3 -p -r1.30 x_window.c
--- gaf/gschem/src/x_window.c	15 Jul 2006 18:51:41 -0000	1.30
+++ gaf/gschem/src/x_window.c	24 Jul 2006 18:48:21 -0000
@@ -118,14 +118,14 @@ void x_window_setup (TOPLEVEL *toplevel)
   toplevel->ltwindow = NULL;
   toplevel->ftwindow = NULL;
   toplevel->sewindow = NULL;
-  toplevel->fileselect[FILESELECT].xfwindow = NULL;
-  toplevel->fileselect[FILESELECT].directory = NULL;
-  toplevel->fileselect[FILESELECT].filename = NULL;
-  x_fileselect_init_list_buffers(&toplevel->fileselect[FILESELECT]);
-  toplevel->fileselect[COMPSELECT].xfwindow = NULL;
-  toplevel->fileselect[COMPSELECT].directory = NULL;
-  toplevel->fileselect[COMPSELECT].filename = NULL;
-  x_fileselect_init_list_buffers(&toplevel->fileselect[COMPSELECT]);
+  toplevel->fileselect.xfwindow = NULL;
+  toplevel->fileselect.directory = NULL;
+  toplevel->fileselect.filename = NULL;
+  x_fileselect_init_list_buffers(&toplevel->fileselect);
+  toplevel->compselect.xfwindow = NULL;
+  toplevel->compselect.directory = NULL;
+  toplevel->compselect.filename = NULL;
+  x_compselect_init_list_buffers(&toplevel->compselect);
 
   toplevel->coord_world = NULL;
   toplevel->coord_screen = NULL;
@@ -983,16 +983,16 @@ void x_window_close(TOPLEVEL *w_current)
   if (w_current->sewindow)
   gtk_widget_destroy(w_current->sewindow);
 
-  if (w_current->fileselect[FILESELECT].xfwindow) {
-    gtk_widget_destroy(w_current->fileselect[FILESELECT].xfwindow);
+  if (w_current->fileselect.xfwindow) {
+    gtk_widget_destroy(w_current->fileselect.xfwindow);
   }
 
-  if (w_current->fileselect[COMPSELECT].xfwindow) {
-    gtk_widget_destroy(w_current->fileselect[COMPSELECT].xfwindow);
+  if (w_current->compselect.xfwindow) {
+    gtk_widget_destroy(w_current->compselect.xfwindow);
   }
 
-  x_fileselect_free_list_buffers(&w_current->fileselect[FILESELECT]);
-  x_fileselect_free_list_buffers(&w_current->fileselect[COMPSELECT]);
+  x_fileselect_free_list_buffers(&w_current->fileselect);
+  x_compselect_free_list_buffers(&w_current->compselect);
 
   if (w_current->next == NULL && w_current->prev->prev == NULL) {
     /* no more window after this one, remember to quit */
Index: gaf/libgeda/include/defines.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/libgeda/include/defines.h,v
retrieving revision 1.54
diff -U3 -p -r1.54 defines.h
--- gaf/libgeda/include/defines.h	23 Jul 2006 21:49:02 -0000	1.54
+++ gaf/libgeda/include/defines.h	24 Jul 2006 18:48:21 -0000
@@ -36,7 +36,7 @@
 /* for color mechanism used in gschem */
 #define MAX_COLORS 25
 
-/* for new fileselection dialog box */
+/* for new fileselection and component selection dialog boxes */
 #define MAX_FILES 2048
 #define MAX_DIRS 2048
 
@@ -117,10 +117,6 @@
 #define NEW	3 /* next action after click is new */
 #define CLOSE	4 /* next action after click is close */
 
-/* for xfwindow array */
-#define FILESELECT	0
-#define COMPSELECT	1
-
 /* vvvvvvv this is a mess */
 
 /* flags to setup_saveas_file_selector() */
@@ -148,6 +144,12 @@
 #define FILEDIALOG_SCH_SYM	2
 #define FILEDIALOG_ALL_FILES	3
 
+/* for COMPDIALOG filter_type var */
+#define COMPDIALOG_SCH_ONLY	0
+#define COMPDIALOG_SYM_ONLY	1
+#define COMPDIALOG_SCH_SYM	2
+#define COMPDIALOG_ALL_FILES	3
+
 /* for attrib_edit_dialog invocation flag */
 #define FROM_MENU		0
 #define FROM_HOTKEY		1
Index: gaf/libgeda/include/struct.h
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/libgeda/include/struct.h,v
retrieving revision 1.85
diff -U3 -p -r1.85 struct.h
--- gaf/libgeda/include/struct.h	24 Jul 2006 03:29:21 -0000	1.85
+++ gaf/libgeda/include/struct.h	24 Jul 2006 18:48:21 -0000
@@ -37,6 +37,7 @@ typedef struct st_page PAGE;
 typedef struct st_toplevel TOPLEVEL;
 typedef struct st_color COLOR;
 typedef struct st_filedialog FILEDIALOG;
+typedef struct st_compdialog COMPDIALOG;
 typedef struct st_selection SELECTION;
 typedef struct st_undo UNDO;
 typedef struct st_tile TILE;
@@ -410,7 +411,6 @@ struct st_page {
 struct st_filedialog {
   GtkWidget *xfwindow;		
 
-  int type;
   int filesel_type;
 
   GtkWidget *filter;
@@ -418,7 +418,6 @@ struct st_filedialog {
 
   GtkWidget *search_entry;
   GtkWidget *search_label;
-  int last_search_lib;
   int last_search;		
 
   GtkWidget *filename_entry;
@@ -437,7 +436,39 @@ struct st_filedialog {
   GtkWidget *preview_checkbox;
   int preview_control;
 
-  GtkWidget *component_pulldown;
+  /* this points to the owner of this filedialog structure */
+  /* should NEVER be freed */
+  TOPLEVEL *toplevel;
+
+}; 
+
+struct st_compdialog {
+  GtkWidget *xfwindow;		
+
+  int filesel_type;
+
+  int filter_type;
+
+  GtkWidget *search_entry;
+  GtkWidget *search_label;
+  int last_search_lib;
+  int last_search;		
+
+  GtkWidget *filename_entry;
+
+  GtkWidget *dir_list;
+  GtkWidget *file_list;
+
+  char *directory;
+  char *filename;
+
+  /* need to make this dynamic TODO ?? */
+  char *directory_entries[MAX_DIRS];
+  char *file_entries[MAX_FILES];
+
+  TOPLEVEL *preview;
+  GtkWidget *preview_checkbox;
+  int preview_control;
 
   /* this points to the owner of this filedialog structure */
   /* should NEVER be freed */
@@ -613,7 +644,8 @@ struct st_toplevel {
   char current_basename[256]; 	
 
 
-  FILEDIALOG fileselect[2];
+  FILEDIALOG fileselect;
+  COMPDIALOG compselect;
   /* see define.h for what */
   /* each of the different */
   /* members of this array are */
Index: gaf/gschem/src/x_compselect.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gschem/src/x_compselect.c,v
retrieving revision 1.00
diff -U3 -p -r1.00 -N x_comp_select.c
--- gaf/gschem/src/x_compselect.c	1970-01-01 01:00:00.000000000 +0100
+++ gaf/gschem/src/x_compselect.c	2006-07-24 19:47:35.000000000 +0100
@@ -0,0 +1,1537 @@
+/* gEDA - GPL Electronic Design Automation
+ * gschem - gEDA Schematic Capture
+ * Copyright (C) 1998-2000 Ales V. Hvezda
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
+ */
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <libgeda/libgeda.h>
+#include <gtk/gtk.h>
+
+#include "../include/globals.h"
+#include "../include/prototype.h"
+
+#ifdef HAVE_LIBDMALLOC
+#include <dmalloc.h>
+#endif
+
+#define LIB_LIST_WIDTH   180
+#define LIB_LIST_HEIGHT  180
+#define COMP_LIST_WIDTH  180
+#define COMP_LIST_HEIGHT 180
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_destroy_window(GtkWidget *widget, COMPDIALOG *f_current)
+{
+
+#if DEBUG
+  printf("destroy\n");
+#endif
+  x_compselect_free_list_buffers(f_current);
+
+  if (f_current->directory) {
+    g_free(f_current->directory);
+    f_current->directory = NULL;
+  }
+
+  if (f_current->filename) {
+    g_free(f_current->filename);
+    f_current->filename = NULL;
+  }
+
+  x_preview_close(f_current->preview);
+  gtk_grab_remove(f_current->xfwindow);
+  f_current->toplevel = NULL;
+  f_current->xfwindow = NULL;
+  /* *window = NULL;*/
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+int x_compselect_keypress(GtkWidget * widget, GdkEventKey * event, 
+			  COMPDIALOG* f_current)
+{
+  if (strcmp(gdk_keyval_name(event->keyval), "Escape") == 0) {
+    x_compselect_close (NULL, f_current);
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_init_list_buffers(COMPDIALOG *f_current) 
+{
+  int i;
+
+  for (i = 0; i < MAX_FILES; i++) {
+    f_current->file_entries[i] = NULL;
+  }
+
+  for (i = 0; i < MAX_DIRS; i++) {
+    f_current->directory_entries[i] = NULL;
+  }
+	
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_free_list_buffers(COMPDIALOG *f_current) 
+{
+  int i;
+
+  for (i = 0; i < MAX_FILES; i++) {
+    if (f_current->file_entries[i]) 
+      g_free(f_current->file_entries[i]);
+
+    f_current->file_entries[i] = NULL;
+  }
+
+  for (i = 0; i < MAX_DIRS; i++) {
+    if (f_current->directory_entries[i]) 
+    g_free(f_current->directory_entries[i]);
+
+    f_current->directory_entries[i] = NULL;
+  }
+}
+
+/*********** File Open/Save As... specific code starts here ***********/
+/*! \section file-open-save-as File Open/Save As Functions.
+ *  \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_update_dirfile(COMPDIALOG *f_current, char *filename)
+{
+  char *temp=NULL;
+
+  if (f_current->filename) {
+    g_free(f_current->filename);
+    f_current->filename = NULL;
+  }
+
+  if (f_current->directory) {
+    g_free(f_current->directory);
+    f_current->directory = NULL;
+  }
+
+  /* this may cause problems on non POSIX complient systems */	
+  temp = getcwd(NULL, 1024);
+	
+  if (filename) {
+    f_current->directory = g_strdup (temp); 
+    f_current->filename = g_strdup (filename);
+					
+    g_free(temp); 
+#ifdef __MINGW32__
+    if (u_basic_has_trailing(f_current->directory, G_DIR_SEPARATOR)) {
+       temp = g_strconcat (f_current->directory, 
+                           f_current->filename, NULL);
+    } else {
+#endif
+       temp = g_strconcat (f_current->directory, 
+                           G_DIR_SEPARATOR_S,
+                           f_current->filename, NULL);
+#ifdef __MINGW32__
+    }
+#endif
+
+    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), temp);
+
+  } else {
+    f_current->directory = g_strdup (temp);
+
+    if (f_current->filename) { 
+      g_free(f_current->filename);
+      f_current->filename=NULL;
+    }
+
+    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), 
+                       f_current->directory);
+  }
+
+  g_free(temp);
+
+#if DEBUG
+  printf("directory: %s\n", f_current->directory);
+#endif
+
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_setup_list_buffers(COMPDIALOG *f_current, 
+				     int num_files, int num_directories)
+{
+  int i;
+
+  for (i = 0; i < num_files+1; i++) {
+    if (f_current->file_entries[i]) {
+      g_free(f_current->file_entries[i]);
+    }
+    f_current->file_entries[i] = NULL;
+  }
+
+  for (i = 0; i < num_directories+1; i++) {
+    if (f_current->directory_entries[i]) {
+      g_free(f_current->directory_entries[i]);
+    }
+    f_current->directory_entries[i] = NULL;
+  }
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ *  \return TRUE if the file should be included (passes the filter),
+ *          FALSE otherwise.
+ */
+int x_compselect_include_file(char *filename, int filter_type)
+{
+  switch(filter_type) {
+    case(COMPDIALOG_SCH_ONLY):
+    if (strstr(filename, ".sch")) {
+      return(TRUE);
+    }
+    break;
+
+    case(COMPDIALOG_SYM_ONLY):
+    if (strstr(filename, ".sym")) {
+      return(TRUE);
+    }
+    break;
+
+    case(COMPDIALOG_SCH_SYM):
+    if (strstr(filename, ".sch") || 
+        strstr(filename, ".sym")) {
+      return(TRUE);
+    }
+    break;
+
+    case(COMPDIALOG_ALL_FILES):
+    return(TRUE);
+    break;
+  }
+
+  return(FALSE);
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_fill_lists(COMPDIALOG *f_current)
+{
+  DIR* directory;
+  struct dirent *dirent_ptr;
+  int num_files=0;
+  int num_directories=0;
+  int file_count = 0;
+  int dir_count = 0;
+  struct stat stat_en;
+  char path_buf[MAXPATHLEN*2];
+  char *text[2];
+  char *temp;
+  int i;
+  int max_width=0;
+  int width;
+  int first, last, j, done=0;
+#ifdef __MINGW32__
+  int has_trailing = FALSE;
+#endif
+
+  directory = opendir(f_current->directory);
+#ifdef __MINGW32__
+  has_trailing = u_basic_has_trailing(f_current->directory, 
+				      G_DIR_SEPARATOR);
+#endif
+
+  if (!directory) {
+    fprintf(stderr, _("Agg, could not open directory: %s\n"), f_current->directory);
+    return;
+  }
+
+  while((dirent_ptr = readdir(directory)) != NULL) {
+#ifdef __MINGW32__
+    if (has_trailing) {
+    	sprintf(path_buf, "%s%s", f_current->directory, dirent_ptr->d_name);
+    } else {
+#endif
+    	sprintf(path_buf, "%s%c%s", f_current->directory, G_DIR_SEPARATOR,
+	        dirent_ptr->d_name);
+#ifdef __MINGW32__
+    }
+#endif
+
+    if(stat(path_buf, &stat_en) >= 0 && S_ISDIR(stat_en.st_mode)) {
+/*     	printf("dir: %s\n", path_buf);	 */
+      num_directories++;	
+    } else {
+/*     	printf("file: %s\n", path_buf);	*/
+      num_files++;	
+    }
+  }
+
+
+  if (num_directories > MAX_DIRS) {
+    fprintf(stderr, _("Too many directories! Increase MAX_DIRS\n"));
+    exit(-1);
+  }
+
+  if (num_files > MAX_FILES) {
+    fprintf(stderr, _("Too many files! Increase MAX_FILES\n"));
+    exit(-1);
+  }
+
+  x_compselect_setup_list_buffers(f_current, num_directories, num_files);
+
+  rewinddir(directory);
+
+  while((dirent_ptr = readdir(directory)) != NULL) {
+#ifdef __MINGW32__
+    if (has_trailing) {
+    	sprintf(path_buf, "%s%s", f_current->directory, dirent_ptr->d_name);
+    } else {
+#endif
+    	sprintf(path_buf, "%s%c%s", f_current->directory, G_DIR_SEPARATOR,
+	        dirent_ptr->d_name);
+#ifdef __MINGW32__
+    }
+#endif
+    if(stat(path_buf, &stat_en) >= 0 && S_ISDIR(stat_en.st_mode) &&
+       (strcmp(dirent_ptr->d_name, ".") != 0)) {
+
+      f_current->directory_entries[dir_count] = (char *)
+        g_malloc(sizeof(char)*(strlen(dirent_ptr->d_name)+2));
+	
+      sprintf(f_current->directory_entries[dir_count], 
+              "%s", dirent_ptr->d_name);
+      dir_count++;
+
+    } else {
+      if (x_compselect_include_file(dirent_ptr->d_name,
+                                    f_current->filter_type)) {	
+        f_current->file_entries[file_count] = (char *)
+          g_malloc(sizeof(char)*(strlen(dirent_ptr->d_name)+1));
+        strcpy(f_current->file_entries[file_count], 
+               dirent_ptr->d_name);
+        file_count++;
+      } 
+    }
+  }
+
+#if DEBUG
+  printf("FILE COUNT: %d\n", file_count);
+#endif
+
+  /* lame bubble sort */
+  first = 0;
+  last = file_count;
+  while(!done) {
+
+    done = 1;
+    for (j = first ; j < last-1; j++) {
+      if (strcmp(f_current->file_entries[j], 
+                 f_current->file_entries[j+1]) > 0) {
+        temp = f_current->file_entries[j];
+        f_current->file_entries[j] = 
+          f_current->file_entries[j+1];
+        f_current->file_entries[j+1] = temp;
+        done = 0;
+      }
+    }
+    last = last - 1;
+
+#if DEBUG 
+    pass_count++;
+#endif
+  }
+
+#if DEBUG 
+  printf("file passes: %d\n", pass_count);
+  pass_count = 0;
+  printf("test: %d\n", strcmp("./", "../"));
+  printf("DIR COUNT: %d\n", dir_count);
+#endif
+
+
+  /* lame bubble sort */
+  done = 0;
+  first = 0;
+  last = dir_count;
+  while(!done) {
+    done = 1;
+    for (j = first ; j < last-1; j++) {
+      if (strcmp(f_current->directory_entries[j], 
+                 f_current->directory_entries[j+1]) > 0) {
+        temp = f_current->directory_entries[j];
+        f_current->directory_entries[j] = 
+          f_current->directory_entries[j+1];
+        f_current->directory_entries[j+1] = temp;
+        done = 0;
+      }
+    }
+    last = last - 1;
+
+#if DEBUG 
+    pass_count++;
+#endif
+  }
+
+#if DEBUG
+  printf("directory passes: %d\n", pass_count);
+#endif
+
+
+  gtk_clist_freeze (GTK_CLIST (f_current->dir_list));
+  gtk_clist_clear (GTK_CLIST (f_current->dir_list));
+  gtk_clist_freeze (GTK_CLIST (f_current->file_list));
+  gtk_clist_clear (GTK_CLIST (f_current->file_list));
+
+  text[0] = NULL;
+  text[1] = NULL;
+  max_width = 0;
+  for (i = 0 ; i < dir_count; i++) {
+    temp = g_strconcat (f_current->directory_entries[i],
+                        G_DIR_SEPARATOR_S, NULL);
+    text[0] = temp; 
+    gtk_clist_append (GTK_CLIST (f_current->dir_list), text);
+
+#ifdef HAS_GTK22
+    width = gdk_string_width(gtk_style_get_font(f_current->dir_list->style),
+                             f_current->directory_entries[i]);
+#else
+    width = gdk_string_width(f_current->dir_list->style->font,
+                             f_current->directory_entries[i]);
+#endif
+
+    if (width > max_width) {
+      gtk_clist_set_column_width(GTK_CLIST(f_current->
+                                           dir_list), 0, width);
+      max_width = width;
+    }
+
+    g_free(temp);
+#if DEBUG
+    printf("directory: %s\n", f_current->directory_entries[i]);
+#endif
+  }
+
+  max_width = 0;
+  for (i = 0 ; i < file_count; i++) {
+    text[0] = f_current->file_entries[i]; 
+    gtk_clist_append (GTK_CLIST (f_current->file_list), text);
+
+#ifdef HAS_GTK22
+    width = gdk_string_width(gtk_style_get_font(f_current->dir_list->style), 
+                             f_current->file_entries[i]);
+#else
+    width = gdk_string_width(f_current->dir_list->style->font,
+                             f_current->file_entries[i]);
+#endif
+
+    if (width > max_width) {
+      gtk_clist_set_column_width(GTK_CLIST(f_current->
+                                           file_list), 0, width);
+      max_width = width;
+    }
+
+#if DEBUG
+    printf("file: %s\n", f_current->file_entries[i]);
+#endif
+  }
+
+  closedir(directory);
+  gtk_clist_thaw (GTK_CLIST (f_current->file_list));
+  gtk_clist_thaw (GTK_CLIST (f_current->dir_list));
+  f_current->last_search = -1;
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+int x_compselect_preview_checkbox(GtkWidget *widget, COMPDIALOG *f_current)
+{
+  if (f_current == NULL) {
+    fprintf(stderr, _("x_compselect_preview_checkbox: Oops got a null f_current!\n"));
+    exit(-1);
+  }
+
+  if (f_current->preview_control) {
+    f_current->preview_control = FALSE;
+    x_repaint_background(f_current->preview);
+  } else {
+    f_current->preview_control = TRUE;
+
+    if (f_current->directory && f_current->filename) {
+       x_preview_update(f_current->preview, f_current->directory, 
+	             f_current->filename);
+    }
+  }
+  return(0);
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_close (GtkWidget *w, COMPDIALOG *f_current)
+{
+  gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
+  f_current->xfwindow = NULL;
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ *  \note
+ *  don't use widget, since it can be NULL
+ */
+void x_compselect_search(GtkWidget *w, COMPDIALOG *f_current)
+{
+  TOPLEVEL *w_current;
+  const char *string;
+  int i;
+
+  w_current = f_current->toplevel;
+
+  string = gtk_entry_get_text(GTK_ENTRY(f_current->search_entry));
+	
+  if (!string) {
+    return;
+  }
+
+  gtk_entry_select_region(GTK_ENTRY(f_current->search_entry), 0, -1);
+
+#if 0 /* not used right now */
+  /* search directories */
+  i = 0;
+  if (f_current->file_entries[0] == NULL) {
+    while (f_current->directory_entries[i] != NULL) {
+      printf("compare: %s %s\n", f_current->directory_entries[i], string);
+      if (strstr(f_current->directory_entries[i], string)) {
+
+				/*text[0] = f_current->directory_entries[i];
+                                  text[1] = NULL; 
+                                  row = gtk_clist_find_row_from_data(GTK_CLIST(
+                                  f_current->dir_list),
+                                  f_current->directory_entries[i]);
+				*/
+				
+        gtk_clist_select_row(GTK_CLIST(
+                                       f_current->dir_list), 
+                             i, 0);
+        printf("%d found: %s\n", i, f_current->directory_entries[i]);
+				
+				/*x_compselect_update_dirfile(f_current, NULL);
+                                  x_compselect_fill_lists(f_current);*/
+        return;
+      }
+      i++;
+    }
+  }
+#endif
+
+  if (f_current->last_search != -1) {
+    i = f_current->last_search;	
+    gtk_label_set(GTK_LABEL(f_current->search_label), 
+                  _("Search in Files")); 
+  } else {
+    gtk_label_set(GTK_LABEL(f_current->search_label), 
+                  _("Search in Files")); 
+    i = 0;
+  }
+
+  while (f_current->file_entries[i] != NULL) {
+    if (strstr(f_current->file_entries[i], string)) {
+      gtk_clist_select_row(GTK_CLIST(f_current->file_list), 
+                           i, 0);
+
+      gtk_clist_moveto(GTK_CLIST(
+                                 f_current->file_list), 
+                       i, 0, -1, -1);
+
+      x_compselect_update_dirfile(f_current, 
+                                  f_current->file_entries[i]);
+      f_current->last_search = i + 1;
+      return;
+    }
+    i++;
+  }
+  f_current->last_search = -1;
+  gtk_label_set(GTK_LABEL(f_current->search_label), 
+		_("Search in Files - End of list")); 
+}
+/*********** File Open/Save As... specific code ends here ***********/
+
+/*********** Component Place specific code starts here **************/
+/*! \section component-place-specific-code Component Place Specific Code.
+ *  \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+gint default_components(GtkWidget *w, TOPLEVEL *w_current)
+{
+  w_current->embed_complex = 0;
+  w_current->include_complex = 0;
+  return(0);
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+gint embed_components(GtkWidget *w, TOPLEVEL *w_current)
+{
+  w_current->embed_complex = 1;
+  w_current->include_complex = 0;
+  return(0);
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+gint include_components(GtkWidget *w, TOPLEVEL *w_current)
+{
+  w_current->include_complex = 1;
+  w_current->embed_complex = 0;
+  return(0);
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ *  \note
+ *  this is from gtktest.c
+ */
+static GtkWidget *create_menu (TOPLEVEL *w_current)
+{
+  GtkWidget *menu;
+  GtkWidget *menuitem;
+  GSList *group;
+  char *buf;
+
+  menu = gtk_menu_new ();
+  group = NULL;
+
+  buf = g_strdup_printf(_("Reference to library (Default)"));
+  menuitem = gtk_radio_menu_item_new_with_label (group, buf);
+  g_free(buf);
+  group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
+  gtk_menu_append (GTK_MENU (menu), menuitem);
+  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
+                     (GtkSignalFunc) default_components,
+                     w_current);
+
+  gtk_widget_show(menuitem);
+
+  buf = g_strdup_printf(_("Embed in schematic"));
+  menuitem = gtk_radio_menu_item_new_with_label (group, buf);
+  g_free(buf);
+  group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
+  gtk_menu_append (GTK_MENU (menu), menuitem);
+  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
+                     (GtkSignalFunc) embed_components,
+                     w_current);
+  gtk_widget_show(menuitem);
+
+  buf = g_strdup_printf(_("Include as individual objects"));
+  menuitem = gtk_radio_menu_item_new_with_label (group, buf);
+  g_free(buf);
+  group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem));
+  gtk_menu_append (GTK_MENU (menu), menuitem);
+  gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
+                     (GtkSignalFunc) include_components,
+                     w_current);
+  gtk_widget_show(menuitem);
+
+  if (w_current->embed_complex) {
+    gtk_menu_set_active(GTK_MENU (menu),1);
+    embed_components(NULL, w_current);
+  } else {
+    default_components(NULL, w_current);
+  }
+
+  return menu;
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_comp_fill_libs(TOPLEVEL *w_current, COMPDIALOG *f_current)
+{
+  char *text[2];
+  char *temp;
+  int i;
+  int max_width=0;
+  int width;
+  int first,last,done,j;		/* variables for the sort */
+  const GSList *dirs, *dir;
+
+  gtk_clist_freeze (GTK_CLIST (f_current->dir_list));
+  gtk_clist_clear (GTK_CLIST (f_current->dir_list));
+
+  i = 0;
+  text[0] = NULL;
+  text[1] = NULL;
+  max_width = 0;
+
+  /* populate the directory list */
+  dirs = s_clib_get_directories ();
+  for (dir = dirs; dir != NULL; dir = g_slist_next (dir)) {
+    gchar *string = (gchar*)dir->data;
+
+    temp = strrchr(string, G_DIR_SEPARATOR);
+    if (temp) {
+      temp++; /* get past last '/' */
+      text[0] = temp;
+    } else {
+      text[0] = string;
+    }
+
+    f_current->directory_entries[i++] = g_strdup (string);
+    
+    gtk_clist_append (GTK_CLIST (f_current->dir_list), text);
+
+#ifdef HAS_GTK22
+    width = gdk_string_width(gtk_style_get_font(f_current->dir_list->style), 
+                             text[0]);
+#else
+    width = gdk_string_width(f_current->dir_list->style->font,
+                             text[0]);
+#endif
+
+    if (width > max_width) {
+      gtk_clist_set_column_width(GTK_CLIST(f_current->
+                                           dir_list), 0, width);
+      max_width = width;
+    }
+  }
+
+  gtk_clist_thaw (GTK_CLIST (f_current->dir_list));
+  f_current->last_search_lib = -1;
+
+  /* added sort for the directory list so it would match the 
+     automatically sorted clist of directories
+     Chris Ellec - May 2001                           */
+  if (w_current->sort_component_library == TRUE) {
+    done = 0;
+    first = 0;
+    last = i;
+    while(!done) {
+      done = 1;
+      for (j = first ; j < last-1; j++) {
+        /*printf ("%i:",j);*/
+        if (strcmp(f_current->directory_entries[j], 
+                   f_current->directory_entries[j+1]) > 0) {
+          temp = f_current->directory_entries[j];
+          f_current->directory_entries[j] = 
+            f_current->directory_entries[j+1];
+          f_current->directory_entries[j+1] = temp;
+          done = 0;
+        }
+      }
+      last = last - 1;
+
+#if DEBUG 
+      pass_count++;
+#endif
+    }
+  }
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_comp_fill_components(COMPDIALOG *f_current, int row)
+{
+  GSList *filenames, *filename;
+  gint width = 0, max_width = 0;
+	
+  gtk_clist_freeze (GTK_CLIST (f_current->file_list));
+  gtk_clist_clear (GTK_CLIST (f_current->file_list));
+
+  /* update current_clib in toplevel with new directory name */
+  if (f_current->toplevel->current_clib) {
+    g_free (f_current->toplevel->current_clib);
+  }
+  f_current->toplevel->current_clib = g_strdup (
+    f_current->directory_entries[row]);
+
+  /* get the list of filenames in directory */
+  filenames = s_clib_get_files (f_current->directory_entries[row], ".sym");
+
+  filename = filenames;
+  while (filename != NULL) {
+    gchar *text[2];
+
+    text[0] = (gchar*) filename->data;
+    text[1] = NULL;
+    
+    /* add filename to the clist */
+    gtk_clist_append (GTK_CLIST (f_current->file_list), text);
+    
+#ifdef HAS_GTK22
+    width = gdk_string_width (gtk_style_get_font (
+                                f_current->file_list->style),
+                              (gchar*) filename->data);
+#else
+    width = gdk_string_width (f_current->file_list->style->font,
+                              (gchar*) filename->data);
+#endif
+    if (width > max_width) {
+      /* increase the width of the column */
+      gtk_clist_set_column_width (GTK_CLIST (f_current->file_list),
+                                  0, width);
+      max_width = width;
+    }
+    
+    /* continue with the next filename */
+    filename = g_slist_next (filename);
+  }
+
+  /* get ride of the list of filenames */
+  g_slist_foreach (filenames, (GFunc)g_free, NULL);
+  g_slist_free (filenames);
+
+  /* allow visual updates to clist */
+  gtk_clist_thaw (GTK_CLIST (f_current->file_list));
+      
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ *  \note
+ *  don't pass in f_current->filename or f_current->directory for component
+ *  or library
+ */
+void x_compselect_comp_update_current(COMPDIALOG *f_current, 
+				      char *library, char *component)
+{
+  char *temp=NULL;
+
+  /* component */
+  if (f_current->filename) {
+    g_free(f_current->filename);
+    f_current->filename = NULL;
+  }
+
+  /* library */
+  if (f_current->directory) {
+    g_free(f_current->directory);
+    f_current->directory = NULL;
+  }
+
+  if (library) {
+    f_current->directory = g_strdup(library);
+  } else {
+    f_current->directory = NULL;
+  }
+
+  if (component) {
+    f_current->filename = g_strdup(component);
+  } else {
+    f_current->filename = NULL;
+  }
+
+  if (f_current->directory && f_current->filename) {
+#ifdef __MINGW32__
+    if (u_basic_has_trailing(f_current->directory, G_DIR_SEPARATOR)) {
+    	temp = g_strconcat (f_current->directory, 
+                            f_current->filename, NULL);
+    } else {
+#endif
+    	temp = g_strconcat (f_current->directory, 
+                            G_DIR_SEPARATOR_S,
+                            f_current->filename, NULL);
+#ifdef __MINGW32__
+    }
+#endif
+    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), temp);
+    g_free(temp);
+  } else if (f_current->directory && !f_current->filename) {
+    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), 
+                       f_current->directory);
+  } else if (!f_current->directory) {
+    gtk_entry_set_text(GTK_ENTRY(f_current->filename_entry), 
+                       "NONE");
+  }
+
+#if 0 /* old code */
+  if (f_current->directory && f_current->filename) {
+    temp = g_strconcat (f_current->directory, 
+                        f_current->filename, NULL);
+    gtk_label_set(GTK_LABEL(f_current->filename_entry), temp);
+  } else if (f_current->directory && !f_current->filename) {
+    gtk_label_set(GTK_LABEL(f_current->filename_entry), 
+                  f_current->directory);
+  } else if (!f_current->directory) {
+    gtk_label_set(GTK_LABEL(f_current->filename_entry), 
+                  " ");
+  }
+#endif
+
+#if DEBUG 
+  printf("directory: %s\n", f_current->directory);
+  printf("filename: %s\n", f_current->filename);
+#endif
+
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_change_clib(COMPDIALOG *f_current, char *new_clib,
+			      int row)
+{
+  x_compselect_comp_update_current(f_current, new_clib, NULL);
+  x_compselect_comp_fill_components(f_current, row);
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_lib_select (GtkWidget *widget, gint row, gint column,
+			      GdkEventButton *bevent, COMPDIALOG *f_current)
+{
+  char *temp = NULL;
+
+  gtk_clist_get_text (GTK_CLIST (f_current->dir_list), row, 0, &temp);
+
+  if (temp) {	
+#if DEBUG 
+    printf("selected: %d _%s_ _%s_\n", row, temp, 
+           f_current->directory_entries[row]);
+#endif
+    if (bevent) {
+      switch (bevent->type) {
+        /*	case(GDK_2BUTTON_PRESS): */
+        default:
+          x_compselect_change_clib(f_current, 
+                                   f_current->directory_entries[row],
+                                   row);
+          break;
+
+      }
+    }
+  }
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_comp_select (GtkWidget *widget, gint row, gint column,
+			       GdkEventButton *bevent, COMPDIALOG *f_current)
+{
+  char *comp = NULL;
+  int diff_x, diff_y;
+  TOPLEVEL *w_current;
+
+  w_current = f_current->toplevel;
+
+  gtk_clist_get_text (GTK_CLIST (f_current->file_list), row, 0, &comp);
+
+  if (comp) {	
+    strcpy(w_current->current_basename, comp);
+
+    if (f_current->preview_control && w_current->current_clib && comp) { 
+      x_preview_update(f_current->preview, 
+                       w_current->current_clib,
+                       comp);
+    }
+
+    x_compselect_comp_update_current(f_current, 
+                                     w_current->current_clib, comp);
+
+    if (w_current->event_state == ENDCOMP) {
+      diff_x = w_current->last_x - w_current->start_x;
+      diff_y = w_current->last_y - w_current->start_y;
+
+      o_complex_translate_display(w_current,
+                                  diff_x, diff_y,
+                                  w_current->page_current->complex_place_head);
+    }
+
+    o_list_delete_rest(w_current,
+                       w_current->page_current->complex_place_head);
+    o_complex_set_filename(w_current, w_current->current_clib,
+                           w_current->current_basename);
+
+    w_current->event_state = DRAWCOMP;
+  }
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_comp_apply(GtkWidget *w, COMPDIALOG *f_current)
+{
+  TOPLEVEL *w_current;
+  int diff_x, diff_y;
+	
+  w_current = f_current->toplevel;
+
+  if (w_current->current_basename && w_current->current_clib) {
+    if (w_current->event_state == ENDCOMP) {
+      diff_x = w_current->last_x - w_current->start_x;
+      diff_y = w_current->last_y - w_current->start_y;
+
+      o_complex_translate_display(w_current,
+                                  diff_x, diff_y,
+                                  w_current->page_current->complex_place_head);
+    }
+
+    o_list_delete_rest(w_current,
+                       w_current->page_current->complex_place_head);
+    o_complex_set_filename(w_current, w_current->current_clib,
+                           w_current->current_basename);
+
+    w_current->event_state = DRAWCOMP;
+  }
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_comp_close (GtkWidget *w, COMPDIALOG *f_current)
+{
+  TOPLEVEL *w_current;
+
+  w_current = f_current->toplevel;
+
+  /* erase any existing component while it's being placed */
+  /* do this instead of the below o_redraw_all */
+  if (w_current->inside_action &&
+      (w_current->event_state == ENDCOMP ||
+       w_current->event_state == DRAWCOMP)) {
+    o_complex_rubbercomplex(w_current);
+  }
+
+  o_list_delete_rest(w_current, w_current->page_current->
+                     complex_place_head);
+
+  i_set_state(w_current, SELECT);
+  i_update_toolbar(w_current);
+
+  gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
+  f_current->xfwindow = NULL;
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+int x_compselect_search_library(COMPDIALOG *f_current,
+				char *library, const char *string) 
+{
+  GSList *filenames, *filename;
+  int ret;
+
+  /* get the filenames with '.sym' in library */
+  filenames = s_clib_get_files(library, ".sym");
+
+  if (f_current->last_search == -1) {
+    /* last search failed: start over */
+    f_current->last_search = 0;
+  }
+
+  /* start search from last known position */
+  filename = g_slist_nth (filenames, (guint)f_current->last_search);
+  while (filename != NULL) {
+    /* increase position in search */
+    f_current->last_search++;
+
+    /* does filename match the query? */
+    if (strstr ((gchar*) filename->data, string)) {
+      /* yes, stop the search, prepare to return last_search */
+#if DEBUG
+      printf("found: %s %s %s %d\n", library, filename->data, string, f_current->last_search - 1);
+#endif
+      break;
+    }
+    
+    filename = g_slist_next (filename);
+  }
+
+  /* free the list of filenames */
+  g_slist_foreach (filenames, (GFunc)g_free, NULL);
+  g_slist_free (filenames);
+
+  /* nothing found? */
+  if (filename == NULL) {
+    /* no, reset for next search */
+    f_current->last_search = -1;
+    ret = -1;
+  } else {
+    /* yes, return the position in the list of the filename found */
+    ret = f_current->last_search - 1;
+  }
+
+  return ret;
+}
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ *  \note
+ *  don't use widget, since it can be NULL
+ */
+void x_compselect_comp_search(GtkWidget *w, COMPDIALOG *f_current)
+{
+  TOPLEVEL *w_current;
+  const char *string;
+  int lib_count;
+  int flag;
+
+  w_current = f_current->toplevel;
+
+  string = gtk_entry_get_text(GTK_ENTRY(f_current->search_entry));
+	
+  if (!string) {
+    return;
+  }
+
+  gtk_entry_select_region(GTK_ENTRY(f_current->search_entry), 0, -1);
+
+  if (f_current->last_search_lib != -1) {
+    lib_count = f_current->last_search_lib;	
+    gtk_label_set(GTK_LABEL(f_current->search_label),
+                  _("Search in Components")); 
+  } else {
+    lib_count = 0;
+    gtk_label_set(GTK_LABEL(f_current->search_label),
+                  _("Search in Components")); 
+  }
+
+  while(f_current->directory_entries[lib_count] != NULL) {
+    flag = x_compselect_search_library(f_current, 
+                                       f_current->directory_entries[lib_count], 
+                                       string);
+    if (flag != -1) {
+      gtk_clist_select_row(GTK_CLIST(f_current->dir_list), 
+                           lib_count, 0);
+
+      gtk_clist_moveto(GTK_CLIST(
+                                 f_current->dir_list), 
+                       lib_count, 0, -1, -1);
+
+      x_compselect_change_clib(f_current, 
+                               f_current->
+                               directory_entries[lib_count],
+                               lib_count);
+
+      gtk_clist_select_row(GTK_CLIST(f_current->file_list), 
+                           flag, 0);
+
+      gtk_clist_moveto(GTK_CLIST(
+                                 f_current->file_list), 
+                       flag, 0, -1, -1);
+
+      f_current->last_search_lib = lib_count; 
+      return;
+    } else {
+      lib_count++;
+    }
+  }
+
+
+  f_current->last_search_lib = -1;
+  f_current->last_search = -1;
+
+#if 0 /* I'm not sure this is worth the effort and the confusion it causes */
+  /* now search the library names */
+  lib_count = 0;
+  while(f_current->directory_entries[lib_count] != NULL) {
+    if (strstr(f_current->directory_entries[lib_count], string)) {
+
+      printf("%s %s\n", f_current->directory_entries[lib_count], string);
+
+      gtk_clist_select_row(GTK_CLIST(f_current->dir_list), 
+                           lib_count, 0);
+
+      gtk_clist_moveto(GTK_CLIST(
+                                 f_current->dir_list), 
+                       lib_count, 0, -1, -1);
+
+      x_compselect_change_clib(f_current, 
+                               f_current->
+                               directory_entries[lib_count],
+                               lib_count);
+
+      gtk_label_set(GTK_LABEL(f_current->search_label),
+                    _("Search in Components - Found library only")); 
+      return;
+    }
+    lib_count++;
+  }
+  f_current->last_search_lib = -1;
+#endif
+
+  gtk_label_set(GTK_LABEL(f_current->search_label),
+                _("Search in Components - End of list")); 
+
+}
+/*********** Component Place specific code ends here **************/
+
+/*! \todo Finish function documentation!!!
+ *  \brief
+ *  \par Function Description
+ *
+ */
+void x_compselect_setup (TOPLEVEL *w_current)
+{
+  GtkWidget *buttonapply = NULL;
+  GtkWidget *buttonclose = NULL;
+  GtkWidget *scrolled_win;
+  GtkWidget *action_area;
+  GtkWidget *separator;
+  GtkWidget *optionmenu;
+  GtkWidget *drawbox;
+  GtkWidget *label;
+  GtkWidget *searchbox;
+	
+  COMPDIALOG *f_current;
+
+  GtkWidget *vbox;
+  GtkWidget *list_hbox;
+  char *dir_title [2];
+  char *file_title [2];
+
+
+  f_current = &w_current->compselect;
+
+  if (!f_current->xfwindow) {
+
+    f_current->xfwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+    f_current->toplevel = w_current;
+    f_current->filesel_type = -1;
+    f_current->last_search = -1;
+    f_current->filename = NULL;
+    f_current->directory = NULL;
+
+    gtk_window_position(GTK_WINDOW(f_current->xfwindow),
+                        GTK_WIN_POS_NONE);
+    gtk_window_set_title(GTK_WINDOW(f_current->xfwindow),
+                         _("Select Component..."));
+
+    gtk_signal_connect(GTK_OBJECT(f_current->xfwindow),
+                       "destroy",
+                       GTK_SIGNAL_FUNC(x_compselect_destroy_window),
+                       f_current);
+
+    gtk_signal_connect(GTK_OBJECT(f_current->xfwindow), "key_press_event",
+                       (GtkSignalFunc) x_compselect_keypress, f_current);
+
+    vbox = gtk_vbox_new (FALSE, 0);
+    gtk_container_set_border_width(GTK_CONTAINER (
+                                                  f_current->xfwindow), 10);
+    gtk_container_add(GTK_CONTAINER (f_current->xfwindow), 
+                      vbox);
+    gtk_widget_show (vbox);
+
+#if 0
+    action_area = gtk_hbox_new (TRUE, 0);
+    gtk_container_set_border_width(GTK_CONTAINER (
+                                                  f_current->xfwindow), 10);
+    gtk_box_pack_end(GTK_BOX (vbox), action_area, FALSE, FALSE, 0);
+    gtk_widget_show (action_area);
+#endif
+
+    action_area = gtk_hbutton_box_new ();
+    gtk_button_box_set_layout(GTK_BUTTON_BOX(action_area), 
+                              GTK_BUTTONBOX_END);
+    gtk_button_box_set_spacing(GTK_BUTTON_BOX(action_area), 5);
+    gtk_box_pack_end (GTK_BOX (vbox), action_area, TRUE, FALSE, 10);
+    gtk_widget_show (action_area);
+
+
+    /*  ----- Create the filter selection area -----  */
+    f_current->filter_type = COMPDIALOG_SYM_ONLY;
+
+    list_hbox = gtk_hbox_new (FALSE, 5);
+    gtk_box_pack_start (GTK_BOX (vbox), list_hbox, TRUE, TRUE, 0);
+    gtk_widget_show (list_hbox);
+
+    separator = gtk_hseparator_new ();
+    gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, TRUE, 0);
+    gtk_widget_show (separator);
+
+#if 0 /* for demonstration only */
+    frame = gtk_frame_new (NULL);
+    gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);
+    gtk_widget_show (frame);
+    /*		gtk_container_add (GTK_CONTAINER (frame), drawbox); */
+#endif
+
+    drawbox = gtk_hbox_new (FALSE, 0);
+    gtk_box_pack_start (GTK_BOX (vbox), drawbox, TRUE, FALSE, 5);
+    gtk_widget_show (drawbox);
+
+    searchbox = gtk_vbox_new (FALSE, 0);
+    gtk_box_pack_end (GTK_BOX (drawbox), searchbox, TRUE, TRUE, 10);
+    gtk_widget_show (searchbox);
+
+    
+    /*  -----  Create the "directories"/"libraries" clist widgets -----  */
+    dir_title[0] = g_strdup(_("Libraries"));
+    dir_title[1] = NULL;
+    f_current->dir_list = gtk_clist_new_with_titles(1, 
+                                                    (char**) dir_title);
+    gtk_widget_set_usize(f_current->dir_list, 
+                         LIB_LIST_WIDTH, LIB_LIST_HEIGHT);
+    gtk_signal_connect (GTK_OBJECT (f_current->dir_list), 
+                          "select_row", (GtkSignalFunc) 
+                          x_compselect_lib_select, f_current);
+    gtk_clist_column_titles_passive(GTK_CLIST(f_current->dir_list));
+
+    scrolled_win = gtk_scrolled_window_new(NULL, NULL);
+    gtk_container_add(GTK_CONTAINER (scrolled_win), 
+                      f_current->dir_list);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
+                                                       scrolled_win),
+                                   GTK_POLICY_AUTOMATIC, 
+                                   GTK_POLICY_ALWAYS);
+    gtk_container_set_border_width(GTK_CONTAINER (scrolled_win), 5);
+    gtk_box_pack_start(GTK_BOX (list_hbox), scrolled_win, 
+                       TRUE, TRUE, 0);
+    if (w_current->sort_component_library) {
+      gtk_clist_set_auto_sort(GTK_CLIST(f_current->dir_list), TRUE);
+    }
+    gtk_widget_show (f_current->dir_list);
+    gtk_widget_show (scrolled_win);
+    g_free(dir_title[0]);
+    
+    /*  ----- Create the files clist -----  */
+    file_title[0] = g_strdup (_("Components"));
+    file_title[1] = NULL;
+    f_current->file_list = gtk_clist_new_with_titles(1, 
+                                                     (gchar**) file_title);
+    gtk_widget_set_usize(f_current->file_list, 
+                         COMP_LIST_WIDTH, COMP_LIST_HEIGHT);
+    
+    gtk_signal_connect(GTK_OBJECT (f_current->file_list), 
+                         "select_row",
+                         (GtkSignalFunc) x_compselect_comp_select,
+                         f_current);
+    gtk_clist_column_titles_passive(GTK_CLIST(f_current->file_list));
+
+    scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+    gtk_container_add(GTK_CONTAINER(scrolled_win), 
+                      f_current->file_list);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
+                                                       scrolled_win),
+                                   GTK_POLICY_AUTOMATIC, 
+                                   GTK_POLICY_ALWAYS);
+    gtk_container_set_border_width(GTK_CONTAINER(scrolled_win), 5);
+    gtk_box_pack_start(GTK_BOX (list_hbox), scrolled_win, 
+                       TRUE, TRUE, 0);
+    if (w_current->sort_component_library) {
+      gtk_clist_set_auto_sort(GTK_CLIST(f_current->file_list), TRUE);
+    }
+    gtk_widget_show (f_current->file_list);
+    gtk_widget_show (scrolled_win);
+    g_free(file_title[0]);
+
+    /*  ----- create the preview widget -----  */
+    f_current->preview = x_preview_setup(f_current->xfwindow, 
+                                         drawbox);
+
+    f_current->preview_checkbox = gtk_check_button_new_with_label(
+                                                                  _("Preview"));
+    gtk_box_pack_start(GTK_BOX(searchbox), 
+                       f_current->preview_checkbox, 
+                       FALSE, FALSE, 0);
+    /* other checkbox stuff is done AFTER drawing area is mapped */
+    gtk_widget_show(f_current->preview_checkbox);
+
+    /* -----  Create the search input text box -----  */
+    f_current->search_label=gtk_label_new(_("Search in Components"));
+    gtk_misc_set_alignment(GTK_MISC(f_current->search_label), 0, 0);
+    gtk_box_pack_start(GTK_BOX(searchbox), f_current->search_label,
+                       FALSE, FALSE, 5);
+    gtk_widget_show(f_current->search_label);
+
+
+    f_current->search_entry = gtk_entry_new_with_max_length (255);
+    gtk_editable_select_region(GTK_EDITABLE(
+                                            f_current->search_entry), 0, -1);
+    gtk_box_pack_start(GTK_BOX (searchbox), 
+                       f_current->search_entry, FALSE, FALSE, 0);
+    gtk_signal_connect(GTK_OBJECT(f_current->search_entry), 
+                       "activate", 
+                       GTK_SIGNAL_FUNC(x_compselect_comp_search),
+                       f_current);
+    gtk_widget_grab_focus(f_current->search_entry);
+    gtk_widget_show(f_current->search_entry);
+
+    /*  ----- Create the "Filename" text entry area -----  */
+    optionmenu = gtk_option_menu_new ();
+    gtk_option_menu_set_menu(GTK_OPTION_MENU(optionmenu),
+                             create_menu (w_current));
+    gtk_box_pack_start(GTK_BOX(vbox), optionmenu, 
+                       FALSE, FALSE, 10);
+    gtk_widget_show (optionmenu);
+
+    label=gtk_label_new(_("Filename"));
+    gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
+    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
+    gtk_widget_show(label);
+
+    f_current->filename_entry = 
+      gtk_entry_new_with_max_length(1024);
+    gtk_editable_select_region(GTK_EDITABLE(
+                                            f_current->filename_entry), 0, -1);
+    gtk_box_pack_start(GTK_BOX (vbox), 
+                       f_current->filename_entry, FALSE, FALSE, 0);
+
+    gtk_entry_set_editable(GTK_ENTRY(
+                                       f_current->filename_entry), FALSE);
+	
+    gtk_widget_show(f_current->filename_entry);
+
+#ifdef HAS_GTK12
+    buttonapply = gtk_button_new_with_label (_("Apply"));
+#else
+    buttonapply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
+#endif
+    gtk_signal_connect(GTK_OBJECT(buttonapply),
+                       "clicked",
+                       GTK_SIGNAL_FUNC(x_compselect_comp_apply),
+                       f_current);
+
+    GTK_WIDGET_SET_FLAGS(buttonapply, GTK_CAN_DEFAULT);
+    gtk_box_pack_start(GTK_BOX(action_area),
+                       buttonapply, TRUE, TRUE, 0);
+    /* This makes the "open" button the default */
+    gtk_widget_grab_default (buttonapply);
+    gtk_widget_show(buttonapply);
+
+    /*  ----- Here we create the "cancel"/"close" buttons -----  */
+#ifdef HAS_GTK12
+    buttonclose = gtk_button_new_with_label (_("Close"));
+#else
+    buttonclose = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+#endif
+    GTK_WIDGET_SET_FLAGS(buttonclose, GTK_CAN_DEFAULT);
+    gtk_box_pack_start(GTK_BOX(action_area),
+                       buttonclose, TRUE, TRUE, 0);
+    gtk_signal_connect(GTK_OBJECT(buttonclose),
+                       "clicked",
+                       GTK_SIGNAL_FUNC(x_compselect_comp_close),
+                       f_current);
+    gtk_widget_show(buttonclose);
+
+    /* files data structure is not used for components */
+    x_compselect_setup_list_buffers(f_current,
+                                    g_slist_length ((GSList *) s_clib_get_directories()), 0);
+    x_compselect_comp_update_current(f_current, NULL, NULL);
+    x_compselect_comp_fill_libs(w_current, f_current);
+  }
+
+  if (!GTK_WIDGET_VISIBLE(f_current->xfwindow)) {
+    gtk_widget_show(f_current->xfwindow);
+    gdk_window_raise(f_current->xfwindow->window);
+    x_preview_setup_rest(f_current->preview);
+
+    /* need to delay this till the drawing area is created and
+     * is showing */
+    gtk_signal_connect (GTK_OBJECT(f_current->preview_checkbox), 
+                        "toggled", GTK_SIGNAL_FUNC(x_compselect_preview_checkbox),
+                        f_current);
+    if (w_current->file_preview) {
+      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
+                                                     f_current->preview_checkbox), 
+                                   TRUE);
+      f_current->preview_control = TRUE;
+    } else {
+      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
+                                                     f_current->preview_checkbox), 
+                                   FALSE);
+      f_current->preview_control = FALSE;
+    }
+
+  } else {
+    /* window should already be mapped, otherwise this
+     * will core */
+    gdk_window_raise(f_current->xfwindow->window);
+  }
+  
+}
+


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