mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
1c010afc88
commit
3d01a5f71a
1 changed files with 40 additions and 0 deletions
40
main.c
40
main.c
|
|
@ -5,6 +5,8 @@
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
GtkWidget *main_window;
|
||||||
|
|
||||||
static int sortfn(const void *_a, const void *_b)
|
static int sortfn(const void *_a, const void *_b)
|
||||||
{
|
{
|
||||||
const struct dive *a = *(void **)_a;
|
const struct dive *a = *(void **)_a;
|
||||||
|
|
@ -55,12 +57,49 @@ void repaint_dive(void)
|
||||||
gtk_widget_queue_draw(dive_profile);
|
gtk_widget_queue_draw(dive_profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *existing_filename;
|
||||||
|
|
||||||
static void file_open(GtkWidget *w, gpointer data)
|
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)
|
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[] = {
|
static GtkItemFactoryEntry menu_items[] = {
|
||||||
|
|
@ -113,6 +152,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
|
g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
|
||||||
|
main_window = win;
|
||||||
|
|
||||||
vbox = gtk_vbox_new(FALSE, 1);
|
vbox = gtk_vbox_new(FALSE, 1);
|
||||||
gtk_container_add(GTK_CONTAINER(win), vbox);
|
gtk_container_add(GTK_CONTAINER(win), vbox);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue