[dia] Bug 636781 - Close diagram: Save did not ask for the name
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Bug 636781 - Close diagram: Save did not ask for the name
- Date: Sat, 8 Jan 2011 21:16:31 +0000 (UTC)
commit a54a2b34103f17673f3bd8e81a22d1ac2ad55746
Author: Hans Breuer <hans breuer org>
Date: Sat Jan 8 22:15:47 2011 +0100
Bug 636781 - Close diagram: Save did not ask for the name
The special handling for yet unknown filename was only working
for direct save. Now it is extended to also handle the
"Close diagram" case.
app/display.c | 32 +++++++++++++++++++++++++-------
app/filedlg.c | 42 ++++++++++++++++++++++++++++++++++++------
app/filedlg.h | 2 ++
3 files changed, 63 insertions(+), 13 deletions(-)
---
diff --git a/app/display.c b/app/display.c
index d85f0aa..a2ba76c 100644
--- a/app/display.c
+++ b/app/display.c
@@ -47,6 +47,7 @@
#include "render_gdk.h"
#include "diatransform.h"
#include "recent_files.h"
+#include "filedlg.h"
static GdkCursor *current_cursor = NULL;
@@ -654,11 +655,20 @@ ddisplay_render_pixmap(DDisplay *ddisp, Rectangle *update)
/* Erase background */
g_return_if_fail (renderer->fill_pixel_rect != NULL);
DIA_RENDERER_GET_CLASS(ddisp->renderer)->begin_render(ddisp->renderer);
- renderer->fill_pixel_rect (ddisp->renderer,
- 0, 0,
- dia_renderer_get_width_pixels (ddisp->renderer),
- dia_renderer_get_height_pixels (ddisp->renderer),
- &ddisp->diagram->data->bg_color);
+ if (update) {
+ int x0, y0, x1, y1;
+
+ ddisplay_transform_coords (ddisp, update->left, update->top, &x0, &y0);
+ ddisplay_transform_coords (ddisp, update->right, update->bottom, &x1, &y1);
+ renderer->fill_pixel_rect (ddisp->renderer,
+ x0, y0, x1-x0, y1-y0,
+ &ddisp->diagram->data->bg_color);
+ } else
+ renderer->fill_pixel_rect (ddisp->renderer,
+ 0, 0,
+ dia_renderer_get_width_pixels (ddisp->renderer),
+ dia_renderer_get_height_pixels (ddisp->renderer),
+ &ddisp->diagram->data->bg_color);
/* Draw grid */
grid_draw(ddisp, update);
@@ -1216,9 +1226,17 @@ are_you_sure_close_dialog_respond(GtkWidget *widget, /* the dialog */
switch (response_id) {
case GTK_RESPONSE_YES :
/* save changes */
- if (!diagram_save(ddisp->diagram, ddisp->diagram->filename))
+ if (ddisp->diagram->unsaved) {
+ /* we have to open the file dlg, close this one first */
+ gtk_widget_destroy(widget);
+ if (file_save_as(ddisp->diagram, ddisp))
+ ddisp_destroy (ddisp);
+ /* no way back */
+ return;
+ } else if (!diagram_save(ddisp->diagram, ddisp->diagram->filename))
close_ddisp = FALSE;
- else
+
+ if (close_ddisp) /* saving succeeded */
recent_file_history_add(ddisp->diagram->filename);
if (ddisp->update_id && close_ddisp) {
diff --git a/app/filedlg.c b/app/filedlg.c
index 5e75c14..b3ae712 100644
--- a/app/filedlg.c
+++ b/app/filedlg.c
@@ -413,9 +413,13 @@ file_save_as_response_callback(GtkWidget *fs,
g_object_set_data (G_OBJECT(fs), "user_data", NULL);
g_object_unref (dia);
}
- gtk_widget_destroy(GTK_WIDGET(fs));
+ /* if we destroy it gtk_dialog_run wont give the response */
+ if (!g_object_get_data (G_OBJECT(fs), "dont-destroy"))
+ gtk_widget_destroy(GTK_WIDGET(fs));
}
+static GtkWidget *file_save_as_dialog_prepare (Diagram *dia, DDisplay *ddisp);
+
/**
* Respond to the File/Save As.. menu
*
@@ -426,14 +430,40 @@ file_save_as_response_callback(GtkWidget *fs,
void
file_save_as_callback(gpointer data, guint action, GtkWidget *widget)
{
- DDisplay *ddisp;
- Diagram *dia;
- gchar *filename = NULL;
+ DDisplay *ddisp;
+ Diagram *dia;
+ GtkWidget *dlg;
ddisp = ddisplay_active();
if (!ddisp) return;
dia = ddisp->diagram;
+ dlg = file_save_as_dialog_prepare(dia, ddisp);
+
+ gtk_widget_show(dlg);
+}
+
+gboolean
+file_save_as(Diagram *dia, DDisplay *ddisp)
+{
+ GtkWidget *dlg;
+ gint response;
+
+ dlg = file_save_as_dialog_prepare(dia, ddisp);
+
+ /* if we destroy it gtk_dialog_run wont give the response */
+ g_object_set_data (G_OBJECT(dlg), "dont-destroy", GINT_TO_POINTER (1));
+ response = gtk_dialog_run(GTK_DIALOG(dlg));
+ gtk_widget_destroy(GTK_WIDGET(dlg));
+
+ return (GTK_RESPONSE_ACCEPT == response);
+}
+
+static GtkWidget *
+file_save_as_dialog_prepare (Diagram *dia, DDisplay *ddisp)
+{
+ gchar *filename = NULL;
+
if (!savedlg) {
GtkWidget *compressbutton;
@@ -485,7 +515,7 @@ file_save_as_callback(gpointer data, guint action, GtkWidget *widget)
g_object_ref(dia);
g_object_set_data (G_OBJECT (savedlg), "user_data", dia);
gtk_window_present (GTK_WINDOW(savedlg));
- return;
+ return savedlg;
}
}
if (dia && dia->filename)
@@ -506,7 +536,7 @@ file_save_as_callback(gpointer data, guint action, GtkWidget *widget)
g_object_ref(dia);
g_object_set_data (G_OBJECT (savedlg), "user_data", dia);
- gtk_widget_show(savedlg);
+ return savedlg;
}
/**
diff --git a/app/filedlg.h b/app/filedlg.h
index 8428c1b..e19827e 100644
--- a/app/filedlg.h
+++ b/app/filedlg.h
@@ -29,4 +29,6 @@ void file_save_callback(gpointer data, guint action, GtkWidget *widget);
void file_save_as_callback(gpointer data, guint action, GtkWidget *widget);
void file_export_callback(gpointer data, guint action, GtkWidget *widget);
+gboolean file_save_as(Diagram *dia, DDisplay *ddisp);
+
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]