X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fui%2Fgui%2Fpsppire-window.c;h=1475398b03b6725bb3bb162e48610f1410914460;hb=339f1956cc72;hp=8dcde94ad53c739ff20f6900967932cf16a8af86;hpb=38a69a5fad0b824bbcb7662f8fa1aa23f04b3349;p=pspp diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 8dcde94ad5..1475398b03 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -32,11 +32,9 @@ #include "data/file-handle-def.h" #include "data/dataset.h" #include "libpspp/version.h" -#include "output/group-item.h" +#include "output/output-item.h" #include "output/pivot-table.h" #include "output/spv/spv.h" -#include "output/spv/spv-output.h" -#include "output/spv/spv-select.h" #include "helper.h" #include "psppire-data-window.h" @@ -44,41 +42,12 @@ #include "psppire-syntax-window.h" #include "psppire-window-register.h" -static void psppire_window_base_init (PsppireWindowClass *class); static void psppire_window_class_init (PsppireWindowClass *class); static void psppire_window_init (PsppireWindow *window); - static GObjectClass *parent_class; -GType -psppire_window_get_type (void) -{ - static GType psppire_window_type = 0; - - if (!psppire_window_type) - { - static const GTypeInfo psppire_window_info = - { - sizeof (PsppireWindowClass), - (GBaseInitFunc) psppire_window_base_init, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) psppire_window_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (PsppireWindow), - 0, - (GInstanceInitFunc) psppire_window_init, - }; - - psppire_window_type = - g_type_register_static (PSPPIRE_TYPE_WINDOW_BASE, "PsppireWindow", - &psppire_window_info, G_TYPE_FLAG_ABSTRACT); - } - - return psppire_window_type; -} - +G_DEFINE_ABSTRACT_TYPE (PsppireWindow, psppire_window, PSPPIRE_TYPE_WINDOW_BASE) /* Properties */ enum @@ -268,6 +237,8 @@ psppire_window_class_init (PsppireWindowClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + object_class->finalize = psppire_window_finalize; + GParamSpec *description_spec = null_if_empty_param ("description", "Description", @@ -309,16 +280,6 @@ psppire_window_class_init (PsppireWindowClass *class) } -static void -psppire_window_base_init (PsppireWindowClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->finalize = psppire_window_finalize; -} - - - static void insert_menuitem_into_menu (PsppireWindow *window, gpointer key) { @@ -472,7 +433,7 @@ psppire_window_query_save (PsppireWindow *se) gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("If you don't save, changes from the last %ld seconds will be permanently lost."), - timespan / G_TIME_SPAN_SECOND); + (long int) (timespan / G_TIME_SPAN_SECOND)); gtk_dialog_add_button (GTK_DIALOG (dialog), _("Close _without saving"), @@ -565,7 +526,8 @@ psppire_window_model_get_type (void) NULL, /* class_data */ 0, 0, /* n_preallocs */ - NULL + NULL, + NULL /* value_table */ }; window_model_type = @@ -734,85 +696,11 @@ psppire_window_file_chooser_dialog (PsppireWindow *toplevel) return dialog; } -struct item_path - { - const struct spv_item **nodes; - size_t n; - -#define N_STUB 10 - const struct spv_item *stub[N_STUB]; - }; - -static void -swap_nodes (const struct spv_item **a, const struct spv_item **b) -{ - const struct spv_item *tmp = *a; - *a = *b; - *b = tmp; -} - -static void -get_path (const struct spv_item *item, struct item_path *path) -{ - size_t allocated = 10; - path->nodes = path->stub; - path->n = 0; - - while (item) - { - if (path->n >= allocated) - { - if (path->nodes == path->stub) - path->nodes = xmemdup (path->stub, sizeof path->stub); - path->nodes = x2nrealloc (path->nodes, &allocated, - sizeof *path->nodes); - } - path->nodes[path->n++] = item; - item = item->parent; - } - - for (size_t i = 0; i < path->n / 2; i++) - swap_nodes (&path->nodes[i], &path->nodes[path->n - i - 1]); -} - -static void -free_path (struct item_path *path) -{ - if (path && path->nodes != path->stub) - free (path->nodes); -} - -static void -dump_heading_transition (const struct spv_item *old, - const struct spv_item *new) -{ - if (old == new) - return; - - struct item_path old_path, new_path; - get_path (old, &old_path); - get_path (new, &new_path); - - size_t common = 0; - for (; common < old_path.n && common < new_path.n; common++) - if (old_path.nodes[common] != new_path.nodes[common]) - break; - - for (size_t i = common; i < old_path.n; i++) - group_close_item_submit (group_close_item_create ()); - for (size_t i = common; i < new_path.n; i++) - group_open_item_submit (group_open_item_create ( - new_path.nodes[i]->command_id)); - - free_path (&old_path); - free_path (&new_path); -} - void read_spv_file (const char *filename) { - struct spv_reader *spv; - char *error = spv_open (filename, &spv); + struct output_item *root; + char *error = spv_read (filename, &root, NULL); if (error) { /* XXX */ @@ -820,24 +708,7 @@ read_spv_file (const char *filename) return; } - struct spv_item **items; - size_t n_items; - spv_select (spv, NULL, 0, &items, &n_items); - struct spv_item *prev_heading = spv_get_root (spv); - for (size_t i = 0; i < n_items; i++) - { - struct spv_item *heading - = items[i]->type == SPV_ITEM_HEADING ? items[i] : items[i]->parent; - dump_heading_transition (prev_heading, heading); - if (items[i]->type == SPV_ITEM_TEXT) - spv_text_submit (items[i]); - else if (items[i]->type == SPV_ITEM_TABLE) - pivot_table_submit (spv_item_get_table (items[i])); - prev_heading = heading; - } - dump_heading_transition (prev_heading, spv_get_root (spv)); - free (items); - spv_close (spv); + output_item_submit_children (root); } /* Callback for the file_open action. @@ -944,4 +815,3 @@ delete_recent (const char *file_name) g_free (uri); } -