extern struct dataset *the_dataset;
extern PsppireDataStore *the_data_store ;
+extern GtkRecentManager *the_recent_mgr;
static void
set_paste_menuitem_sensitivity (PsppireDataWindow *de, gboolean x)
#endif
-void
-psppire_data_window_load_file (PsppireDataWindow *de,
- const gchar *file_name)
+static gboolean
+load_file (PsppireWindow *de, const gchar *file_name)
{
struct getl_interface *sss;
struct string filename;
sss = create_syntax_string_source ("GET FILE=%s.",
ds_cstr (&filename));
+
ds_destroy (&filename);
if (execute_syntax (sss) )
{
- psppire_window_set_filename (PSPPIRE_WINDOW (de), file_name);
- add_most_recent (file_name, the_recent_mgr);
- }
- else
- {
- delete_recent (file_name, the_recent_mgr);
+ psppire_window_set_filename (de, file_name);
+ return TRUE;
}
- psppire_window_set_unsaved (PSPPIRE_WINDOW (de), FALSE);
+ return FALSE;
}
/* Callback for the data_open action.
Prompts for a filename and opens it */
static void
-open_data_dialog (GtkAction *action, PsppireDataWindow *de)
+open_data_dialog (GtkAction *action, PsppireWindow *de)
{
GtkWidget *dialog =
gtk_file_chooser_dialog_new (_("Open"),
gchar *name =
gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- psppire_data_window_load_file (de, name);
+ psppire_window_load (de, name);
g_free (name);
}
static void
on_recent_data_select (GtkMenuShell *menushell,
- gpointer user_data)
+ PsppireWindow *window)
{
gchar *file;
- PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (user_data);
gchar *uri =
gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (menushell));
g_free (uri);
- psppire_data_window_load_file (de, file);
+ psppire_window_load (window, file);
g_free (file);
}
se = psppire_syntax_window_new ();
- psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file, NULL);
- gtk_widget_show (se);
+ if ( psppire_window_load (PSPPIRE_WINDOW (se), file) )
+ gtk_widget_show (se);
+ else
+ gtk_widget_destroy (se);
g_free (file);
}
psppire_data_window_iface_init (PsppireWindowIface *iface)
{
iface->save = data_save;
+ iface->load = load_file;
}
GType psppire_data_window_get_type (void);
GtkWidget* psppire_data_window_new (void);
-void psppire_data_window_load_file (PsppireDataWindow *, const gchar *);
-
G_END_DECLS
GtkWidget *se = psppire_syntax_window_new ();
- if ( psppire_syntax_window_load_from_file (PSPPIRE_SYNTAX_WINDOW (se), file_name, NULL) )
- {
- add_most_recent (file_name, the_recent_mgr);
- }
+ if ( psppire_window_load (PSPPIRE_WINDOW (se), file_name) )
+ gtk_widget_show (se);
else
- {
- delete_recent (file_name, the_recent_mgr);
- }
-
- gtk_widget_show (se);
+ gtk_widget_destroy (se);
}
gtk_widget_destroy (dialog);
/*
Loads the buffer from the file called FILENAME
*/
-gboolean
-psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se,
- const gchar *filename,
- GError **err)
+static gboolean
+syntax_load (PsppireWindow *window, const gchar *filename)
{
gchar *text;
GtkTextIter iter;
+ PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window);
- gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, err);
+ gchar *glibfilename = g_filename_from_utf8 (filename, -1, 0, 0, NULL);
if ( ! glibfilename )
return FALSE;
/* FIXME: What if it's a very big file ? */
- if ( ! g_file_get_contents (glibfilename, &text, NULL, err) )
+ if ( ! g_file_get_contents (glibfilename, &text, NULL, NULL) )
{
g_free (glibfilename);
return FALSE;
}
+
g_free (glibfilename);
- gtk_text_buffer_get_iter_at_line (se->buffer, &iter, 0);
+ gtk_text_buffer_get_iter_at_line (sw->buffer, &iter, 0);
- gtk_text_buffer_insert (se->buffer, &iter, text, -1);
+ gtk_text_buffer_insert (sw->buffer, &iter, text, -1);
- psppire_window_set_filename (PSPPIRE_WINDOW (se), filename);
+ psppire_window_set_filename (window, filename);
- gtk_text_buffer_set_modified (se->buffer, FALSE);
+ gtk_text_buffer_set_modified (sw->buffer, FALSE);
return TRUE;
}
psppire_syntax_window_iface_init (PsppireWindowIface *iface)
{
iface->save = syntax_save;
+ iface->load = syntax_load;
}
GType psppire_syntax_window_get_type (void);
GtkWidget* psppire_syntax_window_new (void);
-gboolean psppire_syntax_window_load_from_file (PsppireSyntaxWindow *se,
- const gchar *filename,
- GError **err);
-
void open_syntax_window (GtkMenuItem *menuitem, gpointer parent);
void create_syntax_window (void);
#include <config.h>
+
#include <gtk/gtkstock.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtksignal.h>
i->save (w);
}
+extern GtkRecentManager *the_recent_mgr;
+
+static void add_most_recent (const char *file_name, GtkRecentManager *rm);
+static void delete_recent (const char *file_name, GtkRecentManager *rm);
+
+gboolean
+psppire_window_load (PsppireWindow *w, const gchar *file)
+{
+ gboolean ok;
+ PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w);
+
+ g_assert (PSPPIRE_IS_WINDOW_MODEL (w));
+
+ g_assert (i);
+
+ g_return_val_if_fail (i->load, FALSE);
+
+ ok = i->load (w, file);
+
+ if ( ok )
+ add_most_recent (file, the_recent_mgr);
+ else
+ delete_recent (file, the_recent_mgr);
+
+ psppire_window_set_unsaved (w, FALSE);
+
+ return ok;
+}
+
/* Puts FILE_NAME into the recent list.
If it's already in the list, it moves it to the top
*/
-void
+static void
add_most_recent (const char *file_name, GtkRecentManager *rm)
{
gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
/*
If FILE_NAME exists in the recent list, then delete it.
*/
-void
+static void
delete_recent (const char *file_name, GtkRecentManager *rm)
{
gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
GTypeInterface g_iface;
void (*save) (PsppireWindow *w);
+ gboolean (*load) (PsppireWindow *w, const gchar *);
};
gint psppire_window_query_save (PsppireWindow *);
void psppire_window_save (PsppireWindow *w);
-
-void add_most_recent (const char *file_name, GtkRecentManager *rm);
-void delete_recent (const char *file_name, GtkRecentManager *rm);
+gboolean psppire_window_load (PsppireWindow *w, const gchar *file);
G_END_DECLS
{
case ARGP_KEY_ARG:
{
- psppire_data_window_load_file (PSPPIRE_DATA_WINDOW (the_data_window),
- arg);
+ psppire_window_load (PSPPIRE_WINDOW (the_data_window), arg);
break;
}
default:
struct command_line_processor ;
extern const struct argp non_option_argp ;
-extern GtkRecentManager *the_recent_mgr;
-
void initialize (struct command_line_processor *, int argc, char **argv);
void de_initialize (void);
void psppire_quit (void);