aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-11-09 19:23:19 +0100
committerThomas White <taw@bitwiz.org.uk>2011-11-09 19:23:19 +0100
commite471515d34ee636a23e763782cfd4ac80bf63eb1 (patch)
treed16a0a4c87c00b8c468b70ad39d149f52efc556b
parent9c4933dfe7306080056beaaff99c27991a7c473d (diff)
Implement File->New, don't quit until last file is closed
-rw-r--r--src/mainwindow.c19
-rw-r--r--src/presentation.c29
-rw-r--r--src/presentation.h2
3 files changed, 48 insertions, 2 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c
index 8af543d..1c5f467 100644
--- a/src/mainwindow.c
+++ b/src/mainwindow.c
@@ -177,6 +177,21 @@ static gint open_sig(GtkWidget *widget, struct presentation *p)
}
+static gint new_sig(GtkWidget *widget, struct presentation *pnn)
+{
+ struct presentation *p;
+
+ p = new_presentation();
+ if ( p != NULL ) {
+ p->cur_edit_slide = add_slide(p, 0);
+ p->completely_empty = 1;
+ open_mainwindow(p);
+ }
+
+ return 0;
+}
+
+
static gint saveas_response_sig(GtkWidget *d, gint response,
struct presentation *p)
{
@@ -472,7 +487,7 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
{ "FileAction", NULL, "_File", NULL, NULL, NULL },
{ "NewAction", GTK_STOCK_NEW, "_New",
- NULL, NULL, NULL },
+ NULL, NULL, G_CALLBACK(new_sig) },
{ "OpenAction", GTK_STOCK_OPEN, "_Open...",
NULL, NULL, G_CALLBACK(open_sig) },
{ "SaveAction", GTK_STOCK_SAVE, "_Save",
@@ -589,7 +604,7 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox)
static gint close_sig(GtkWidget *window, struct presentation *p)
{
- gtk_main_quit();
+ free_presentation(p);
return 0;
}
diff --git a/src/presentation.c b/src/presentation.c
index f954503..7cce628 100644
--- a/src/presentation.c
+++ b/src/presentation.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <gtk/gtk.h>
#include "presentation.h"
#include "slide_render.h"
@@ -38,6 +39,31 @@
#include "tool_image.h"
+static int num_presentations = 0;
+
+
+void free_presentation(struct presentation *p)
+{
+ int i;
+ int final = 0;
+
+ for ( i=0; i<p->num_slides; i++ ) {
+ free_slide(p->slides[i]);
+ }
+
+ (*p->num_presentations)--;
+ if ( *p->num_presentations == 0 ) final = 1;
+
+ /* FIXME: Loads of stuff leaks here */
+ free(p->filename);
+ free(p);
+
+ if ( final ) {
+ gtk_main_quit();
+ }
+}
+
+
int insert_slide(struct presentation *p, struct slide *new, int pos)
{
struct slide **try;
@@ -247,6 +273,9 @@ struct presentation *new_presentation()
new = calloc(1, sizeof(struct presentation));
+ num_presentations++;
+ new->num_presentations = &num_presentations;
+
new->filename = NULL;
new->titlebar = NULL;
get_titlebar_string(new);
diff --git a/src/presentation.h b/src/presentation.h
index 9b03af1..d766a6d 100644
--- a/src/presentation.h
+++ b/src/presentation.h
@@ -105,6 +105,7 @@ struct presentation
char *titlebar;
char *filename;
int completely_empty;
+ int *num_presentations;
struct toolinfo *select_tool;
struct toolinfo *text_tool;
@@ -181,6 +182,7 @@ struct presentation
extern struct presentation *new_presentation(void);
+extern void free_presentation(struct presentation *p);
extern struct slide *new_slide(void);
extern struct slide *add_slide(struct presentation *p, int pos);