moved several game/position opening/saving functions to gtk
[xboard.git] / interface.c
index ef59a5f..e1a2069 100644 (file)
@@ -31,6 +31,7 @@
 # define N_(s)  s
 #endif
 
+extern GtkWidget *GUI_Window;
 
 
 GdkPixbuf *load_pixbuf(char *filename,int size)
@@ -49,3 +50,53 @@ GdkPixbuf *load_pixbuf(char *filename,int size)
     }
   return image;
 }
+
+void
+FileNamePopUp(label, def, proc, openMode)
+     char *label;
+     char *def;
+     FileProc proc;
+     char *openMode;
+{
+  /* TODO:
+   *   implement look for certain file types
+   *   use save/load button depending on what function is calling
+   */
+
+  GtkWidget *dialog;
+
+  dialog = gtk_file_chooser_dialog_new (label,
+                                       GTK_WINDOW(GUI_Window),
+                                       GTK_FILE_CHOOSER_ACTION_OPEN,
+                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+                                       NULL);
+  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 
+       {
+         printf( "DEBUG: before call\n");
+         /* TODO add indec */
+         (*proc)(f, 0, filename);
+         printf( "DEBUG: after call\n");
+       }
+      g_free (filename);
+    };
+  
+  gtk_widget_destroy (dialog);
+  ModeHighlight();
+  
+  return;
+
+}