mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-08-18 00:45:04 -05:00
Manage account windows with component manager.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3280 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -38,7 +38,7 @@
|
|||||||
*
|
*
|
||||||
* entity: the GUID of the entity generating the event
|
* entity: the GUID of the entity generating the event
|
||||||
* event_type: the type of event -- this should be one of the
|
* event_type: the type of event -- this should be one of the
|
||||||
* GNCEngineEventType values, not a combination.
|
* single-bit GNCEngineEventType values, not a combination.
|
||||||
*/
|
*/
|
||||||
void gnc_engine_generate_event (GUID *entity, GNCEngineEventType event_type);
|
void gnc_engine_generate_event (GUID *entity, GNCEngineEventType event_type);
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,9 @@ gnc_engine_generate_event (GUID *entity, GNCEngineEventType event_type)
|
|||||||
|
|
||||||
switch (event_type)
|
switch (event_type)
|
||||||
{
|
{
|
||||||
|
case GNC_EVENT_NONE:
|
||||||
|
return;
|
||||||
|
|
||||||
case GNC_EVENT_CREATE:
|
case GNC_EVENT_CREATE:
|
||||||
case GNC_EVENT_MODIFY:
|
case GNC_EVENT_MODIFY:
|
||||||
case GNC_EVENT_DESTROY:
|
case GNC_EVENT_DESTROY:
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
GNC_EVENT_NONE = 0,
|
||||||
GNC_EVENT_CREATE = 1 << 0,
|
GNC_EVENT_CREATE = 1 << 0,
|
||||||
GNC_EVENT_MODIFY = 1 << 1,
|
GNC_EVENT_MODIFY = 1 << 1,
|
||||||
GNC_EVENT_DESTROY = 1 << 2,
|
GNC_EVENT_DESTROY = 1 << 2,
|
||||||
@@ -42,7 +43,7 @@ typedef enum
|
|||||||
* Callback invoked when an engine event occurs.
|
* Callback invoked when an engine event occurs.
|
||||||
*
|
*
|
||||||
* entity: GUID of entity generating event
|
* entity: GUID of entity generating event
|
||||||
* event_type: one of GNCEngineEventType, not a combination
|
* event_type: one of the single-bit GNCEngineEventTypes, not a combination
|
||||||
* user_data: user_data supplied when callback was registered.
|
* user_data: user_data supplied when callback was registered.
|
||||||
*/
|
*/
|
||||||
typedef void (*GNCEngineEventHandler) (GUID *entity,
|
typedef void (*GNCEngineEventHandler) (GUID *entity,
|
||||||
|
|||||||
@@ -292,13 +292,14 @@ gnc_register_gui_component (const char *component_class,
|
|||||||
if (!component_class)
|
if (!component_class)
|
||||||
{
|
{
|
||||||
PERR ("no class specified");
|
PERR ("no class specified");
|
||||||
return G_MININT;
|
return NO_COMPONENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look for a free handler id */
|
/* look for a free handler id */
|
||||||
component_id = next_component_id;
|
component_id = next_component_id;
|
||||||
|
|
||||||
while (find_component (component_id))
|
while (find_component (component_id))
|
||||||
|
if (++component_id == NO_COMPONENT)
|
||||||
component_id++;
|
component_id++;
|
||||||
|
|
||||||
/* found one, add the handler */
|
/* found one, add the handler */
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include "gnc-event.h"
|
#include "gnc-event.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define NO_COMPONENT (-1)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GNCEngineEventType event_mask;
|
GNCEngineEventType event_mask;
|
||||||
@@ -133,7 +135,7 @@ void gnc_component_manager_shutdown (void);
|
|||||||
* is not watching anything, and thus will
|
* is not watching anything, and thus will
|
||||||
* not receive refresh handlers.
|
* not receive refresh handlers.
|
||||||
*
|
*
|
||||||
* Return: id of component
|
* Return: id of component, or NO_COMPONENT, if error
|
||||||
*/
|
*/
|
||||||
gint gnc_register_gui_component (const char *component_class,
|
gint gnc_register_gui_component (const char *component_class,
|
||||||
GNCComponentRefreshHandler refresh_handler,
|
GNCComponentRefreshHandler refresh_handler,
|
||||||
|
|||||||
+67
-34
@@ -38,6 +38,7 @@
|
|||||||
#include "global-options.h"
|
#include "global-options.h"
|
||||||
#include "gnc-commodity-edit.h"
|
#include "gnc-commodity-edit.h"
|
||||||
#include "gnc-commodity.h"
|
#include "gnc-commodity.h"
|
||||||
|
#include "gnc-component-manager.h"
|
||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-ui.h"
|
#include "gnc-ui.h"
|
||||||
@@ -47,6 +48,9 @@
|
|||||||
#include "window-main.h"
|
#include "window-main.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define DIALOG_NEW_ACCOUNT_CM_CLASS "dialog-new-account"
|
||||||
|
#define DIALOG_EDIT_ACCOUNT_CM_CLASS "dialog-edit-account"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
NEW_ACCOUNT,
|
NEW_ACCOUNT,
|
||||||
@@ -82,7 +86,7 @@ struct _AccountWindow
|
|||||||
|
|
||||||
GtkWidget * tax_related_button;
|
GtkWidget * tax_related_button;
|
||||||
|
|
||||||
gint source;
|
gint component_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -94,9 +98,6 @@ static gint last_height = 0;
|
|||||||
|
|
||||||
static int last_used_account_type = BANK;
|
static int last_used_account_type = BANK;
|
||||||
|
|
||||||
static GList *new_account_windows = NULL;
|
|
||||||
static AccountWindow ** editAccountList = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
/** Declarations *********************************************************/
|
/** Declarations *********************************************************/
|
||||||
static void gnc_account_window_set_name (AccountWindow *aw);
|
static void gnc_account_window_set_name (AccountWindow *aw);
|
||||||
@@ -297,7 +298,7 @@ gnc_finish_ok (AccountWindow *aw)
|
|||||||
/* so it doesn't get freed on close */
|
/* so it doesn't get freed on close */
|
||||||
aw->account = NULL;
|
aw->account = NULL;
|
||||||
|
|
||||||
gnome_dialog_close (GNOME_DIALOG(aw->dialog));
|
gnc_close_gui_component (aw->component_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -449,21 +450,19 @@ gnc_account_change_currency_security(Account *account,
|
|||||||
|
|
||||||
while (stack != NULL)
|
while (stack != NULL)
|
||||||
{
|
{
|
||||||
Split *split;
|
|
||||||
GSList *pop;
|
GSList *pop;
|
||||||
gint i;
|
GList *node;
|
||||||
|
|
||||||
pop = stack;
|
pop = stack;
|
||||||
account = pop->data;
|
account = pop->data;
|
||||||
stack = g_slist_remove_link(stack, pop);
|
stack = g_slist_remove_link(stack, pop);
|
||||||
g_slist_free_1(pop);
|
g_slist_free_1(pop);
|
||||||
|
|
||||||
i = 0;
|
for (node = xaccAccountGetSplitList (account); node; node = node->next)
|
||||||
while ((split = xaccAccountGetSplit(account, i++)) != NULL)
|
|
||||||
{
|
{
|
||||||
|
Split *split = node->data;
|
||||||
Transaction *trans;
|
Transaction *trans;
|
||||||
Split *s;
|
GList *n;
|
||||||
gint j;
|
|
||||||
|
|
||||||
trans = xaccSplitGetParent(split);
|
trans = xaccSplitGetParent(split);
|
||||||
if (trans == NULL)
|
if (trans == NULL)
|
||||||
@@ -475,9 +474,9 @@ gnc_account_change_currency_security(Account *account,
|
|||||||
if (xaccTransIsCommonExclSCurrency(trans, security, split))
|
if (xaccTransIsCommonExclSCurrency(trans, security, split))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
j = 0;
|
for (n = xaccTransGetSplitList (trans); n; n = n->next)
|
||||||
while ((s = xaccTransGetSplit(trans, j++)) != NULL)
|
|
||||||
{
|
{
|
||||||
|
Split *s = n->data;
|
||||||
gboolean add_it = FALSE;
|
gboolean add_it = FALSE;
|
||||||
const gnc_commodity * commodity;
|
const gnc_commodity * commodity;
|
||||||
Account * a;
|
Account * a;
|
||||||
@@ -1003,7 +1002,7 @@ gnc_account_window_cancel_cb(GtkWidget * widget, gpointer data)
|
|||||||
{
|
{
|
||||||
AccountWindow *aw = data;
|
AccountWindow *aw = data;
|
||||||
|
|
||||||
gnome_dialog_close(GNOME_DIALOG(aw->dialog));
|
gnc_close_gui_component (aw->component_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1037,8 +1036,6 @@ gnc_account_window_destroy_cb (GtkObject *object, gpointer data)
|
|||||||
switch (aw->dialog_type)
|
switch (aw->dialog_type)
|
||||||
{
|
{
|
||||||
case NEW_ACCOUNT:
|
case NEW_ACCOUNT:
|
||||||
new_account_windows = g_list_remove (new_account_windows, object);
|
|
||||||
|
|
||||||
if (aw->account != NULL)
|
if (aw->account != NULL)
|
||||||
{
|
{
|
||||||
xaccFreeAccount (aw->account);
|
xaccFreeAccount (aw->account);
|
||||||
@@ -1046,11 +1043,9 @@ gnc_account_window_destroy_cb (GtkObject *object, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUG ("account add window destroyed\n");
|
DEBUG ("account add window destroyed\n");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EDIT_ACCOUNT:
|
case EDIT_ACCOUNT:
|
||||||
REMOVE_FROM_LIST (AccountWindow, editAccountList, aw->account, account);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1058,6 +1053,8 @@ gnc_account_window_destroy_cb (GtkObject *object, gpointer data)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gnc_unregister_gui_component (aw->component_id);
|
||||||
|
|
||||||
xaccFreeAccount (aw->top_level_account);
|
xaccFreeAccount (aw->top_level_account);
|
||||||
aw->top_level_account = NULL;
|
aw->top_level_account = NULL;
|
||||||
|
|
||||||
@@ -1397,6 +1394,14 @@ gnc_account_window_set_name (AccountWindow *aw)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
close_handler (gpointer user_data)
|
||||||
|
{
|
||||||
|
AccountWindow *aw = user_data;
|
||||||
|
|
||||||
|
gnome_dialog_close (GNOME_DIALOG (aw->dialog));
|
||||||
|
}
|
||||||
|
|
||||||
static AccountWindow *
|
static AccountWindow *
|
||||||
gnc_ui_new_account_window_internal (Account *base_account,
|
gnc_ui_new_account_window_internal (Account *base_account,
|
||||||
GList *subaccount_names)
|
GList *subaccount_names)
|
||||||
@@ -1409,6 +1414,9 @@ gnc_ui_new_account_window_internal (Account *base_account,
|
|||||||
aw->dialog_type = NEW_ACCOUNT;
|
aw->dialog_type = NEW_ACCOUNT;
|
||||||
aw->account = xaccMallocAccount ();
|
aw->account = xaccMallocAccount ();
|
||||||
|
|
||||||
|
aw->component_id = gnc_register_gui_component (DIALOG_NEW_ACCOUNT_CM_CLASS,
|
||||||
|
NULL, close_handler, aw);
|
||||||
|
|
||||||
if (base_account)
|
if (base_account)
|
||||||
aw->type = xaccAccountGetType (base_account);
|
aw->type = xaccAccountGetType (base_account);
|
||||||
else
|
else
|
||||||
@@ -1431,8 +1439,6 @@ gnc_ui_new_account_window_internal (Account *base_account,
|
|||||||
|
|
||||||
gnc_account_window_set_name (aw);
|
gnc_account_window_set_name (aw);
|
||||||
|
|
||||||
new_account_windows = g_list_prepend (new_account_windows, aw->dialog);
|
|
||||||
|
|
||||||
commodity = gnc_lookup_currency_option ("International",
|
commodity = gnc_lookup_currency_option ("International",
|
||||||
"Default Currency",
|
"Default Currency",
|
||||||
gnc_locale_default_currency ());
|
gnc_locale_default_currency ());
|
||||||
@@ -1450,12 +1456,13 @@ gnc_ui_new_account_window_internal (Account *base_account,
|
|||||||
return aw;
|
return aw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* gnc_ui_new_account_window *
|
* gnc_ui_new_account_window *
|
||||||
* opens up a window to create a new account. *
|
* opens up a window to create a new account. *
|
||||||
* *
|
* *
|
||||||
* Args: group - not used *
|
* Args: group - not used *
|
||||||
* Return: NewAccountWindow object *
|
* Return: AccountWindow object *
|
||||||
\*******************************************************************/
|
\*******************************************************************/
|
||||||
AccountWindow *
|
AccountWindow *
|
||||||
gnc_ui_new_account_window (AccountGroup *this_is_not_used)
|
gnc_ui_new_account_window (AccountGroup *this_is_not_used)
|
||||||
@@ -1561,12 +1568,26 @@ gnc_ui_new_accounts_from_name_window (const char *name)
|
|||||||
gtk_signal_connect(GTK_OBJECT (aw->dialog), "close",
|
gtk_signal_connect(GTK_OBJECT (aw->dialog), "close",
|
||||||
GTK_SIGNAL_FUNC (from_name_close_cb), &created_account);
|
GTK_SIGNAL_FUNC (from_name_close_cb), &created_account);
|
||||||
|
|
||||||
|
gtk_window_set_modal (GTK_WINDOW (aw->dialog), TRUE);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
return created_account;
|
return created_account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
find_by_account (gpointer find_data, gpointer user_data)
|
||||||
|
{
|
||||||
|
Account *account = find_data;
|
||||||
|
AccountWindow *aw = user_data;
|
||||||
|
|
||||||
|
if (!aw)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
return (aw->account == account);
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* gnc_ui_edit_account_window *
|
* gnc_ui_edit_account_window *
|
||||||
* opens up a window to edit an account *
|
* opens up a window to edit an account *
|
||||||
@@ -1583,11 +1604,20 @@ gnc_ui_edit_account_window(Account *account)
|
|||||||
if (account == NULL)
|
if (account == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
FETCH_FROM_LIST (AccountWindow, editAccountList, account, account, aw);
|
aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
|
||||||
|
find_by_account, account);
|
||||||
|
if (aw)
|
||||||
|
return aw;
|
||||||
|
|
||||||
|
aw = g_new0 (AccountWindow, 1);
|
||||||
|
|
||||||
aw->dialog_type = EDIT_ACCOUNT;
|
aw->dialog_type = EDIT_ACCOUNT;
|
||||||
aw->account = account;
|
aw->account = account;
|
||||||
aw->subaccount_names = NULL;
|
aw->subaccount_names = NULL;
|
||||||
|
|
||||||
|
aw->component_id = gnc_register_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
|
||||||
|
NULL, close_handler, aw);
|
||||||
|
|
||||||
gnc_account_window_create (aw);
|
gnc_account_window_create (aw);
|
||||||
|
|
||||||
gnc_account_to_ui (aw);
|
gnc_account_to_ui (aw);
|
||||||
@@ -1608,6 +1638,14 @@ gnc_ui_edit_account_window(Account *account)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroy_new_helper (const char *component_class,
|
||||||
|
gint component_id,
|
||||||
|
gpointer iter_data)
|
||||||
|
{
|
||||||
|
gnc_close_gui_component (component_id);
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* Function: gnc_ui_destroy_account_add_windows - destroy all open *
|
* Function: gnc_ui_destroy_account_add_windows - destroy all open *
|
||||||
* account add windows. *
|
* account add windows. *
|
||||||
@@ -1618,14 +1656,8 @@ gnc_ui_edit_account_window(Account *account)
|
|||||||
void
|
void
|
||||||
gnc_ui_destroy_account_add_windows (void)
|
gnc_ui_destroy_account_add_windows (void)
|
||||||
{
|
{
|
||||||
GnomeDialog *dialog;
|
gnc_forall_gui_components (DIALOG_NEW_ACCOUNT_CM_CLASS,
|
||||||
|
destroy_new_helper, NULL);
|
||||||
while (new_account_windows != NULL)
|
|
||||||
{
|
|
||||||
dialog = GNOME_DIALOG(new_account_windows->data);
|
|
||||||
|
|
||||||
gnome_dialog_close(dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1641,7 +1673,8 @@ gnc_ui_refresh_edit_account_window(Account *account)
|
|||||||
{
|
{
|
||||||
AccountWindow *aw;
|
AccountWindow *aw;
|
||||||
|
|
||||||
FIND_IN_LIST (AccountWindow, editAccountList, account, account, aw);
|
aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
|
||||||
|
find_by_account, account);
|
||||||
if (aw == NULL)
|
if (aw == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1654,12 +1687,12 @@ gnc_ui_destroy_edit_account_window (Account * account)
|
|||||||
{
|
{
|
||||||
AccountWindow *aw;
|
AccountWindow *aw;
|
||||||
|
|
||||||
FIND_IN_LIST (AccountWindow, editAccountList, account, account, aw);
|
aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
|
||||||
|
find_by_account, account);
|
||||||
if (aw == NULL)
|
if (aw == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gnome_dialog_close(GNOME_DIALOG(aw->dialog));
|
gnc_close_gui_component (aw->component_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user