Merge remote-tracking branch 'origin/master' into sheet
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 22 Apr 2017 18:56:00 +0000 (20:56 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 22 Apr 2017 18:56:00 +0000 (20:56 +0200)
1  2 
lib/gtk-contrib/gtkxpaned.c
src/data/variable.c
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-import-assistant.c
src/ui/gui/psppire-import-assistant.h
src/ui/gui/widgets.c

Simple merge
Simple merge
index c0da89e92f7868a3cd3dcb5973514452c2ebc712,99c0c6ac69b331e06698c4930a501b3b669b2e09..bdbdd085ef3de95537bd84b0ddf1682645f5059a
@@@ -974,11 -972,9 +974,11 @@@ file_import (PsppireDataWindow *dw
    g_main_loop_run (asst->main_loop);
    g_main_loop_unref (asst->main_loop);
  
- #if TEXT_FILE  
++#if TEXT_FILE
    if (!asst->file_name)
      goto end;
  
-   
++
    switch (asst->response)
      {
      case GTK_RESPONSE_APPLY:
      default:
        break;
      }
- #endif    
-  end:  
 -
++#endif
+  end:
    gtk_widget_destroy (GTK_WIDGET (asst));
  }
  
@@@ -1071,52 -1067,10 +1071,52 @@@ static voi
  on_cut (PsppireDataWindow *dw)
  {
    int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
 -  if (p == 0)
 -    {
 -      PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
 -      psppire_data_sheet_edit_cut (ds);
 +  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
 +  {
 +      PsppireDict *dict = NULL;
 +      g_object_get (dw->data_editor, "dictionary", &dict, NULL);
-       
++
 +      gint x, y;
 +      JmdSheet *sheet = JMD_SHEET (dw->data_editor->data_sheet);
 +      JmdRange sel = *sheet->selection;
 +
 +      GtkClipboard *clip =
 +      gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
 +                                     GDK_SELECTION_CLIPBOARD);
 +
 +      /* Save the selected area to a string */
 +      GString *str = g_string_new ("");
 +      for (y = sel.start_y ; y <= sel.end_y; ++y)
 +      {
 +        for (x = sel.start_x ; x <= sel.end_x; ++x)
 +          {
 +            const struct variable * var = psppire_dict_get_variable (dict, x);
 +            gchar *s = psppire_data_store_get_string (dw->data_editor->data_store,
 +                                                        y, var, FALSE);
 +            g_string_append (str, s);
 +            g_string_append (str, "\t");
 +            g_free (s);
 +          }
 +        g_string_append (str, "\n");
 +      }
-       
++
 +      gtk_clipboard_set_text (clip, str->str, str->len);
 +      g_string_free (str, TRUE);
 +
 +      /* Now fill the selected area with SYSMIS */
 +      union value sm ;
 +      sm.f = SYSMIS;
 +      for (x = sel.start_x ; x <= sel.end_x; ++x)
 +      {
 +        const struct variable * var = psppire_dict_get_variable (dict, x);
 +        for (y = sel.start_y ; y <= sel.end_y; ++y)
 +          {
 +            psppire_data_store_set_value (dw->data_editor->data_store,
 +                                          y,
 +                                          var, &sm);
 +          }
 +      }
 +
      }
  }
  
index d8695706a317a4c3b9ff859c578bae2debf1ce15,5f8793186b3303e8201c724f48c6b5cfe0892239..9dc2385f541cb6e10c0f8629e3e87bff61b690f6
@@@ -267,67 -279,11 +267,67 @@@ choose_likely_separators (PsppireImport
  
  static void set_separators (PsppireImportAssistant *ia);
  
-       
 +
 +static void
 +repopulate_delimiter_columns (PsppireImportAssistant *ia)
 +{
 +  /* Remove all the columns */
 +  while (gtk_tree_view_get_n_columns (GTK_TREE_VIEW (ia->fields_tree_view)) > 0)
 +    {
 +      GtkTreeViewColumn *tvc = gtk_tree_view_get_column (GTK_TREE_VIEW (ia->fields_tree_view), 0);
 +      gtk_tree_view_remove_column (GTK_TREE_VIEW (ia->fields_tree_view), tvc);
 +    }
 +
 +  gint n_fields = gtk_tree_model_get_n_columns (ia->delimiters_model);
 +
 +  /* ... and put them back again. */
 +  gint f;
 +  for (f = gtk_tree_view_get_n_columns (GTK_TREE_VIEW (ia->fields_tree_view));
 +       f < n_fields; f++)
 +    {
 +      GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
 +      GtkTreeViewColumn *column =
 +      gtk_tree_view_column_new_with_attributes ("var", renderer,
 +                                                "text", f,
 +                                                NULL);
 +      g_object_set (column,
 +                  "resizable", TRUE,
 +                  "sizing", GTK_TREE_VIEW_COLUMN_AUTOSIZE,
 +                  NULL);
++
 +      gtk_tree_view_append_column (GTK_TREE_VIEW (ia->fields_tree_view), column);
 +    }
 +}
 +
 +static void
 +reset_tree_view_model (PsppireImportAssistant *ia)
 +{
 +  GtkTreeModel *tm = gtk_tree_view_get_model (GTK_TREE_VIEW (ia->fields_tree_view));
 +  g_object_ref (tm);
 +  gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view), NULL);
 +
 +
 +  repopulate_delimiter_columns (ia);
 +
 +  gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view), tm);
 +  //  gtk_tree_view_columns_autosize (GTK_TREE_VIEW (ia->fields_tree_view));
 +
 +  g_object_unref (tm);
 +}
 +
  /* Called just before the separators page becomes visible in the
     assistant, and when the Reset button is clicked. */
  static void
  prepare_separators_page (PsppireImportAssistant *ia, GtkWidget *page)
  {
-      
 +  gtk_tree_view_set_model (GTK_TREE_VIEW (ia->fields_tree_view), ia->delimiters_model);
++
 +  g_signal_connect_swapped (ia->delimiters_model, "notify::delimiters",
 +                      G_CALLBACK (reset_tree_view_model), ia);
 +
 +
 +  repopulate_delimiter_columns (ia);
 +
    revise_fields_preview (ia);
    choose_likely_separators (ia);
    set_separators (ia);
@@@ -963,33 -1103,6 +963,33 @@@ reset_first_line_page (PsppireImportAss
    gtk_widget_set_sensitive (ia->variable_names_cb, FALSE);
  }
  
-       
 +#endif
 +
 +static void
 +on_cursor_change (GtkTreeView *treeview, gpointer user_data)
 +{
 +  PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (user_data);
 +  GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
 +  GtkTreeModel *model = NULL;
 +  GtkTreeIter iter;
 +  if (gtk_tree_selection_get_selected (selection, &model, &iter))
 +    {
 +      int n;
 +      PsppireTextFile *tf = PSPPIRE_TEXT_FILE (model);
 +      GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
 +      gint *index = gtk_tree_path_get_indices (path);
-       
++
 +      n = *index;
++
 +      gtk_tree_path_free (path);
 +
 +      g_print ("%s:%d Setting first line to %d\n", __FILE__, __LINE__, n);
 +
 +      ia->delimiters_model = psppire_delimited_text_new (ia->text_file);
 +      g_object_set (ia->delimiters_model, "first-line", n, NULL);
 +    }
 +}
 +
  
  /* Initializes IA's first_line substructure. */
  static void
Simple merge
index da62642870f01f05ae2b70bef2094d84637b631e,37d13bf9723198f4d8a664de2370d207f2b9f240..e969eb5ae21c3fd4a69a50def4e5c83cfefeb388
@@@ -121,65 -120,9 +121,65 @@@ preregister_actions (void
  }
  
  
 +static void
 +tx_string_to_double (const GValue *src, GValue *dest)
 +{
 +  const gchar *str = g_value_get_string (src);
 +  gdouble dble = g_strtod (str, NULL);
 +  g_value_set_double (dest, dble);
 +}
 +
 +
 +static void
 +tx_string_to_int (const GValue *src, GValue *dest)
 +{
 +  const gchar *str = g_value_get_string (src);
 +  gint x = atoi (str);
 +  g_value_set_int (dest, x);
 +}
 +
 +static void
 +enum_to_string (const GValue *src, GValue *dest)
 +{
 +  gint n = g_value_get_enum (src);
 +  GType t = G_VALUE_TYPE (src);
 +  GEnumClass *ec = g_type_class_ref (t);
 +  GEnumValue *ev = g_enum_get_value (ec, n);
 +
 +  g_value_set_string (dest, gettext (ev->value_nick));
 +}
 +
 +
 +
 +GType align_enum_type;
 +GType measure_enum_type;
 +GType role_enum_type;
 +
 +
 +extern const GEnumValue align[];
 +extern const GEnumValue measure[];
 +extern const GEnumValue role[];
 +
 +
 +
 +static void
 +preregister_misc (void)
 +{
 +  align_enum_type = g_enum_register_static ("PsppAlignment", align);
 +  measure_enum_type = g_enum_register_static ("PsppMeasure", measure);
 +  role_enum_type = g_enum_register_static ("PsppRole", role);
 +
 +  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DOUBLE, tx_string_to_double);
 +  g_value_register_transform_func (G_TYPE_STRING, G_TYPE_INT, tx_string_to_int);
 +  
 +  g_value_register_transform_func (measure_enum_type, G_TYPE_STRING, enum_to_string);
 +  g_value_register_transform_func (align_enum_type, G_TYPE_STRING, enum_to_string);
 +  g_value_register_transform_func (role_enum_type, G_TYPE_STRING, enum_to_string);
 +}
 +
  
  /* Any custom widgets which are to be used in GtkBuilder ui files
-    need to be preregistered, otherwise GtkBuilder refuses to 
+    need to be preregistered, otherwise GtkBuilder refuses to
     acknowledge their existence. */
  void
  preregister_widgets (void)