app: Add a 'restore_func' to GimpDialogFactoryEntry

In gimp_session_info_restore() there is code to create a dialog from a
session info. GimpSessionInfo lives in the widgets module. Thus we
can't add restoration code that depends on a higher level module. In
particular, we can't add code to restore docks in an GimpImageWindow
since GimpImageWindow lives in the display module. And we need such
code to be able to restore a single-window mode session.

Since dialogs are defined in the dialogs module, it makes sense to
also have the code that restores a dialog in that module.

So, add a 'restore_func' member to GimpRestoreDialogFunc of type
GimpRestoreDialogFunc and move the code there.
This commit is contained in:
Martin Nordholts
2011-05-27 17:16:04 +02:00
parent c73ff51b82
commit 396d5fd5e8
6 changed files with 208 additions and 147 deletions

View File

@ -28,6 +28,8 @@
#include "dialogs-types.h" #include "dialogs-types.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h" #include "core/gimp.h"
#include "core/gimpcontext.h" #include "core/gimpcontext.h"
#include "core/gimplist.h" #include "core/gimplist.h"
@ -37,11 +39,14 @@
#include "widgets/gimphelp-ids.h" #include "widgets/gimphelp-ids.h"
#include "widgets/gimpmenufactory.h" #include "widgets/gimpmenufactory.h"
#include "widgets/gimpsessioninfo.h" #include "widgets/gimpsessioninfo.h"
#include "widgets/gimpsessioninfo-aux.h"
#include "widgets/gimptoolbox.h" #include "widgets/gimptoolbox.h"
#include "dialogs.h" #include "dialogs.h"
#include "dialogs-constructors.h" #include "dialogs-constructors.h"
#include "gimp-log.h"
#include "gimp-intl.h" #include "gimp-intl.h"
@ -49,100 +54,106 @@ GimpContainer *global_recent_docks = NULL;
#define FOREIGN(id, singleton, remember_size) \ #define FOREIGN(id, singleton, remember_size) \
{ id /* identifier */, \ { id /* identifier */, \
NULL /* name */, \ NULL /* name */, \
NULL /* blurb */, \ NULL /* blurb */, \
NULL /* stock_id */, \ NULL /* stock_id */, \
NULL /* help_id */, \ NULL /* help_id */, \
NULL /* new_func */, \ NULL /* new_func */, \
0 /* view_size */, \ dialogs_restore_dialog /* restore_func */, \
singleton /* singleton */, \ 0 /* view_size */, \
TRUE /* session_managed */, \ singleton /* singleton */, \
remember_size /* remember_size */, \ TRUE /* session_managed */, \
FALSE /* remember_if_open */, \ remember_size /* remember_size */, \
TRUE /* hideable */, \ FALSE /* remember_if_open */, \
FALSE /* image_window */, \ TRUE /* hideable */, \
FALSE /* dockable */} FALSE /* image_window */, \
FALSE /* dockable */}
#define IMAGE_WINDOW(id, singleton, remember_size) \ #define IMAGE_WINDOW(id, singleton, remember_size) \
{ id /* identifier */, \ { id /* identifier */, \
NULL /* name */, \ NULL /* name */, \
NULL /* blurb */, \ NULL /* blurb */, \
NULL /* stock_id */, \ NULL /* stock_id */, \
NULL /* help_id */, \ NULL /* help_id */, \
NULL /* new_func */, \ NULL /* new_func */, \
0 /* view_size */, \ NULL /* restore_func */, \
singleton /* singleton */, \ 0 /* view_size */, \
TRUE /* session_managed */, \ singleton /* singleton */, \
remember_size /* remember_size */, \ TRUE /* session_managed */, \
FALSE /* remember_if_open */, \ remember_size /* remember_size */, \
FALSE /* hideable */, \ FALSE /* remember_if_open */, \
TRUE /* image_window */, \ FALSE /* hideable */, \
FALSE /* dockable */} TRUE /* image_window */, \
FALSE /* dockable */}
#define TOPLEVEL(id, new_func, singleton, session_managed, remember_size) \ #define TOPLEVEL(id, new_func, singleton, session_managed, remember_size) \
{ id /* identifier */, \ { id /* identifier */, \
NULL /* name */, \ NULL /* name */, \
NULL /* blurb */, \ NULL /* blurb */, \
NULL /* stock_id */, \ NULL /* stock_id */, \
NULL /* help_id */, \ NULL /* help_id */, \
new_func /* new_func */, \ new_func /* new_func */, \
0 /* view_size */, \ dialogs_restore_dialog /* restore_func */, \
singleton /* singleton */, \ 0 /* view_size */, \
session_managed /* session_managed */, \ singleton /* singleton */, \
remember_size /* remember_size */, \ session_managed /* session_managed */, \
FALSE /* remember_if_open */, \ remember_size /* remember_size */, \
TRUE /* hideable */, \ FALSE /* remember_if_open */, \
FALSE /* image_window */, \ TRUE /* hideable */, \
FALSE /* dockable */} FALSE /* image_window */, \
FALSE /* dockable */}
#define DOCKABLE(id, name, blurb, stock_id, help_id, new_func, view_size, singleton) \ #define DOCKABLE(id, name, blurb, stock_id, help_id, new_func, view_size, singleton) \
{ id /* identifier */, \ { id /* identifier */, \
name /* name */, \ name /* name */, \
blurb /* blurb */, \ blurb /* blurb */, \
stock_id /* stock_id */, \ stock_id /* stock_id */, \
help_id /* help_id */, \ help_id /* help_id */, \
new_func /* new_func */, \ new_func /* new_func */, \
view_size /* view_size */, \ NULL /* restore_func */, \
singleton /* singleton */, \ view_size /* view_size */, \
FALSE /* session_managed */, \ singleton /* singleton */, \
FALSE /* remember_size */, \ FALSE /* session_managed */, \
TRUE /* remember_if_open */, \ FALSE /* remember_size */, \
TRUE /* hideable */, \ TRUE /* remember_if_open */, \
FALSE /* image_window */, \ TRUE /* hideable */, \
TRUE /* dockable */} FALSE /* image_window */, \
TRUE /* dockable */}
#define DOCK(id, new_func) \ #define DOCK(id, new_func) \
{ id /* identifier */, \ { id /* identifier */, \
NULL /* name */, \ NULL /* name */, \
NULL /* blurb */, \ NULL /* blurb */, \
NULL /* stock_id */, \ NULL /* stock_id */, \
NULL /* help_id */, \ NULL /* help_id */, \
new_func /* new_func */, \ new_func /* new_func */, \
0 /* view_size */, \ dialogs_restore_dialog /* restore_func */, \
FALSE /* singleton */, \ 0 /* view_size */, \
FALSE /* session_managed */, \ FALSE /* singleton */, \
FALSE /* remember_size */, \ FALSE /* session_managed */, \
FALSE /* remember_if_open */, \ FALSE /* remember_size */, \
TRUE /* hideable */, \ FALSE /* remember_if_open */, \
FALSE /* image_window */, \ TRUE /* hideable */, \
FALSE /* dockable */} FALSE /* image_window */, \
FALSE /* dockable */}
#define DOCK_WINDOW(id, new_func) \ #define DOCK_WINDOW(id, new_func) \
{ id /* identifier */, \ { id /* identifier */, \
NULL /* name */, \ NULL /* name */, \
NULL /* blurb */, \ NULL /* blurb */, \
NULL /* stock_id */, \ NULL /* stock_id */, \
NULL /* help_id */, \ NULL /* help_id */, \
new_func /* new_func */, \ new_func /* new_func */, \
0 /* view_size */, \ dialogs_restore_dialog /* restore_func */, \
FALSE /* singleton */, \ 0 /* view_size */, \
TRUE /* session_managed */, \ FALSE /* singleton */, \
TRUE /* remember_size */, \ TRUE /* session_managed */, \
TRUE /* remember_if_open */, \ TRUE /* remember_size */, \
TRUE /* hideable */, \ TRUE /* remember_if_open */, \
FALSE /* image_window */, \ TRUE /* hideable */, \
FALSE /* dockable */} FALSE /* image_window */, \
FALSE /* dockable */}
#define LISTGRID(id, name, blurb, stock_id, help_id, view_size) \ #define LISTGRID(id, name, blurb, stock_id, help_id, view_size) \
{ "gimp-"#id"-list" /* identifier */, \ { "gimp-"#id"-list" /* identifier */, \
@ -151,6 +162,7 @@ GimpContainer *global_recent_docks = NULL;
stock_id /* stock_id */, \ stock_id /* stock_id */, \
help_id /* help_id */, \ help_id /* help_id */, \
dialogs_##id##_list_view_new /* new_func */, \ dialogs_##id##_list_view_new /* new_func */, \
NULL /* restore_func */, \
view_size /* view_size */, \ view_size /* view_size */, \
FALSE /* singleton */, \ FALSE /* singleton */, \
FALSE /* session_managed */, \ FALSE /* session_managed */, \
@ -165,6 +177,7 @@ GimpContainer *global_recent_docks = NULL;
stock_id /* stock_id */, \ stock_id /* stock_id */, \
help_id /* help_id */, \ help_id /* help_id */, \
dialogs_##id##_grid_view_new /* new_func */, \ dialogs_##id##_grid_view_new /* new_func */, \
NULL /* restore_func */, \
view_size /* view_size */, \ view_size /* view_size */, \
FALSE /* singleton */, \ FALSE /* singleton */, \
FALSE /* session_managed */, \ FALSE /* session_managed */, \
@ -181,6 +194,7 @@ GimpContainer *global_recent_docks = NULL;
stock_id /* stock_id */, \ stock_id /* stock_id */, \
help_id /* help_id */, \ help_id /* help_id */, \
dialogs_##new_func##_list_view_new /* new_func */, \ dialogs_##new_func##_list_view_new /* new_func */, \
NULL /* restore_func */, \
view_size /* view_size */, \ view_size /* view_size */, \
FALSE /* singleton */, \ FALSE /* singleton */, \
FALSE /* session_managed */, \ FALSE /* session_managed */, \
@ -191,6 +205,11 @@ GimpContainer *global_recent_docks = NULL;
TRUE /* dockable */} TRUE /* dockable */}
static GtkWidget * dialogs_restore_dialog (GimpDialogFactory *factory,
GdkScreen *screen,
GimpSessionInfo *info);
static const GimpDialogFactoryEntry entries[] = static const GimpDialogFactoryEntry entries[] =
{ {
/* foreign toplevels without constructor */ /* foreign toplevels without constructor */
@ -386,6 +405,49 @@ static const GimpDialogFactoryEntry entries[] =
TRUE, TRUE) TRUE, TRUE)
}; };
/**
* dialogs_restore_dialog:
* @factory:
* @screen:
* @info:
*
* Creates a top level widget based on the given session info object
* in which other widgets later can be be put, typically also restored
* from the same session info object.
*
* Returns:
**/
static GtkWidget *
dialogs_restore_dialog (GimpDialogFactory *factory,
GdkScreen *screen,
GimpSessionInfo *info)
{
GtkWidget *dialog;
GimpCoreConfig *config = gimp_dialog_factory_get_context (factory)->gimp->config;
GIMP_LOG (DIALOG_FACTORY, "restoring toplevel \"%s\" (info %p)",
gimp_session_info_get_factory_entry (info)->identifier,
info);
dialog =
gimp_dialog_factory_dialog_new (factory, screen,
NULL /*ui_manager*/,
gimp_session_info_get_factory_entry (info)->identifier,
gimp_session_info_get_factory_entry (info)->view_size,
! GIMP_GUI_CONFIG (config)->hide_docks);
g_object_set_data (G_OBJECT (dialog), GIMP_DIALOG_VISIBILITY_KEY,
GINT_TO_POINTER (GIMP_GUI_CONFIG (config)->hide_docks ?
GIMP_DIALOG_VISIBILITY_HIDDEN :
GIMP_DIALOG_VISIBILITY_VISIBLE));
if (dialog && gimp_session_info_get_aux_info (info))
gimp_session_info_aux_set_list (dialog,
gimp_session_info_get_aux_info (info));
return dialog;
}
/* public functions */ /* public functions */
@ -412,6 +474,7 @@ dialogs_init (Gimp *gimp,
entries[i].stock_id, entries[i].stock_id,
entries[i].help_id, entries[i].help_id,
entries[i].new_func, entries[i].new_func,
entries[i].restore_func,
entries[i].view_size, entries[i].view_size,
entries[i].singleton, entries[i].singleton,
entries[i].session_managed, entries[i].session_managed,

View File

@ -260,21 +260,22 @@ gimp_dialog_factory_new (const gchar *name,
} }
void void
gimp_dialog_factory_register_entry (GimpDialogFactory *factory, gimp_dialog_factory_register_entry (GimpDialogFactory *factory,
const gchar *identifier, const gchar *identifier,
const gchar *name, const gchar *name,
const gchar *blurb, const gchar *blurb,
const gchar *stock_id, const gchar *stock_id,
const gchar *help_id, const gchar *help_id,
GimpDialogNewFunc new_func, GimpDialogNewFunc new_func,
gint view_size, GimpDialogRestoreFunc restore_func,
gboolean singleton, gint view_size,
gboolean session_managed, gboolean singleton,
gboolean remember_size, gboolean session_managed,
gboolean remember_if_open, gboolean remember_size,
gboolean hideable, gboolean remember_if_open,
gboolean image_window, gboolean hideable,
gboolean dockable) gboolean image_window,
gboolean dockable)
{ {
GimpDialogFactoryEntry *entry; GimpDialogFactoryEntry *entry;
@ -289,6 +290,7 @@ gimp_dialog_factory_register_entry (GimpDialogFactory *factory,
entry->stock_id = g_strdup (stock_id); entry->stock_id = g_strdup (stock_id);
entry->help_id = g_strdup (help_id); entry->help_id = g_strdup (help_id);
entry->new_func = new_func; entry->new_func = new_func;
entry->restore_func = restore_func;
entry->view_size = view_size; entry->view_size = view_size;
entry->singleton = singleton ? TRUE : FALSE; entry->singleton = singleton ? TRUE : FALSE;
entry->session_managed = session_managed ? TRUE : FALSE; entry->session_managed = session_managed ? TRUE : FALSE;

View File

@ -48,28 +48,29 @@ typedef GtkWidget * (* GimpDialogNewFunc) (GimpDialogFactory *factory,
struct _GimpDialogFactoryEntry struct _GimpDialogFactoryEntry
{ {
gchar *identifier; gchar *identifier;
gchar *name; gchar *name;
gchar *blurb; gchar *blurb;
gchar *stock_id; gchar *stock_id;
gchar *help_id; gchar *help_id;
GimpDialogNewFunc new_func; GimpDialogNewFunc new_func;
gint view_size; GimpDialogRestoreFunc restore_func;
gint view_size;
gboolean singleton; gboolean singleton;
gboolean session_managed; gboolean session_managed;
gboolean remember_size; gboolean remember_size;
gboolean remember_if_open; gboolean remember_if_open;
/* If TRUE the visibility of the dialog is toggleable */ /* If TRUE the visibility of the dialog is toggleable */
gboolean hideable; gboolean hideable;
/* If TRUE the entry is for a GimpImageWindow, FALSE otherwise */ /* If TRUE the entry is for a GimpImageWindow, FALSE otherwise */
gboolean image_window; gboolean image_window;
/* If TRUE the entry is for a dockable, FALSE otherwise */ /* If TRUE the entry is for a dockable, FALSE otherwise */
gboolean dockable; gboolean dockable;
}; };
@ -120,6 +121,7 @@ void gimp_dialog_factory_register_entry (GimpDialogFactory
const gchar *stock_id, const gchar *stock_id,
const gchar *help_id, const gchar *help_id,
GimpDialogNewFunc new_func, GimpDialogNewFunc new_func,
GimpDialogRestoreFunc restore_func,
gint view_size, gint view_size,
gboolean singleton, gboolean singleton,
gboolean session_managed, gboolean session_managed,

View File

@ -481,29 +481,11 @@ gimp_session_info_restore (GimpSessionInfo *info,
info->p->screen = DEFAULT_SCREEN; info->p->screen = DEFAULT_SCREEN;
if (info->p->factory_entry && if (info->p->factory_entry &&
! info->p->factory_entry->dockable && info->p->factory_entry->restore_func)
! info->p->factory_entry->image_window)
{ {
GimpCoreConfig *config = gimp_dialog_factory_get_context (factory)->gimp->config; dialog = info->p->factory_entry->restore_func (factory,
screen,
GIMP_LOG (DIALOG_FACTORY, "restoring toplevel \"%s\" (info %p)", info);
info->p->factory_entry->identifier,
info);
dialog =
gimp_dialog_factory_dialog_new (factory, screen,
NULL /*ui_manager*/,
info->p->factory_entry->identifier,
info->p->factory_entry->view_size,
! GIMP_GUI_CONFIG (config)->hide_docks);
g_object_set_data (G_OBJECT (dialog), GIMP_DIALOG_VISIBILITY_KEY,
GINT_TO_POINTER (GIMP_GUI_CONFIG (config)->hide_docks ?
GIMP_DIALOG_VISIBILITY_HIDDEN :
GIMP_DIALOG_VISIBILITY_VISIBLE));
if (dialog && info->p->aux_info)
gimp_session_info_aux_set_list (dialog, info->p->aux_info);
} }
/* We expect expect there to always be docks. In sessionrc files /* We expect expect there to always be docks. In sessionrc files
@ -795,6 +777,14 @@ gimp_session_info_get_info_with_widget (GimpSessionInfo *info,
gimp_session_info_set_widget (info, old_widget); gimp_session_info_set_widget (info, old_widget);
} }
GList *
gimp_session_info_get_aux_info (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), NULL);
return info->p->aux_info;
}
void void
gimp_session_info_clear_info (GimpSessionInfo *info) gimp_session_info_clear_info (GimpSessionInfo *info)
{ {

View File

@ -66,6 +66,7 @@ void gimp_session_info_read_geometry (GimpSe
void gimp_session_info_get_info (GimpSessionInfo *info); void gimp_session_info_get_info (GimpSessionInfo *info);
void gimp_session_info_get_info_with_widget (GimpSessionInfo *info, void gimp_session_info_get_info_with_widget (GimpSessionInfo *info,
GtkWidget *widget); GtkWidget *widget);
GList * gimp_session_info_get_aux_info (GimpSessionInfo *info);
void gimp_session_info_clear_info (GimpSessionInfo *info); void gimp_session_info_clear_info (GimpSessionInfo *info);
gboolean gimp_session_info_is_singleton (GimpSessionInfo *info); gboolean gimp_session_info_is_singleton (GimpSessionInfo *info);
gboolean gimp_session_info_is_session_managed (GimpSessionInfo *info); gboolean gimp_session_info_is_session_managed (GimpSessionInfo *info);

View File

@ -260,20 +260,23 @@ typedef struct _GimpDialogFactoryEntry GimpDialogFactoryEntry;
/* function types */ /* function types */
typedef void (* GimpActionGroupSetupFunc) (GimpActionGroup *group); typedef GtkWidget * (* GimpDialogRestoreFunc) (GimpDialogFactory *factory,
typedef void (* GimpActionGroupUpdateFunc) (GimpActionGroup *group, GdkScreen *screen,
gpointer data); GimpSessionInfo *info);
typedef void (* GimpActionGroupSetupFunc) (GimpActionGroup *group);
typedef void (* GimpActionGroupUpdateFunc) (GimpActionGroup *group,
gpointer data);
typedef void (* GimpUIManagerSetupFunc) (GimpUIManager *manager, typedef void (* GimpUIManagerSetupFunc) (GimpUIManager *manager,
const gchar *ui_path); const gchar *ui_path);
typedef void (* GimpMenuPositionFunc) (GtkMenu *menu, typedef void (* GimpMenuPositionFunc) (GtkMenu *menu,
gint *x, gint *x,
gint *y, gint *y,
gpointer data); gpointer data);
typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *source, typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *source,
gint insert_index, gint insert_index,
gpointer data); gpointer data);
/* temp hack as replacement for GdkSegment */ /* temp hack as replacement for GdkSegment */