[gnumeric] some autofilter top 10 changes



commit bb7964d9004b39493359b94a903579dc35559730
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Wed Apr 13 23:56:26 2011 -0600

    some autofilter top 10 changes
    
    2011-04-13  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* dialog-autofilter.c (cb_top10_count_changed): use the true count
    	(cb_top10_type_changed): ditto
    	(dialog_auto_filter): set the spin button to a reasonable value
    	* autofilter-top10.ui: move spin button

 src/dialogs/ChangeLog           |   11 +++++-
 src/dialogs/autofilter-top10.ui |   68 +++++++++++++++++++-------------------
 src/dialogs/dialog-autofilter.c |   37 ++++++++++++++++-----
 3 files changed, 71 insertions(+), 45 deletions(-)
---
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index f6dd0e5..3750e88 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,7 +1,14 @@
+2011-04-13  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* dialog-autofilter.c (cb_top10_count_changed): use the true count
+	(cb_top10_type_changed): ditto
+	(dialog_auto_filter): set the spin button to a reasonable value
+	* autofilter-top10.ui: move spin button
+
 2011-04-10  Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* dialog-autofilter.c (cb_top10_count_changed): clarify the meaning of the 
-	percentage option
+	* dialog-autofilter.c (cb_top10_count_changed): clarify the meaning 
+	of the percentage option
 
 2011-04-10  Andreas J. Guelzow <aguelzow pyrshep ca>
 
diff --git a/src/dialogs/autofilter-top10.ui b/src/dialogs/autofilter-top10.ui
index a28273b..dafd5d5 100644
--- a/src/dialogs/autofilter-top10.ui
+++ b/src/dialogs/autofilter-top10.ui
@@ -56,32 +56,12 @@
           </packing>
         </child>
         <child>
-          <object class="GtkHBox" id="hbox1">
+          <object class="GtkRadioButton" id="items-largest">
             <property name="visible">True</property>
-            <property name="border_width">6</property>
-            <property name="spacing">12</property>
-            <child>
-              <object class="GtkLabel" id="label1">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Count or percentage:</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkSpinButton" id="item_count">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="adjustment">adjustment1</property>
-                <property name="climb_rate">1</property>
-              </object>
-              <packing>
-                <property name="position">1</property>
-              </packing>
-            </child>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="active">True</property>
+            <property name="draw_indicator">True</property>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -90,12 +70,13 @@
           </packing>
         </child>
         <child>
-          <object class="GtkRadioButton" id="items-largest">
+          <object class="GtkRadioButton" id="items-smallest">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
             <property name="active">True</property>
             <property name="draw_indicator">True</property>
+            <property name="group">items-largest</property>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -104,7 +85,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkRadioButton" id="items-smallest">
+          <object class="GtkRadioButton" id="percentage-largest">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
@@ -119,7 +100,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkRadioButton" id="percentage-largest">
+          <object class="GtkRadioButton" id="percentage-smallest">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
@@ -134,13 +115,32 @@
           </packing>
         </child>
         <child>
-          <object class="GtkRadioButton" id="percentage-smallest">
+          <object class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="active">True</property>
-            <property name="draw_indicator">True</property>
-            <property name="group">items-largest</property>
+            <property name="border_width">6</property>
+            <property name="spacing">12</property>
+            <property name="homogeneous">True</property>
+            <child>
+              <object class="GtkLabel" id="cp-label">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Count or Percentage:</property>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSpinButton" id="item_count">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="adjustment">adjustment1</property>
+                <property name="climb_rate">1</property>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/src/dialogs/dialog-autofilter.c b/src/dialogs/dialog-autofilter.c
index de51cc3..8d9c7cd 100644
--- a/src/dialogs/dialog-autofilter.c
+++ b/src/dialogs/dialog-autofilter.c
@@ -32,6 +32,7 @@
 #include <wbc-gtk.h>
 #include <sheet.h>
 #include <cell.h>
+#include <ranges.h>
 #include <value.h>
 #include <sheet-filter.h>
 #include <number-match.h>
@@ -194,13 +195,20 @@ cb_top10_count_changed (GtkSpinButton *button,
 	int val = 0.5 + gtk_spin_button_get_value (button);
 	GtkWidget *w;
 	gchar *label;
+	int cval = val, count;
+
+	count = range_height(&(state->filter->r)) - 1;
+
+	if (cval > count)
+		cval = count;
 
 	w = go_gtk_builder_get_widget (state->gui, type_group[0]);
 	/* xgettext : %d gives the number of items in the autofilter. */
 	/* This is input to ngettext. */
 	label = g_strdup_printf (ngettext ("Show the largest item", 
-					   "Show the %3d largest items", val), 
-				 val);
+					   "Show the %3d largest items", 
+					   cval), 
+				 cval);
 	gtk_button_set_label (GTK_BUTTON (w),label);
 	g_free(label);
 
@@ -208,8 +216,9 @@ cb_top10_count_changed (GtkSpinButton *button,
 	/* xgettext : %d gives the number of items in the autofilter. */
 	/* This is input to ngettext. */
 	label = g_strdup_printf (ngettext ("Show the smallest item", 
-					   "Show the %3d smallest items", val), 
-				 val);
+					   "Show the %3d smallest items", 
+					   cval), 
+				 cval);
 	gtk_button_set_label (GTK_BUTTON (w),label);
 	g_free(label);
 
@@ -245,11 +254,19 @@ cb_top10_type_changed (G_GNUC_UNUSED GtkToggleButton *button,
 {
 	GnmFilterOp op = autofilter_get_type (state);
 	GtkWidget *spin = go_gtk_builder_get_widget (state->gui, "item_count");
+	GtkWidget *label = go_gtk_builder_get_widget (state->gui, "cp-label");
 
-	gtk_spin_button_set_range (GTK_SPIN_BUTTON (spin), 1.,
-				   (op == GNM_FILTER_OP_TOP_N_PERCENT || 
-				    op == GNM_FILTER_OP_BOTTOM_N_PERCENT) ? 100. 
-				   : 500.);
+	if (op == GNM_FILTER_OP_TOP_N_PERCENT || 
+	    op == GNM_FILTER_OP_BOTTOM_N_PERCENT) {
+		gtk_spin_button_set_range (GTK_SPIN_BUTTON (spin), 1.,
+					   100.);
+		gtk_label_set_text (GTK_LABEL (label), _("Percentage:"));
+	} else {
+		gtk_spin_button_set_range 
+			(GTK_SPIN_BUTTON (spin), 1.,
+			 range_height(&(state->filter->r)) - 1);
+		gtk_label_set_text (GTK_LABEL (label), _("Count:"));
+	}
 }
 
 static void
@@ -490,6 +507,9 @@ dialog_auto_filter (WBCGtk *wbcg,
 			  "value-changed",
 			  G_CALLBACK (cb_top10_count_changed), state);
 	cb_top10_count_changed (GTK_SPIN_BUTTON (w), state);
+	cb_top10_type_changed (NULL, state);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (w), 
+				   range_height(&(state->filter->r))/2);
 
 	rb = type_group;
 	while (*rb != NULL) {
@@ -500,7 +520,6 @@ dialog_auto_filter (WBCGtk *wbcg,
 		rb++;
 	}
 	
-	cb_top10_type_changed (NULL, state);
 
 	w = go_gtk_builder_get_widget (state->gui, "ok_button");
 	g_signal_connect (G_OBJECT (w),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]