From: H.G.Muller Date: Sat, 9 Apr 2016 18:12:26 +0000 (+0200) Subject: Fix browsing for folders, and allow starting in DATADIR X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=70a154066b96d5390c133ae8800ff1943d21ac0c;p=xboard.git Fix browsing for folders, and allow starting in DATADIR The previous path seemed to cause a segfault when browsing for a folder with an empty text-edit. In addition there existed a bug for browsing from the Engine Settings dialog, where the value of the option was taken as a filter. Both are fixed now. The Option.textValue field, which for FileName Options holds the filter, for PatName Options could be NULL or "". The latter is now taken to mean that browsing should start in DATADIR, and is only used when browsing for sound files or pieceImageDir with empty pathname field. --- diff --git a/dialogs.c b/dialogs.c index 43f762e..8624ff4 100644 --- a/dialogs.c +++ b/dialogs.c @@ -625,9 +625,9 @@ CommonOptionsOK (int n) static Option commonEngineOptions[] = { { 0, 0, 0, NULL, (void*) &appData.ponderNextMove, "", NULL, CheckBox, N_("Ponder Next Move") }, { 0, 0, 1000, NULL, (void*) &appData.smpCores, "", NULL, Spin, N_("Maximum Number of CPUs per Engine:") }, -{ 0, 0, 0, NULL, (void*) &appData.polyglotDir, "", NULL, PathName, N_("Polygot Directory:") }, +{ 0, 0, 0, NULL, (void*) &appData.polyglotDir, NULL, NULL, PathName, N_("Polygot Directory:") }, { 0, 0,16000, NULL, (void*) &appData.defaultHashSize, "", NULL, Spin, N_("Hash-Table Size (MB):") }, -{ 0, 0, 0, NULL, (void*) &egtPath, "", NULL, PathName, N_("EGTB Path:") }, +{ 0, 0, 0, NULL, (void*) &egtPath, NULL, NULL, PathName, N_("EGTB Path:") }, { 0, 0, 1000, NULL, (void*) &appData.defaultCacheSizeEGTB, "", NULL, Spin, N_("EGTB Cache Size (MB):") }, { 0, 0, 0, NULL, (void*) &appData.usePolyglotBook, "", NULL, CheckBox, N_("Use GUI Book") }, { 0, 0, 0, NULL, (void*) &appData.polyglotBook, ".bin", NULL, FileName, N_("Opening-Book Filename:") }, @@ -3313,10 +3313,14 @@ DirSelProc (int n, int sel) void StartDir (char *filter, char *newName) { - static char *gamesDir, *trnDir, *imgDir, *bookDir; + static char *gamesDir, *trnDir, *imgDir, *bookDir, *dirDir; static char curDir[MSG_SIZ]; char **res = NULL; if(!filter || !*filter) return; + if(strstr(filter, "dir")) { + res = &dirDir; + if(!dirDir) dirDir= strdup(dataDir); + } else if(strstr(filter, "pgn")) res = &gamesDir; else if(strstr(filter, "bin")) res = &bookDir; else if(strstr(filter, "png")) res = &imgDir; else diff --git a/gtk/xoptions.c b/gtk/xoptions.c index 7a3a831..fd9bc07 100644 --- a/gtk/xoptions.c +++ b/gtk/xoptions.c @@ -1113,11 +1113,11 @@ void BrowseGTK(GtkWidget *widget, gpointer gdata) gtkfilter = gtk_file_filter_new(); gtkfilter_all = gtk_file_filter_new(); - char fileext[MSG_SIZ], *filter = currentOption[opt_i].textValue, *old; + char fileext[MSG_SIZ], *filter = currentOption[opt_i].textValue, *old = NULL; + if(currentCps) filter = NULL; else if(currentOption[opt_i].type == PathName && filter) filter = "dir"; GetWidgetText(¤tOption[opt_i], &old); // start in same directory as current widget contents StartDir(filter, old); // change to start directory for this file type - g_free(old); /* select file or folder depending on option_type */ if (currentOption[opt_i].type == PathName) @@ -1138,7 +1138,7 @@ void BrowseGTK(GtkWidget *widget, gpointer gdata) gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),gtkfilter_all); /* filter for specific filetypes e.g. pgn or fen */ - if (currentOption[opt_i].textValue != NULL) + if (currentOption[opt_i].textValue != NULL && !currentCps) // no filters for engine options! { char *q, *p = currentOption[opt_i].textValue; gtk_file_filter_set_name (gtkfilter, p);