Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=grape.git;a=commitdiff;h=78cc0744487c9f76fbccbba308fe67c4cb95543e
commit 78cc0744487c9f76fbccbba308fe67c4cb95543e Author: James Buren <r...@frugalware.org> Date: Tue Apr 6 14:09:29 2010 -0500 exports.h io.c * initial draft diff --git a/src/exports.h b/src/exports.h new file mode 100644 index 0000000..cf15a7d --- /dev/null +++ b/src/exports.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2010 James Buren + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef _exports_header_ +#define _exports_header_ +#include <gtk/gtk.h> + +gchar *prompt_for_filename(GtkWidget *parent,gboolean open); +#endif diff --git a/src/io.c b/src/io.c new file mode 100644 index 0000000..dcf3f16 --- /dev/null +++ b/src/io.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2010 James Buren + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "exports.h" + +/* Display a dialog for the user to select a file for + opening or saving. Returns NULL if user cancels. The + string must be freed after you are done using it. */ +gchar *prompt_for_filename(GtkWidget *parent,gboolean open) { + GtkWidget *dialog; + gchar *filename; + + g_assert(parent != NULL); + + dialog = gtk_file_chooser_dialog_new( (open) ? "Open File" : "Save File", + GTK_WINDOW(parent), + (open) ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + (open) ? GTK_STOCK_OPEN : GTK_STOCK_SAVE, + GTK_RESPONSE_ACCEPT, + NULL ); + + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + else + filename = NULL; + + gtk_widget_destroy(dialog); + + return filename; +} _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git