app: Add GimpSessionInfo getters and setters

This commit is contained in:
Martin Nordholts 2009-09-20 14:51:03 +02:00
parent 7cac9dff67
commit 8bfcd14f9a
11 changed files with 167 additions and 69 deletions

View File

@ -871,8 +871,8 @@ context_get_palette_editor (void)
info = gimp_dialog_factory_find_session_info (dialog_factory,
"gimp-palette-editor");
if (info && info->widget)
return GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));
if (info && gimp_session_info_get_widget (info))
return GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (info))));
return NULL;
}
@ -889,8 +889,8 @@ context_get_colormap_editor (void)
info = gimp_dialog_factory_find_session_info (dialog_factory,
"gimp-indexed-palette");
if (info && info->widget)
return GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));
if (info && gimp_session_info_get_widget (info))
return GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (info))));
return NULL;
}

View File

@ -165,11 +165,11 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell,
factory = gimp_dialog_factory_from_name ("dock");
session_info = gimp_dialog_factory_find_session_info (factory,
"gimp-cursor-view");
if (session_info && session_info->widget)
if (session_info && gimp_session_info_get_widget (session_info))
{
GtkWidget *cursor_view;
cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget));
cursor_view = gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (session_info)));
if (cursor_view)
{
@ -201,11 +201,11 @@ gimp_display_shell_clear_cursor (GimpDisplayShell *shell)
factory = gimp_dialog_factory_from_name ("dock");
session_info = gimp_dialog_factory_find_session_info (factory,
"gimp-cursor-view");
if (session_info && session_info->widget)
if (session_info && gimp_session_info_get_widget (session_info))
{
GtkWidget *cursor_view;
cursor_view = gtk_bin_get_child (GTK_BIN (session_info->widget));
cursor_view = gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (session_info)));
if (cursor_view)
gimp_cursor_view_clear_cursor (GIMP_CURSOR_VIEW (cursor_view));

View File

@ -1428,8 +1428,8 @@ gimp_display_shell_empty (GimpDisplayShell *shell)
if (session_info)
{
width = session_info->width;
height = session_info->height;
width = gimp_session_info_get_width (session_info);
height = gimp_session_info_get_height (session_info);
}
else
{

View File

@ -105,8 +105,8 @@ gui_message_error_console (GimpMessageSeverity severity,
info = gimp_dialog_factory_find_session_info (global_dock_factory,
"gimp-error-console");
if (info && GIMP_IS_DOCKABLE (info->widget))
dockable = info->widget;
if (info && GIMP_IS_DOCKABLE (gimp_session_info_get_widget (info)))
dockable = gimp_session_info_get_widget (info);
}
if (! dockable)

View File

@ -675,11 +675,11 @@ gui_device_change_notify (Gimp *gimp)
session_info = gimp_dialog_factory_find_session_info (global_dock_factory,
"gimp-device-status");
if (session_info && session_info->widget)
if (session_info && gimp_session_info_get_widget (session_info))
{
GtkWidget *device_status;
device_status = gtk_bin_get_child (GTK_BIN (session_info->widget));
device_status = gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (session_info)));
gimp_device_status_update (GIMP_DEVICE_STATUS (device_status));
}

View File

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

View File

@ -646,11 +646,11 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
{
info = gimp_dialog_factory_find_session_info (dialog_factory,
"gimp-indexed-palette");
if (info && info->widget)
if (info && gimp_session_info_get_widget (info))
{
GimpColormapEditor *editor;
editor = GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));
editor = GIMP_COLORMAP_EDITOR (gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (info))));
gimp_colormap_editor_set_index (editor, color_index, NULL);
}
@ -660,12 +660,12 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
{
info = gimp_dialog_factory_find_session_info (dialog_factory,
"gimp-palette-editor");
if (info && info->widget)
if (info && gimp_session_info_get_widget (info))
{
GimpPaletteEditor *editor;
gint index;
editor = GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (info->widget)));
editor = GIMP_PALETTE_EDITOR (gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (info))));
index = gimp_palette_editor_get_index (editor, color);
if (index != -1)

View File

@ -387,8 +387,9 @@ gimp_dialog_factory_find_session_info (GimpDialogFactory *factory,
{
GimpSessionInfo *info = list->data;
if (info->factory_entry &&
g_str_equal (identifier, info->factory_entry->identifier))
if (gimp_session_info_get_factory_entry (info) &&
g_str_equal (identifier,
gimp_session_info_get_factory_entry (info)->identifier))
{
return info;
}
@ -472,7 +473,7 @@ gimp_dialog_factory_dialog_new_internal (GimpDialogFactory *factory,
info = gimp_dialog_factory_find_session_info (factory, identifier);
if (info)
dialog = info->widget;
dialog = gimp_session_info_get_widget (info);
}
/* create the dialog if it was not found */
@ -682,7 +683,7 @@ gimp_dialog_factory_dialog_raise (GimpDialogFactory *factory,
GimpSessionInfo *info;
info = gimp_dialog_factory_find_session_info (factory, ids[i]);
if (info && info->widget)
if (info && gimp_session_info_get_widget (info))
break;
}
@ -821,9 +822,9 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
{
GimpSessionInfo *current_info = list->data;
if (current_info->factory_entry == entry)
if (gimp_session_info_get_factory_entry (current_info) == entry)
{
if (current_info->widget)
if (gimp_session_info_get_widget (current_info))
{
if (gimp_session_info_is_singleton (current_info))
{
@ -832,7 +833,8 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
GIMP_LOG (DIALOG_FACTORY,
"corrupt session info: %p (widget %p)",
current_info, current_info->widget);
current_info,
gimp_session_info_get_widget (current_info));
return;
}
@ -840,11 +842,11 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
continue;
}
current_info->widget = dialog;
gimp_session_info_set_widget (current_info, dialog);
GIMP_LOG (DIALOG_FACTORY,
"updating session info %p (widget %p) for %s \"%s\"",
current_info, current_info->widget,
current_info, gimp_session_info_get_widget (current_info),
toplevel ? "toplevel" : "dockable",
entry->identifier);
@ -864,15 +866,15 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
{
info = gimp_session_info_new ();
info->widget = dialog;
gimp_session_info_set_widget (info, dialog);
GIMP_LOG (DIALOG_FACTORY,
"creating session info %p (widget %p) for %s \"%s\"",
info, info->widget,
info, gimp_session_info_get_widget (info),
toplevel ? "toplevel" : "dockable",
entry->identifier);
info->factory_entry = entry;
gimp_session_info_set_factory_entry (info, entry);
/* if we create a new session info, we never call
* gimp_session_info_apply_geometry(), but still the
@ -896,14 +898,14 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
GimpSessionInfo *current_info = list->data;
/* take the first empty slot */
if (! current_info->factory_entry &&
! current_info->widget)
if (! gimp_session_info_get_factory_entry (current_info) &&
! gimp_session_info_get_widget (current_info))
{
current_info->widget = dialog;
gimp_session_info_set_widget (current_info, dialog);
GIMP_LOG (DIALOG_FACTORY,
"updating session info %p (widget %p) for dock",
current_info, current_info->widget);
current_info, gimp_session_info_get_widget (current_info));
gimp_session_info_apply_geometry (current_info);
@ -917,11 +919,11 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
{
info = gimp_session_info_new ();
info->widget = dialog;
gimp_session_info_set_widget (info, dialog);
GIMP_LOG (DIALOG_FACTORY,
"creating session info %p (widget %p) for dock",
info, info->widget);
info, gimp_session_info_get_widget (info));
/* let new docks appear at the pointer position */
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
@ -1032,14 +1034,14 @@ gimp_dialog_factory_remove_dialog (GimpDialogFactory *factory,
{
GimpSessionInfo *session_info = list->data;
if (session_info->widget == dialog)
if (gimp_session_info_get_widget (session_info) == dialog)
{
GIMP_LOG (DIALOG_FACTORY,
"clearing session info %p (widget %p) for \"%s\"",
session_info, session_info->widget,
session_info, gimp_session_info_get_widget (session_info),
entry ? entry->identifier : "dock");
session_info->widget = NULL;
gimp_session_info_set_widget (session_info, NULL);
gimp_dialog_factory_unset_widget_data (dialog);
@ -1375,7 +1377,7 @@ gimp_dialog_factory_dialog_configure (GtkWidget *dialog,
{
GimpSessionInfo *session_info = list->data;
if (session_info->widget == dialog)
if (gimp_session_info_get_widget (session_info) == dialog)
{
gimp_session_info_read_geometry (session_info);
@ -1383,8 +1385,10 @@ gimp_dialog_factory_dialog_configure (GtkWidget *dialog,
"updated session info for \"%s\" from window geometry "
"(x=%d y=%d %dx%d)",
entry ? entry->identifier : "dock",
session_info->x, session_info->y,
session_info->width, session_info->height);
gimp_session_info_get_x (session_info),
gimp_session_info_get_y (session_info),
gimp_session_info_get_width (session_info),
gimp_session_info_get_height (session_info));
break;
}
@ -1411,15 +1415,15 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
if (! gimp_session_info_is_session_managed (info))
continue;
if (info->widget)
if (gimp_session_info_get_widget (info))
gimp_session_info_get_info (info);
gimp_config_writer_open (writer, "session-info");
gimp_config_writer_string (writer,
gimp_object_get_name (factory));
gimp_config_writer_string (writer,
info->factory_entry ?
info->factory_entry->identifier :
gimp_session_info_get_factory_entry (info) ?
gimp_session_info_get_factory_entry (info)->identifier :
"dock");
GIMP_CONFIG_GET_INTERFACE (info)->serialize (GIMP_CONFIG (info),
@ -1428,7 +1432,7 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
gimp_config_writer_close (writer);
if (info->widget)
if (gimp_session_info_get_widget (info))
gimp_session_info_clear_info (info);
}
}
@ -1444,7 +1448,7 @@ gimp_dialog_factories_restore_foreach (gconstpointer key,
{
GimpSessionInfo *info = infos->data;
if (info->open)
if (gimp_session_info_get_open (info))
{
gimp_session_info_restore (info, factory);
gimp_session_info_clear_info (info);
@ -1463,7 +1467,7 @@ gimp_dialog_factories_clear_foreach (gconstpointer key,
{
GimpSessionInfo *info = list->data;
if (info->widget)
if (gimp_session_info_get_widget (info))
continue;
/* FIXME: implement session info deletion */

View File

@ -434,9 +434,9 @@ gimp_dock_window_delete_event (GtkWidget *widget,
gimp_object_set_name (GIMP_OBJECT (info),
gtk_window_get_title (GTK_WINDOW (dock_window)));
info->widget = GTK_WIDGET (dock);
gimp_session_info_set_widget (info, GTK_WIDGET (dock));
gimp_session_info_get_info (info);
info->widget = NULL;
gimp_session_info_set_widget (info, NULL);
gimp_container_add (global_recent_docks, GIMP_OBJECT (info));
g_object_unref (info);

View File

@ -654,3 +654,77 @@ gimp_session_info_get_remember_if_open (GimpSessionInfo *info)
(info->factory_entry &&
info->factory_entry->remember_if_open));
}
GtkWidget *
gimp_session_info_get_widget (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return info->widget;
}
void
gimp_session_info_set_widget (GimpSessionInfo *info,
GtkWidget *widget)
{
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
info->widget = widget;
}
GimpDialogFactoryEntry *
gimp_session_info_get_factory_entry (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return info->factory_entry;
}
void
gimp_session_info_set_factory_entry (GimpSessionInfo *info,
GimpDialogFactoryEntry *entry)
{
g_return_if_fail (GIMP_IS_SESSION_INFO (info));
info->factory_entry = entry;
}
gboolean
gimp_session_info_get_open (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
return info->open;
}
gint
gimp_session_info_get_x (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
return info->x;
}
gint
gimp_session_info_get_y (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
return info->y;
}
gint
gimp_session_info_get_width (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
return info->width;
}
gint
gimp_session_info_get_height (GimpSessionInfo *info)
{
g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), 0);
return info->height;
}

View File

@ -86,6 +86,19 @@ gboolean gimp_session_info_is_singleton (GimpSessionInfo *inf
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);
GtkWidget * gimp_session_info_get_widget (GimpSessionInfo *info);
void gimp_session_info_set_widget (GimpSessionInfo *info,
GtkWidget *widget);
GimpDialogFactoryEntry * gimp_session_info_get_factory_entry (GimpSessionInfo *info);
void gimp_session_info_set_factory_entry (GimpSessionInfo *info,
GimpDialogFactoryEntry *entry);
gboolean gimp_session_info_get_open (GimpSessionInfo *info);
void gimp_session_info_append_book (GimpSessionInfo *info,
GimpSessionInfoBook *book);
gint gimp_session_info_get_x (GimpSessionInfo *info);
gint gimp_session_info_get_y (GimpSessionInfo *info);
gint gimp_session_info_get_width (GimpSessionInfo *info);
gint gimp_session_info_get_height (GimpSessionInfo *info);
#endif /* __GIMP_SESSION_INFO_H__ */