static int GLT_OK P((int n));
static Option listOptions[] = {
-{300, LR|TB, 200, NULL, (void*) strings, "", NULL, ListBox, "" },
+{300, LR|TB, 200, NULL, (void*) strings, "", NULL, ListBox, "" }, // For GTK we need to specify a height, as default would just show 3 lines
{ 0, 0, 0, NULL, (void*) &GLT_Button, NULL, NULL, Button, N_("factory") },
{ 0, SAME_ROW, 0, NULL, (void*) &GLT_Button, NULL, NULL, Button, N_("up") },
{ 0, SAME_ROW, 0, NULL, (void*) &GLT_Button, NULL, NULL, Button, N_("down") },
if(index >= strlen(GLT_ALL_TAGS)) return;
strings[index] = strings[index+1];
strings[++index] = p;
- LoadListBox(&listOptions[0], "?", index, index-1); // only change the two specified entries
+ LoadListBox(&listOptions[0], "?", index, index-1); // only change the two specified entries
} else
if (n == 2) {
if(index == 0) return;
strings[index] = strings[index-1];
strings[--index] = p;
- LoadListBox(&listOptions[0], "?", index, index+1);
+ LoadListBox(&listOptions[0], "?", index, index+1);
} else
if (n == 1) {
safeStrCpy(lpUserGLT, GLT_DEFAULT_TAGS, LPUSERGLT_SIZE);
{
fileProc = proc; /* I can't see a way not */
fileOpenMode = openMode; /* to use globals here */
+#ifdef TODO_GTK
{ // [HGM] use file-selector dialog stolen from Ghostview
// int index; // this is not supported yet
Browse(BoardWindow, label, (def[0] ? def : NULL), filter, False, openMode, &openName, &openFP);
}
+#else
+ FileNamePopUpGTK(label, def, filter, proc, False, openMode, &openName, &openFP);
+#endif
}
return;
}
+void FileNamePopUpGTK(label, def, filter, proc, pathFlag, openMode, name, fp)
+ char *label;
+ char *def;
+ char *filter;
+ FileProc proc;
+ char *openMode;
+ Boolean pathFlag;
+ char **name;
+ FILE **fp;
+{
+ GtkWidget *dialog;
+ GtkFileFilter *gtkfilter;
+ GtkFileFilter *gtkfilter_all;
+ char space[] = " ";
+ char fileext[10] = "";
+ char *result = NULL;
+ char *cp;
+
+ /* make a copy of the filter string, so that strtok can work with it*/
+ cp = strndup(filter,strlen(filter));
+
+ /* add filters for file extensions */
+ gtkfilter = gtk_file_filter_new();
+ gtkfilter_all = gtk_file_filter_new();
+
+ /* one filter to show everything */
+ gtk_file_filter_add_pattern(gtkfilter_all, "*.*");
+ gtk_file_filter_set_name (gtkfilter_all, "All Files");
+
+ /* add filter if present */
+ result = strtok(cp, space);
+ while( result != NULL ) {
+ snprintf(fileext,10,"*%s",result);
+ result = strtok( NULL, space );
+ gtk_file_filter_add_pattern(gtkfilter, fileext);
+ };
+
+ /* second filter to only show what's useful */
+ gtk_file_filter_set_name (gtkfilter,filter);
+
+ if (openMode[0] == 'r')
+ {
+ dialog = gtk_file_chooser_dialog_new (label,
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+ }
+ else
+ {
+ dialog = gtk_file_chooser_dialog_new (label,
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+ /* add filename suggestions */
+ if (strlen(def) > 0 )
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), def);
+
+ //gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER (dialog),TRUE);
+ }
+
+ /* add filters */
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog),gtkfilter_all);
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog),gtkfilter);
+ /* activate filter */
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(dialog),gtkfilter);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ char *filename;
+ FILE *f;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ //see loadgamepopup
+ f = fopen(filename, openMode);
+ if (f == NULL)
+ {
+ DisplayError(_("Failed to open file"), errno);
+ }
+ else
+ {
+ /* TODO add indec */
+ *fp = f;
+ ASSIGN(*name, filename);
+ ScheduleDelayedEvent(DelayedLoad, 50);
+ }
+ g_free (filename);
+ };
+
+ gtk_widget_destroy (dialog);
+ ModeHighlight();
+
+ free(cp);
+ return;
+
+}
+