From 6487eb595b4ee51f8eab706698333e57c5dc4ff8 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Fri, 22 Apr 2016 11:37:58 +0200 Subject: [PATCH] Also supply shortcut for start directory in GTK file chooser The first shortcut entry in the Places list is now created for the directory in which XBoard started (which is $CHESSDIR if that was set). This is suppressed if it would be a user home directory, as this would already be in the list by default. --- gtk/xboard.c | 4 +++- gtk/xboard.h | 1 + gtk/xoptions.c | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gtk/xboard.c b/gtk/xboard.c index 423f304..4a2731a 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -984,7 +984,9 @@ main (int argc, char **argv) } if ((chessDir = (char *) getenv("CHESSDIR")) == NULL) { - chessDir = "."; + static char dirName[MSG_SIZ]; + getcwd(dirName, MSG_SIZ); + chessDir = dirName; } else { if (chdir(chessDir) != 0) { fprintf(stderr, _("%s: can't cd to CHESSDIR: "), programName); diff --git a/gtk/xboard.h b/gtk/xboard.h index 3318cb7..8878d2a 100644 --- a/gtk/xboard.h +++ b/gtk/xboard.h @@ -165,6 +165,7 @@ extern char *layoutName; extern int useImages, useImageSqs; extern char ICSInputTranslations[]; extern char *selected_fen_position; +extern char *chessDir; #define TOPLEVEL 1 /* preference item; 1 = make popup windows toplevel */ diff --git a/gtk/xoptions.c b/gtk/xoptions.c index 18024e8..fbe1c23 100644 --- a/gtk/xoptions.c +++ b/gtk/xoptions.c @@ -1126,7 +1126,7 @@ void BrowseGTK(GtkWidget *widget, gpointer gdata) GtkFileFilter *gtkfilter_all; int n, opt_i = (intptr_t) gdata; GtkFileChooserAction fc_action; - char buf[MSG_SIZ]; + char buf[MSG_SIZ], *p; gtkfilter = gtk_file_filter_new(); gtkfilter_all = gtk_file_filter_new(); @@ -1150,6 +1150,8 @@ void BrowseGTK(GtkWidget *widget, gpointer gdata) GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + if(*chessDir && (!(p = strstr(chessDir, "/home/")) || strchr(p+6, '/'))) + gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), chessDir, NULL); gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), dataDir, NULL); snprintf(buf, MSG_SIZ, "%s/themes", dataDir); gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog), buf, NULL); -- 1.7.0.4