}
psppire_window_set_unsaved (PSPPIRE_WINDOW (de), FALSE);
- free (de->file_name);
-
- de->file_name = g_strdup (file_name);
}
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
- if (de->file_name)
- {
- gchar *dir_name = g_path_get_dirname (de->file_name);
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
- dir_name);
- free (dir_name);
- }
+ {
+ gchar *dir_name;
+ gchar *filename = NULL;
+ g_object_get (de, "filename", &filename, NULL);
+
+ dir_name = g_path_get_dirname (filename);
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+ dir_name);
+ free (dir_name);
+ }
switch (gtk_dialog_run (GTK_DIALOG (dialog)))
{
}
-/* Append SUFFIX to the filename of DE */
-static void
-append_filename_suffix (PsppireDataWindow *de, const gchar *suffix)
-{
- if ( ! name_has_suffix (de->file_name))
- {
- gchar *s = de->file_name;
- de->file_name = g_strconcat (de->file_name, suffix, NULL);
- g_free (s);
- }
-}
-
/* Save DE to file */
static void
save_file (PsppireDataWindow *de)
{
+ gchar *fn = NULL;
+ GString *fnx;
struct getl_interface *sss;
struct string file_name ;
- g_assert (de->file_name);
+ g_object_get (de, "filename", &fn, NULL);
+
+ fnx = g_string_new (fn);
+
+ if ( ! name_has_suffix (fnx->str))
+ {
+ if ( de->save_as_portable)
+ g_string_append (fnx, ".por");
+ else
+ g_string_append (fnx, ".sav");
+ }
ds_init_empty (&file_name);
- syntax_gen_string (&file_name, ss_cstr (de->file_name));
+ syntax_gen_string (&file_name, ss_cstr (fnx->str));
+ g_string_free (fnx, FALSE);
if ( de->save_as_portable )
{
- append_filename_suffix (de, ".por");
sss = create_syntax_string_source ("EXPORT OUTFILE=%s.",
ds_cstr (&file_name));
}
else
{
- append_filename_suffix (de, ".sav");
sss = create_syntax_string_source ("SAVE OUTFILE=%s.",
ds_cstr (&file_name));
}
{
case GTK_RESPONSE_ACCEPT:
{
- g_free (de->file_name);
-
- de->file_name =
- gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ GString *filename =
+ g_string_new
+ (
+ gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog))
+ );
de->save_as_portable =
! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys));
- if ( de->save_as_portable)
- append_filename_suffix (de, ".por");
- else
- append_filename_suffix (de, ".sav");
+ if ( ! name_has_suffix (filename->str))
+ {
+ if ( de->save_as_portable)
+ g_string_append (filename, ".por");
+ else
+ g_string_append (filename, ".sav");
+ }
+
+ psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str);
save_file (de);
- psppire_window_set_filename (PSPPIRE_WINDOW (de), de->file_name);
+ g_string_free (filename, TRUE);
}
break;
default:
/* Callback for data_save action.
- If there's an existing file name, then just save,
- otherwise prompt for a file name, then save */
+ */
static void
data_save (PsppireDataWindow *de)
{
- if (de->file_name)
+ const gchar *fn = psppire_window_get_filename (PSPPIRE_WINDOW (de));
+
+ if ( NULL != fn)
save_file (de);
else
data_save_as_dialog (de);
execute_syntax (sss);
- g_free (de->file_name);
- de->file_name = NULL;
-
psppire_window_set_filename (PSPPIRE_WINDOW (de), NULL);
}
{
PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (user_data);
+ if (psppire_window_query_save (PSPPIRE_WINDOW (dw)))
+ {
+ data_save (dw);
+ }
+
return FALSE;
}
hb = get_widget_assert (de->builder, "handlebox1");
sb = get_widget_assert (de->builder, "status-bar");
- de->file_name = NULL;
-
de->data_editor =
PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
return result;
}
-/* If the buffer's modified flag is set, then save it, and close the window.
- Otherwise just close the window.
-*/
-static void
-save_if_modified (PsppireWindow *se)
-{
- if ( TRUE == psppire_window_get_unsaved (se))
- {
- gint response;
- GtkWidget *dialog;
-
- const gchar *description;
- const gchar *filename = psppire_window_get_filename (se);
-
- g_object_get (se, "description", &description, NULL);
-
- g_return_if_fail (filename != NULL);
-
- dialog =
- gtk_message_dialog_new (GTK_WINDOW (se),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- _("Save contents of %s to \"%s\"?"),
- description,
- filename);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_YES,
- GTK_RESPONSE_ACCEPT);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_NO,
- GTK_RESPONSE_REJECT);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL);
-
- response = gtk_dialog_run (GTK_DIALOG (dialog));
-
- gtk_widget_destroy (dialog);
-
- if ( response == GTK_RESPONSE_ACCEPT )
- {
- GError *err = NULL;
-
- if ( ! save_editor_to_file (se, filename, &err) )
- {
- msg (ME, err->message);
- g_error_free (err);
- }
- psppire_window_set_filename (se, filename);
- }
-
- if ( response == GTK_RESPONSE_CANCEL )
- return ;
- }
-
- gtk_widget_destroy (GTK_WIDGET (se));
-}
/* Callback for the File->SaveAs menuitem */
static void
static gboolean
on_quit (GtkMenuItem *menuitem, gpointer user_data)
{
- PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
- save_if_modified (se);
+ PsppireWindow *se = PSPPIRE_WINDOW (user_data);
+
return FALSE;
}
static gboolean
on_delete (GtkWidget *w, GdkEvent *event, gpointer user_data)
{
- PsppireSyntaxWindow *se = PSPPIRE_SYNTAX_WINDOW (user_data);
+ PsppireWindow *se = PSPPIRE_WINDOW (user_data);
+
+ if ( psppire_window_query_save (se) )
+ {
+ gchar *filename = NULL;
+ GError *err = NULL;
+
+ g_object_get (se, "filename", &filename, NULL);
+
+ if ( ! save_editor_to_file (se, filename, &err) )
+ {
+ msg (ME, err->message);
+ g_error_free (err);
+ }
+ }
- save_if_modified (se);
return FALSE;
}
#include <config.h>
+#include <gtk/gtkstock.h>
+#include <gtk/gtkmessagedialog.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkcheckmenuitem.h>
}
+/* If the buffer's modified flag is set,
+ ask the user if the buffer should be saved.
+ Return TRUE if is should.
+*/
+gboolean
+psppire_window_query_save (PsppireWindow *se)
+{
+ gint response;
+ GtkWidget *dialog;
+
+ const gchar *description;
+ const gchar *filename = psppire_window_get_filename (se);
+
+ if ( ! psppire_window_get_unsaved (se))
+ return FALSE;
+
+ g_object_get (se, "description", &description, NULL);
+
+ g_return_val_if_fail (filename != NULL, FALSE);
+
+ dialog =
+ gtk_message_dialog_new (GTK_WINDOW (se),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _("Save contents of %s to \"%s\"?"),
+ description,
+ filename);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_YES,
+ GTK_RESPONSE_ACCEPT);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_NO,
+ GTK_RESPONSE_REJECT);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ if ( response == GTK_RESPONSE_ACCEPT )
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
const gchar *
psppire_window_get_filename (PsppireWindow *w)
{