[Gnucash-changes] r12157 - gnucash/trunk - David Jafferian's account deletion patch that queries the user about

David Hampton hampton at cvs.gnucash.org
Sat Dec 10 19:52:13 EST 2005


Author: hampton
Date: 2005-12-10 19:52:12 -0500 (Sat, 10 Dec 2005)
New Revision: 12157
Trac: http://svn.gnucash.org/trac/changeset/12157

Modified:
   gnucash/trunk/AUTHORS
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Account.h
   gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
   gnucash/trunk/src/gnome/glade/account.glade
   gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c
Log:
David Jafferian's account deletion patch that queries the user about
whether to delete or move any contained transactions and sub-accounts.


Modified: gnucash/trunk/AUTHORS
===================================================================
--- gnucash/trunk/AUTHORS	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/AUTHORS	2005-12-11 00:52:12 UTC (rev 12157)
@@ -148,6 +148,7 @@
 Péter Hosszú <hosszu at web.de> Hungarian translation
 Edward J. Huff <ejhuff at huff20may77.us> Date handling in reports, quarterly option
 Tomokazu Iwashita <iwashita at center.nitech.ac.jp> Japanese translation of xea
+David Jafferian <david.jafferian at east.sun.com> Delete account query code.
 Miquel Jordana Vilamitjana <jjvmjv at mundomail.net> Spanish translation of manual
 Prakash Kailasa <PrakashK at bigfoot.com> for gnome build fixes
 Alexey Kakunin <small at arcadia.spb.ru> quickfill patch for Cyrillic

Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/ChangeLog	2005-12-11 00:52:12 UTC (rev 12157)
@@ -1,5 +1,12 @@
 2005-12-10  David Hampton  <hampton at employees.org>
 
+	* src/gnome-utils/gnc-tree-model-account.c:
+	* src/gnome/gnc-plugin-page-account-tree.c:
+	* src/gnome/glade/account.glade:
+	* src/engine/Account.[ch]: David Jafferian's account deletion
+	patch that queries the user about whether to delete or move any
+	contained transactions and sub-accounts.
+
 	* src/gnome-utils/dialog-utils.c: Fix the glade auto-connect code
 	so it doesn't swap the callback arguments when an explicit
 	"object" is provided to the callback.  (This is an unused code

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/src/engine/Account.c	2005-12-11 00:52:12 UTC (rev 12157)
@@ -935,7 +935,88 @@
   LEAVE ("(acc=%p, split=%p)", acc, split);
 }
 
+/********************************************************************\
+\********************************************************************/
 
+static void
+xaccPreSplitMove (Split *split, gpointer dummy)
+{
+  xaccTransBeginEdit (xaccSplitGetParent (split));
+}
+
+static void
+xaccPostSplitMove (Split *split, Account *accto)
+{
+  Transaction *trans;
+
+  split->acc = accto;
+  split->amount = gnc_numeric_convert (split->amount,
+				       xaccAccountGetCommoditySCU(accto),
+				       GNC_HOW_RND_ROUND);
+  trans = xaccSplitGetParent (split);
+  xaccTransCommitEdit (trans);
+  gnc_engine_gen_event (&trans->inst.entity, GNC_EVENT_MODIFY);
+}
+
+void
+xaccAccountMoveAllSplits (Account *accfrom, Account *accto)
+{
+  /* Handle special cases. */
+  if (!accfrom) return;
+  if (!accto) return;
+  if (!accfrom->splits) return;
+  if (accfrom == accto) return;
+
+  ENTER ("(accfrom=%p, accto=%p)", accfrom, accto);
+
+  /* check for book mix-up */
+  g_return_if_fail (accfrom->inst.book == accto->inst.book);
+
+  /* Begin editing both accounts and all transactions in accfrom. */
+  g_list_foreach(accfrom->splits, (GFunc)xaccPreSplitMove, NULL);
+  xaccAccountBeginEdit(accfrom);
+  xaccAccountBeginEdit(accto);
+
+  /* Concatenate accfrom's lists of splits and lots to accto's lists. */
+  accto->splits = g_list_concat(accto->splits, accfrom->splits);
+  accto->lots = g_list_concat(accto->lots, accfrom->lots);
+
+  /* Set appropriate flags. */
+  accfrom->balance_dirty = TRUE;
+  accfrom->sort_dirty = FALSE;
+  accto->balance_dirty = TRUE;
+  accto->sort_dirty = TRUE;
+
+  /*
+   * Change each split's account back pointer to accto.
+   * Convert each split's amount to accto's commodity.
+   * Commit to editing each transaction.
+   */
+  g_list_foreach(accfrom->splits, (GFunc)xaccPostSplitMove, (gpointer)accto);
+
+  /* Finally empty accfrom. */
+  accfrom->splits = NULL;
+  accto->lots = NULL;
+
+  /*
+   * DNJ - I don't really understand why this is necessary,
+   *       but xaccAccountInsertSplit does it.
+   */
+  if (accto->inst.editlevel == 1)
+  {
+    accto->splits = g_list_sort(accto->splits, split_sort_func);
+    accto->sort_dirty = FALSE;
+  }
+
+  /* Commit to editing both accounts. */
+  mark_account (accfrom);
+  mark_account (accto);
+  xaccAccountCommitEdit(accfrom);
+  xaccAccountCommitEdit(accto);
+  LEAVE ("(accfrom=%p, accto=%p)", accfrom, accto);
+}
+
+
 /********************************************************************\
  * xaccAccountRecomputeBalance                                      *
  *   recomputes the partial balances and the current balance for    *

Modified: gnucash/trunk/src/engine/Account.h
===================================================================
--- gnucash/trunk/src/engine/Account.h	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/src/engine/Account.h	2005-12-11 00:52:12 UTC (rev 12157)
@@ -512,6 +512,10 @@
  *    pointer. */
 SplitList*      xaccAccountGetSplitList (Account *account);
 
