app: Have only one GimpDialogFactoryEntry member in GimpSessionInfo

Simplify the code a bit by replacing the 'toplevel_entry' and
'dockable_entry' members in GimpSessionInfo with a single
'factory_entry'. We compensate for this by adding a 'dockable'
gboolean to GimpDialogFactoryEntry.
This commit is contained in:
Martin Nordholts
2009-09-20 12:17:22 +02:00
parent 44d5728d7b
commit 4ab58d2e77
6 changed files with 49 additions and 53 deletions

View File

@ -50,11 +50,11 @@ GimpContainer *global_recent_docks = NULL;
#define FOREIGN(id, singleton, remember_size) \ #define FOREIGN(id, singleton, remember_size) \
{ id, NULL, NULL, NULL, NULL, \ { id, NULL, NULL, NULL, NULL, \
NULL, 0, singleton, TRUE, remember_size, FALSE } NULL, 0, singleton, TRUE, remember_size, FALSE, FALSE }
#define TOPLEVEL(id, new_func, singleton, session_managed, remember_size) \ #define TOPLEVEL(id, new_func, singleton, session_managed, remember_size) \
{ id, NULL, NULL, NULL, NULL, \ { id, NULL, NULL, NULL, NULL, \
new_func, 0, singleton, session_managed, remember_size, FALSE } new_func, 0, singleton, session_managed, remember_size, FALSE, FALSE }
static const GimpDialogFactoryEntry toplevel_entries[] = static const GimpDialogFactoryEntry toplevel_entries[] =
@ -123,14 +123,14 @@ static const GimpDialogFactoryEntry toplevel_entries[] =
#define DOCKABLE(id,name,blurb,stock_id,help_id,\ #define DOCKABLE(id,name,blurb,stock_id,help_id,\
new_func,view_size,singleton) \ new_func,view_size,singleton) \
{ id, name, blurb, stock_id, help_id, \ { id, name, blurb, stock_id, help_id, \
new_func, view_size, singleton, FALSE, FALSE, TRUE } new_func, view_size, singleton, FALSE, FALSE, TRUE, TRUE }
#define LISTGRID(id,name,blurb,stock_id,help_id,\ #define LISTGRID(id,name,blurb,stock_id,help_id,\
view_size) \ view_size) \
{ "gimp-"#id"-list", name, blurb, stock_id, help_id, \ { "gimp-"#id"-list", name, blurb, stock_id, help_id, \
dialogs_##id##_list_view_new, view_size, FALSE, FALSE, FALSE, TRUE }, \ dialogs_##id##_list_view_new, view_size, FALSE, FALSE, FALSE, TRUE, TRUE }, \
{ "gimp-"#id"-grid", name, blurb, stock_id, help_id, \ { "gimp-"#id"-grid", name, blurb, stock_id, help_id, \
dialogs_##id##_grid_view_new, view_size, FALSE, FALSE, FALSE, TRUE } dialogs_##id##_grid_view_new, view_size, FALSE, FALSE, FALSE, TRUE, TRUE }
static const GimpDialogFactoryEntry dock_entries[] = static const GimpDialogFactoryEntry dock_entries[] =
{ {

View File

@ -153,13 +153,13 @@ session_init (Gimp *gimp)
*/ */
if (!g_str_equal (entry_name, "dock")) if (!g_str_equal (entry_name, "dock"))
{ {
info->toplevel_entry = gimp_dialog_factory_find_entry (factory, info->factory_entry = gimp_dialog_factory_find_entry (factory,
entry_name); entry_name);
/* If we expected a dialog factory entry but failed /* If we expected a dialog factory entry but failed
* to find one, skip to add this session info object * to find one, skip to add this session info object
*/ */
skip = (info->toplevel_entry == NULL); skip = (info->factory_entry == NULL);
} }
g_free (entry_name); g_free (entry_name);

View File

@ -387,10 +387,8 @@ gimp_dialog_factory_find_session_info (GimpDialogFactory *factory,
{ {
GimpSessionInfo *info = list->data; GimpSessionInfo *info = list->data;
if ((info->toplevel_entry && if (info->factory_entry &&
! strcmp (identifier, info->toplevel_entry->identifier)) || g_str_equal (identifier, info->factory_entry->identifier))
(info->dockable_entry &&
! strcmp (identifier, info->dockable_entry->identifier)))
{ {
return info; return info;
} }
@ -823,8 +821,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
{ {
GimpSessionInfo *current_info = list->data; GimpSessionInfo *current_info = list->data;
if ((current_info->toplevel_entry == entry) || if (current_info->factory_entry == entry)
(current_info->dockable_entry == entry))
{ {
if (current_info->widget) if (current_info->widget)
{ {
@ -875,24 +872,17 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
toplevel ? "toplevel" : "dockable", toplevel ? "toplevel" : "dockable",
entry->identifier); entry->identifier);
if (toplevel) info->factory_entry = entry;
{
info->toplevel_entry = entry;
/* if we create a new session info, we never call /* if we create a new session info, we never call
* gimp_session_info_set_geometry(), but still the * gimp_session_info_set_geometry(), but still the
* dialog needs GDK_HINT_USER_POS so it keeps its * dialog needs GDK_HINT_USER_POS so it keeps its
* position when hidden/shown within this(!) session. * position when hidden/shown within this(!) session.
*/ */
if (gimp_session_info_is_session_managed (info)) if (gimp_session_info_is_session_managed (info))
g_signal_connect (dialog, "configure-event", g_signal_connect (dialog, "configure-event",
G_CALLBACK (gimp_dialog_factory_set_user_pos), G_CALLBACK (gimp_dialog_factory_set_user_pos),
NULL); NULL);
}
else
{
info->dockable_entry = entry;
}
factory->session_infos = g_list_append (factory->session_infos, info); factory->session_infos = g_list_append (factory->session_infos, info);
} }
@ -906,8 +896,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
GimpSessionInfo *current_info = list->data; GimpSessionInfo *current_info = list->data;
/* take the first empty slot */ /* take the first empty slot */
if (! current_info->toplevel_entry && if (! current_info->factory_entry &&
! current_info->dockable_entry &&
! current_info->widget) ! current_info->widget)
{ {
current_info->widget = dialog; current_info->widget = dialog;
@ -1429,8 +1418,8 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
gimp_config_writer_string (writer, gimp_config_writer_string (writer,
gimp_object_get_name (factory)); gimp_object_get_name (factory));
gimp_config_writer_string (writer, gimp_config_writer_string (writer,
info->toplevel_entry ? info->factory_entry ?
info->toplevel_entry->identifier : info->factory_entry->identifier :
"dock"); "dock");
GIMP_CONFIG_GET_INTERFACE (info)->serialize (GIMP_CONFIG (info), GIMP_CONFIG_GET_INTERFACE (info)->serialize (GIMP_CONFIG (info),

View File

@ -58,6 +58,11 @@ struct _GimpDialogFactoryEntry
gboolean session_managed; gboolean session_managed;
gboolean remember_size; gboolean remember_size;
gboolean remember_if_open; gboolean remember_if_open;
/* If TRUE the entry is for a dockable, otherwise it is for a
* toplevel
*/
gboolean dockable;
}; };

View File

@ -268,7 +268,7 @@ gimp_session_info_deserialize (GimpConfig *config,
break; break;
case SESSION_INFO_DOCK: case SESSION_INFO_DOCK:
if (info->toplevel_entry) if (info->factory_entry)
goto error; goto error;
g_scanner_set_scope (scanner, scope_id + 1); g_scanner_set_scope (scanner, scope_id + 1);
@ -323,8 +323,7 @@ gimp_session_info_deserialize (GimpConfig *config,
static gboolean static gboolean
gimp_session_info_is_for_dock (GimpSessionInfo *info) gimp_session_info_is_for_dock (GimpSessionInfo *info)
{ {
gboolean entry_state_for_dock = (! info->toplevel_entry && gboolean entry_state_for_dock = info->factory_entry == NULL;
! info->dockable_entry);
gboolean widget_state_for_dock = (info->widget == NULL || gboolean widget_state_for_dock = (info->widget == NULL ||
GIMP_IS_DOCK (info->widget)); GIMP_IS_DOCK (info->widget));
@ -361,14 +360,14 @@ gimp_session_info_restore (GimpSessionInfo *info,
info->open = FALSE; info->open = FALSE;
info->screen = DEFAULT_SCREEN; info->screen = DEFAULT_SCREEN;
if (info->toplevel_entry) if (info->factory_entry && ! info->factory_entry->dockable)
{ {
GtkWidget *dialog; GtkWidget *dialog;
dialog = dialog =
gimp_dialog_factory_dialog_new (factory, screen, gimp_dialog_factory_dialog_new (factory, screen,
info->toplevel_entry->identifier, info->factory_entry->identifier,
info->toplevel_entry->view_size, info->factory_entry->view_size,
TRUE); TRUE);
if (dialog && info->aux_info) if (dialog && info->aux_info)
@ -574,7 +573,9 @@ gimp_session_info_get_info (GimpSessionInfo *info)
info->aux_info = gimp_session_info_aux_get_list (info->widget); info->aux_info = gimp_session_info_aux_get_list (info->widget);
if (! info->toplevel_entry) if (info->factory_entry == NULL ||
(info->factory_entry &&
info->factory_entry->dockable))
info->books = gimp_session_info_dock_from_widget (GIMP_DOCK (info->widget)); info->books = gimp_session_info_dock_from_widget (GIMP_DOCK (info->widget));
} }
@ -606,8 +607,8 @@ gimp_session_info_is_singleton (GimpSessionInfo *info)
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE); g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (! gimp_session_info_is_for_dock (info) && return (! gimp_session_info_is_for_dock (info) &&
info->toplevel_entry && info->factory_entry &&
info->toplevel_entry->singleton); info->factory_entry->singleton);
} }
gboolean gboolean
@ -616,8 +617,8 @@ gimp_session_info_is_session_managed (GimpSessionInfo *info)
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE); g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (gimp_session_info_is_for_dock (info) || return (gimp_session_info_is_for_dock (info) ||
(info->toplevel_entry && (info->factory_entry &&
info->toplevel_entry->session_managed)); info->factory_entry->session_managed));
} }
@ -627,8 +628,8 @@ gimp_session_info_get_remember_size (GimpSessionInfo *info)
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE); g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (gimp_session_info_is_for_dock (info) || return (gimp_session_info_is_for_dock (info) ||
(info->toplevel_entry && (info->factory_entry &&
info->toplevel_entry->remember_size)); info->factory_entry->remember_size));
} }
gboolean gboolean
@ -637,6 +638,6 @@ gimp_session_info_get_remember_if_open (GimpSessionInfo *info)
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE); g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (gimp_session_info_is_for_dock (info) || return (gimp_session_info_is_for_dock (info) ||
(info->toplevel_entry && (info->factory_entry &&
info->toplevel_entry->remember_if_open)); info->factory_entry->remember_if_open));
} }

View File

@ -59,9 +59,10 @@ struct _GimpSessionInfo
GtkWidget *widget; GtkWidget *widget;
/* only one of these is valid */ /* the dialog factory entry for object we have session info for
GimpDialogFactoryEntry *toplevel_entry; * note that pure "dock" entries don't have any factory entry
GimpDialogFactoryEntry *dockable_entry; */
GimpDialogFactoryEntry *factory_entry;
/* list of GimpSessionInfoBook */ /* list of GimpSessionInfoBook */
GList *books; GList *books;