Commit 87480880 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

Cleaned up session management and changed the format of sessionrc in a way

2003-10-10  Michael Natterer  <mitch@gimp.org>

	Cleaned up session management and changed the format of sessionrc
	in a way that allows extensions without changing the format during
	the 2.0 cycle:

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpsessioninfo.[ch]: new files implementing the whole
	GimpSessionInfo stuff (parsing, saving, restoring, utility functions).
	Save / parse the position of GimpDock's panes (bug #122964).

	* app/widgets/gimpdialogfactory.[ch]: removed saving, restoring
	and session related utility functions and use the ones from
	the new files above.

	* app/gui/session.c: removed parsing and use the new stuff.

	* app/widgets/gimpdock.[ch]: added new virtual functions
	GimpDock::set_aux_info() and GimpDock::get_aux_info():

	* app/widgets/gimpimagedock.c: implement them and handle the
	"auto_follow_active" and "show_image_menu" properties.

	* app/widgets/gimpdockable.[ch]: added the same virtual functions
	to the GimpDockable class. Enables forward-compatible per-dockable
	session management (bug #122964).

	* app/gui/dialogs-commands.c
	* app/gui/gui.c: changed accordingly.

	* etc/sessionrc: ditto. Look at this file and update your own
	sessionrc manually if you don't want to lose it.
parent c87b6cb4
2003-10-10 Michael Natterer <mitch@gimp.org>
Cleaned up session management and changed the format of sessionrc
in a way that allows extensions without changing the format during
the 2.0 cycle:
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpsessioninfo.[ch]: new files implementing the whole
GimpSessionInfo stuff (parsing, saving, restoring, utility functions).
Save / parse the position of GimpDock's panes (bug #122964).
* app/widgets/gimpdialogfactory.[ch]: removed saving, restoring
and session related utility functions and use the ones from
the new files above.
* app/gui/session.c: removed parsing and use the new stuff.
* app/widgets/gimpdock.[ch]: added new virtual functions
GimpDock::set_aux_info() and GimpDock::get_aux_info():
* app/widgets/gimpimagedock.c: implement them and handle the
"auto_follow_active" and "show_image_menu" properties.
* app/widgets/gimpdockable.[ch]: added the same virtual functions
to the GimpDockable class. Enables forward-compatible per-dockable
session management (bug #122964).
* app/gui/dialogs-commands.c
* app/gui/gui.c: changed accordingly.
* etc/sessionrc: ditto. Look at this file and update your own
sessionrc manually if you don't want to lose it.
2003-10-10 Sven Neumann <sven@gimp.org>
 
* plug-ins/script-fu/scripts/burn-in-anim.scm: repaired this script
......@@ -30,6 +30,7 @@
#include "widgets/gimpdockable.h"
#include "widgets/gimpdockbook.h"
#include "widgets/gimpimagedock.h"
#include "widgets/gimpsessioninfo.h"
#include "dialogs.h"
#include "dialogs-commands.h"
......
......@@ -30,6 +30,7 @@
#include "widgets/gimpdockable.h"
#include "widgets/gimpdockbook.h"
#include "widgets/gimpimagedock.h"
#include "widgets/gimpsessioninfo.h"
#include "dialogs.h"
#include "dialogs-commands.h"
......
......@@ -51,6 +51,7 @@
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpmenufactory.h"
#include "widgets/gimpsessioninfo.h"
#include "widgets/gimpwidgets-utils.h"
#include "dialogs.h"
......
......@@ -38,6 +38,7 @@
#include "config/gimpscanner.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpsessioninfo.h"
#include "color-history.h"
#include "session.h"
......@@ -45,29 +46,15 @@
#include "gimp-intl.h"
/* local function prototypes */
static GTokenType session_info_deserialize (GScanner *scanner,
Gimp *gimp);
static GTokenType session_info_dock_deserialize (GScanner *scanner,
GimpSessionInfo *info);
/* public functions */
enum
{
SESSION_INFO = 1,
COLOR_HISTORY,
LAST_TIP_SHOWN,
LAST_TIP_SHOWN
};
SESSION_INFO_POSITION,
SESSION_INFO_SIZE,
SESSION_INFO_OPEN,
SESSION_INFO_AUX,
SESSION_INFO_DOCK,
SESSION_INFO_DOCK_BOOK
};
/* public functions */
void
session_init (Gimp *gimp)
......@@ -99,20 +86,6 @@ session_init (Gimp *gimp)
g_scanner_scope_add_symbol (scanner, 0, "last-tip-shown",
GINT_TO_POINTER (LAST_TIP_SHOWN));
g_scanner_scope_add_symbol (scanner, SESSION_INFO, "position",
GINT_TO_POINTER (SESSION_INFO_POSITION));
g_scanner_scope_add_symbol (scanner, SESSION_INFO, "size",
GINT_TO_POINTER (SESSION_INFO_SIZE));
g_scanner_scope_add_symbol (scanner, SESSION_INFO, "open-on-exit",
GINT_TO_POINTER (SESSION_INFO_OPEN));
g_scanner_scope_add_symbol (scanner, SESSION_INFO, "aux-info",
GINT_TO_POINTER (SESSION_INFO_AUX));
g_scanner_scope_add_symbol (scanner, SESSION_INFO, "dock",
GINT_TO_POINTER (SESSION_INFO_DOCK));
g_scanner_scope_add_symbol (scanner, SESSION_INFO_DOCK, "book",
GINT_TO_POINTER (SESSION_INFO_DOCK_BOOK));
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
......@@ -129,7 +102,7 @@ session_init (Gimp *gimp)
if (scanner->value.v_symbol == GINT_TO_POINTER (SESSION_INFO))
{
g_scanner_set_scope (scanner, SESSION_INFO);
token = session_info_deserialize (scanner, gimp);
token = gimp_session_info_deserialize (scanner, SESSION_INFO);
if (token == G_TOKEN_RIGHT_PAREN)
g_scanner_set_scope (scanner, 0);
......@@ -245,215 +218,3 @@ session_clear (Gimp *gimp)
g_print ("TODO: implement session_clear()\n");
}
/* private functions */
static GTokenType
session_info_deserialize (GScanner *scanner,
Gimp *gimp)
{
GimpDialogFactory *factory;
GimpSessionInfo *info = NULL;
GTokenType token;
gchar *factory_name;
gchar *entry_name;
gchar *string;
token = G_TOKEN_STRING;
if (! gimp_scanner_parse_string (scanner, &factory_name))
goto error;
factory = gimp_dialog_factory_from_name (factory_name);
g_free (factory_name);
if (! factory)
goto error;
if (! gimp_scanner_parse_string (scanner, &entry_name))
goto error;
info = g_new0 (GimpSessionInfo, 1);
if (strcmp (entry_name, "dock"))
{
info->toplevel_entry = gimp_dialog_factory_find_entry (factory,
entry_name);
g_free (entry_name);
if (! info->toplevel_entry)
goto error;
}
else
{
g_free (entry_name);
}
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
{
case SESSION_INFO_POSITION:
token = G_TOKEN_INT;
if (! gimp_scanner_parse_int (scanner, &info->x))
goto error;
if (! gimp_scanner_parse_int (scanner, &info->y))
goto error;
break;
case SESSION_INFO_SIZE:
token = G_TOKEN_INT;
if (! gimp_scanner_parse_int (scanner, &info->width))
goto error;
if (! gimp_scanner_parse_int (scanner, &info->height))
goto error;
break;
case SESSION_INFO_OPEN:
info->open = TRUE;
break;
case SESSION_INFO_AUX:
while ((token =
g_scanner_peek_next_token (scanner)) == G_TOKEN_STRING)
{
if (gimp_scanner_parse_string (scanner, &string))
info->aux_info = g_list_append (info->aux_info, string);
else
break;
}
if (token != G_TOKEN_RIGHT_PAREN)
token = G_TOKEN_STRING;
break;
case SESSION_INFO_DOCK:
if (info->toplevel_entry)
goto error;
g_scanner_set_scope (scanner, SESSION_INFO_DOCK);
token = session_info_dock_deserialize (scanner, info);
if (token == G_TOKEN_LEFT_PAREN)
g_scanner_set_scope (scanner, SESSION_INFO);
else
goto error;
break;
default:
break;
}
token = G_TOKEN_RIGHT_PAREN;
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default:
break;
}
}
if (token == G_TOKEN_LEFT_PAREN)
{
token = G_TOKEN_RIGHT_PAREN;
if (g_scanner_peek_next_token (scanner) == token)
{
factory->session_infos = g_list_append (factory->session_infos, info);
}
return token;
}
error:
if (info)
{
GList *list;
for (list = info->sub_dialogs; list; list = g_list_next (list))
{
g_list_foreach (list->data, (GFunc) g_free, NULL);
g_list_free (list->data);
}
g_list_free (info->sub_dialogs);
g_free (info);
}
return token;
}
static GTokenType
session_info_dock_deserialize (GScanner *scanner,
GimpSessionInfo *info)
{
GList *list;
gchar *string;
GTokenType token;
token = G_TOKEN_LEFT_PAREN;
while (g_scanner_peek_next_token (scanner) == token)
{
token = g_scanner_get_next_token (scanner);
switch (token)
{
case G_TOKEN_LEFT_PAREN:
token = G_TOKEN_SYMBOL;
break;
case G_TOKEN_SYMBOL:
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
{
case SESSION_INFO_DOCK_BOOK:
list = NULL;
while ((token =
g_scanner_peek_next_token (scanner)) == G_TOKEN_STRING)
{
if (gimp_scanner_parse_string (scanner, &string))
list = g_list_append (list, string);
else
break;
}
if (list)
info->sub_dialogs = g_list_append (info->sub_dialogs, list);
if (token != G_TOKEN_RIGHT_PAREN)
token = G_TOKEN_STRING;
break;
default:
return token;
}
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default:
break;
}
}
return token;
}
......@@ -148,6 +148,8 @@ libappwidgets_a_sources = \
gimppropwidgets.h \
gimpselectioneditor.c \
gimpselectioneditor.h \
gimpsessioninfo.c \
gimpsessioninfo.h \
gimpstrokeeditor.c \
gimpstrokeeditor.h \
gimptemplateeditor.c \
......
......@@ -32,17 +32,13 @@
#include "core/gimpcontext.h"
#include "config/gimpconfigwriter.h"
#include "gimpcontainerview.h"
#include "gimpcontainerview-utils.h"
#include "gimpcursor.h"
#include "gimpdialogfactory.h"
#include "gimpdock.h"
#include "gimpdockbook.h"
#include "gimpdockable.h"
#include "gimpimagedock.h"
#include "gimpmenufactory.h"
#include "gimpsessioninfo.h"
/* #define DEBUG_FACTORY */
......@@ -90,14 +86,6 @@ static void gimp_dialog_factories_restore_foreach (gconstpointer key,
static void gimp_dialog_factories_clear_foreach (gconstpointer key,
GimpDialogFactory *factory,
gpointer data);
static void gimp_dialog_factory_get_window_info (GtkWidget *window,
GimpSessionInfo *info);
static void gimp_dialog_factory_set_window_geometry (GtkWidget *window,
GimpSessionInfo *info);
static void gimp_dialog_factory_get_aux_info (GtkWidget *dialog,
GimpSessionInfo *info);
static void gimp_dialog_factory_set_aux_info (GtkWidget *dialog,
GimpSessionInfo *info);
static void gimp_dialog_factories_hide_foreach (gconstpointer key,
GimpDialogFactory *factory,
gpointer data);
......@@ -348,9 +336,7 @@ gimp_dialog_factory_find_entry (GimpDialogFactory *factory,
entry = (GimpDialogFactoryEntry *) list->data;
if (! strcmp (identifier, entry->identifier))
{
return entry;
}
return entry;
}
return NULL;
......@@ -761,7 +747,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
entry->identifier));
if (entry->session_managed)
gimp_dialog_factory_set_window_geometry (info->widget, info);
gimp_session_info_set_geometry (info);
break;
}
......@@ -820,7 +806,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
G_GNUC_FUNCTION,
info, info->widget));
gimp_dialog_factory_set_window_geometry (info->widget, info);
gimp_session_info_set_geometry (info);
break;
}
......@@ -1144,7 +1130,7 @@ gimp_dialog_factory_dialog_configure (GtkWidget *dialog,
D (g_print ("%s: updating session info for \"%s\"\n",
G_GNUC_FUNCTION, entry->identifier));
gimp_dialog_factory_get_window_info (dialog, session_info);
gimp_session_info_get_geometry (session_info);
break;
}
......@@ -1158,17 +1144,11 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
GimpDialogFactory *factory,
GimpConfigWriter *writer)
{
GEnumClass *enum_class;
GList *list;
GList *infos;
enum_class = g_type_class_ref (GIMP_TYPE_TAB_STYLE);
for (list = factory->session_infos; list; list = g_list_next (list))
for (infos = factory->session_infos; infos; infos = g_list_next (infos))
{
GimpSessionInfo *info;
const gchar *dialog_name;
info = (GimpSessionInfo *) list->data;
GimpSessionInfo *info = infos->data;
/* we keep session info entries for all toplevel dialogs created
* by the factory but don't save them if they don't want to be
......@@ -1178,138 +1158,8 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
(info->toplevel_entry && ! info->toplevel_entry->session_managed))
continue;
if (info->widget)
gimp_dialog_factory_get_window_info (info->widget, info);
if (info->toplevel_entry)
dialog_name = info->toplevel_entry->identifier;
else
dialog_name = "dock";
gimp_config_writer_open (writer, "session-info");
gimp_config_writer_string (writer, GIMP_OBJECT (factory)->name);
gimp_config_writer_string (writer, dialog_name);
gimp_config_writer_open (writer, "position");
gimp_config_writer_printf (writer, "%d %d", info->x, info->y);
gimp_config_writer_close (writer);
if (info->width > 0 && info->height > 0)
{
gimp_config_writer_open (writer, "size");
gimp_config_writer_printf (writer, "%d %d",
info->width, info->height);
gimp_config_writer_close (writer);
}
if (info->open)
{
gimp_config_writer_open (writer, "open-on-exit");
gimp_config_writer_close (writer);
}
/* save aux-info */
if (info->widget)
{
gimp_dialog_factory_get_aux_info (info->widget, info);
if (info->aux_info)
{
GList *aux;
gimp_config_writer_open (writer, "aux-info");
for (aux = info->aux_info; aux; aux = g_list_next (aux))
gimp_config_writer_string (writer, (gchar *) aux->data);
gimp_config_writer_close (writer);
g_list_foreach (info->aux_info, (GFunc) g_free, NULL);
g_list_free (info->aux_info);
info->aux_info = NULL;
}
}
if (! info->toplevel_entry && info->widget)
{
GimpDock *dock;
GList *books;
dock = GIMP_DOCK (info->widget);
gimp_config_writer_open (writer, "dock");
for (books = dock->dockbooks; books; books = g_list_next (books))
{
GimpDockbook *dockbook;
GList *children;
GList *pages;
dockbook = (GimpDockbook *) books->data;
gimp_config_writer_open (writer, "book");
children = gtk_container_get_children (GTK_CONTAINER (dockbook));
for (pages = children; pages; pages = g_list_next (pages))
{
GimpDockable *dockable;
GimpDialogFactoryEntry *entry;
dockable = (GimpDockable *) pages->data;
entry = g_object_get_data (G_OBJECT (dockable),
"gimp-dialog-factory-entry");
if (entry)
{
GimpContainerView *view;
GEnumValue *enum_value;
gchar *tab_style = "icon";
gint preview_size = -1;
gimp_config_writer_linefeed (writer);
enum_value = g_enum_get_value (enum_class,
dockable->tab_style);
if (enum_value)
tab_style = enum_value->value_nick;
view = gimp_container_view_get_by_dockable (dockable);
if (view && view->preview_size >= GIMP_PREVIEW_SIZE_TINY)
preview_size = view->preview_size;
if (preview_size > 0 &&
preview_size != entry->preview_size)
{
gimp_config_writer_printf (writer, "\"%s@%s:%d\"",
entry->identifier,
tab_style,
preview_size);
}
else
{
gimp_config_writer_printf (writer, "\"%s@%s\"",
entry->identifier,
tab_style);
}
}
}
g_list_free (children);
gimp_config_writer_close (writer); /* book */
}
gimp_config_writer_close (writer); /* dock */
}
gimp_config_writer_close (writer); /* session-info */
gimp_session_info_save (info, GIMP_OBJECT (factory)->name, writer);
}
g_type_class_unref (enum_class);
}
static void
......@@ -1317,151 +1167,14 @@ gimp_dialog_factories_restore_foreach (gconstpointer key,
GimpDialogFactory *factory,
gpointer data)
{
GList *list;
GList *infos;
for (list = factory->session_infos; list; list = g_list_next (list))
for (infos = factory->session_infos; infos; infos = g_list_next (infos))
{
GimpSessionInfo *info;
info = (GimpSessionInfo *) list->data;
if (! info->open)
continue;
info->open = FALSE;
if (info->toplevel_entry)
{
GtkWidget *dialog;
dialog =
gimp_dialog_factory_dialog_new (factory,
info->toplevel_entry->identifier,
info->toplevel_entry->preview_size);
GimpSessionInfo *info = infos->data;
if (dialog && info->aux_info)
gimp_dialog_factory_set_aux_info (dialog, info);
}
else
{
GimpDock *dock;
GList *books;
GEnumClass *enum_class;
dock = GIMP_DOCK (gimp_dialog_factory_dock_new (factory));