Sort the price database by clicking on column titles.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6956 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2002-06-10 00:35:31 +00:00
parent c7fd015311
commit 919425012c
4 changed files with 187 additions and 85 deletions

View File

@ -1,3 +1,14 @@
2002-06-09 David Hampton <hampton@employees.org>
* src/gnome/glade/price.glade:
* src/gnome/dialog-price-editor.c: Set up all fields so that the
Enter key triggers the OK button.
* src/gnome/glade/price.glade:
* src/gnome/dialog-price-edit-db.c: Sort the database by clicking
on the column titles. Removed old radio-buttons for sorting. A
double-click on an item will also open it for editing.
2002-06-08 David Hampton <hampton@employees.org>
* src/app-file/gnome/gnc-file-history.c (gnc_history_update_menu):

View File

@ -46,6 +46,9 @@
#define DIALOG_PRICE_DB_CM_CLASS "dialog-price-edit-db"
#define COMMODITY_COLUMN 0
#define DATE_COLUMN 2
/* This static indicates the debugging module that this .o belongs to. */
/* static short module = MOD_GUI; */
@ -53,7 +56,10 @@ typedef struct
{
GtkWidget * dialog;
GtkWidget * sort_radio;
gint sort_column;
gboolean ascending;
GtkWidget * commodity_arrow;
GtkWidget * date_arrow;
GtkWidget * price_list;
GtkWidget * edit_button;
@ -150,6 +156,10 @@ gnc_prices_load_prices (PricesDialog *pdb_dialog)
gnc_commodity *current_commodity;
GNCPrintAmountInfo print_info;
gboolean sort_commodity;
GtkArrowType arrow_dir;
GtkWidget *show, *hide;
GCompareFunc sort_fn;
gboolean sort_ascending;
GNCPrice *old_price;
GNCBook *book;
GList *prices;
@ -164,11 +174,28 @@ gnc_prices_load_prices (PricesDialog *pdb_dialog)
gnc_pricedb_foreach_price (gnc_book_get_pricedb (book),
load_price_helper, &prices, FALSE);
sort_commodity = gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (pdb_dialog->sort_radio));
sort_commodity = (pdb_dialog->sort_column == COMMODITY_COLUMN);
prices = g_list_sort (prices,
sort_commodity ? price_compare : price_date_compare);
if (sort_commodity) {
show = pdb_dialog->commodity_arrow;
hide = pdb_dialog->date_arrow;
sort_fn = price_compare;
sort_ascending = pdb_dialog->ascending;
} else {
show = pdb_dialog->date_arrow;
hide = pdb_dialog->commodity_arrow;
sort_fn = price_date_compare;
sort_ascending = !pdb_dialog->ascending; /* Aren't date sorts fun */
}
prices = g_list_sort (prices, sort_fn);
if (!sort_ascending)
prices = g_list_reverse (prices);
arrow_dir = pdb_dialog->ascending ? GTK_ARROW_DOWN: GTK_ARROW_UP;
gtk_arrow_set(GTK_ARROW(show), arrow_dir, GTK_SHADOW_ETCHED_IN);
gtk_widget_show(show);
gtk_widget_hide(hide);
gtk_clist_freeze (GTK_CLIST (pdb_dialog->price_list));
@ -385,6 +412,35 @@ get_quotes_clicked (GtkWidget *widget, gpointer data)
gnc_gui_refresh_all ();
}
/**
* gnc_prices_click_column_cb
*
* @par1: A pointer to the clist.
* @par2: The column number clicked (0 based).
* @par3: A pointer to the data structure describing this window.
*
* This function checks for a valid column number, and determines
* whether or not to invert the current sort or select a new column
* for sorting. It calls the gnc_prices_load_prices() function to
* sort and display the data.
*/
static void
gnc_prices_click_column_cb(GtkCList *clist, gint column, gpointer data)
{
PricesDialog *pdb_dialog = data;
if ((column != COMMODITY_COLUMN) && (column != DATE_COLUMN))
return;
if (pdb_dialog->sort_column == column) {
pdb_dialog->ascending = !pdb_dialog->ascending;
} else {
pdb_dialog->sort_column = column;
pdb_dialog->ascending = TRUE;
}
gnc_prices_load_prices (pdb_dialog);
}
static void
gnc_prices_select_price_cb (GtkCList *clist, gint row, gint col,
GdkEventButton *event, gpointer data)
@ -405,6 +461,10 @@ gnc_prices_select_price_cb (GtkCList *clist, gint row, gint col,
pdb_dialog->price != NULL);
gtk_widget_set_sensitive (pdb_dialog->remove_old_button,
pdb_dialog->price != NULL);
if (event && (event->type == GDK_2BUTTON_PRESS)) {
edit_clicked(NULL, data);
}
}
static void
@ -450,15 +510,6 @@ prices_set_min_widths (PricesDialog *pdb_dialog)
}
}
static void
sort_commodity_toggled_cb (GtkToggleButton *togglebutton,
gpointer user_data)
{
PricesDialog *pdb_dialog = user_data;
gnc_prices_load_prices (pdb_dialog);
}
static void
gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
{
@ -490,6 +541,12 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
list = glade_xml_get_widget (xml, "price_list");
pdb_dialog->price_list = list;
pdb_dialog->sort_column = COMMODITY_COLUMN;
pdb_dialog->ascending = TRUE;
gtk_clist_column_titles_passive(GTK_CLIST(list));
gtk_clist_column_title_active(GTK_CLIST(list), COMMODITY_COLUMN);
gtk_clist_column_title_active(GTK_CLIST(list), DATE_COLUMN);
gtk_signal_connect (GTK_OBJECT(list), "select_row",
GTK_SIGNAL_FUNC(gnc_prices_select_price_cb),
@ -498,19 +555,16 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
gtk_signal_connect (GTK_OBJECT(list), "unselect_row",
GTK_SIGNAL_FUNC(gnc_prices_unselect_price_cb),
pdb_dialog);
gtk_signal_connect (GTK_OBJECT(list), "click_column",
GTK_SIGNAL_FUNC(gnc_prices_click_column_cb),
pdb_dialog);
}
/* buttons */
{
GtkWidget *button;
button = glade_xml_get_widget (xml, "sort_by_commodity_radio");
pdb_dialog->sort_radio = button;
gtk_signal_connect (GTK_OBJECT (button), "toggled",
GTK_SIGNAL_FUNC (sort_commodity_toggled_cb),
pdb_dialog);
button = glade_xml_get_widget (xml, "edit_button");
pdb_dialog->edit_button = button;
@ -540,6 +594,17 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
GTK_SIGNAL_FUNC (get_quotes_clicked), pdb_dialog);
}
/* arrows */
{
GtkWidget *arrow;
arrow = glade_xml_get_widget (xml, "commodity_arrow");
pdb_dialog->commodity_arrow = arrow;
arrow = glade_xml_get_widget (xml, "date_arrow");
pdb_dialog->date_arrow = arrow;
}
gnc_prices_load_prices (pdb_dialog);
prices_set_min_widths (pdb_dialog);

View File

@ -356,7 +356,8 @@ gnc_price_pedit_dialog_create (GtkWidget * parent, PriceEditDialog *pedit_dialog
gtk_widget_show (w);
gtk_signal_connect (GTK_OBJECT (GTK_COMBO(w)->entry), "changed",
GTK_SIGNAL_FUNC (currency_changed_cb), pedit_dialog);
gnome_dialog_editable_enters(GNOME_DIALOG(dialog),
GTK_EDITABLE(GTK_COMBO(w)->entry));
box = glade_xml_get_widget (xml, "date_box");
w = gnc_date_edit_new (time (NULL), FALSE, FALSE);
@ -367,6 +368,7 @@ gnc_price_pedit_dialog_create (GtkWidget * parent, PriceEditDialog *pedit_dialog
GTK_SIGNAL_FUNC (date_changed_cb), pedit_dialog);
gtk_signal_connect (GTK_OBJECT (GNC_DATE_EDIT (w)->date_entry), "changed",
GTK_SIGNAL_FUNC (date_entry_changed_cb), pedit_dialog);
gnc_date_editable_enters(GNOME_DIALOG(dialog), GNC_DATE_EDIT(w));
w = glade_xml_get_widget (xml, "source_entry");
@ -389,6 +391,7 @@ gnc_price_pedit_dialog_create (GtkWidget * parent, PriceEditDialog *pedit_dialog
print_info = gnc_default_price_print_info ();
gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (w), print_info);
gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (w), 1000000);
gnome_dialog_editable_enters(GNOME_DIALOG(dialog), GTK_EDITABLE(w));
gtk_widget_show (w);
entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (w));

View File

@ -107,11 +107,18 @@
<name>price_list</name>
<can_focus>True</can_focus>
<columns>6</columns>
<column_widths>80,80,80,80,80,80</column_widths>
<column_widths>117,80,80,80,80,80</column_widths>
<selection_mode>GTK_SELECTION_BROWSE</selection_mode>
<show_titles>True</show_titles>
<shadow_type>GTK_SHADOW_IN</shadow_type>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox109</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
@ -123,6 +130,29 @@
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>commodity_arrow</name>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
<pack>GTK_PACK_END</pack>
</child>
</widget>
</widget>
<widget>
@ -138,6 +168,13 @@
<ypad>0</ypad>
</widget>
<widget>
<class>GtkHBox</class>
<child_name>CList:title</child_name>
<name>hbox110</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<widget>
<class>GtkLabel</class>
<child_name>CList:title</child_name>
@ -149,6 +186,29 @@
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkArrow</class>
<name>date_arrow</name>
<arrow_type>GTK_ARROW_DOWN</arrow_type>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
<pack>GTK_PACK_END</pack>
</child>
</widget>
</widget>
<widget>
@ -192,49 +252,6 @@
</widget>
</widget>
<widget>
<class>GtkHBox</class>
<name>hbox108</name>
<border_width>3</border_width>
<homogeneous>True</homogeneous>
<spacing>10</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkRadioButton</class>
<name>sort_by_commodity_radio</name>
<can_focus>True</can_focus>
<label>Sort by Commodity</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>price_sort_radio</group>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkRadioButton</class>
<name>radiobutton10</name>
<can_focus>True</can_focus>
<label>Sort by Date</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
<group>price_sort_radio</group>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkHButtonBox</class>
<name>hbuttonbox5</name>
@ -257,6 +274,7 @@
<can_default>True</can_default>
<can_focus>True</can_focus>
<label>Add</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
<widget>
@ -266,6 +284,7 @@
<can_default>True</can_default>
<can_focus>True</can_focus>
<label>Remove</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
<widget>
@ -275,6 +294,7 @@
<can_default>True</can_default>
<can_focus>True</can_focus>
<label>Remove Old...</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
<widget>
@ -284,6 +304,7 @@
<can_default>True</can_default>
<can_focus>True</can_focus>
<label>Edit</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
<widget>
@ -293,6 +314,7 @@
<can_default>True</can_default>
<can_focus>True</can_focus>
<label>Get Quotes</label>
<relief>GTK_RELIEF_NORMAL</relief>
</widget>
</widget>
</widget>
@ -347,6 +369,7 @@
<class>GtkButton</class>
<name>ok_button</name>
<can_default>True</can_default>
<has_default>True</has_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_OK</stock_button>
</widget>