[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: CVS update: gattrib.c
User: pbernaud
Date: 06/09/23 05:04:30
Modified: . gattrib.c s_toplevel.c x_fileselect.c
Log:
Modified the file selection dialog with a GtkFileChooserDialog widget
Revision Changes Path
1.20 +1 -1 eda/geda/gaf/gattrib/src/gattrib.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: gattrib.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/gattrib.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- gattrib.c 16 Sep 2006 11:37:03 -0000 1.19
+++ gattrib.c 23 Sep 2006 09:04:13 -0000 1.20
@@ -329,7 +329,7 @@
#if DEBUG
printf("In gattrib_main -- no files specified on command line. Throw up filedialog.\n");
#endif
- x_fileselect_setup(pr_current, OPEN);
+ x_fileselect_open ();
gtk_widget_show( GTK_WIDGET(notebook) );
gtk_widget_show( GTK_WIDGET(window) );
1.21 +2 -4 eda/geda/gaf/gattrib/src/s_toplevel.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: s_toplevel.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/s_toplevel.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- s_toplevel.c 22 Aug 2006 18:20:00 -0000 1.20
+++ s_toplevel.c 23 Sep 2006 09:04:26 -0000 1.21
@@ -1,4 +1,4 @@
-/* $Id: s_toplevel.c,v 1.20 2006/08/22 18:20:00 sdb Exp $ */
+/* $Id: s_toplevel.c,v 1.21 2006/09/23 09:04:26 pbernaud Exp $ */
/* gEDA - GPL Electronic Design Automation
* gattrib -- gEDA component and net attribute manipulation using spreadsheet.
@@ -180,13 +180,11 @@
*------------------------------------------------------------------*/
void s_toplevel_menubar_file_open(TOPLEVEL *pr_current)
{
- int filesel_type = OPEN;
-
#ifdef DEBUG
printf("In s_toplevel_menubar_file_open, about to create fileselect box\n");
#endif
- x_fileselect_setup(pr_current, filesel_type);
+ x_fileselect_open ();
return;
}
1.13 +211 -1194 eda/geda/gaf/gattrib/src/x_fileselect.c
(In the diff below, changes in quantity of whitespace are not shown.)
Index: x_fileselect.c
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/gaf/gattrib/src/x_fileselect.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- x_fileselect.c 12 Aug 2006 18:58:48 -0000 1.12
+++ x_fileselect.c 23 Sep 2006 09:04:27 -0000 1.13
@@ -79,585 +79,12 @@
/* ----- x_fileselect stuff begins here ----- */
-#define DIR_LIST_WIDTH 180
-#define DIR_LIST_HEIGHT 180
-#define FILE_LIST_WIDTH 180
-#define FILE_LIST_HEIGHT 180
-
-/* ------------------------------------------------------------- *
- * This destroys the entire FILEDIALOG structure & frees its memory.
- * There is another fcn which just closes the window.
- * ------------------------------------------------------------- */
-void
-x_fileselect_destroy_window(GtkWidget * widget, FILEDIALOG * f_current)
-{
-
-#if DEBUG
- printf("In x_fileselect_destroy_window, about to destroy window!\n");
-#endif
- x_fileselect_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;
- }
-
- gtk_grab_remove(f_current->xfwindow);
- f_current->toplevel = NULL;
- f_current->xfwindow = NULL;
- g_free(f_current);
- /* *window = NULL; */
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-int
-x_fileselect_keypress(GtkWidget * widget, GdkEventKey * event,
- FILEDIALOG * f_current)
-{
- if (strcmp(gdk_keyval_name(event->keyval), "Escape") == 0) {
- x_fileselect_close(NULL, f_current);
- return TRUE;
- }
-
- return FALSE;
-}
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-void x_fileselect_init_list_buffers(FILEDIALOG * f_current)
-{
- int i;
-
- /* Shouldn't we malloc something in here?? */
- for (i = MAX_FILES; i >= 0; i--) {
- f_current->file_entries[i] = NULL;
- }
-
- for (i = MAX_DIRS; i >= 0; i--) {
- f_current->directory_entries[i] = NULL;
- }
-
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-void x_fileselect_free_list_buffers(FILEDIALOG * f_current)
-{
- int i;
-
- for (i = MAX_FILES; i >= 0; i--) {
- if (f_current->file_entries[i])
- g_free(f_current->file_entries[i]);
-
- f_current->file_entries[i] = NULL;
- }
-
- for (i = MAX_DIRS; i >= 0; i--) {
- if (f_current->directory_entries[i])
- g_free(f_current->directory_entries[i]);
-
- f_current->directory_entries[i] = NULL;
- }
- return;
-}
-
-
-
-/*********** File Open/Save As... specific code starts here ***********/
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-void x_fileselect_update_dirfile(FILEDIALOG * 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("In x_fileselect_update_dirfile, directory: %s\n", f_current->directory);
-#endif
-
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-void
-x_fileselect_setup_list_buffers(FILEDIALOG * f_current,
- int num_directories, int num_files)
-{
- int i;
-
- for (i = num_files+1; i >= 0; i--) {
- if (f_current->file_entries[i]) {
- g_free(f_current->file_entries[i]);
- }
- f_current->file_entries[i] = NULL;
- }
-
- for (i = num_directories+1; i >= 0; i--) {
- if (f_current->directory_entries[i]) {
- g_free(f_current->directory_entries[i]);
- }
- f_current->directory_entries[i] = NULL;
- }
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-/* returns TRUE if the file should be included (passes the filter) */
-/* else returns FALSE */
-int x_fileselect_include_file(char *filename, int filter_type)
-{
- switch (filter_type) {
- case (FILEDIALOG_SCH_ONLY):
- if (strstr(filename, ".sch")) {
- return (TRUE);
- }
- break;
-
- case (FILEDIALOG_SYM_ONLY):
- if (strstr(filename, ".sym")) {
- return (TRUE);
- }
- break;
-
- case (FILEDIALOG_SCH_SYM):
- if (strstr(filename, ".sch") || strstr(filename, ".sym")) {
- return (TRUE);
- }
- break;
-
- case (FILEDIALOG_ALL_FILES):
- return (TRUE);
- break;
- }
-
- return (FALSE);
-}
-
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-void x_fileselect_fill_lists(FILEDIALOG * 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 DEBUG
- printf("In x_fileselect_fill_lists, directory = %s\n", directory);
-#endif
-
-
-#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_fileselect_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_fileselect_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("In x_fileselect_fill_lists, 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;
-
- }
-
- /* 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;
-
- }
-
- 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);
-
- width =
- gdk_string_width(gtk_style_get_font(f_current->dir_list->style),
- f_current->directory_entries[i]);
-
- 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("In x_fileselect_fill_lists, 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);
-
- width =
- gdk_string_width(gtk_style_get_font(f_current->dir_list->style),
- f_current->file_entries[i]);
-
- if (width > max_width) {
- gtk_clist_set_column_width(GTK_CLIST(f_current->
- file_list), 0, width);
- max_width = width;
- }
-#if DEBUG
- printf("In x_fileselect_fill_lists, 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;
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- * This is a support fcn for the filter menu
- * ------------------------------------------------------------- */
-gint x_fileselect_sch_files(GtkWidget * w, FILEDIALOG * f_current)
-{
- f_current->filter_type = FILEDIALOG_SCH_ONLY;
- x_fileselect_fill_lists(f_current);
- return (0);
-}
-
-
-
-/* ------------------------------------------------------------- *
- * This is a support fcn for the filter menu
- * ------------------------------------------------------------- */
-gint x_fileselect_all_files(GtkWidget * w, FILEDIALOG * f_current)
-{
- f_current->filter_type = FILEDIALOG_ALL_FILES;
- x_fileselect_fill_lists(f_current);
- return (0);
-}
-
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-/* this is from gtktest.c */
-static GtkWidget *x_fileselect_filter_menu(FILEDIALOG * f_current)
-{
- GtkWidget *menu;
- GtkWidget *menuitem;
- GSList *group;
- char *buf;
-
- menu = gtk_menu_new();
- group = NULL;
-
- buf = g_strdup_printf("sch - Schematics");
- 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) x_fileselect_sch_files, f_current);
- gtk_widget_show(menuitem);
-
- buf = g_strdup_printf("* - All Files");
- 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) x_fileselect_all_files, f_current);
- gtk_widget_show(menuitem);
-
- switch (f_current->filter_type) {
-
- case (FILEDIALOG_SCH_ONLY):
- gtk_menu_set_active(GTK_MENU(menu), 0);
- break;
-
- case (FILEDIALOG_SYM_ONLY):
- gtk_menu_set_active(GTK_MENU(menu), 1);
- break;
-
- case (FILEDIALOG_SCH_SYM):
- gtk_menu_set_active(GTK_MENU(menu), 2);
- break;
-
- case (FILEDIALOG_ALL_FILES):
- gtk_menu_set_active(GTK_MENU(menu), 3);
- break;
- }
-
- return menu;
-}
-
-
-
-
-/* ------------------------------------------------------------- *
- * This fcn just closes the window and does nothing else.
- * It is invoked when you click "cancel" during a save
- * operation.
- * ------------------------------------------------------------- */
-void x_fileselect_saveas_close(GtkWidget * w, FILEDIALOG * f_current)
-{
- gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
-
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- * This fcn saves out the files and then closes the fileselect
- * dialog box. It is invoked when you click "save" during a save
- * operation.
- * ------------------------------------------------------------- */
-void x_fileselect_saveas(GtkWidget * w, FILEDIALOG * f_current)
-{
-
- TOPLEVEL *w_current;
- gchar *string;
- int len;
-
- w_current = f_current->toplevel;
-
- string = (gchar *) gtk_entry_get_text(GTK_ENTRY(f_current->filename_entry));
-
- if (!string) {
- return;
- }
-
- len = strlen(string);
-
- if (string[len - 1] != G_DIR_SEPARATOR) {
- if (w_current->page_current->page_filename) {
- g_free(w_current->page_current->page_filename);
- }
-
- w_current->page_current->page_filename = g_strdup(string);
-
- /* Try to do save by calling f_save . . . . */
- if (f_save(w_current, string)) {
- s_log_message("Saved As [%s]\n",
- w_current->page_current->page_filename);
-
- /* Update filename for "saveas" operation */
- x_fileselect_set_filename(w_current, string);
-
- w_current->page_current->CHANGED = 0;
- } else {
- s_log_message("Could NOT save [%s]\n",
- w_current->page_current->page_filename);
- }
-
- x_fileselect_close(NULL, f_current);
-
- } else {
- s_log_message("Specify a Filename!\n");
- }
- return;
-}
-
-
/* ------------------------------------------------------------- *
* I think this puts the new filename back into pr_current as part
* of a "save as" operation. This was originally i_set_filename
* in gschem/src/i_basic.c
* ------------------------------------------------------------- */
-void x_fileselect_set_filename(TOPLEVEL * w_current, const char *string)
+static void x_fileselect_set_filename(TOPLEVEL * w_current, const char *string)
{
char trunc_string[41];
int len;
@@ -700,67 +127,62 @@
return;
}
-
-/* ------------------------------------------------------------- *
- *
- * ------------------------------------------------------------- */
-void x_fileselect_change_dir(FILEDIALOG * f_current, char *new_directory)
+/*------------------------------------------------------------------
+ * This fcn creates and sets the file filter for the filechooser.
+ *------------------------------------------------------------------*/
+static void
+x_fileselect_setup_filechooser_filters (GtkFileChooser *filechooser)
{
- if (new_directory) {
- chdir(new_directory);
- x_fileselect_update_dirfile(f_current, NULL);
- x_fileselect_fill_lists(f_current);
- }
-}
+ GtkFileFilter *filter;
+ /* file filter for schematic files (*.sch) */
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Schematics"));
+ gtk_file_filter_add_pattern (filter, "*.sch");
+ gtk_file_chooser_add_filter (filechooser, filter);
+ /* file filter for symbol files (*.sym) */
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Symbols"));
+ gtk_file_filter_add_pattern (filter, "*.sym");
+ gtk_file_chooser_add_filter (filechooser, filter);
+ /* file filter for both symbol and schematic files (*.sym+*.sch) */
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("Schematics and symbols"));
+ gtk_file_filter_add_pattern (filter, "*.sym");
+ gtk_file_filter_add_pattern (filter, "*.sch");
+ gtk_file_chooser_add_filter (filechooser, filter);
+ /* file filter that match any file */
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_set_name (filter, _("All files"));
+ gtk_file_filter_add_pattern (filter, "*");
+ gtk_file_chooser_add_filter (filechooser, filter);
-/* ------------------------------------------------------------- *
- * This is the callback from the fileselect "open" button. It does
- * the following:
- * 1. It loops over all filenames returned in the CLIST
- * 2. For each filenname, it calls s_toplevel_open_file, which
- * reads in the file & fills out pr_current (which is a gloabal).
- * If this is a new file, it also calls s_sheet_data_add_master_*_list
- * to fill out the master lists.
- * ------------------------------------------------------------- */
-/* don't use widget, since it can be NULL */
-void x_fileselect_open_file(GtkWidget *w, FILEDIALOG *f_current)
+}
+
+/*------------------------------------------------------------------
+ *
+ *------------------------------------------------------------------*/
+static void
+x_fileselect_open_files (GSList *filenames)
{
PAGE *p_local;
- char *string;
int return_code = 0;
int old_num_rows, old_num_cols; /* There is a better way . . . */
- char *filename = NULL;
- GList *files;
- int row;
+ GSList *filename;
#ifdef DEBUG
printf("We have just entered x_fileselect_open_file.\n");
#endif
- /* get GList of selected files */
- files = (GTK_CLIST(f_current->file_list))->selection;
- if (files) {
-
old_num_rows = sheet_head->comp_count;
old_num_cols = sheet_head->comp_attrib_count;
/* iterate over selected files */
- for (; files; files = files->next) {
- row = (int) files->data; /* Why do we need to do cast here? */
- /* because files->data is a void * */
- gtk_clist_get_text(GTK_CLIST(f_current->file_list), row, 0,
- &filename);
-
- /* allocate space, then stick full, absolute filename into string */
- string = g_malloc(strlen(f_current->directory) + strlen(filename) + 2);
- if (!string) { /* sanity check . . . */
- /* g_free(string); freeing a null pointer is bad. */
- return;
- }
- /* string is full name of file. */
- sprintf(string, "%s/%s", f_current->directory, filename);
+ for (filename = filenames;
+ filename != NULL;
+ filename = g_slist_next (filename)) {
+ gchar *string = (gchar*)filename->data;
#if DEBUG
printf("In x_fileselect_open_file, opening string = %s\n", string);
@@ -770,8 +192,7 @@
s_log_message("Loading file [%s]\n", string);
}
- s_page_goto (pr_current,
- s_page_new (pr_current, string));
+ s_page_goto (pr_current, s_page_new (pr_current, string));
return_code = 0;
if (first_page == 1) {
@@ -856,10 +277,6 @@
} else {
fprintf(stderr, "Couldn't open any file!.\n");
}
- } /* if (files) */
-
- /* Now close file dialog window . . . . */
- gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
/* try showing all windows now */
gtk_widget_show( GTK_WIDGET(notebook));
@@ -868,511 +285,111 @@
/* ---------- Now verify correctness of entire design. ---------- */
s_toplevel_verify_design(pr_current); /* pr_current is a global */
-
- return;
}
-
-
-/* ------------------------------------------------------------- *
+/*------------------------------------------------------------------
+ * This function opens a file chooser dialog and wait for the user to
+ * select at least one file to load as toplevel's new pages.
*
- * ------------------------------------------------------------- */
-void
-x_fileselect_dir_button(GtkWidget * widget, gint row, gint column,
- GdkEventButton * bevent, FILEDIALOG * f_current)
-/*
- * SDB notes: This fcn is called for almost every event which occurs
- * to the "open file" widget, except when the actual file is to be
- * opened. Stuff handled by this fcn are e.g. highlighting the file
- * selected in the file list, updating the dir/file lists upon change
- * of directory, etc.
- */
-{
- char *temp = NULL;
-
- gtk_clist_get_text(GTK_CLIST(f_current->dir_list), row, 0, &temp);
-
- if (temp) {
-#if DEBUG
- printf("In x_fileselect_dir_button, selected: %d _%s_\n", row, temp);
-#endif
- if (bevent) {
- switch (bevent->type) {
- case (GDK_2BUTTON_PRESS):
- x_fileselect_change_dir(f_current, temp);
- break;
-
- default:
-
- break;
- }
- }
- }
-}
-
-
-/* ------------------------------------------------------------- *
+ * The function updates the user interface.
*
- * ------------------------------------------------------------- */
+ * At the end of the function, the toplevel's current page is set to
+ * the page of the last loaded page.
+ *------------------------------------------------------------------*/
void
-x_fileselect_file_button(GtkWidget * widget, gint row, gint column,
- GdkEventButton * bevent, FILEDIALOG * f_current)
-/*
- * SDB notes: This fcn is apparently called for each event occuring to
- * the file clist. This fcn determines if the button event captured was to
- * update the directory/file display or was a doubleclick on a file
- * in the clist meant to open the file. It then
- * calls the appropriate handler. Unfortunately, in the event of
- * selecting multiple files (using ENHANCED mode), bevent is nonnull
- * only on the first call.
- */
+x_fileselect_open (void)
{
- char *temp = NULL;
+ GtkWidget *dialog;
- /* put name of desired file into temp */
- gtk_clist_get_text(GTK_CLIST(f_current->file_list), row, 0, &temp);
-
- if (temp) {
-
-#if DEBUG
- printf("In x_fileselect_file_button, file selected: %d %s\n", row,
- temp);
- if (bevent) {
- printf("in x_fileselect_file_button, bevent->type = %d\n",
- bevent->type);
- } else {
- printf("In x_fileselect_file_button, bevent = NULL\n");
+ dialog = gtk_file_chooser_dialog_new (_("Open..."),
+ GTK_WINDOW(window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ g_object_set (dialog,
+ /* GtkFileChooser */
+ "select-multiple", TRUE,
+ NULL);
+ /* add file filters to dialog */
+ x_fileselect_setup_filechooser_filters (GTK_FILE_CHOOSER (dialog));
+ gtk_widget_show (dialog);
+ if (gtk_dialog_run ((GtkDialog*)dialog) == GTK_RESPONSE_ACCEPT) {
+ GSList *filenames =
+ gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dialog));
+
+ /* open each file */
+ x_fileselect_open_files (filenames);
+
+ if (filenames != NULL) {
+ /* free the list of filenames */
+ g_slist_foreach (filenames, (GFunc)g_free, NULL);
+ g_slist_free (filenames);
}
-#endif
-
- if (bevent) {
- switch (bevent->type) {
- case (GDK_2BUTTON_PRESS):
- x_fileselect_open_file(NULL, f_current);
- break;
- default:
- x_fileselect_update_dirfile(f_current, temp);
- break;
- }
}
- }
-}
+ gtk_widget_destroy (dialog);
+}
-/* ------------------------------------------------------------- *
+/*------------------------------------------------------------------
+ * This function opens a file chooser dialog and wait for the user to
+ * select a file where the toplevel's current page will be
+ * saved.
*
- * ------------------------------------------------------------- */
+ * If the user cancels the operation (with the cancel button), the
+ * page is not saved.
+ *
+ * The function updates the user interface.
+ *------------------------------------------------------------------*/
void
-x_fileselect_update_dirfile_saveas(FILEDIALOG * f_current,
- char *new_filename)
+x_fileselect_save (void)
{
- char *temp = NULL;
- char *filename = NULL;
- char *directory = NULL;
-
-#ifdef DEBUG
- printf("In x_fileselect_update_dirfile_saveas, new_filename = [%s]\n", new_filename);
-#endif
-
- if (new_filename == NULL) {
- return;
- }
-
- 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;
- }
+ GtkWidget *dialog;
- /* I wonder if I should do some checking on the
- * filename to make sure it is sane? */
- directory = getcwd(NULL, 1024);
- filename = g_strdup(new_filename);
+ dialog = gtk_file_chooser_dialog_new (_("Save as..."),
+ GTK_WINDOW(window),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ g_object_set (dialog,
+ /* GtkFileChooser */
+ "select-multiple", FALSE,
+ /* only in GTK 2.8 */
+ /* "do-overwrite-confirmation", TRUE, */
+ NULL);
+ /* add file filters to dialog */
+ x_fileselect_setup_filechooser_filters (GTK_FILE_CHOOSER (dialog));
+ gtk_widget_show (dialog);
+ if (gtk_dialog_run ((GtkDialog*)dialog) == GTK_RESPONSE_ACCEPT) {
+ gchar *filename =
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ /* try saving current page of toplevel to file filename */
+ if (filename != NULL &&
+ f_save (pr_current, filename)) {
+ s_log_message (_("Saved As [%s]\n"), filename);
+ /* Update filename for "saveas" operation */
+ x_fileselect_set_filename (pr_current, filename);
-#if DEBUG
- printf("In x_fileselect_update_dirfile_saveas, directory = %s\n", directory);
- printf("In x_fileselect_update_dirfile_saveas, filename = %s\n", filename);
-#endif
+ /* replace page filename with new one, do not free filename */
+ g_free (pr_current->page_current->page_filename);
+ pr_current->page_current->page_filename = filename;
- if (directory) {
- f_current->directory = g_strdup(directory);
- g_free(directory);
- }
+ /* reset the changed flag of current page*/
+ pr_current->page_current->CHANGED = 0;
- if (filename) {
- f_current->filename = g_strdup(filename);
- g_free(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);
-
-#if DEBUG
- printf("In x_fileselect_update_dirfile_saveas, f_current->directory = %s\n", f_current->directory);
- printf("In x_fileselect_update_dirfile_saveas, f_current->filename = %s\n", f_current->filename);
-#endif
-
- return;
-}
-
-
-/* ------------------------------------------------------------- *
- * This fcn closes the filedialog window, but doesn't kill the
- * filedialog object. There is another fcn which will kill
- * the whole object.
- * ------------------------------------------------------------- */
-void x_fileselect_close(GtkWidget * w, FILEDIALOG * f_current)
-{
- if(f_current->filter)
- gtk_widget_destroy(GTK_WIDGET(f_current->filter));
-
- if(f_current->search_entry)
- gtk_widget_destroy(GTK_WIDGET(f_current->search_entry));
-
- if(f_current->search_label)
- gtk_widget_destroy(GTK_WIDGET(f_current->search_label));
-
- if(f_current->filename_entry)
- gtk_widget_destroy(GTK_WIDGET(f_current->filename_entry));
-
- if(f_current->dir_list)
- gtk_widget_destroy(GTK_WIDGET(f_current->dir_list));
-
- if(f_current->file_list)
- gtk_widget_destroy(GTK_WIDGET(f_current->file_list));
-
- 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));
+ /* report error in log and status bar */
+ s_log_message (_("Could NOT save [%s]\n"),
+ pr_current->page_current->page_filename);
- /* Finally kill main widget */
- gtk_widget_destroy(GTK_WIDGET(f_current->xfwindow));
- return;
-}
-
-
-
-/*********** File Open/Save As... specific code ends here ***********/
-
-
-/******************************************************************/
-/*------------------------------------------------------------------
- * This is the main fcn which creates the "open file" dialog box.
- * filesel_type can be one of:
- *------------------------------------------------------------------*/
-void x_fileselect_setup(TOPLEVEL *pr_current, int filesel_type)
-{
- GtkWidget *buttonapply = NULL;
- GtkWidget *buttonclose = NULL;
- GtkWidget *scrolled_win;
- GtkWidget *action_area;
- GtkWidget *separator;
- GtkWidget *drawbox;
- GtkWidget *label;
- GtkWidget *searchbox;
-
-
- FILEDIALOG *f_current;
-
- GtkWidget *vbox;
- GtkWidget *list_hbox;
- char *dir_title[2];
- char *file_title[2];
-
- /* Initialize filedialog object. This object holds pointers
- * to all information in filedialog window, including pointers
- * to several widgets in the window. */
- f_current = g_malloc(sizeof(FILEDIALOG));
- /* (pr_current->fileselect)[0] = f_current; */ /* Keep a pointer to the file dialog in TOPLEVEL */
-
- 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;
- f_current->directory = NULL;
- f_current->dir_list = NULL;
- f_current->file_list = NULL;
- x_fileselect_init_list_buffers(f_current); /* initializes the directory and file lists */
-
-
- /* These widgets are not used in gattrib. I need to make them
- * null so that I don't get segfaults when manipulating windows */
- f_current->filter = NULL;
- f_current->search_entry = NULL;
- f_current->search_label = NULL;
- 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");
-#endif
-
- /* ----- Create main fileselect popup window ----- */
- gtk_window_position(GTK_WINDOW(f_current->xfwindow),
- GTK_WIN_POS_MOUSE);
-
- /* This places window on top and forces user to interact with it. */
- gtk_window_set_modal(GTK_WINDOW(f_current->xfwindow), TRUE);
- gtk_grab_add(GTK_WIDGET(f_current->xfwindow));
- gtk_window_set_transient_for(GTK_WINDOW(f_current->xfwindow),
- GTK_WINDOW(window)); /* window is global */
-
- /* Set window title depending upon which type it is */
- 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),
- "destroy",
- GTK_SIGNAL_FUNC(x_fileselect_destroy_window),
- f_current);
-
- gtk_signal_connect(GTK_OBJECT(f_current->xfwindow), "key_press_event",
- (GtkSignalFunc) x_fileselect_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);
-
- 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 = FILEDIALOG_SCH_ONLY; /* we only handle schematics in gattrib */
-
- 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);
- gtk_widget_show(list_hbox);
-
- separator = gtk_hseparator_new();
- gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, TRUE, 0);
- gtk_widget_show(separator);
-
- 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("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);
- 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);
- 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);
- 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("Files");
- 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, FILE_LIST_WIDTH,
- FILE_LIST_HEIGHT);
-
- /* Stuff added by SDB to enable opening multiple files at once */
- 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);
- 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);
- 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 "Filename" text entry area ----- */
- 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);
-
- 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);
+ g_free (filename);
- /* ----- Here we create the "open"/"save as"/"apply" buttons ----- */
- if (filesel_type == OPEN) {
- buttonapply = gtk_button_new_from_stock (GTK_STOCK_OPEN);
- gtk_signal_connect(GTK_OBJECT(buttonapply),
- "clicked",
- GTK_SIGNAL_FUNC(x_fileselect_open_file),
- f_current); /* Note that f_current points to pr_current
- which is important when reading in
- files. */
- } else if ((filesel_type == SAVEAS_NONE) ||
- (filesel_type == SAVEAS_QUIT) ||
- (filesel_type == SAVEAS_OPEN) ||
- (filesel_type == SAVEAS_CLOSE) ||
- (filesel_type == SAVEAS_NEW)) {
- buttonapply = gtk_button_new_from_stock (GTK_STOCK_SAVE_AS);
- gtk_signal_connect(GTK_OBJECT(buttonapply),
- "clicked",
- GTK_SIGNAL_FUNC(x_fileselect_saveas), 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 ----- */
- 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_CLOSE);
- 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,
- pr_current->page_current->
- page_filename);
-
- x_fileselect_fill_lists(f_current);
}
+ gtk_widget_destroy (dialog);
- if (!GTK_WIDGET_VISIBLE(f_current->xfwindow)) {
- gtk_widget_show(f_current->xfwindow);
- gdk_window_raise(f_current->xfwindow->window);
-
- gtk_grab_add(f_current->xfwindow);
-
- } else {
- /* window should already be mapped, otherwise this
- * will core */
- gdk_window_raise(f_current->xfwindow->window);
- }
}
_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs