Commit 44d5728d authored by Martin Nordholts's avatar Martin Nordholts

app: Add and use factory entry related getters for GimpSessionInfo

Add GimpSessionInfo getters for a bunch of dialog factory entry
fields. This moves much of the GimpDock special casing to a common
place and also reduces direct access to session info fields.
parent 8d86735f
......@@ -828,7 +828,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
{
if (current_info->widget)
{
if (entry->singleton)
if (gimp_session_info_is_singleton (current_info))
{
g_warning ("%s: singleton dialog \"%s\" created twice",
G_STRFUNC, entry->identifier);
......@@ -851,7 +851,8 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
toplevel ? "toplevel" : "dockable",
entry->identifier);
if (toplevel && entry->session_managed &&
if (toplevel &&
gimp_session_info_is_session_managed (current_info) &&
! GTK_WIDGET_VISIBLE (dialog))
{
gimp_session_info_set_geometry (current_info);
......@@ -883,7 +884,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
* dialog needs GDK_HINT_USER_POS so it keeps its
* position when hidden/shown within this(!) session.
*/
if (entry->session_managed)
if (gimp_session_info_is_session_managed (info))
g_signal_connect (dialog, "configure-event",
G_CALLBACK (gimp_dialog_factory_set_user_pos),
NULL);
......@@ -958,7 +959,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
factory,
G_CONNECT_SWAPPED);
if ((entry && entry->session_managed && toplevel) || GIMP_IS_DOCK (dialog))
if (gimp_session_info_is_session_managed (info))
g_signal_connect_object (dialog, "configure-event",
G_CALLBACK (gimp_dialog_factory_dialog_configure),
factory,
......@@ -1060,7 +1061,7 @@ gimp_dialog_factory_remove_dialog (GimpDialogFactory *factory,
gimp_dialog_factory_remove_dialog,
factory);
if (entry && entry->session_managed && GTK_WIDGET_TOPLEVEL (dialog))
if (gimp_session_info_is_session_managed (session_info))
g_signal_handlers_disconnect_by_func (dialog,
gimp_dialog_factory_dialog_configure,
factory);
......@@ -1418,8 +1419,7 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
* by the factory but don't save them if they don't want to be
* managed
*/
if (info->dockable_entry ||
(info->toplevel_entry && ! info->toplevel_entry->session_managed))
if (! gimp_session_info_is_session_managed (info))
continue;
if (info->widget)
......
......@@ -62,6 +62,7 @@ static gboolean gimp_session_info_deserialize (GimpConfig *config,
GScanner *scanner,
gint nest_level,
gpointer data);
static gboolean gimp_session_info_is_for_dock (GimpSessionInfo *info);
G_DEFINE_TYPE_WITH_CODE (GimpSessionInfo, gimp_session_info, GIMP_TYPE_OBJECT,
......@@ -309,6 +310,27 @@ gimp_session_info_deserialize (GimpConfig *config,
return gimp_config_deserialize_return (scanner, token, nest_level);
}
/**
* gimp_session_info_is_for_dock:
* @info:
*
* Helper function to determine if the session info is for a dock. It
* uses the dialog factory entry state and the associated widget state
* if any to determine that.
*
* Returns: %TRUE if session info is for a dock, %FALSE otherwise.
**/
static gboolean
gimp_session_info_is_for_dock (GimpSessionInfo *info)
{
gboolean entry_state_for_dock = (! info->toplevel_entry &&
! info->dockable_entry);
gboolean widget_state_for_dock = (info->widget == NULL ||
GIMP_IS_DOCK (info->widget));
return entry_state_for_dock && widget_state_for_dock;
}
/* public functions */
......@@ -417,8 +439,9 @@ gimp_session_info_set_geometry (GimpSessionInfo *info)
screen = gtk_widget_get_screen (info->widget);
use_size = ((! info->toplevel_entry || info->toplevel_entry->remember_size) &&
(info->width > 0 && info->height > 0));
use_size = (gimp_session_info_get_remember_size (info) &&
info->width > 0 &&
info->height > 0);
if (use_size)
{
......@@ -491,7 +514,7 @@ gimp_session_info_get_geometry (GimpSessionInfo *info)
info->x = MAX (0, x);
info->y = MAX (0, y);
if (! info->toplevel_entry || info->toplevel_entry->remember_size)
if (gimp_session_info_get_remember_size (info))
{
gdk_drawable_get_size (GDK_DRAWABLE (window),
&info->width, &info->height);
......@@ -505,7 +528,7 @@ gimp_session_info_get_geometry (GimpSessionInfo *info)
info->open = FALSE;
if (! info->toplevel_entry || info->toplevel_entry->remember_if_open)
if (gimp_session_info_get_remember_if_open (info))
{
GimpDialogVisibilityState visibility;
......@@ -576,3 +599,44 @@ gimp_session_info_clear_info (GimpSessionInfo *info)
info->books = NULL;
}
}
gboolean
gimp_session_info_is_singleton (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (! gimp_session_info_is_for_dock (info) &&
info->toplevel_entry &&
info->toplevel_entry->singleton);
}
gboolean
gimp_session_info_is_session_managed (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (gimp_session_info_is_for_dock (info) ||
(info->toplevel_entry &&
info->toplevel_entry->session_managed));
}
gboolean
gimp_session_info_get_remember_size (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (gimp_session_info_is_for_dock (info) ||
(info->toplevel_entry &&
info->toplevel_entry->remember_size));
}
gboolean
gimp_session_info_get_remember_if_open (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return (gimp_session_info_is_for_dock (info) ||
(info->toplevel_entry &&
info->toplevel_entry->remember_if_open));
}
......@@ -73,18 +73,18 @@ struct _GimpSessionInfoClass
};
GType gimp_session_info_get_type (void) G_GNUC_CONST;
GimpSessionInfo * gimp_session_info_new (void);
void gimp_session_info_restore (GimpSessionInfo *info,
GimpDialogFactory *factory);
void gimp_session_info_set_geometry (GimpSessionInfo *info);
void gimp_session_info_get_geometry (GimpSessionInfo *info);
void gimp_session_info_get_info (GimpSessionInfo *info);
void gimp_session_info_clear_info (GimpSessionInfo *info);
GType gimp_session_info_get_type (void) G_GNUC_CONST;
GimpSessionInfo * gimp_session_info_new (void);
void gimp_session_info_restore (GimpSessionInfo *info,
GimpDialogFactory *factory);
void gimp_session_info_set_geometry (GimpSessionInfo *info);
void gimp_session_info_get_geometry (GimpSessionInfo *info);
void gimp_session_info_get_info (GimpSessionInfo *info);
void gimp_session_info_clear_info (GimpSessionInfo *info);
gboolean gimp_session_info_is_singleton (GimpSessionInfo *info);
gboolean gimp_session_info_is_session_managed (GimpSessionInfo *info);
gboolean gimp_session_info_get_remember_size (GimpSessionInfo *info);
gboolean gimp_session_info_get_remember_if_open (GimpSessionInfo *info);
#endif /* __GIMP_SESSION_INFO_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment