r16725 - gnucash/trunk/src - Allow creation of new lots from lot viewer. (#420543)
Derek Atkins
warlord at cvs.gnucash.org
Tue Dec 25 21:14:56 EST 2007
Author: warlord
Date: 2007-12-25 21:14:55 -0500 (Tue, 25 Dec 2007)
New Revision: 16725
Trac: http://svn.gnucash.org/trac/changeset/16725
Modified:
gnucash/trunk/src/engine/Account.c
gnucash/trunk/src/engine/cap-gains.c
gnucash/trunk/src/engine/gnc-lot.c
gnucash/trunk/src/engine/gnc-lot.h
gnucash/trunk/src/gnome/glade/lots.glade
gnucash/trunk/src/gnome/lot-viewer.c
Log:
Allow creation of new lots from lot viewer. (#420543)
Patch by Klee Dienes <klee at mit.edu>
* src/engine/Account.c (xaccAccountRemoveLot): Generate a
QOF_EVENT_REMOVE for the lot and QOF_EVENT_MODIFY for the account.
(xaccAccountInsertLot): Ditto, but QOF_EVENT_ADD.
* src/engine/gnc-lot.c (gnc_lot_make_default): Move from
cap-gains.c.
* src/engine/gnc-lot.h (gnc_lot_make_default): Add prototype.
* src/engine/cap-gains.c (MakeDefaultLot): Move to gnc-lot.c as
gnc_lot_make_default().
* src/gnome/lot-viewer.c: Add code to support lot creation:
(RESPONSE_NEW_LOT): Add enumerated value.
(lv_save_current_row): New function.
(lv_select_row): Add call to lv_save_current_row.
(lv_unselect_row): Use lv_save_current_row.
(lv_close_handler): Use lv_save_current_row.
(lv_response_cb): Handle RESPONSE_NEW_LOT.
(gnc_lot_viewer_dialog): Watch for QOF_EVENT_ADD and
QOF_EVENT_REMOVE for lots.
* src/gnome/glade/lots.glade: Add "new lot" button.
Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c 2007-12-26 01:38:45 UTC (rev 16724)
+++ gnucash/trunk/src/engine/Account.c 2007-12-26 02:14:55 UTC (rev 16725)
@@ -1650,6 +1650,8 @@
ENTER ("(acc=%p, lot=%p)", acc, lot);
priv->lots = g_list_remove(priv->lots, lot);
+ qof_event_gen (&lot->inst, QOF_EVENT_REMOVE, NULL);
+ qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
LEAVE ("(acc=%p, lot=%p)", acc, lot);
}
@@ -1685,6 +1687,9 @@
* called from gnc_book_close_period since xaccAccountInsertSplit
* will try to balance capital gains and things aren't ready for that. */
+ qof_event_gen (&lot->inst, QOF_EVENT_ADD, NULL);
+ qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
+
LEAVE ("(acc=%p, lot=%p)", acc, lot);
}
Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c 2007-12-26 01:38:45 UTC (rev 16724)
+++ gnucash/trunk/src/engine/cap-gains.c 2007-12-26 02:14:55 UTC (rev 16725)
@@ -571,25 +571,6 @@
/* ============================================================== */
-static GNCLot *
-MakeDefaultLot (Account *acc)
-{
- GNCLot * lot;
- gint64 id;
- char buff[200];
-
- lot = gnc_lot_new (qof_instance_get_book(acc));
-
- /* Provide a reasonable title for the new lot */
- id = kvp_frame_get_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id");
- snprintf (buff, 200, ("%s %" G_GINT64_FORMAT), _("Lot"), id);
- kvp_frame_set_str (gnc_lot_get_slots (lot), "/title", buff);
- id ++;
- kvp_frame_set_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id", id);
-
- return lot;
-}
-
/* Accounting-policy callback. Given an account and an amount,
* this routine should return a lot. By implementing this as
* a callback, we can 'easily' add other accounting policies.
@@ -632,7 +613,7 @@
lot = pcy->PolicyGetLot (pcy, split);
if (!lot)
{
- lot = MakeDefaultLot (acc);
+ lot = gnc_lot_make_default (acc);
PINFO ("start new lot (%s)", gnc_lot_get_title(lot));
}
split = xaccSplitAssignToLot (split, lot);
Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c 2007-12-26 01:38:45 UTC (rev 16724)
+++ gnucash/trunk/src/engine/gnc-lot.c 2007-12-26 02:14:55 UTC (rev 16725)
@@ -39,8 +39,12 @@
* Copyright (c) 2002,2003 Linas Vepstas <linas at linas.org>
*/
+#include <glib.h>
+#include <glib/gi18n.h>
+
#include "config.h"
#include "Account.h"
+#include "AccountP.h"
#include "gnc-lot.h"
#include "gnc-lot-p.h"
#include "cap-gains.h"
@@ -454,4 +458,22 @@
return qof_object_register(&gncLotDesc);
}
+GNCLot * gnc_lot_make_default (Account *acc)
+{
+ GNCLot * lot;
+ gint64 id;
+ char buff[200];
+
+ lot = gnc_lot_new (qof_instance_get_book(acc));
+
+ /* Provide a reasonable title for the new lot */
+ id = kvp_frame_get_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id");
+ snprintf (buff, 200, ("%s %" G_GINT64_FORMAT), _("Lot"), id);
+ kvp_frame_set_str (gnc_lot_get_slots (lot), "/title", buff);
+ id ++;
+ kvp_frame_set_gint64 (xaccAccountGetSlots (acc), "/lot-mgmt/next-id", id);
+
+ return lot;
+}
+
/* ========================== END OF FILE ========================= */
Modified: gnucash/trunk/src/engine/gnc-lot.h
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.h 2007-12-26 01:38:45 UTC (rev 16724)
+++ gnucash/trunk/src/engine/gnc-lot.h 2007-12-26 02:14:55 UTC (rev 16725)
@@ -156,6 +156,9 @@
* */
KvpFrame * gnc_lot_get_slots (const GNCLot *);
+/** XXX: Document? */
+GNCLot * gnc_lot_make_default (Account * acc);
+
#define gnc_lot_get_guid(X) qof_entity_get_guid(QOF_INSTANCE(X))
#define LOT_IS_CLOSED "is-closed?"
Modified: gnucash/trunk/src/gnome/glade/lots.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/lots.glade 2007-12-26 01:38:45 UTC (rev 16724)
+++ gnucash/trunk/src/gnome/glade/lots.glade 2007-12-26 02:14:55 UTC (rev 16725)
@@ -35,6 +35,81 @@
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
+ <widget class="GtkButton" id="new lot button">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="response_id">5</property>
+
+ <child>
+ <widget class="GtkAlignment" id="alignment3">
+ <property name="visible">True</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xscale">0</property>
+ <property name="yscale">0</property>
+ <property name="top_padding">0</property>
+ <property name="bottom_padding">0</property>
+ <property name="left_padding">0</property>
+ <property name="right_padding">0</property>
+
+ <child>
+ <widget class="GtkHBox" id="hbox4">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">2</property>
+
+ <child>
+ <widget class="GtkImage" id="image3">
+ <property name="visible">True</property>
+ <property name="stock">gtk-new</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label21">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_New Lot</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
<widget class="GtkButton" id="scrub account button">
<property name="visible">True</property>
<property name="can_default">True</property>
Modified: gnucash/trunk/src/gnome/lot-viewer.c
===================================================================
--- gnucash/trunk/src/gnome/lot-viewer.c 2007-12-26 01:38:45 UTC (rev 16724)
+++ gnucash/trunk/src/gnome/lot-viewer.c 2007-12-26 02:14:55 UTC (rev 16725)
@@ -64,6 +64,7 @@
#define RESPONSE_DELETE 2
#define RESPONSE_SCRUB_LOT 3
#define RESPONSE_SCRUB_ACCOUNT 4
+#define RESPONSE_NEW_LOT 5
#define GCONF_SECTION "dialogs/lot_viewer"
#define GCONF_KEY_HPOSITION "hpane_position"
@@ -77,6 +78,7 @@
#endif
GtkButton * delete_button;
GtkButton * scrub_lot_button;
+ GtkButton * new_lot_button;
GtkPaned * lot_hpaned;
GtkPaned * lot_vpaned;
GtkTreeView * lot_view;
@@ -210,6 +212,26 @@
gtk_clist_clear (lv->mini_clist);
}
+static void
+lv_save_current_row (GNCLotViewer *lv)
+{
+ GNCLot *lot = lv->selected_lot;
+ const char * str;
+ char * notes;
+
+ if (lot)
+ {
+ /* Get the title, save_the_title */
+ str = gtk_entry_get_text (lv->title_entry);
+ gnc_lot_set_title (lot, str);
+
+ /* Get the notes, save the notes */
+ notes = xxxgtk_textview_get_text (lv->lot_notes);
+ gnc_lot_set_notes (lot, notes);
+ g_free(notes);
+ }
+}
+
/* ======================================================================== */
/* Callback for selecting a row the the list-of-list clist */
@@ -219,6 +241,8 @@
{
const char * str;
+ lv_save_current_row (lv);
+
str = gnc_lot_get_title (lot);
if (!str) str = "";
gtk_entry_set_text (lv->title_entry, str);
@@ -273,22 +297,8 @@
static void
lv_unselect_row (GNCLotViewer *lv)
{
- GNCLot *lot = lv->selected_lot;
- const char * str;
- char * notes;
+ lv_save_current_row (lv);
- if (lot)
- {
- /* Get the title, save_the_title */
- str = gtk_entry_get_text (lv->title_entry);
- gnc_lot_set_title (lot, str);
-
- /* Get the notes, save the notes */
- notes = xxxgtk_textview_get_text (lv->lot_notes);
- gnc_lot_set_notes (lot, notes);
- g_free(notes);
- }
-
lv_unset_lot (lv);
}
@@ -488,21 +498,8 @@
GNCLotViewer *lv = user_data;
GNCLot *lot = lv->selected_lot;
- if (lot)
- {
- const char * str;
- char *notes;
+ lv_save_current_row (lv);
- /* Get the title, save the title */
- str = gtk_entry_get_text (lv->title_entry);
- gnc_lot_set_title (lot, str);
-
- /* Get the notes, save the notes */
- notes = xxxgtk_textview_get_text (lv->lot_notes);
- gnc_lot_set_notes (lot, notes);
- g_free(notes);
- }
-
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(lv->window));
gtk_widget_destroy (lv->window);
}
@@ -582,6 +579,12 @@
gnc_lot_viewer_fill (lv);
lv_show_splits (lv);
break;
+
+ case RESPONSE_NEW_LOT:
+ lv_save_current_row (lv);
+ lot = gnc_lot_make_default (lv->account);
+ xaccAccountInsertLot (lv->account, lot);
+ break;
}
}
@@ -659,6 +662,7 @@
#endif
lv->delete_button = GTK_BUTTON(glade_xml_get_widget (xml, "delete button"));
lv->scrub_lot_button = GTK_BUTTON(glade_xml_get_widget (xml, "scrub lot button"));
+ lv->new_lot_button = GTK_BUTTON(glade_xml_get_widget (xml, "new lot button"));
lv->lot_view = GTK_TREE_VIEW(glade_xml_get_widget (xml, "lot view"));
lv_init_lot_view(lv);
@@ -709,7 +713,7 @@
gnc_gui_component_watch_entity_type (component_id,
GNC_ID_LOT,
- QOF_EVENT_CREATE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
+ QOF_EVENT_CREATE | QOF_EVENT_ADD | QOF_EVENT_REMOVE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
gtk_widget_show_all (lv->window);
gnc_window_adjust_for_screen (GTK_WINDOW(lv->window));
More information about the gnucash-changes
mailing list