+/** The xaccAccountMoveAllSplits() routine reassigns each of the splits
+ *  in accfrom to accto. */
+void xaccAccountMoveAllSplits (Account *accfrom, Account *accto);
+
 /** \warning  Unimplemented */
 gpointer xaccAccountForEachSplit(Account *account,
                                  SplitCallback,

Modified: gnucash/trunk/src/gnome/glade/account.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/account.glade	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/src/gnome/glade/account.glade	2005-12-11 00:52:12 UTC (rev 12157)
@@ -138,7 +138,7 @@
 		      <child>
 			<widget class="GtkLabel" id="label">
 			  <property name="visible">True</property>
-			  <property name="label" translatable="no">    </property>
+			  <property name="label">    </property>
 			  <property name="use_underline">False</property>
 			  <property name="use_markup">False</property>
 			  <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -617,7 +617,7 @@
 		      <child>
 			<widget class="GtkLabel" id="label">
 			  <property name="visible">True</property>
-			  <property name="label" translatable="no">    </property>
+			  <property name="label">    </property>
 			  <property name="use_underline">False</property>
 			  <property name="use_markup">False</property>
 			  <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -641,7 +641,7 @@
 		      <child>
 			<widget class="GtkLabel" id="label">
 			  <property name="visible">True</property>
-			  <property name="label" translatable="no">    </property>
+			  <property name="label">    </property>
 			  <property name="use_underline">False</property>
 			  <property name="use_markup">False</property>
 			  <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -689,7 +689,7 @@
 		      <child>
 			<widget class="GtkLabel" id="label">
 			  <property name="visible">True</property>
-			  <property name="label" translatable="no">    </property>
+			  <property name="label">    </property>
 			  <property name="use_underline">False</property>
 			  <property name="use_markup">False</property>
 			  <property name="justify">GTK_JUSTIFY_LEFT</property>
@@ -1297,6 +1297,9 @@
 			      <property name="rules_hint">False</property>
 			      <property name="reorderable">False</property>
 			      <property name="enable_search">True</property>
+			      <property name="fixed_height_mode">False</property>
+			      <property name="hover_selection">False</property>
+			      <property name="hover_expand">False</property>
 			    </widget>
 			  </child>
 			</widget>
@@ -1945,9 +1948,11 @@
 			  <child>
 			    <widget class="GtkComboBox" id="combobox1">
 			      <property name="visible">True</property>
-			      <property name="items" translatable="no">USD
+			      <property name="items">USD
 GBP
 EUR</property>
+			      <property name="add_tearoffs">False</property>
+			      <property name="focus_on_click">True</property>
 			    </widget>
 			  </child>
 			</widget>
@@ -2040,6 +2045,9 @@
 					  <property name="rules_hint">False</property>
 					  <property name="reorderable">False</property>
 					  <property name="enable_search">True</property>
+					  <property name="fixed_height_mode">False</property>
+					  <property name="hover_selection">False</property>
+					  <property name="hover_expand">False</property>
 					</widget>
 				      </child>
 				    </widget>
@@ -2191,6 +2199,9 @@
 				      <property name="rules_hint">False</property>
 				      <property name="reorderable">False</property>
 				      <property name="enable_search">True</property>
+				      <property name="fixed_height_mode">False</property>
+				      <property name="hover_selection">False</property>
+				      <property name="hover_expand">False</property>
 				    </widget>
 				  </child>
 				</widget>
@@ -2293,6 +2304,9 @@
 		      <property name="rules_hint">False</property>
 		      <property name="reorderable">False</property>
 		      <property name="enable_search">True</property>
+		      <property name="fixed_height_mode">False</property>
+		      <property name="hover_selection">False</property>
+		      <property name="hover_expand">False</property>
 		    </widget>
 		  </child>
 		</widget>
@@ -2317,4 +2331,608 @@
   </child>
 </widget>
 
+<widget class="GtkDialog" id="Delete Account">
+  <property name="border_width">6</property>
+  <property name="title" translatable="yes">Delete Account</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">True</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">True</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="has_separator">True</property>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="vbox126">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">6</property>
+
+      <child internal-child="action_area">
+	<widget class="GtkHButtonBox" id="hbuttonbox2">
+	  <property name="visible">True</property>
+	  <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+	  <child>
+	    <widget class="GtkButton" id="cancelbutton">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-cancel</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="response_id">-6</property>
+	    </widget>
+	  </child>
+
+	  <child>
+	    <widget class="GtkButton" id="deletebutton">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-delete</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="response_id">-3</property>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">True</property>
+	  <property name="pack_type">GTK_PACK_END</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkVBox" id="vbox127">
+	  <property name="visible">True</property>
+	  <property name="homogeneous">False</property>
+	  <property name="spacing">12</property>
+
+	  <child>
+	    <widget class="GtkLabel" id="header">
+	      <property name="visible">True</property>
+	      <property name="label">Deleting account xxx</property>
+	      <property name="use_underline">False</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>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="transactions">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label8477423">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;b&gt;Transactions&lt;/b&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</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="GtkAlignment" id="alignment8">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">1</property>
+		  <property name="yscale">1</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">12</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkTable" id="table8">
+		      <property name="visible">True</property>
+		      <property name="n_rows">4</property>
+		      <property name="n_columns">2</property>
+		      <property name="homogeneous">False</property>
+		      <property name="row_spacing">0</property>
+		      <property name="column_spacing">12</property>
+
+		      <child>
+			<widget class="Custom" id="tmas">
+			  <property name="visible">True</property>
+			  <property name="sensitive">False</property>
+			  <property name="creation_function">gnc_account_sel_new</property>
+			  <property name="int1">0</property>
+			  <property name="int2">0</property>
+			  <property name="last_modification_time">Fri, 02 Dec 2005 04:05:05 GMT</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">1</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">3</property>
+			  <property name="bottom_attach">4</property>
+			  <property name="y_options">fill</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkRadioButton" id="tmrb">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">M_ove to:</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">True</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">1</property>
+			  <property name="top_attach">3</property>
+			  <property name="bottom_attach">4</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkRadioButton" id="tdrb">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">Delete all _transactions</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">False</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			  <property name="group">tmrb</property>
+			  <signal name="toggled" handler="gppat_set_insensitive_iff_rb_active" object="tmas" last_modification_time="Sat, 10 Dec 2005 22:28:06 GMT"/>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">2</property>
+			  <property name="bottom_attach">3</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkLabel" id="trans_rw">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">This account contains transactions. What would you like to do with these transactions?</property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">True</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">1</property>
+			  <property name="bottom_attach">2</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkLabel" id="trans_ro">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">This account contains read-only transactions which may not be deleted.</property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">True</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">0</property>
+			  <property name="bottom_attach">1</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="subaccounts">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label8477419">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;b&gt;Sub-accounts&lt;/b&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</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="GtkAlignment" id="alignment7">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">1</property>
+		  <property name="yscale">1</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">12</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkTable" id="table7">
+		      <property name="visible">True</property>
+		      <property name="n_rows">3</property>
+		      <property name="n_columns">2</property>
+		      <property name="homogeneous">False</property>
+		      <property name="row_spacing">0</property>
+		      <property name="column_spacing">12</property>
+
+		      <child>
+			<widget class="GtkLabel" id="label8477420">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">This account contains sub-accounts.  What would you like to do with these sub-accounts?</property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">True</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">0</property>
+			  <property name="bottom_attach">1</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkRadioButton" id="damrb">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">_Move to:</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">True</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			  <signal name="toggled" handler="gppat_set_insensitive_iff_rb_active" object="subaccount_trans" last_modification_time="Sat, 10 Dec 2005 22:26:11 GMT"/>
+			  <signal name="toggled" handler="gppat_populate_tmas_list" object="tmas" last_modification_time="Sat, 10 Dec 2005 22:26:02 GMT"/>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">1</property>
+			  <property name="top_attach">2</property>
+			  <property name="bottom_attach">3</property>
+			  <property name="x_options"></property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkRadioButton" id="dadrb">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">Delete all _subaccounts</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">False</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			  <property name="group">damrb</property>
+			  <signal name="toggled" handler="gppat_set_insensitive_iff_rb_active" object="damas" last_modification_time="Sat, 10 Dec 2005 22:27:29 GMT"/>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">1</property>
+			  <property name="bottom_attach">2</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="Custom" id="damas">
+			  <property name="visible">True</property>
+			  <property name="sensitive">False</property>
+			  <property name="creation_function">gnc_account_sel_new</property>
+			  <property name="int1">0</property>
+			  <property name="int2">0</property>
+			  <property name="last_modification_time">Fri, 02 Dec 2005 04:04:31 GMT</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">1</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">2</property>
+			  <property name="bottom_attach">3</property>
+			  <property name="y_options">fill</property>
+			</packing>
+		      </child>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="subaccount_trans">
+	      <property name="visible">True</property>
+	      <property name="sensitive">False</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label8477429">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;b&gt;Sub-account Transactions&lt;/b&gt;</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">False</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</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="GtkAlignment" id="alignment9">
+		  <property name="visible">True</property>
+		  <property name="xalign">0.5</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xscale">1</property>
+		  <property name="yscale">1</property>
+		  <property name="top_padding">0</property>
+		  <property name="bottom_padding">0</property>
+		  <property name="left_padding">12</property>
+		  <property name="right_padding">0</property>
+
+		  <child>
+		    <widget class="GtkTable" id="table9">
+		      <property name="visible">True</property>
+		      <property name="n_rows">4</property>
+		      <property name="n_columns">2</property>
+		      <property name="homogeneous">False</property>
+		      <property name="row_spacing">0</property>
+		      <property name="column_spacing">12</property>
+
+		      <child>
+			<widget class="Custom" id="dtmas">
+			  <property name="visible">True</property>
+			  <property name="sensitive">False</property>
+			  <property name="creation_function">gnc_account_sel_new</property>
+			  <property name="int1">0</property>
+			  <property name="int2">0</property>
+			  <property name="last_modification_time">Fri, 02 Dec 2005 04:05:05 GMT</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">1</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">3</property>
+			  <property name="bottom_attach">4</property>
+			  <property name="y_options">fill</property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkRadioButton" id="dtmrb">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">M_ove to:</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">True</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">1</property>
+			  <property name="top_attach">3</property>
+			  <property name="bottom_attach">4</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkRadioButton" id="dtdrb">
+			  <property name="visible">True</property>
+			  <property name="can_focus">True</property>
+			  <property name="label" translatable="yes">Delete all _transactions</property>
+			  <property name="use_underline">True</property>
+			  <property name="relief">GTK_RELIEF_NORMAL</property>
+			  <property name="focus_on_click">True</property>
+			  <property name="active">False</property>
+			  <property name="inconsistent">False</property>
+			  <property name="draw_indicator">True</property>
+			  <property name="group">dtmrb</property>
+			  <signal name="toggled" handler="gppat_set_insensitive_iff_rb_active" object="dtmas" last_modification_time="Sat, 10 Dec 2005 22:27:50 GMT"/>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">2</property>
+			  <property name="bottom_attach">3</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkLabel" id="sa_trans_rw">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">One or more sub- accounts contain transactions. What would you like to do with these transactions?</property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">True</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">1</property>
+			  <property name="bottom_attach">2</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+
+		      <child>
+			<widget class="GtkLabel" id="sa_trans_ro">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">One or more sub-accounts contain read-only transactions which may not be deleted.</property>
+			  <property name="use_underline">False</property>
+			  <property name="use_markup">False</property>
+			  <property name="justify">GTK_JUSTIFY_LEFT</property>
+			  <property name="wrap">True</property>
+			  <property name="selectable">False</property>
+			  <property name="xalign">0</property>
+			  <property name="yalign">0.5</property>
+			  <property name="xpad">0</property>
+			  <property name="ypad">0</property>
+			</widget>
+			<packing>
+			  <property name="left_attach">0</property>
+			  <property name="right_attach">2</property>
+			  <property name="top_attach">0</property>
+			  <property name="bottom_attach">1</property>
+			  <property name="x_options">fill</property>
+			  <property name="y_options"></property>
+			</packing>
+		      </child>
+		    </widget>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">True</property>
+		  <property name="fill">True</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">False</property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
 </glade-interface>

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c	2005-12-11 00:52:12 UTC (rev 12157)
@@ -47,7 +47,9 @@
 #include "dialog-account.h"
 #include "dialog-options.h"
 #include "dialog-transfer.h"
+#include "dialog-utils.h"
 #include "druid-merge.h"
+#include "gnc-account-sel.h"
 #include "gnc-component-manager.h"
 #include "gnc-engine.h"
 #include "gnc-gnome-utils.h"
@@ -118,6 +120,8 @@
 
 static void gnc_plugin_page_account_tree_selection_changed_cb (GtkTreeSelection *selection,
 							       GncPluginPageAccountTree *page);
+void gppat_populate_tmas_list(GtkToggleButton *dmrb, gpointer tmas);
+void gppat_set_insensitive_iff_rb_active(GtkToggleButton *b, GtkWidget *widget);
 
 /* Command callbacks */
 static void gnc_plugin_page_account_tree_cmd_new_account (GtkAction *action, GncPluginPageAccountTree *plugin_page);
@@ -164,7 +168,7 @@
 	{ "EditEditAccountAction", GNC_STOCK_EDIT_ACCOUNT, N_("_Edit Account"), "<control>e",
 	  N_("Edit the selected account"),
 	  G_CALLBACK (gnc_plugin_page_account_tree_cmd_edit_account) },
-	{ "EditDeleteAccountAction", GNC_STOCK_DELETE_ACCOUNT, N_("_Delete Account"), NULL,
+	{ "EditDeleteAccountAction", GNC_STOCK_DELETE_ACCOUNT, N_("_Delete Account..."), NULL,
 	  N_("Delete selected account"),
 	  G_CALLBACK (gnc_plugin_page_account_tree_cmd_delete_account) },
 	{ "EditAccountViewOptionsAction", GTK_STOCK_PROPERTIES, N_("Account Tree _Options..."), NULL,
@@ -952,74 +956,355 @@
 	return GINT_TO_POINTER (helper_res->has_splits || helper_res->has_ro_splits);
 }
 
+/***
+ *** The OK button of a Delete Account dialog is insensitive if
+ *** and only if a sensitive account selector contains no accounts.
+ ***/
 static void
+set_ok_sensitivity(GtkWidget *dialog)
+{
+  GtkWidget *button;
+  gpointer dmas, tmas;
+  gboolean sensitive;
+
+  dmas = g_object_get_data(G_OBJECT(dialog), "dmas");
+  tmas = g_object_get_data(G_OBJECT(dialog), "tmas");
+  sensitive = (((NULL == dmas) ||
+		(!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(dmas)) ||
+		 GTK_LIST(GNC_ACCOUNT_SEL(dmas)->combo->list)->children)) &&
+	       ((NULL == tmas) ||
+		(!GTK_WIDGET_IS_SENSITIVE(GTK_WIDGET(tmas)) ||
+		 GTK_LIST(GNC_ACCOUNT_SEL(tmas)->combo->list)->children)));
+
+  button = gnc_glade_lookup_widget(dialog, "deletebutton");
+  gtk_widget_set_sensitive(button, sensitive);
+}
+
+/***
+ *** GNCAccountSel has an odd habit of adding a
+ *** blank item when its list is otherwise empty.
+ ***/
+
+static void
+exclude_account(GtkWidget *item,
+		gpointer name)
+{
+  char *text;
+
+  gtk_label_get(GTK_LABEL(GTK_BIN(item)->child), &text);
+  if ((0 == strlen(text)) || (0 == strcmp(text, name))) {
+    gtk_widget_destroy(GTK_WIDGET(item));
+  }
+}
+
+static void
+exclude_account_subtree(GtkWidget *item,
+			gpointer prefix)
+{
+  char *text;
+
+  gtk_label_get(GTK_LABEL(GTK_BIN(item)->child), &text);
+  if ((0 == strlen(text)) || 0 == strncmp(text, prefix, strlen(prefix))) {
+    gtk_widget_destroy(GTK_WIDGET(item));
+  }
+}
+
+static gint
+compare_listitem_text(gconstpointer item,
+		      gconstpointer entrytext)
+{
+  char *text;
+
+  gtk_label_get(GTK_LABEL(GTK_BIN(item)->child), &text);
+  return strcmp(text, entrytext);
+}
+
+static void
+gppat_populate_gas_list(GtkWidget *dialog,
+			GNCAccountSel *gas,
+			gboolean exclude_subaccounts)
+{
+  GtkList *list;
+  GtkEntry *entry;
+  gpointer name, filter;
+
+  g_return_if_fail(GTK_IS_DIALOG(dialog));
+  if (gas == NULL)
+    return;
+  list = GTK_LIST(gas->combo->list);
+  entry = GTK_ENTRY(gas->combo->entry);
+  name = g_object_get_data(G_OBJECT(dialog), "name");
+  filter = g_object_get_data(G_OBJECT(dialog), "filter");
+
+  /* Setting the account type filter triggers GNCAccountSel population. */
+  gnc_account_sel_set_acct_filters (gas, filter);
+
+  /* Accounts to be deleted must be removed. */
+  gtk_container_foreach(GTK_CONTAINER(list), (exclude_subaccounts ?
+					      exclude_account_subtree :
+					      exclude_account), name);
+
+  /* The entry widget may need to be reset. */
+  if (NULL == g_list_find_custom(list->children, 
+				 gtk_entry_get_text(entry),
+				 compare_listitem_text)) {
+    gtk_entry_set_text(entry, "");
+    gtk_list_select_item(list, 0);
+  }
+
+  /* The sensitivity of the OK button needs to be reevaluated. */
+  set_ok_sensitivity(GTK_WIDGET(dialog));
+}
+
+void
+gppat_populate_tmas_list(GtkToggleButton *damrb,
+			 gpointer tmas)
+{
+  GtkWidget *dialog;
+
+  /* Cannot move transactions to subaccounts if they are to be deleted. */
+  dialog = gnc_glade_lookup_widget(GTK_WIDGET(damrb), "Delete Account");
+  gppat_populate_gas_list(dialog, tmas, !gtk_toggle_button_get_active(damrb));
+}
+
+void
+gppat_set_insensitive_iff_rb_active(GtkToggleButton *b, GtkWidget *widget)
+{
+  gtk_widget_set_sensitive(widget, !gtk_toggle_button_get_active(b));
+  set_ok_sensitivity(gtk_widget_get_toplevel(widget));
+}
+
+static void
 gnc_plugin_page_account_tree_cmd_delete_account (GtkAction *action, GncPluginPageAccountTree *page)
 {
-	Account *account = gnc_plugin_page_account_tree_get_current_account (page);
+  Account *account = gnc_plugin_page_account_tree_get_current_account (page);
+  gchar *acct_name;
+  GList *splits;
+  AccountGroup *children;
+  delete_helper_t delete_res = { FALSE, FALSE };
+  GtkWidget *widget;
+  GtkWidget *window;
+  GtkWidget *dialog = NULL;
+  GNCAccountSel *damas = NULL; /* descendant account move account selector */
+  GNCAccountSel *dtmas = NULL; /* descendant transaction move account selector */
+  GNCAccountSel *tmas = NULL; /* transaction move account selector */
+  gint response;
+  Account *ta = NULL; /* transaction adopter */
+  Account *daa = NULL; /* descendant account adopter */
+  Account *dta = NULL; /* descendant transaction adopter */
 
-	const char *no_splits_no_children = _("Are you sure you want to delete the %s account?");
-	const char *no_splits = _("Are you sure you want to delete the %s\n"
-				  "account and all its children?");
-	const char *acct_has_splits =
-		_("This account contains transactions.  Are you sure you\n"
-		  "want to delete the %s account?");
-	const char *child_has_splits =
-		_("One (or more) children of this account contain\n"
-		  "transactions.  Are you sure you want to delete the\n"
-		  "%s account and all its children?");
-	const char *acct_has_ro_splits =
-		_("This account contains read-only transactions.  You " "may not delete %s.");
-	const char *child_has_ro_splits =
-		_("One (or more) children of this account contains "
-		  "read-only transactions.  You may not delete %s.");
-	const char *format;
-	char *name;
-	GList *splits;
+  if (NULL == account)
+    return;
 
-	g_return_if_fail (account != NULL);
+  window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
+  acct_name = xaccAccountGetFullName(account, gnc_get_account_separator ());
+  if (!acct_name) {
+    acct_name = g_strdup (_("(no name)"));
+  }
 
-	name = xaccAccountGetFullName (account, gnc_get_account_separator ());
-	if (!name)
-		name = g_strdup ("");
+  splits = xaccAccountGetSplitList(account);
+  children = xaccAccountGetChildren(account);
 
-	if ((splits = xaccAccountGetSplitList (account)) != NULL) {
-		/* Check for RO txns -- if there are any, disallow deletion */
-		for (; splits; splits = splits->next) {
-			Split *s = splits->data;
-			Transaction *txn = xaccSplitGetParent (s);
-			if (xaccTransGetReadOnly (txn)) {
-				gnc_error_dialog (NULL, acct_has_ro_splits, name);
-				return;
-			}
-		}
-		format = acct_has_splits;
-	} else {
-		AccountGroup *children;
-		delete_helper_t delete_res = { FALSE, FALSE };
+  /*
+   * If the account has transactions or child accounts then conduct a
+   * dialog to allow the user to specify what should be done with them.
+   */
+  if ((NULL != splits) || (NULL != children)) {
+    GList *filter;
+    GladeXML *xml;
+    GtkWidget *label;
+    gchar *message;
 
-		children = xaccAccountGetChildren (account);
-		xaccGroupForEachAccount (children, delete_account_helper, &delete_res, TRUE);
+    xml = gnc_glade_xml_new ("account.glade", "Delete Account");
+    dialog = glade_xml_get_widget (xml, "Delete Account");
+    gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window));
+    glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, dialog);
 
-		/* Check for RO txns in the children -- disallow deletion if there are any */
-		if (delete_res.has_ro_splits) {
-			gnc_error_dialog (NULL, child_has_ro_splits, name);
-			return;
+    label = glade_xml_get_widget (xml, "header");
+    message = g_strdup_printf("Deleting account %s", acct_name);
+    gtk_label_set_text(GTK_LABEL(label), message);
+    g_free(message);
 
-		} else if (delete_res.has_splits)
-			format = child_has_splits;
-		else
-			format = children ? no_splits : no_splits_no_children;
+    /*
+     * Reparent only to accounts of the same
+     * type as the one being deleted.
+     */
+    filter = g_list_prepend(NULL, (gpointer)xaccAccountGetType(account));
+    g_object_set_data(G_OBJECT(dialog), "filter", filter);
+    g_object_set_data(G_OBJECT(dialog), "name", acct_name);
+
+    /*
+     * Adjust the dialog based on whether the account has
+     * transactions.
+     */
+    if (splits) {
+      delete_helper_t delete_res2 = { FALSE, FALSE };
+
+      tmas = GNC_ACCOUNT_SEL(glade_xml_get_widget (xml, "tmas"));
+      gppat_populate_gas_list(dialog, tmas, FALSE);
+
+      delete_account_helper(account, &delete_res2);
+      if (delete_res2.has_ro_splits) {
+	gtk_widget_destroy(glade_xml_get_widget (xml, "trans_rw"));
+	widget = glade_xml_get_widget (xml, "tdrb");
+	gtk_widget_set_sensitive(widget, FALSE);
+      } else {
+	gtk_widget_destroy(glade_xml_get_widget (xml, "trans_ro"));
+      }
+    } else {
+      gtk_widget_destroy(glade_xml_get_widget (xml, "transactions"));
+    }
+
+    /*
+     * Adjust the dialog based on whether the account has children.
+     */
+    if (children != NULL) {
+      /*
+       * Check for RO txns in descendants
+       */
+      xaccGroupForEachAccount(children, delete_account_helper,
+			      &delete_res, TRUE);
+      if (delete_res.has_ro_splits) {
+	gtk_widget_destroy(glade_xml_get_widget (xml, "sa_trans_rw"));
+	widget = glade_xml_get_widget (xml, "dtdrb");
+	gtk_widget_set_sensitive(widget, FALSE);
+      } else if (delete_res.has_splits) {
+	gtk_widget_destroy(glade_xml_get_widget (xml, "sa_trans_ro"));
+      } else {
+	gtk_widget_destroy(glade_xml_get_widget (xml, "subaccount_trans"));
+      }
+      damas = GNC_ACCOUNT_SEL(glade_xml_get_widget (xml, "damas"));
+      gppat_populate_gas_list(dialog, damas, TRUE);
+      dtmas = GNC_ACCOUNT_SEL(glade_xml_get_widget (xml, "dtmas"));
+      gppat_populate_gas_list(dialog, dtmas, TRUE);
+    } else {
+      gtk_widget_destroy(glade_xml_get_widget (xml, "subaccounts"));
+      gtk_widget_destroy(glade_xml_get_widget (xml, "subaccount_trans"));
+    }
+
+    /* default to cancel */
+    gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
+
+    /*
+     * Note that one effect of the modal dialog is preventing
+     * the account selectors from being repopulated.
+     */ 
+    gtk_widget_show_all(dialog);
+    response = gtk_dialog_run(GTK_DIALOG(dialog));
+    if (GTK_RESPONSE_ACCEPT != response) {
+      /* Account deletion is cancelled, so clean up and return. */
+      gtk_widget_destroy(dialog);
+      g_list_free(filter);
+      g_free(acct_name);
+      return;
+    }
+    if (tmas && GTK_WIDGET_IS_SENSITIVE(tmas))
+      ta = gnc_account_sel_get_account(tmas);
+    if (damas && GTK_WIDGET_IS_SENSITIVE(damas))
+      daa = gnc_account_sel_get_account(damas);
+    if (dtmas && GTK_WIDGET_IS_SENSITIVE(dtmas))
+      dta = gnc_account_sel_get_account(dtmas);
+    gtk_widget_destroy(dialog);
+    g_list_free(filter);
+  } /* (NULL != splits) || (NULL != children) */
+
+  /*
+   * Present a message to the user which specifies what will be
+   * deleted and what will be reparented, then ask for verification.
+   */
+  {
+    const char *format = _("The account %s will be deleted.");
+    char *lines[8];
+    char *message;
+    char *name;
+    int i = 0;
+
+    lines[0] = g_strdup_printf(format, acct_name);
+    if (splits) {
+      if (ta) {
+	name = xaccAccountGetFullName(ta, gnc_get_account_separator ());
+	format = _("All transactions in this account will be moved to "
+		   "the account %s.");
+	lines[++i] = g_strdup_printf(format, name);
+      } else if (splits) {
+	format = _("All transactions in this account will be deleted.");
+	lines[++i] = g_strdup_printf(format);
+      }
+    }
+    if (children) {
+      if (daa) {
+	name = xaccAccountGetFullName(daa, gnc_get_account_separator ());
+	format = _("All of its sub-accounts will be moved to "
+		   "the account %s.");
+	lines[++i] = g_strdup_printf(format, name);
+      } else {
+	format = _("All of its subaccounts will be deleted.");
+	lines[++i] = g_strdup_printf(format);
+	if (dta) {
+	  name = xaccAccountGetFullName(ta, gnc_get_account_separator ());
+	  format = _("All sub-account transactions will be moved to "
+		     "the account %s.");
+	  lines[++i] = g_strdup_printf(format, name);
+	} else if (delete_res.has_splits) {
+	  format = _("All sub-account transactions will be deleted.");
+	  lines[++i] = g_strdup_printf(format);
 	}
+      }
+    }
+    lines[++i] = _("Are you sure you want to do this ?");
+    lines[i] = NULL;
+    i--; /* Don't try to free the constant question. */
+    message = g_strjoinv(" ", lines);
+    while (i--) {
+	g_free(lines[i]);
+    }
 
-	if (gnc_verify_dialog (NULL, FALSE, format, name)) {
-		gnc_suspend_gui_refresh ();
+    dialog =  gtk_message_dialog_new(GTK_WINDOW(window),
+				       GTK_DIALOG_DESTROY_WITH_PARENT,
+				       GTK_MESSAGE_QUESTION,
+				       GTK_BUTTONS_NONE,
+				       message);
+    g_free(message);
+    gtk_dialog_add_buttons(GTK_DIALOG(dialog),
+			     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+			     GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
+			     (gchar *)NULL);
+    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
+    response = gtk_dialog_run(GTK_DIALOG(dialog));
+    gtk_widget_destroy(dialog);
 
-		xaccAccountBeginEdit (account);
-		xaccAccountDestroy (account);
+    if (GTK_RESPONSE_ACCEPT == response) {
+      gnc_suspend_gui_refresh ();
+      xaccAccountBeginEdit (account);
+      if (NULL != daa) {
+	GList *acct_list, *ptr;
 
-		gnc_resume_gui_refresh ();
-	}
-	g_free (name);
+	xaccAccountBeginEdit (daa);
+	acct_list = xaccGroupGetSubAccounts(children);
+	for (ptr = acct_list; ptr; ptr = g_list_next(ptr))
+	  xaccAccountInsertSubAccount (daa, ptr->data);
+	g_list_free(acct_list);
+	xaccAccountCommitEdit (daa);
+      } else if (NULL != dta) {
+	/* Move the splits of its subaccounts, if any. */
+	xaccGroupForEachAccount (children,
+				 (gpointer (*)(Account *, gpointer))
+				 xaccAccountMoveAllSplits,
+				 dta, TRUE);
+      }
+      if (NULL != ta) {
+	/* Move the splits of the account to be deleted. */
+	xaccAccountMoveAllSplits (account, ta);
+      }
+      /*
+       * Finally, delete the account, any subaccounts it may still
+       * have, and any splits it or its subaccounts may still have.
+       */
+      xaccAccountDestroy (account);
+      gnc_resume_gui_refresh ();
+    }
+  }
+  g_free(acct_name);
 }
 
 /******************************/

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c	2005-12-11 00:50:57 UTC (rev 12156)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-account.c	2005-12-11 00:52:12 UTC (rev 12157)
@@ -1406,8 +1406,8 @@
   GtkTreeIter iter;
 
   if (gtk_tree_path_up (path)) {
-    gtk_tree_model_get_iter (GTK_TREE_MODEL(model), &iter, path);
-    gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL(model), path, &iter);
+    if (gtk_tree_model_get_iter (GTK_TREE_MODEL(model), &iter, path))
+      gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL(model), path, &iter);
   }
 
   do {



More information about the gnucash-changes mailing list