diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-08-31 18:04:25 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-08-31 18:04:25 -0700 |
commit | 3d01a5f71a29a8b7ce2a3648130660dabe62fae9 (patch) | |
tree | 5fb8b74942d3688ea75e3b9ccc4ddca7abdf8053 | |
parent | 1c010afc88897e0a5a7293cff81ae2875fa91838 (diff) | |
download | subsurface-3d01a5f71a29a8b7ce2a3648130660dabe62fae9.tar.gz |
Boiler-plate code for opening/saving a file
All just copied from the gtk docs. No actual loading or saving is
taking place, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | main.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -5,6 +5,8 @@ #include "dive.h" #include "display.h" +GtkWidget *main_window; + static int sortfn(const void *_a, const void *_b) { const struct dive *a = *(void **)_a; @@ -55,12 +57,49 @@ void repaint_dive(void) gtk_widget_queue_draw(dive_profile); } +static char *existing_filename; + static void file_open(GtkWidget *w, gpointer data) { + GtkWidget *dialog; + dialog = gtk_file_chooser_dialog_new("Open File", + GTK_WINDOW(main_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; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + printf("Open: '%s'\n", filename); + g_free(filename); + } + gtk_widget_destroy(dialog); } static void file_save(GtkWidget *w, gpointer data) { + GtkWidget *dialog; + dialog = gtk_file_chooser_dialog_new("Save File", + GTK_WINDOW(main_window), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); + if (!existing_filename) { + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document"); + } else + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), existing_filename); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + char *filename; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + printf("Save: '%s'\n", filename); + g_free(filename); + } + gtk_widget_destroy(dialog); } static GtkItemFactoryEntry menu_items[] = { @@ -113,6 +152,7 @@ int main(int argc, char **argv) win = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL); + main_window = win; vbox = gtk_vbox_new(FALSE, 1); gtk_container_add(GTK_CONTAINER(win), vbox); |