Added popup menu to row titles in variable sheet
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 1 Dec 2008 03:46:28 +0000 (12:46 +0900)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 1 Dec 2008 03:46:28 +0000 (12:46 +0900)
src/ui/gui/data-editor.c
src/ui/gui/data-editor.h
src/ui/gui/psppire-data-editor.c

index 42ecdef0d0ac30c950ab3b8c5ccb19d97fef2473..13cc29a941f8be002bcbe10103fbddc590be04e6 100644 (file)
@@ -74,6 +74,9 @@ static void on_edit_paste (GtkAction *a, gpointer data);
 
 
 static GtkWidget * create_data_sheet_variable_popup_menu (struct data_editor *);
+
+static GtkWidget * create_var_sheet_variable_popup_menu (struct data_editor *);
+
 static GtkWidget * create_data_sheet_cases_popup_menu (struct data_editor *);
 
 static void register_data_editor_actions (struct data_editor *de);
@@ -933,17 +936,20 @@ new_data_editor (void)
   de->data_sheet_variable_popup_menu =
     GTK_MENU (create_data_sheet_variable_popup_menu (de));
 
+  de->var_sheet_variable_popup_menu =
+    GTK_MENU (create_var_sheet_variable_popup_menu (de));
+
   de->data_sheet_cases_popup_menu =
     GTK_MENU (create_data_sheet_cases_popup_menu (de));
 
 
   g_object_set (de->data_editor,
-               "datasheet-column-menu", de->data_sheet_variable_popup_menu, NULL);
+               "datasheet-column-menu", de->data_sheet_variable_popup_menu,
+               "datasheet-row-menu", de->data_sheet_cases_popup_menu,
+               "varsheet-row-menu", de->var_sheet_variable_popup_menu,
+               NULL);
 
 
-  g_object_set (de->data_editor,
-               "datasheet-row-menu", de->data_sheet_cases_popup_menu, NULL);
-
   return de;
 }
 
@@ -1627,6 +1633,43 @@ create_data_sheet_cases_popup_menu (struct data_editor *de)
 }
 
 
+static GtkWidget *
+create_var_sheet_variable_popup_menu (struct data_editor *de)
+{
+  GtkWidget *menu = gtk_menu_new ();
+
+  GtkWidget *insert_variable =
+    gtk_menu_item_new_with_label (_("Insert Variable"));
+
+  GtkWidget *delete_variable =
+    gtk_menu_item_new_with_label (_("Clear"));
+
+
+  gtk_action_connect_proxy (de->delete_variables,
+                           delete_variable);
+
+
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), insert_variable);
+
+  g_signal_connect_swapped (G_OBJECT (insert_variable), "activate",
+                           G_CALLBACK (gtk_action_activate),
+                           de->insert_variable);
+
+
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu),
+                        gtk_separator_menu_item_new ());
+
+
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), delete_variable);
+
+
+  gtk_widget_show_all (menu);
+
+  return menu;
+}
+
+
+
 \f
 
 static void
index 237b6769a896ecd4bb8580e3e2b7d0e43cf2e6bd..af282e26fb0f947e6896269c53183967d5be0ad2 100644 (file)
@@ -77,6 +77,8 @@ struct data_editor
   GtkMenu *data_sheet_variable_popup_menu;
   GtkMenu *data_sheet_cases_popup_menu;
 
+  GtkMenu *var_sheet_variable_popup_menu;
+
   PsppireDataEditor *data_editor;
 
   gboolean save_as_portable;
index ac90bd1df6ca82d294e791969c288bc39b911e17..ff96109d451ffd21e10582c82ea911beaf4e2acc 100644 (file)
@@ -109,8 +109,12 @@ psppire_data_editor_finalize (GObject *obj)
 
 
 
-static void popup_variable_menu (GtkSheet *sheet, gint column,
-                                GdkEventButton *event, gpointer data);
+static void popup_variable_column_menu (GtkSheet *sheet, gint column,
+                                       GdkEventButton *event, gpointer data);
+
+static void popup_variable_row_menu (GtkSheet *sheet, gint row,
+                                    GdkEventButton *event, gpointer data);
+
 
 static void popup_cases_menu (GtkSheet *sheet, gint row,
                              GdkEventButton *event, gpointer data);
