--- gnubg/backgammon.h 2005-02-15 19:13:01.000000000 +0100 +++ gnubgP/backgammon.h 2005-02-16 17:14:15.140625000 +0100 @@ -467,11 +467,13 @@ typedef enum _pathformat { PATH_EPS, PATH_GAM, PATH_HTML, PATH_LATEX, PATH_MAT, PATH_OLDMOVES, PATH_PDF, PATH_PNG, PATH_POS, PATH_POSTSCRIPT, PATH_SGF, PATH_SGG, PATH_TEXT, PATH_MET, PATH_TMG, PATH_BKG, PATH_SNOWIE_TXT, - NUM_PATHS } + NUM_PATHS, + PATH_NULL +} pathformat; extern char aaszPaths[ NUM_PATHS ][ 2 ][ BIG_PATH ]; extern char* aszExtensions[ NUM_PATHS ]; extern char* szCurrentFileName; --- gnubg/gtkgame.c 2005-02-10 19:46:29.000000000 +0100 +++ gnubgP/gtkgame.c 2005-02-17 02:32:34.125000000 +0100 @@ -4193,12 +4193,13 @@ gtk_widget_get_parent(gtk_widget_get_parent( GTK_FILE_SELECTION( pw )->ok_button ) )), pwhbox); gtk_widget_show_all(pwhbox); } - if( szDefault ) + if( szDefault ) { gtk_file_selection_set_filename( GTK_FILE_SELECTION( pw ), szDefault ); + } gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( pw )->ok_button ), "clicked", GTK_SIGNAL_FUNC( FileOK ), &ft ); gtk_signal_connect_object( GTK_OBJECT( GTK_FILE_SELECTION( pw )-> cancel_button ), "clicked", @@ -4217,20 +4218,402 @@ GTKAllowStdin(); return ft.pch; } +/* --------------------------------------------------------------------------------------------- */ + +#if GTK_CHECK_VERSION(2,4,0) + +// This is a temporary hack and will move and mutate. Too many places where things +// are hardcoded or omplicated to access -- this clumsy switch is my dynamic copy. +// I'm not convinced a giant switch statement and pseudo-object orientation are the final +// solution, but for the time being it's easy to maintain. +// Disclaimer: This is not optimized or even written with performance as #1 priority (yet), +// and BETA anyway ... + +typedef struct { + char *description_long, // Description of the media type for use in e.g. Bubble Help + *description_short, // Description of the media type for use in e.g. a label + *path_current, // Path where the last file operation on this media type took place + // or NULL if none happened during the lifetime of this gnubg + *path_default, // Path where operations on this media type should be started if + // none happened during the lifetime of this gnubg so far + *file_suffix, // the file extension used this type + *command; // corresponding no-gui command FIXME: immature + pathformat path_format; // LEGACY: existing enumeration, De-facto ID. + int capabilities; // What degree of import / export this format offers? + + +} External_IO_Format; + +#define External_IO_none (1<<0) +#define External_IO_position (1<<1) +#define External_IO_game (1<<2) +#define External_IO_match (1<<3) +#define External_IO_session (1<<4) +#define External_IO_import (1<<29) +#define External_IO_export (1<<30) +#define External_IO_all_game_types (External_IO_position | External_IO_game | External_IO_match | External_IO_session) + +External_IO_Format *External_IO_Format_new (pathformat id) { + + External_IO_Format eiof; + External_IO_Format *result; + + switch (id) { + case PATH_EPS: { + eiof.description_long = "FIXME"; + eiof.description_short = "Encapsulated Postscript"; + eiof.path_current = aaszPaths[ PATH_EPS ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_EPS ][ 1 ]; + eiof.path_format = PATH_EPS; + eiof.file_suffix = aszExtensions [PATH_EPS]; + eiof.capabilities = External_IO_position | External_IO_export; + break; + } + case PATH_GAM: { + eiof.description_long = "FIXME"; + eiof.description_short = "Jellyfish Game"; + eiof.path_current = aaszPaths[ PATH_GAM ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_GAM ][ 1 ]; + eiof.path_format = PATH_GAM; + eiof.file_suffix = aszExtensions [PATH_GAM]; + eiof.capabilities = External_IO_game | External_IO_import; + break; + } + case PATH_HTML:{ + eiof.description_long = "FIXME"; + eiof.description_short = "Hypertext Markup Language"; + eiof.path_current = aaszPaths[ PATH_HTML ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_HTML ][ 1 ]; + eiof.path_format = PATH_HTML; + eiof.file_suffix = aszExtensions [PATH_HTML]; + eiof.capabilities = External_IO_all_game_types | External_IO_export; + break; + } + case PATH_LATEX: { + eiof.description_long = "FIXME"; + eiof.description_short = "LaTeX"; + eiof.path_current = aaszPaths[ PATH_LATEX ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_LATEX ][ 1 ]; + eiof.path_format = PATH_LATEX; + eiof.file_suffix = aszExtensions [PATH_LATEX]; + eiof.capabilities = External_IO_all_game_types | External_IO_export; + break; + } + case PATH_MAT: { + eiof.description_long = "FIXME"; + eiof.description_short = "Jellyfish Match"; + eiof.path_current = aaszPaths[ PATH_MAT ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_MAT ][ 1 ]; + eiof.path_format = PATH_MAT; + eiof.file_suffix = aszExtensions [PATH_MAT]; + eiof.capabilities = External_IO_match | External_IO_import; + break; + } + case PATH_OLDMOVES: { + eiof.description_long = "FIXME"; + eiof.description_short = "Fibs Oldmoves"; + eiof.path_current = aaszPaths[ PATH_OLDMOVES ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_OLDMOVES ][ 1 ]; + eiof.path_format = PATH_OLDMOVES; + eiof.file_suffix = aszExtensions [PATH_OLDMOVES]; + eiof.capabilities = External_IO_match | External_IO_import; //? + break; + } + case PATH_PDF: { + eiof.description_long = "FIXME"; + eiof.description_short = "Portable Document Format"; + eiof.path_current = aaszPaths[ PATH_PDF ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_PDF ][ 1 ]; + eiof.path_format = PATH_PDF; + eiof.file_suffix = aszExtensions [PATH_PDF]; + eiof.capabilities = External_IO_all_game_types | External_IO_export; + break; + } + case PATH_PNG: { + eiof.description_long = "FIXME"; + eiof.description_short = "Portable Network Graphics"; + eiof.path_current = aaszPaths[ PATH_PNG ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_PNG ][ 1 ]; + eiof.path_format = PATH_PNG; + eiof.file_suffix = aszExtensions [PATH_PNG]; + eiof.capabilities = External_IO_all_game_types | External_IO_export; + break; + } + case PATH_POS: { + eiof.description_long = "FIXME"; + eiof.description_short = "Jellyfish Position"; + eiof.path_current = aaszPaths[ PATH_POS ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_POS ][ 1 ]; + eiof.path_format = PATH_POS; + eiof.file_suffix = aszExtensions [PATH_POS]; + eiof.capabilities = External_IO_position | External_IO_import; + break; + } + case PATH_POSTSCRIPT: { + eiof.description_long = "FIXME"; + eiof.description_short = "PostScript"; + eiof.path_current = aaszPaths[ PATH_POSTSCRIPT ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_POSTSCRIPT ][ 1 ]; + eiof.path_format = PATH_POSTSCRIPT; + eiof.file_suffix = aszExtensions [PATH_POSTSCRIPT]; + eiof.capabilities = External_IO_all_game_types | External_IO_export; + break; + } + case PATH_SGF: { + eiof.description_long = "FIXME"; + eiof.description_short = "Gnu Backgammon Savegame Format"; + eiof.path_current = aaszPaths[ PATH_SGF ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_SGF ][ 1 ]; + eiof.path_format = PATH_SGF; + eiof.file_suffix = aszExtensions [PATH_SGF]; + eiof.capabilities = External_IO_all_game_types | External_IO_export | External_IO_import; + break; + } + case PATH_SGG: { + eiof.description_long = "FIXME"; + eiof.description_short = "Gamesgrind Save Game"; + eiof.path_current = aaszPaths[ PATH_SGG ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_SGG ][ 1 ]; + eiof.path_format = PATH_SGG; + eiof.file_suffix = aszExtensions [PATH_SGG]; + eiof.capabilities = External_IO_game | External_IO_import; + break; + } + case PATH_TEXT: { + eiof.description_long = "FIXME"; + eiof.description_short = "Plain Text"; + eiof.path_current = aaszPaths[ PATH_TEXT ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_TEXT ][ 1 ]; + eiof.path_format = PATH_TEXT; + eiof.file_suffix = aszExtensions [PATH_TEXT]; + eiof.capabilities = External_IO_all_game_types | External_IO_export; + break; + } + case PATH_MET: { + eiof.description_long = "FIXME"; + eiof.description_short = "Match Equity Table"; + eiof.path_current = aaszPaths[ PATH_MET ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_MET ][ 1 ]; + eiof.path_format = PATH_MET; + eiof.file_suffix = aszExtensions [PATH_MET]; + eiof.capabilities = External_IO_none | External_IO_import; + break; + } + case PATH_TMG: { + eiof.description_long = "FIXME"; + eiof.description_short = "True Moneygames"; + eiof.path_current = aaszPaths[ PATH_TMG ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_TMG ][ 1 ]; + eiof.path_format = PATH_TMG; + eiof.file_suffix = aszExtensions [PATH_TMG]; + eiof.capabilities = External_IO_match | External_IO_import; // ? + break; + } + case PATH_BKG: { + eiof.description_long = "FIXME"; + eiof.description_short = "Hans Berliner's BKG Format"; + eiof.path_current = aaszPaths[ PATH_BKG ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_BKG ][ 1 ]; + eiof.path_format = PATH_BKG; + eiof.file_suffix = aszExtensions [PATH_BKG]; + eiof.capabilities = External_IO_match | External_IO_import; // ? + break; + } + case PATH_SNOWIE_TXT: { + eiof.description_long = "FIXME"; + eiof.description_short = "Snowie Text"; + eiof.path_current = aaszPaths[ PATH_SNOWIE_TXT ][ 0 ]; + eiof.path_default = aaszPaths[ PATH_SNOWIE_TXT ][ 1 ]; + eiof.path_format = PATH_SNOWIE_TXT; + eiof.file_suffix = aszExtensions [PATH_SNOWIE_TXT ]; + eiof.capabilities = External_IO_match | External_IO_import; // ? + break; + } + case NUM_PATHS: + case PATH_NULL: + default: { + eiof.description_long = "NUM_PATHS is an error and PATH_NULL a hack"; + eiof.description_short = "error"; + eiof.path_current = ""; + eiof.path_default = ""; + eiof.path_format = PATH_NULL; + eiof.file_suffix = ""; + eiof.capabilities = External_IO_none; + break; + } + } + + result = malloc(sizeof(External_IO_Format)); + memset(result, 0, sizeof(External_IO_Format)); + + /* + result->description_long = malloc(strlen(eiof.description_long)); + result->description_short = malloc(strlen(eiof.description_short)); + result->path_current = malloc(strlen(eiof.path_current)); + result->path_default = malloc(strlen(eiof.path_default)); + result->path_format = eiof.path_format; + result->file_suffix = malloc(strlen(eiof.file_suffix)); + result->capabilities = eiof.capabilities; + + strcpy(result->description_long, eiof.description_long); + strcpy(result->description_short, eiof.description_short); + strcpy(result->path_current, eiof.path_current); + strcpy(result->path_default, eiof.path_default); + strcpy(result->file_suffix, eiof.file_suffix); + */ + + // no need to copy a lot, everything is static already ... + + result->description_long = eiof.description_long; + result->description_short = eiof.description_short; + result->path_current = eiof.path_current; + result->path_default = eiof.path_default; + result->path_format = eiof.path_format; + result->file_suffix = eiof.file_suffix; + result->capabilities = eiof.capabilities; + + + return result; +} + +void External_IO_Format_destroy (External_IO_Format *eiof) { + + if (eiof) { + /* + if (eiof->description_long) free(eiof->description_long); + if (eiof->description_short) free(eiof->description_short); + if (eiof->path_current) free(eiof->path_current); + if (eiof->path_default) free(eiof->path_default); + if (eiof->file_suffix) free(eiof->file_suffix); + */ + free(eiof); + } +} + +extern void GTKFileCommand24( char *szPrompt, char *szDefault, char *szCommand, + char *szPath, filedialogtype fdt, pathformat pathId) { + + char *filename; // the result + External_IO_Format *eiof; // a bunch of data on a file format + + GtkWidget *filechooser; + + char *dialogTitle; + + // Determine dialog title + if (szPrompt) { // FIXME: When the eiof type ist is complete, all + dialogTitle = szPrompt; // titles should be generated. + } else if (fdt == FDT_NONE_SAVE) { + dialogTitle = "GNU Backgammon - Save File"; + } else { + dialogTitle = "GNU Backgammon - Open File"; + } + + // Creaze dialog + filechooser= gtk_file_chooser_dialog_new ( + dialogTitle, // Window Text + NULL, // Parent Window + (fdt == FDT_NONE_OPEN) + ? GTK_FILE_CHOOSER_ACTION_OPEN // Action + : GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, // List of Buttons + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + gtk_window_set_modal( GTK_WINDOW( filechooser ), TRUE ); + gtk_window_set_transient_for( GTK_WINDOW( filechooser ), GTK_WINDOW( pwMain ) ); + // Our DAO + + eiof = External_IO_Format_new(pathId); + + // Set default path on dialog + gtk_file_chooser_set_current_folder((GtkFileChooser *) filechooser, eiof->path_current); + + + if (fdt == FDT_NONE_SAVE) { // Case: we want to save + // Set default filename + gtk_file_chooser_set_current_name((GtkFileChooser *) filechooser, getDefaultFileName(pathId)); + + } else { // FTD_NONE_OPEN, we want to load + + // Create 2 File Filters: *.* and *.suffix + + char *suffixGlobber; + char *filterDescription; + + GtkFileFilter *anyFileFilter, *suffixFileFilter; + + filterDescription = g_strconcat ("Show ", eiof->description_short, " files (*.", eiof->file_suffix, ") only", NULL); + suffixGlobber = g_strconcat("*.", eiof->file_suffix, NULL ); + + suffixFileFilter = gtk_file_filter_new(); + anyFileFilter = gtk_file_filter_new(); + gtk_file_filter_add_pattern (suffixFileFilter, suffixGlobber); + gtk_file_filter_add_pattern (anyFileFilter, "*"); + gtk_file_filter_set_name (anyFileFilter, "Show all Files (*)"); + gtk_file_filter_set_name (suffixFileFilter, filterDescription); + gtk_file_chooser_add_filter ((GtkFileChooser *) filechooser, suffixFileFilter); + gtk_file_chooser_add_filter ((GtkFileChooser *) filechooser, anyFileFilter); + + if (filterDescription) g_free(filterDescription); + if (suffixGlobber) g_free(suffixGlobber); + + } + + // launch dialog + if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_filename ((GtkFileChooser *) filechooser); + + if (filename) { +#if __GNUC__ + char sz[ strlen( pch ) + strlen( szCommand ) + 4 ]; +#elif HAVE_ALLOCA + char *sz = alloca( strlen( filename ) + strlen( szCommand ) + 4 ); +#elif GLIB_CHECK_VERSION(1,1,12) + char *sz = g_alloca(strlen( filename ) + strlen( szCommand ) + 4); +#else + char sz[ 1024 ]; +#endif + // and actually do the requested IO + sprintf( sz, "%s %s", szCommand, filename ); + UserCommand( sz ); + g_free (filename); + } + } + // Cleanup + + gtk_widget_destroy (filechooser); + External_IO_Format_destroy(eiof); + + GTKDisallowStdin(); + gtk_main(); + GTKAllowStdin(); +} +#endif + +/* ------------------------------------------------------------------------------------------ */ + extern void GTKFileCommand( char *szPrompt, char *szDefault, char *szCommand, - char *szPath, filedialogtype fdt ) { + char *szPath, filedialogtype fdt, pathformat pathId ) { char *pch; +#if GTK_CHECK_VERSION(2,4,0) + if (fdt == FDT_NONE_OPEN || fdt == FDT_NONE_SAVE) { + GTKFileCommand24(szPrompt, szDefault, szCommand, szPath, fdt, pathId); + return; + } else { +#endif if( ( pch = SelectFile( szPrompt, szDefault, szPath, fdt ) ) ) { #if __GNUC__ char sz[ strlen( pch ) + strlen( szCommand ) + 4 ]; #elif HAVE_ALLOCA char *sz = alloca( strlen( pch ) + strlen( szCommand ) + 4 ); +#elif GLIB_CHECK_VERSION(1,1,12) + char *sz = g_alloca(strlen( filename ) + strlen( szCommand ) + 4); #else char sz[ 1024 ]; #endif sprintf( sz, "%s %s", szCommand, pch ); UserCommand( sz ); @@ -4232,18 +4615,20 @@ #else char sz[ 1024 ]; #endif sprintf( sz, "%s %s", szCommand, pch ); UserCommand( sz ); - g_free( pch ); } +#if GTK_CHECK_VERSION(2,4,0) + } +#endif } static void LoadCommands( gpointer *p, guint n, GtkWidget *pw ) { - GTKFileCommand( _("Open commands"), NULL, "load commands", NULL, FDT_NONE ); + GTKFileCommand( _("Open commands"), NULL, "load commands", NULL, FDT_NONE_OPEN, PATH_NULL ); } extern void SetMET( GtkWidget *pw, gpointer p ) { char *pchMet = NULL, *pch = NULL; @@ -4258,11 +4643,11 @@ free( pch ); pch = NULL; } GTKFileCommand( _("Set match equity table"), pch, "set matchequitytable ", - "met", FDT_NONE ); + "met", FDT_NONE_OPEN, PATH_NULL ); /* update filename on option page */ if ( p && GTK_WIDGET_VISIBLE( p ) ) gtk_label_set_text( GTK_LABEL( p ), miCurrent.szFileName ); @@ -4273,267 +4658,267 @@ } static void LoadGame( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_SGF ); - GTKFileCommand( _("Open game"), sz, "load game", "sgf", FDT_NONE ); + GTKFileCommand( _("Open game"), sz, "load game", "sgf", FDT_NONE_OPEN, PATH_SGF ); if ( sz ) free ( sz ); } static void LoadMatch( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_SGF ); - GTKFileCommand( _("Open match or session"), sz, "load match", "sgf", FDT_NONE ); + GTKFileCommand( _("Open match or session"), sz, "load match", "sgf", FDT_NONE_OPEN, PATH_SGF ); if ( sz ) free ( sz ); } static void LoadPosition( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_SGF ); - GTKFileCommand( _("Open position"), sz, "load position", "sgf", FDT_NONE ); + GTKFileCommand( _("Open position"), sz, "load position", "sgf", FDT_NONE_OPEN, PATH_SGF ); if ( sz ) free ( sz ); } static void ImportBKG( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_BKG ); - GTKFileCommand( _("Import BKG session"), sz, "import bkg", "bkg", FDT_NONE ); + GTKFileCommand( _("Import BKG session"), sz, "import bkg", "bkg", FDT_NONE_OPEN, PATH_BKG ); if ( sz ) free ( sz ); } static void ImportMat( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_MAT ); - GTKFileCommand( _("Import .mat match"), sz, "import mat", "mat", FDT_NONE ); + GTKFileCommand( _("Import .mat match"), sz, "import mat", "mat", FDT_NONE_OPEN, PATH_MAT ); if ( sz ) free ( sz ); } static void ImportPos( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_POS ); - GTKFileCommand( _("Import .pos position"), sz, "import pos", "pos", FDT_NONE ); + GTKFileCommand( _("Import .pos position"), sz, "import pos", "pos", FDT_NONE_OPEN, PATH_POS ); if ( sz ) free ( sz ); } static void ImportOldmoves( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_OLDMOVES ); - GTKFileCommand( _("Import FIBS oldmoves"), sz, "import oldmoves", "oldmoves", FDT_NONE ); + GTKFileCommand( _("Import FIBS oldmoves"), sz, "import oldmoves", "oldmoves", FDT_NONE_OPEN, PATH_OLDMOVES ); if ( sz ) free ( sz ); } static void ImportSGG( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_SGG ); - GTKFileCommand( _("Import .sgg match"), sz, "import sgg", "sgg", FDT_NONE ); + GTKFileCommand( _("Import .sgg match"), sz, "import sgg", "sgg", FDT_NONE_OPEN, PATH_SGG ); if ( sz ) free ( sz ); } static void ImportTMG( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_TMG ); - GTKFileCommand( _("Import .tmg match"), sz, "import tmg", "tmg", FDT_NONE ); + GTKFileCommand( _("Import .tmg match"), sz, "import tmg", "tmg", FDT_NONE_OPEN, PATH_TMG ); if ( sz ) free ( sz ); } static void ImportSnowieTxt( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultPath ( PATH_SNOWIE_TXT ); GTKFileCommand( _("Import Snowie .txt position"), sz, "import snowietxt", - "snowietxt", FDT_NONE ); + "snowietxt", FDT_NONE_OPEN, PATH_SNOWIE_TXT ); if ( sz ) free ( sz ); } static void SaveGame( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_SGF ); - GTKFileCommand( _("Save game"), sz, "save game", "sgf", FDT_NONE ); + GTKFileCommand( _("Save game"), sz, "save game", "sgf", FDT_NONE_SAVE, PATH_SGF ); if ( sz ) free ( sz ); } static void SaveMatch( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_SGF ); - GTKFileCommand( _("Save match or session"), sz, "save match", "sgf", FDT_NONE ); + GTKFileCommand( _("Save match or session"), sz, "save match", "sgf", FDT_NONE_SAVE, PATH_SGF ); if ( sz ) free ( sz ); } static void SavePosition( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_SGF ); - GTKFileCommand( _("Save position"), sz, "save position", "sgf", FDT_NONE ); + GTKFileCommand( _("Save position"), sz, "save position", "sgf", FDT_NONE_SAVE, PATH_SGF ); if ( sz ) free ( sz ); } static void SaveWeights( gpointer *p, guint n, GtkWidget *pw ) { char *sz = strdup ( PKGDATADIR "/gnubg.weights" ); - GTKFileCommand( _("Save weights"), sz, "save weights", NULL, FDT_NONE ); + GTKFileCommand( _("Save weights"), sz, "save weights", NULL, FDT_NONE_SAVE, PATH_NULL ); if ( sz ) free ( sz ); } static void ExportGameGam( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_GAM ); - GTKFileCommand( _("Export .gam game"), sz, "export game gam", "gam", FDT_EXPORT ); + GTKFileCommand( _("Export .gam game"), sz, "export game gam", "gam", FDT_EXPORT, PATH_GAM ); if ( sz ) free ( sz ); } static void ExportGameHtml( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_HTML ); - GTKFileCommand( _("Export HTML game"), sz, "export game html", "html", FDT_EXPORT ); + GTKFileCommand( _("Export HTML game"), sz, "export game html", "html", FDT_EXPORT, PATH_HTML ); if ( sz ) free ( sz ); } static void ExportGameLaTeX( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_LATEX ); - GTKFileCommand( _("Export LaTeX game"), sz, "export game latex", "latex", FDT_EXPORT ); + GTKFileCommand( _("Export LaTeX game"), sz, "export game latex", "latex", FDT_EXPORT, PATH_LATEX ); if ( sz ) free ( sz ); } static void ExportGamePDF( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_PDF ); - GTKFileCommand( _("Export PDF game"), sz, "export game pdf", "pdf", FDT_EXPORT ); + GTKFileCommand( _("Export PDF game"), sz, "export game pdf", "pdf", FDT_EXPORT, PATH_PDF ); if ( sz ) free ( sz ); } static void ExportGamePostScript( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_POSTSCRIPT ); GTKFileCommand( _("Export PostScript game"), sz, "export game postscript", - "postscript", FDT_EXPORT ); + "postscript", FDT_EXPORT, PATH_POSTSCRIPT ); if ( sz ) free ( sz ); } static void ExportGameText( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_TEXT ); - GTKFileCommand( _("Export text game"), sz, "export game text", "text", FDT_EXPORT ); + GTKFileCommand( _("Export text game"), sz, "export game text", "text", FDT_EXPORT, PATH_TEXT ); if ( sz ) free ( sz ); } static void ExportMatchLaTeX( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_LATEX ); - GTKFileCommand( _("Export LaTeX match"), sz, "export match latex", "latex", FDT_EXPORT ); + GTKFileCommand( _("Export LaTeX match"), sz, "export match latex", "latex", FDT_EXPORT, PATH_LATEX ); if ( sz ) free ( sz ); } static void ExportMatchHtml( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_HTML ); - GTKFileCommand( _("Export HTML match"), sz, "export match html", "html", FDT_EXPORT ); + GTKFileCommand( _("Export HTML match"), sz, "export match html", "html", FDT_EXPORT, PATH_HTML ); if ( sz ) free ( sz ); } static void ExportMatchMat( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_MAT ); - GTKFileCommand( _("Export .mat match"), sz, "export match mat", "mat", FDT_NONE ); + GTKFileCommand( _("Export .mat match"), sz, "export match mat", "mat", FDT_NONE_SAVE, PATH_MAT ); if ( sz ) free ( sz ); } static void ExportMatchPDF( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_PDF ); - GTKFileCommand( _("Export PDF match"), sz, "export match pdf", "pdf", FDT_EXPORT ); + GTKFileCommand( _("Export PDF match"), sz, "export match pdf", "pdf", FDT_EXPORT, PATH_PDF ); if ( sz ) free ( sz ); } static void ExportMatchPostScript( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_POSTSCRIPT ); GTKFileCommand( _("Export PostScript match"), sz, "export match postscript", - "postscript", FDT_EXPORT ); + "postscript", FDT_EXPORT, PATH_POSTSCRIPT ); if ( sz ) free ( sz ); } static void ExportMatchText( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_TEXT ); - GTKFileCommand( _("Export text match"), sz, "export match text", "text", FDT_EXPORT ); + GTKFileCommand( _("Export text match"), sz, "export match text", "text", FDT_EXPORT, PATH_TEXT ); if ( sz ) free ( sz ); } static void ExportPositionEPS( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_EPS ); - GTKFileCommand( _("Export EPS position"), sz, "export position eps", "eps", FDT_NONE ); + GTKFileCommand( _("Export EPS position"), sz, "export position eps", "eps", FDT_NONE_SAVE, PATH_EPS ); if ( sz ) free ( sz ); } static void ExportPositionHtml( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_HTML ); - GTKFileCommand( _("Export HTML position"), sz, "export position html", "html", FDT_EXPORT ); + GTKFileCommand( _("Export HTML position"), sz, "export position html", "html", FDT_EXPORT, PATH_HTML ); if ( sz ) free ( sz ); } static void ExportPositionGammOnLine( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_HTML ); GTKFileCommand( _("Export position to GammOnLine (HTML)"), - sz, "export position gammonline", "html", FDT_NONE ); + sz, "export position gammonline", "html", FDT_NONE_SAVE, PATH_HTML ); if ( sz ) free ( sz ); } static void CopyAsGOL( gpointer *p, guint n, GtkWidget *pw ) { @@ -4543,114 +4928,114 @@ } static void ExportPositionPos( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_POS ); - GTKFileCommand( _("Export .pos position"), sz, "export position pos", "pos", FDT_NONE ); + GTKFileCommand( _("Export .pos position"), sz, "export position pos", "pos", FDT_NONE_SAVE, PATH_POS ); if ( sz ) free ( sz ); } static void ExportPositionPNG( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_PNG ); - GTKFileCommand( _("Export PNG position"), sz, "export position png", "png", FDT_EXPORT ); + GTKFileCommand( _("Export PNG position"), sz, "export position png", "png", FDT_EXPORT, PATH_PNG ); if ( sz ) free ( sz ); } static void ExportPositionText( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_TEXT ); - GTKFileCommand( _("Export text position"), sz, "export position text", "text", FDT_EXPORT ); + GTKFileCommand( _("Export text position"), sz, "export position text", "text", FDT_EXPORT, PATH_TEXT ); if ( sz ) free ( sz ); } static void ExportPositionSnowieTxt( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_SNOWIE_TXT ); GTKFileCommand( _("Export Snowie .txt position"), sz, - "export position snowietxt", "snowietxt", FDT_EXPORT ); + "export position snowietxt", "snowietxt", FDT_EXPORT, PATH_SNOWIE_TXT ); if ( sz ) free ( sz ); } static void ExportSessionLaTeX( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_LATEX ); GTKFileCommand( _("Export LaTeX session"), sz, "export session latex", - "latex", FDT_EXPORT ); + "latex", FDT_EXPORT, PATH_LATEX ); if ( sz ) free ( sz ); } static void ExportSessionPDF( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_PDF ); - GTKFileCommand( _("Export PDF session"), sz, "export session pdf", "pdf", FDT_EXPORT ); + GTKFileCommand( _("Export PDF session"), sz, "export session pdf", "pdf", FDT_EXPORT, PATH_PDF ); if ( sz ) free ( sz ); } static void ExportSessionHtml( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_HTML ); - GTKFileCommand( _("Export HTML session"), sz, "export session html", "html", FDT_EXPORT ); + GTKFileCommand( _("Export HTML session"), sz, "export session html", "html", FDT_EXPORT, PATH_HTML ); if ( sz ) free ( sz ); } static void ExportSessionPostScript( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_POSTSCRIPT ); GTKFileCommand( _("Export PostScript session"), sz, - "export session postscript", "postscript", FDT_EXPORT ); + "export session postscript", "postscript", FDT_EXPORT, PATH_POSTSCRIPT ); if ( sz ) free ( sz ); } static void ExportSessionText( gpointer *p, guint n, GtkWidget *pw ) { char *sz = getDefaultFileName ( PATH_TEXT ); - GTKFileCommand( _("Export text session"), sz, "export session text", "text", FDT_EXPORT ); + GTKFileCommand( _("Export text session"), sz, "export session text", "text", FDT_EXPORT, PATH_TEXT ); if ( sz ) free ( sz ); } static void ExportHTMLImages( gpointer *p, guint n, GtkWidget *pw ) { char *sz = strdup( PKGDATADIR "/html-images" ); - GTKFileCommand( _("Export HTML images"), sz, "export htmlimages", NULL, FDT_EXPORT ); + GTKFileCommand( _("Export HTML images"), sz, "export htmlimages", NULL, FDT_EXPORT, PATH_NULL ); if ( sz ) free ( sz ); } #if ENABLE_TRAIN_MENU static void DatabaseExport( gpointer *p, guint n, GtkWidget *pw ) { char *sz = strdup ( PKGDATADIR "/gnubg.gdbm" ); - GTKFileCommand( _("Export database"), sz, "database export", NULL, FDT_NONE ); + GTKFileCommand( _("Export database"), sz, "database export", NULL, FDT_NONE_SAVE, PATH_NULL ); if ( sz ) free ( sz ); } static void DatabaseImport( gpointer *p, guint n, GtkWidget *pw ) { char *sz = strdup ( PKGDATADIR "/gnubg.gdbm" ); - GTKFileCommand( _("Import database"), sz, "database import", NULL, FDT_NONE ); + GTKFileCommand( _("Import database"), sz, "database import", NULL, FDT_NONE_OPEN, PATH_NULL ); if ( sz ) free ( sz ); } --- gnubg/gtkgame.h 2005-02-10 19:46:30.000000000 +0100 +++ gnubgP/gtkgame.h 2005-02-16 17:51:59.187500000 +0100 @@ -47,11 +47,12 @@ DT_GNU, NUM_DIALOG_TYPES } dialogtype; typedef enum _filedialogtype { - FDT_NONE=0, FDT_SAVE, FDT_EXPORT, FDT_IMPORT, FDT_EXPORT_FULL + FDT_NONE=0, FDT_SAVE, FDT_EXPORT, FDT_IMPORT, FDT_EXPORT_FULL, + FDT_NONE_OPEN, FDT_NONE_SAVE } filedialogtype; typedef enum _warnings { WARN_FULLSCREEN_EXIT=0, WARN_QUICKDRAW_MODE, WARN_SET_SHADOWS, WARN_UNACCELERATED, WARN_NUM_WARNINGS @@ -214,11 +215,11 @@ extern int GTKReadNumber( char *szTitle, char *szPrompt, int nDefault, int nMin, int nMax, int nInc ); extern void GTKFileCommand( char *szPrompt, char *szDefault, char *szCommand, - char *szPath, filedialogtype fdt ); + char *szPath, filedialogtype fdt, pathformat pathFormat ); extern char *SelectFile( char *szTitle, char *szDefault, char *szPath, filedialogtype fdt ); extern void Undo(); --- gnubg/gtkprefs.c 2005-02-10 19:46:30.000000000 +0100 +++ gnubgP/gtkprefs.c 2005-02-16 12:29:16.312500000 +0100 @@ -2388,11 +2388,11 @@ FILE *pf; boarddesign *pbde; renderdata rdNew; if (!( pch = szFile = - SelectFile( _("Export Design"), NULL, NULL, FDT_NONE ) ) ) + SelectFile( _("Export Design"), NULL, NULL, FDT_NONE_SAVE ) ) ) return; szFile = NextToken( &szFile ); /* @@ -2472,11 +2472,11 @@ GList *new_designs; gint old_length; gint num_added; if ( !( pch = szFile = - SelectFile( _("Export Design"), NULL, NULL, FDT_NONE ) ) ) + SelectFile( _("Export Design"), NULL, NULL, FDT_NONE_OPEN ) ) ) return; szFile = NextToken( &szFile ); if ( ! ( new_designs = ParseBoardDesigns( szFile, TRUE ) ) ) { --- gnubg/gtkoptions.c 2005-02-08 17:37:45.000000000 +0100 +++ gnubgP/gtkoptions.c 2005-02-16 17:52:54.453125000 +0100 @@ -1661,11 +1661,11 @@ if (rngCurrent != RNG_USER) UserCommand("set rng user"); break; case 8: GTKFileCommand( _("Select file with dice"), NULL, - "set rng file", NULL, 0 ); + "set rng file", NULL, FDT_NONE_OPEN, PATH_NULL ); break; default: break; } --- gnubg/gtktoolbar.c 2004-10-12 10:41:24.000000000 +0200 +++ gnubgP/gtktoolbar.c 2005-02-16 17:28:18.171875000 +0100 @@ -199,21 +199,21 @@ OpenClicked( GtkWidget *pw, gpointer unused ) { char *sz = getDefaultPath ( PATH_SGF ); GTKFileCommand(_("Open match, session, game or position"), - sz, "load match", "sgf", FDT_NONE); + sz, "load match", "sgf", FDT_NONE_OPEN, PATH_SGF); if ( sz ) free ( sz ); } static void SaveClicked( GtkWidget *pw, gpointer unused ) { char *sz = getDefaultFileName ( PATH_SGF ); GTKFileCommand(_("Save match, session, game or position"), - sz, "save", "sgf", FDT_SAVE); + sz, "save", "sgf", FDT_SAVE, PATH_SGF); if ( sz ) free ( sz ); } static void @@ -226,11 +226,11 @@ if (lastImportType != -1) sz = getDefaultPath(impTypes[lastImportType]); GTKFileCommand(_("Import match, session, game or position"), - sz, "import", "N", FDT_IMPORT); + sz, "import", "N", FDT_IMPORT, impTypes[lastImportType]); if (sz) free(sz); } @@ -244,11 +244,11 @@ if (lastExportType != -1 && expTypes[lastExportType] != -1) sz = getDefaultPath(expTypes[lastExportType]); GTKFileCommand(_("Export match, session, game or position"), - sz, "export", "N", FDT_EXPORT_FULL); + sz, "export", "N", FDT_EXPORT_FULL, expTypes[lastExportType]); if (sz) free(sz); }