mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Use component manager to manage transfer dialogs.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3278 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
529b43e365
commit
74b06ac5c2
@ -19,12 +19,16 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "gnc-component-manager.h"
|
#include "gnc-component-manager.h"
|
||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
|
|
||||||
|
|
||||||
/** Declarations ****************************************************/
|
/** Declarations ****************************************************/
|
||||||
|
|
||||||
|
#define CM_DEBUG 0
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GNCIdType entity_type;
|
GNCIdType entity_type;
|
||||||
@ -72,6 +76,26 @@ static void gnc_gui_refresh_internal (void);
|
|||||||
|
|
||||||
/** Implementations *************************************************/
|
/** Implementations *************************************************/
|
||||||
|
|
||||||
|
#if CM_DEBUG
|
||||||
|
static void
|
||||||
|
dump_components (void)
|
||||||
|
{
|
||||||
|
GList *node;
|
||||||
|
|
||||||
|
fprintf (stderr, "Components:\n");
|
||||||
|
|
||||||
|
for (node = components; node; node = node->next)
|
||||||
|
{
|
||||||
|
ComponentInfo *ci = node->data;
|
||||||
|
|
||||||
|
fprintf (stderr, " %s:\t%d\n",
|
||||||
|
ci->component_class, ci->component_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
destroy_helper (gpointer key, gpointer value, gpointer user_data)
|
destroy_helper (gpointer key, gpointer value, gpointer user_data)
|
||||||
{
|
{
|
||||||
@ -296,6 +320,12 @@ gnc_register_gui_component (const char *component_class,
|
|||||||
/* update id for next registration */
|
/* update id for next registration */
|
||||||
next_component_id = component_id + 1;
|
next_component_id = component_id + 1;
|
||||||
|
|
||||||
|
#if CM_DEBUG
|
||||||
|
fprintf (stderr, "Register component %d in class %s\n",
|
||||||
|
component_id, component_class);
|
||||||
|
dump_components ();
|
||||||
|
#endif
|
||||||
|
|
||||||
return component_id;
|
return component_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,6 +400,11 @@ gnc_unregister_gui_component (gint component_id)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CM_DEBUG
|
||||||
|
fprintf (stderr, "Unregister component %d in class %s\n",
|
||||||
|
ci->component_id, ci->component_class);
|
||||||
|
#endif
|
||||||
|
|
||||||
gnc_gui_component_clear_watches (component_id);
|
gnc_gui_component_clear_watches (component_id);
|
||||||
|
|
||||||
components = g_list_remove (components, ci);
|
components = g_list_remove (components, ci);
|
||||||
@ -381,6 +416,10 @@ gnc_unregister_gui_component (gint component_id)
|
|||||||
ci->component_class = NULL;
|
ci->component_class = NULL;
|
||||||
|
|
||||||
g_free (ci);
|
g_free (ci);
|
||||||
|
|
||||||
|
#if CM_DEBUG
|
||||||
|
dump_components ();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -528,10 +567,7 @@ gnc_close_gui_component (gint component_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ci->close_handler)
|
if (!ci->close_handler)
|
||||||
{
|
|
||||||
PERR ("no close handler");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
ci->close_handler (ci->user_data);
|
ci->close_handler (ci->user_data);
|
||||||
}
|
}
|
||||||
@ -586,16 +622,12 @@ gnc_find_gui_components (const char *component_class,
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static GList *
|
||||||
gnc_forall_gui_components (const char *component_class,
|
find_component_ids_by_class (const char *component_class)
|
||||||
GNCComponentHandler handler,
|
|
||||||
gpointer iter_data)
|
|
||||||
{
|
{
|
||||||
|
GList *list = NULL;
|
||||||
GList *node;
|
GList *node;
|
||||||
|
|
||||||
if (!handler)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (node = components; node; node = node->next)
|
for (node = components; node; node = node->next)
|
||||||
{
|
{
|
||||||
ComponentInfo *ci = node->data;
|
ComponentInfo *ci = node->data;
|
||||||
@ -604,6 +636,35 @@ gnc_forall_gui_components (const char *component_class,
|
|||||||
safe_strcmp (component_class, ci->component_class) != 0)
|
safe_strcmp (component_class, ci->component_class) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
list = g_list_prepend (list, GINT_TO_POINTER (ci->component_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gnc_forall_gui_components (const char *component_class,
|
||||||
|
GNCComponentHandler handler,
|
||||||
|
gpointer iter_data)
|
||||||
|
{
|
||||||
|
GList *list;
|
||||||
|
GList *node;
|
||||||
|
|
||||||
|
if (!handler)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* so components can be destroyed during the forall */
|
||||||
|
list = find_component_ids_by_class (component_class);
|
||||||
|
|
||||||
|
for (node = list; node; node = node->next)
|
||||||
|
{
|
||||||
|
ComponentInfo *ci = find_component (GPOINTER_TO_INT (node->data));
|
||||||
|
|
||||||
|
if (!ci)
|
||||||
|
continue;
|
||||||
|
|
||||||
handler (ci->component_class, ci->component_id, iter_data);
|
handler (ci->component_class, ci->component_id, iter_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free (list);
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,9 @@ void gnc_close_gui_component_by_data (const char *component_class,
|
|||||||
*
|
*
|
||||||
* Returns: GList of user_data of found components, or NULL if none found
|
* Returns: GList of user_data of found components, or NULL if none found
|
||||||
* The list should be freed with g_list_free().
|
* The list should be freed with g_list_free().
|
||||||
|
*
|
||||||
|
* Notes on finding: components should not be registered or unregistered
|
||||||
|
* by the find callback.
|
||||||
*/
|
*/
|
||||||
GList * gnc_find_gui_components (const char *component_class,
|
GList * gnc_find_gui_components (const char *component_class,
|
||||||
GNCComponentFindHandler find_handler,
|
GNCComponentFindHandler find_handler,
|
||||||
@ -258,6 +261,9 @@ GList * gnc_find_gui_components (const char *component_class,
|
|||||||
* all classes are iterated over
|
* all classes are iterated over
|
||||||
* handler: handler to invoke
|
* handler: handler to invoke
|
||||||
* iter_data: data passed to handler
|
* iter_data: data passed to handler
|
||||||
|
*
|
||||||
|
* Notes on forall: components may be unregistered by the handler,
|
||||||
|
* but no components should be registered.
|
||||||
*/
|
*/
|
||||||
void gnc_forall_gui_components (const char *component_class,
|
void gnc_forall_gui_components (const char *component_class,
|
||||||
GNCComponentHandler handler,
|
GNCComponentHandler handler,
|
||||||
|
@ -26,24 +26,27 @@
|
|||||||
|
|
||||||
#include <gnome.h>
|
#include <gnome.h>
|
||||||
|
|
||||||
|
#include "FileDialog.h"
|
||||||
|
#include "MultiLedger.h"
|
||||||
|
#include "Refresh.h"
|
||||||
|
#include "account-tree.h"
|
||||||
#include "dialog-transfer.h"
|
#include "dialog-transfer.h"
|
||||||
#include "dialog-utils.h"
|
#include "dialog-utils.h"
|
||||||
#include "MultiLedger.h"
|
|
||||||
#include "FileDialog.h"
|
|
||||||
#include "Refresh.h"
|
|
||||||
#include "window-reconcile.h"
|
|
||||||
#include "query-user.h"
|
|
||||||
#include "account-tree.h"
|
|
||||||
#include "glade-gnc-dialogs.h"
|
#include "glade-gnc-dialogs.h"
|
||||||
#include "gnc-amount-edit.h"
|
|
||||||
#include "gnc-dateedit.h"
|
|
||||||
#include "gnc-exp-parser.h"
|
|
||||||
#include "messages.h"
|
|
||||||
#include "gnc-ui.h"
|
|
||||||
#include "global-options.h"
|
#include "global-options.h"
|
||||||
|
#include "gnc-amount-edit.h"
|
||||||
|
#include "gnc-component-manager.h"
|
||||||
|
#include "gnc-dateedit.h"
|
||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
|
#include "gnc-exp-parser.h"
|
||||||
|
#include "gnc-ui.h"
|
||||||
|
#include "messages.h"
|
||||||
|
#include "query-user.h"
|
||||||
|
#include "window-reconcile.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define DIALOG_TRANSFER_CM_CLASS "dialog-transfer"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
XFER_DIALOG_FROM,
|
XFER_DIALOG_FROM,
|
||||||
@ -54,8 +57,6 @@ typedef enum
|
|||||||
/* This static indicates the debugging module that this .o belongs to. */
|
/* This static indicates the debugging module that this .o belongs to. */
|
||||||
static short module = MOD_GUI;
|
static short module = MOD_GUI;
|
||||||
|
|
||||||
static GList *xfer_dialogs = NULL;
|
|
||||||
|
|
||||||
struct _xferDialog
|
struct _xferDialog
|
||||||
{
|
{
|
||||||
GtkWidget * dialog;
|
GtkWidget * dialog;
|
||||||
@ -278,6 +279,7 @@ gnc_xfer_dialog_curr_acct_activate(XferDialog *xferData)
|
|||||||
(GNC_AMOUNT_EDIT(xferData->to_amount_edit)));
|
(GNC_AMOUNT_EDIT(xferData->to_amount_edit)));
|
||||||
gtk_entry_set_text(entry, "");
|
gtk_entry_set_text(entry, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free(curr_accts_name_list);
|
g_list_free(curr_accts_name_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -853,7 +855,7 @@ gnc_xfer_dialog_ok_cb(GtkWidget * widget, gpointer data)
|
|||||||
|
|
||||||
gnc_refresh_main_window();
|
gnc_refresh_main_window();
|
||||||
|
|
||||||
gnome_dialog_close(GNOME_DIALOG(xferData->dialog));
|
gnc_close_gui_component_by_data (DIALOG_TRANSFER_CM_CLASS, xferData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -862,7 +864,7 @@ gnc_xfer_dialog_cancel_cb(GtkWidget * widget, gpointer data)
|
|||||||
{
|
{
|
||||||
XferDialog *xferData = data;
|
XferDialog *xferData = data;
|
||||||
|
|
||||||
gnome_dialog_close(GNOME_DIALOG(xferData->dialog));
|
gnc_close_gui_component_by_data (DIALOG_TRANSFER_CM_CLASS, xferData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -889,7 +891,7 @@ gnc_xfer_dialog_close_cb(GnomeDialog *dialog, gpointer data)
|
|||||||
xferData->curr_accts_list = NULL;
|
xferData->curr_accts_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
xfer_dialogs = g_list_remove(xfer_dialogs, dialog);
|
gnc_unregister_gui_component_by_data (DIALOG_TRANSFER_CM_CLASS, xferData);
|
||||||
|
|
||||||
g_free(xferData);
|
g_free(xferData);
|
||||||
|
|
||||||
@ -1050,6 +1052,13 @@ gnc_xfer_dialog_create(GtkWidget * parent, XferDialog *xferData)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
close_handler (gpointer user_data)
|
||||||
|
{
|
||||||
|
XferDialog *xferData = user_data;
|
||||||
|
|
||||||
|
gnome_dialog_close (GNOME_DIALOG (xferData->dialog));
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* gnc_xfer_dialog *
|
* gnc_xfer_dialog *
|
||||||
@ -1070,7 +1079,8 @@ gnc_xfer_dialog(GtkWidget * parent, Account * initial)
|
|||||||
|
|
||||||
gnc_xfer_dialog_create(parent, xferData);
|
gnc_xfer_dialog_create(parent, xferData);
|
||||||
|
|
||||||
xfer_dialogs = g_list_prepend(xfer_dialogs, xferData->dialog);
|
gnc_register_gui_component (DIALOG_TRANSFER_CM_CLASS,
|
||||||
|
NULL, close_handler, xferData);
|
||||||
|
|
||||||
gae = GNC_AMOUNT_EDIT(xferData->amount_edit);
|
gae = GNC_AMOUNT_EDIT(xferData->amount_edit);
|
||||||
amount_entry = gnc_amount_edit_gtk_entry (gae);
|
amount_entry = gnc_amount_edit_gtk_entry (gae);
|
||||||
@ -1091,6 +1101,14 @@ gnc_xfer_dialog(GtkWidget * parent, Account * initial)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
destroy_helper (const char *component_class,
|
||||||
|
gint component_id,
|
||||||
|
gpointer iter_data)
|
||||||
|
{
|
||||||
|
gnc_close_gui_component (component_id);
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* gnc_ui_destroy_xfer_windows *
|
* gnc_ui_destroy_xfer_windows *
|
||||||
* destroy all open transfer dialogs *
|
* destroy all open transfer dialogs *
|
||||||
@ -1101,12 +1119,6 @@ gnc_xfer_dialog(GtkWidget * parent, Account * initial)
|
|||||||
void
|
void
|
||||||
gnc_ui_destroy_xfer_windows (void)
|
gnc_ui_destroy_xfer_windows (void)
|
||||||
{
|
{
|
||||||
GnomeDialog *dialog;
|
gnc_forall_gui_components (DIALOG_TRANSFER_CM_CLASS,
|
||||||
|
destroy_helper, NULL);
|
||||||
while (xfer_dialogs != NULL)
|
|
||||||
{
|
|
||||||
dialog = GNOME_DIALOG(xfer_dialogs->data);
|
|
||||||
|
|
||||||
gnome_dialog_close(dialog);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user