@@ -118,6 +122,7 @@ static void popup_cases_menu (GtkSheet *sheet, gint row,
 
 
 
+
 /* Callback which occurs when the data sheet's column title
    is double clicked */
 static gboolean
@@ -193,6 +198,7 @@ enum
     PROP_0,
     PROP_DATA_STORE,
     PROP_VAR_STORE,
+    PROP_VS_ROW_MENU,
     PROP_DS_COLUMN_MENU,
     PROP_DS_ROW_MENU,
     PROP_VALUE_LABELS,
@@ -374,12 +380,20 @@ psppire_data_editor_set_property (GObject         *object,
                    "model", de->var_store,
                    NULL);
       break;
+    case PROP_VS_ROW_MENU:
+      {
+       GObject *menu = g_value_get_object (value);
+
+       g_signal_connect (de->var_sheet, "button-event-row",
+                         G_CALLBACK (popup_variable_row_menu), menu);
+      }
+      break;
     case PROP_DS_COLUMN_MENU:
       {
        GObject *menu = g_value_get_object (value);
 
        g_signal_connect (de->data_sheet[0], "button-event-column",
-                         G_CALLBACK (popup_variable_menu), menu);
+                         G_CALLBACK (popup_variable_column_menu), menu);
       }
       break;
     case PROP_DS_ROW_MENU:
@@ -482,7 +496,8 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
   GParamSpec *data_store_spec ;
   GParamSpec *var_store_spec ;
   GParamSpec *column_menu_spec;
-  GParamSpec *row_menu_spec;
+  GParamSpec *ds_row_menu_spec;
+  GParamSpec *vs_row_menu_spec;
   GParamSpec *value_labels_spec;
   GParamSpec *current_case_spec;
   GParamSpec *current_var_spec;
@@ -530,7 +545,7 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
                                    column_menu_spec);
 
 
-  row_menu_spec =
+  ds_row_menu_spec =
     g_param_spec_object ("datasheet-row-menu",
                         "Data Sheet Row Menu",
                         "A menu to be displayed when button 3 is pressed in the data sheet's row title buttons",
@@ -539,7 +554,20 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
 
   g_object_class_install_property (object_class,
                                    PROP_DS_ROW_MENU,
-                                   row_menu_spec);
+                                   ds_row_menu_spec);
+
+
+  vs_row_menu_spec =
+    g_param_spec_object ("varsheet-row-menu",
+                        "Variable Sheet Row Menu",
+                        "A menu to be displayed when button 3 is pressed in the variable sheet's row title buttons",
+                        GTK_TYPE_MENU,
+                        G_PARAM_WRITABLE);
+
+  g_object_class_install_property (object_class,
+                                   PROP_VS_ROW_MENU,
+                                   vs_row_menu_spec);
+
 
   value_labels_spec =
     g_param_spec_boolean ("value-labels",
@@ -1096,7 +1124,7 @@ psppire_data_editor_clip_cut (PsppireDataEditor *de)
 /* Popup menu related stuff */
 
 static void
-popup_variable_menu (GtkSheet *sheet, gint column,
+popup_variable_column_menu (GtkSheet *sheet, gint column,
                     GdkEventButton *event, gpointer data)
 {
   GtkMenu *menu = GTK_MENU (data);
@@ -1118,6 +1146,29 @@ popup_variable_menu (GtkSheet *sheet, gint column,
 }
 
 
+static void
+popup_variable_row_menu (GtkSheet *sheet, gint row,
+                    GdkEventButton *event, gpointer data)
+{
+  GtkMenu *menu = GTK_MENU (data);
+
+  PsppireVarStore *var_store =
+    PSPPIRE_VAR_STORE (gtk_sheet_get_model (sheet));
+
+  const struct variable *v =
+    psppire_dict_get_variable (var_store->dict, row);
+
+  if ( v && event->button == 3)
+    {
+      gtk_sheet_select_row (sheet, row);
+
+      gtk_menu_popup (menu,
+                     NULL, NULL, NULL, NULL,
+                     event->button, event->time);
+    }
+}
+
+
 static void
 popup_cases_menu (GtkSheet *sheet, gint row,
                  GdkEventButton *event, gpointer data)