Commit 1093462a authored by Martin Nordholts's avatar Martin Nordholts
Browse files

app: Merge 'global_toolbox_factory' into 'global_dock_factory'

Get rid of 'global_toolbox_factory' and manage everything dock-related
with 'global_dock_factory'. The whole of 'global_toolbox_factory' was
a big special-case and getting rid of it makes it easier to extend the
session management with e.g. single-window mode dock functionality.

To get rid of 'global_toolbox_factory' we, roughly, have to
 * Replace 'global_toolbox_factory' with 'global_dock_factory'
   everywhere. We can also get rid of lots of code that did special
   things for the "toolbox" factory.
 * Make the use or interaction with the toolbox explicit in some
   places. For example, a function gimp_dock_window_has_toolbox() has
   been introduced.
 * Make GimpSessionInfoDock have an 'identifier' parameter so we can
   differentiate between the "gimp-dock" and "gimp-toolbox" dock
   types.
parent dd8b8678
......@@ -102,10 +102,11 @@ windows_show_toolbox (void)
{
GtkWidget *toolbox = NULL;
if (! gimp_dialog_factory_get_open_dialogs (global_toolbox_factory))
if (! dialogs_get_toolbox ())
{
toolbox = gimp_dialog_factory_dock_with_window_new (global_toolbox_factory,
gdk_screen_get_default ());
toolbox = gimp_dialog_factory_dock_with_window_new (global_dock_factory,
gdk_screen_get_default (),
TRUE /*toolbox*/);
gtk_widget_show (toolbox);
}
......
......@@ -235,11 +235,7 @@ dialogs_toolbox_new (GimpDialogFactory *factory,
GimpUIManager *ui_manager,
gint view_size)
{
/* we pass "global_dock_factory", _not_ "global_toolbox_factory" to
* the toolbox constructor, because the global_toolbox_factory has
* no dockables registered
*/
return gimp_toolbox_new (global_dock_factory,
return gimp_toolbox_new (factory,
context,
ui_manager);
}
......
......@@ -30,9 +30,11 @@
#include "core/gimplist.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdockwindow.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpmenufactory.h"
#include "widgets/gimpsessioninfo.h"
#include "widgets/gimptoolbox.h"
#include "dialogs.h"
#include "dialogs-constructors.h"
......@@ -42,7 +44,6 @@
GimpDialogFactory *global_dialog_factory = NULL;
GimpDialogFactory *global_dock_factory = NULL;
GimpDialogFactory *global_toolbox_factory = NULL;
GimpDialogFactory *global_display_factory = NULL;
GimpContainer *global_recent_docks = NULL;
......@@ -343,17 +344,6 @@ static const GimpDialogFactoryEntry dock_entries[] =
dialogs_palette_editor_get, 0, TRUE)
};
static const GimpDialogFactoryEntry toolbox_entries[] =
{
/* docks */
DOCK ("gimp-toolbox",
dialogs_toolbox_new),
/* dock windows */
DOCK_WINDOW ("gimp-toolbox-window",
dialogs_toolbox_dock_window_new)
};
/* public functions */
......@@ -372,12 +362,6 @@ dialogs_init (Gimp *gimp,
menu_factory,
TRUE);
/* Toolbox */
global_toolbox_factory = gimp_dialog_factory_new ("toolbox",
gimp_get_user_context (gimp),
menu_factory,
TRUE);
/* Dock windows and docks */
global_dock_factory = gimp_dialog_factory_new ("dock",
gimp_get_user_context (gimp),
......@@ -421,21 +405,6 @@ dialogs_init (Gimp *gimp,
dock_entries[i].remember_if_open,
dock_entries[i].dockable);
for (i = 0; i < G_N_ELEMENTS (toolbox_entries); i++)
gimp_dialog_factory_register_entry (global_toolbox_factory,
toolbox_entries[i].identifier,
gettext (toolbox_entries[i].name),
gettext (toolbox_entries[i].blurb),
toolbox_entries[i].stock_id,
toolbox_entries[i].help_id,
toolbox_entries[i].new_func,
toolbox_entries[i].view_size,
toolbox_entries[i].singleton,
toolbox_entries[i].session_managed,
toolbox_entries[i].remember_size,
toolbox_entries[i].remember_if_open,
toolbox_entries[i].dockable);
gimp_dialog_factory_register_entry (global_display_factory,
"gimp-empty-image-window",
NULL, NULL,
......@@ -462,18 +431,6 @@ dialogs_exit (Gimp *gimp)
global_dialog_factory = NULL;
}
/* destroy the "global_toolbox_factory" _before_ destroying the
* "global_dock_factory" because the "global_toolbox_factory" owns
* dockables which were created by the "global_dock_factory". This
* way they are properly removed from the "global_dock_factory",
* which would complain about stale entries otherwise.
*/
if (global_toolbox_factory)
{
g_object_unref (global_toolbox_factory);
global_toolbox_factory = NULL;
}
if (global_dock_factory)
{
g_object_unref (global_dock_factory);
......@@ -552,13 +509,14 @@ dialogs_get_toolbox (void)
{
GList *list;
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (global_toolbox_factory), NULL);
g_return_val_if_fail (GIMP_IS_DIALOG_FACTORY (global_dock_factory), NULL);
for (list = gimp_dialog_factory_get_open_dialogs (global_toolbox_factory);
for (list = gimp_dialog_factory_get_open_dialogs (global_dock_factory);
list;
list = g_list_next (list))
{
if (gtk_widget_is_toplevel (list->data))
if (GIMP_IS_DOCK_WINDOW (list->data) &&
gimp_dock_window_has_toolbox (list->data))
return list->data;
}
......
......@@ -21,7 +21,6 @@
extern GimpDialogFactory *global_dialog_factory;
extern GimpDialogFactory *global_dock_factory;
extern GimpDialogFactory *global_toolbox_factory;
extern GimpDialogFactory *global_display_factory;
extern GimpContainer *global_recent_docks;
......
......@@ -66,8 +66,8 @@ static void gimp_ui_configurer_get_property (GObject
GValue *value,
GParamSpec *pspec);
static void gimp_ui_configurer_move_docks_to_columns (GimpUIConfigurer *ui_configurer,
GimpDialogFactory *dialog_factory,
GimpDockColumns *dock_columns);
GimpDockColumns *dock_columns,
gboolean only_toolbox);
static void gimp_ui_configurer_move_shells (GimpUIConfigurer *ui_configurer,
GimpImageWindow *source_image_window,
GimpImageWindow *target_image_window);
......@@ -154,12 +154,15 @@ gimp_ui_configurer_get_property (GObject *object,
static void
gimp_ui_configurer_move_docks_to_columns (GimpUIConfigurer *ui_configurer,
GimpDialogFactory *dialog_factory,
GimpDockColumns *dock_columns)
GimpDockColumns *dock_columns,
gboolean only_toolbox)
{
GList *dialogs = g_list_copy (gimp_dialog_factory_get_open_dialogs (dialog_factory));
GList *dialogs = NULL;
GList *dialog_iter = NULL;
dialogs =
g_list_copy (gimp_dialog_factory_get_open_dialogs (global_dock_factory));
for (dialog_iter = dialogs; dialog_iter; dialog_iter = dialog_iter->next)
{
GimpDockWindow *dock_window = NULL;
......@@ -176,6 +179,10 @@ gimp_ui_configurer_move_docks_to_columns (GimpUIConfigurer *ui_configurer,
{
GimpDock *dock = GIMP_DOCK (dock_iter->data);
if (only_toolbox &&
! GIMP_IS_TOOLBOX (dock))
continue;
/* Move the dock from the image window to the dock columns
* widget. Note that we need a ref while the dock is parentless
*/
......@@ -189,9 +196,14 @@ gimp_ui_configurer_move_docks_to_columns (GimpUIConfigurer *ui_configurer,
/* Kill the window if removing the dock didn't destroy it
* already. This will be the case for the toolbox dock window
*/
if (GTK_IS_WIDGET (dock_window))
/* FIXME: We should solve this in a more elegant way, valgrind
* complains about invalid reads when the dock window already is
* destroyed
*/
if (GTK_IS_WIDGET (dock_window) &&
g_list_length (gimp_dock_window_get_docks (dock_window)) == 0)
{
gimp_dialog_factory_remove_dialog (dialog_factory,
gimp_dialog_factory_remove_dialog (global_dock_factory,
GTK_WIDGET (dock_window));
gtk_widget_destroy (GTK_WIDGET (dock_window));
}
......@@ -271,9 +283,7 @@ gimp_ui_configurer_move_docks_to_window (GimpUIConfigurer *ui_configurer,
* toolbox
*/
dock_window =
gimp_dialog_factory_dialog_new ((GIMP_IS_TOOLBOX (dock) ?
global_toolbox_factory :
global_dock_factory),
gimp_dialog_factory_dialog_new (global_dock_factory,
screen,
(GIMP_IS_TOOLBOX (dock) ?
"gimp-toolbox-window" :
......@@ -362,15 +372,15 @@ gimp_ui_configurer_configure_for_single_window (GimpUIConfigurer *ui_configurer)
* window
*/
gimp_ui_configurer_move_docks_to_columns (ui_configurer,
global_toolbox_factory,
left_docks);
left_docks,
TRUE /*only_toolbox*/);
/* Then move the other docks to the right side of the image
* window
*/
gimp_ui_configurer_move_docks_to_columns (ui_configurer,
global_dock_factory,
right_docks);
right_docks,
FALSE /*only_toolbox*/);
/* Show the docks in the window */
gimp_image_window_set_show_docks (uber_image_window, TRUE);
......
......@@ -138,7 +138,15 @@ session_init (Gimp *gimp)
if (! gimp_scanner_parse_string (scanner, &factory_name))
break;
factory = gimp_dialog_factory_from_name (factory_name);
/* In versions <= GIMP 2.6 there was a "toolbox" and a
* "dock" factory. These are now merged so if the
* factory name is "toolbox", get the "dock" factory
* instead. We don't change factory_name because we need
* it below
*/
factory = gimp_dialog_factory_from_name (strcmp ("toolbox", factory_name) == 0 ?
"dock" :
factory_name);
if (! factory)
break;
......
......@@ -7,7 +7,7 @@
(aux-info
(show-image-menu "false")
(follow-active-image "true"))
(dock
(gimp-dock
(book
(current-page 0)
(dockable "gimp-palette-list"
......@@ -31,7 +31,7 @@
(aux-info
(show-image-menu "false")
(follow-active-image "true"))
(dock
(gimp-dock
(book
(current-page 1)
(dockable "gimp-selection-editor"
......
......@@ -94,9 +94,11 @@ gimp_test_window_roles (GimpTestFixture *fixture,
GimpDockWindow *toolbox_window = NULL;
dock = gimp_dialog_factory_dock_with_window_new (global_dock_factory,
gdk_screen_get_default ());
toolbox = gimp_dialog_factory_dock_with_window_new (global_toolbox_factory,
gdk_screen_get_default ());
gdk_screen_get_default (),
FALSE /*toolbox*/);
toolbox = gimp_dialog_factory_dock_with_window_new (global_dock_factory,
gdk_screen_get_default (),
TRUE /*toolbox*/);
dock_window = gimp_dock_window_from_dock (GIMP_DOCK (dock));
toolbox_window = gimp_dock_window_from_dock (GIMP_DOCK (toolbox));
......
......@@ -210,10 +210,7 @@ gimp_dialog_factory_dispose (GObject *object)
factory->p->session_infos = NULL;
}
if (strcmp (gimp_object_get_name (factory), "toolbox") == 0)
key = "";
else
key = (gpointer)gimp_object_get_name (factory);
key = (gpointer)gimp_object_get_name (factory);
g_hash_table_remove (GIMP_DIALOG_FACTORY_GET_CLASS (object)->factories,
key);
......@@ -274,11 +271,7 @@ gimp_dialog_factory_new (const gchar *name,
gimp_object_set_name (GIMP_OBJECT (factory), name);
/* hack to keep the toolbox on the pool position */
if (strcmp (name, "toolbox") == 0)
key = "";
else
key = (gpointer)gimp_object_get_name (factory);
key = (gpointer)gimp_object_get_name (factory);
g_hash_table_insert (GIMP_DIALOG_FACTORY_GET_CLASS (factory)->factories,
key, factory);
......@@ -302,10 +295,6 @@ gimp_dialog_factory_from_name (const gchar *name)
if (! factory_class)
return NULL;
/* hack to keep the toolbox on the pool position */
if (strcmp (name, "toolbox") == 0)
name = "";
factory =
(GimpDialogFactory *) g_hash_table_lookup (factory_class->factories, name);
......@@ -490,7 +479,9 @@ gimp_dialog_factory_dialog_new_internal (GimpDialogFactory *factory,
* dialog. We do this because the new dockable needs to be
* created in its dock's context.
*/
dock = gimp_dialog_factory_dock_with_window_new (factory, screen);
dock = gimp_dialog_factory_dock_with_window_new (factory,
screen,
FALSE /*toolbox*/);
dockbook = gimp_dockbook_new (factory->p->menu_factory);
gimp_dock_add_book (GIMP_DOCK (dock),
......@@ -813,10 +804,10 @@ gimp_dialog_factory_dockable_new (GimpDialogFactory *factory,
**/
GtkWidget *
gimp_dialog_factory_dock_with_window_new (GimpDialogFactory *factory,
GdkScreen *screen)
GdkScreen *screen,
gboolean toolbox)
{
GtkWidget *dock_window = NULL;
gchar *dock_id = NULL;
GtkWidget *dock = NULL;
GimpUIManager *ui_manager = NULL;
......@@ -830,7 +821,7 @@ gimp_dialog_factory_dock_with_window_new (GimpDialogFactory *factory,
dock_window =
gimp_dialog_factory_dialog_new (factory,
screen,
(strcmp ("toolbox", gimp_object_get_name (factory)) == 0 ?
(toolbox ?
"gimp-toolbox-window" :
"gimp-dock-window"),
-1 /*view_size*/,
......@@ -838,17 +829,13 @@ gimp_dialog_factory_dock_with_window_new (GimpDialogFactory *factory,
/* Create the dock */
ui_manager = gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dock_window));
dock_id = g_strconcat ("gimp-", gimp_object_get_name (factory), NULL);
dock = gimp_dialog_factory_dialog_new (factory,
screen,
(strcmp ("toolbox", gimp_object_get_name (factory)) == 0 ?
"gimp-toolbox" :
"gimp-dock"),
-1 /*view_size*/,
FALSE /*present*/);
g_free (dock_id);
dock = gimp_dialog_factory_dialog_new (factory,
screen,
(toolbox ?
"gimp-toolbox" :
"gimp-dock"),
-1 /*view_size*/,
FALSE /*present*/);
if (dock)
{
/* Put the dock in the dock window */
......@@ -1453,8 +1440,7 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
for (infos = factory->p->session_infos; infos; infos = g_list_next (infos))
{
GimpSessionInfo *info = infos->data;
const gchar *identifier = NULL;
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
......@@ -1470,13 +1456,8 @@ gimp_dialog_factories_save_foreach (gconstpointer key,
gimp_config_writer_open (writer, "session-info");
gimp_config_writer_string (writer,
gimp_object_get_name (factory));
/* Some special casing to be avoid changing sessionrc */
identifier = gimp_session_info_get_factory_entry (info)->identifier;
if (strcmp (identifier, "gimp-dock-window") == 0 ||
strcmp (identifier, "gimp-toolbox-window") == 0)
identifier = "dock";
gimp_config_writer_string (writer, identifier);
gimp_config_writer_string (writer,
gimp_session_info_get_factory_entry (info)->identifier);
GIMP_CONFIG_GET_INTERFACE (info)->serialize (GIMP_CONFIG (info),
writer,
......
......@@ -148,7 +148,8 @@ GtkWidget * gimp_dialog_factory_dockable_new (GimpDialogFactory
const gchar *identifier,
gint view_size);
GtkWidget * gimp_dialog_factory_dock_with_window_new (GimpDialogFactory *factory,
GdkScreen *screen);
GdkScreen *screen,
gboolean toolbox);
void gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
GtkWidget *dialog);
void gimp_dialog_factory_add_foreign (GimpDialogFactory *factory,
......
......@@ -1206,7 +1206,8 @@ gimp_dockable_detach (GimpDockable *dockable)
src_dock_window = gimp_dock_window_from_dock (src_dock);
dock = gimp_dialog_factory_dock_with_window_new (global_dock_factory,
gtk_widget_get_screen (GTK_WIDGET (dockable)));
gtk_widget_get_screen (GTK_WIDGET (dockable)),
FALSE /*toolbox*/);
dock_window = gimp_dock_window_from_dock (GIMP_DOCK (dock));
gtk_window_set_position (GTK_WINDOW (dock_window), GTK_WIN_POS_MOUSE);
if (src_dock_window)
......
......@@ -53,6 +53,7 @@
#include "gimpmenufactory.h"
#include "gimpsessioninfo-aux.h"
#include "gimpsessioninfo.h"
#include "gimptoolbox.h"
#include "gimpuimanager.h"
#include "gimpwidgets-utils.h"
#include "gimpwindow.h"
......@@ -1066,6 +1067,31 @@ gimp_dock_window_get_aux_info (GimpDockWindow *dock_window)
return aux_info;
}
/**
* gimp_dock_window_has_toolbox:
* @dock_window:
*
* Returns: %TRUE if the dock window has a GimpToolbox dock, %FALSE
* otherwise.
**/
gboolean
gimp_dock_window_has_toolbox (GimpDockWindow *dock_window)
{
GList *iter = NULL;
g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (dock_window), FALSE);
for (iter = gimp_dock_columns_get_docks (dock_window->p->dock_columns);
iter;
iter = g_list_next (iter))
{
if (GIMP_IS_TOOLBOX (iter->data))
return TRUE;
}
return FALSE;
}
/**
* gimp_dock_window_from_dock:
......
......@@ -83,8 +83,10 @@ void gimp_dock_window_setup (GimpDockWindow *
void gimp_dock_window_set_aux_info (GimpDockWindow *dock,
GList *aux_info);
GList * gimp_dock_window_get_aux_info (GimpDockWindow *dock);
gboolean gimp_dock_window_has_toolbox (GimpDockWindow *dock_window);
GimpDockWindow * gimp_dock_window_from_dock (GimpDock *dock);
#endif /* __GIMP_DOCK_WINDOW_H__ */
......@@ -34,6 +34,7 @@
#include "gimpsessioninfo-book.h"
#include "gimpsessioninfo-dock.h"
#include "gimpsessioninfo-private.h"
#include "gimptoolbox.h"
enum
......@@ -45,9 +46,14 @@ enum
/* public functions */
GimpSessionInfoDock *
gimp_session_info_dock_new (void)
gimp_session_info_dock_new (const gchar *identifier)
{
return g_slice_new0 (GimpSessionInfoDock);
GimpSessionInfoDock *dock_info = NULL;
dock_info = g_slice_new0 (GimpSessionInfoDock);
dock_info->identifier = g_strdup (identifier);
return dock_info;
}
void
......@@ -55,6 +61,12 @@ gimp_session_info_dock_free (GimpSessionInfoDock *dock_info)
{
g_return_if_fail (dock_info != NULL);
if (dock_info->identifier)
{
g_free (dock_info->identifier);
dock_info->identifier = NULL;
}
if (dock_info->books)
{
g_list_foreach (dock_info->books,
......@@ -76,7 +88,7 @@ gimp_session_info_dock_serialize (GimpConfigWriter *writer,
g_return_if_fail (writer != NULL);
g_return_if_fail (dock_info != NULL);
gimp_config_writer_open (writer, "dock");
gimp_config_writer_open (writer, dock_info->identifier);
for (list = dock_info->books; list; list = g_list_next (list))
gimp_session_info_book_serialize (writer, list->data);
......@@ -87,7 +99,8 @@ gimp_session_info_dock_serialize (GimpConfigWriter *writer,
GTokenType
gimp_session_info_dock_deserialize (GScanner *scanner,
gint scope,
GimpSessionInfoDock **dock_info)
GimpSessionInfoDock **dock_info,
const gchar *identifier)
{
GTokenType token;
......@@ -97,7 +110,7 @@ gimp_session_info_dock_deserialize (GScanner *scanner,
g_scanner_scope_add_symbol (scanner, scope, "book",
GINT_TO_POINTER (SESSION_INFO_BOOK));
*dock_info = gimp_session_info_dock_new ();
*dock_info = gimp_session_info_dock_new (identifier);
token = G_TOKEN_LEFT_PAREN;
......@@ -159,7 +172,9 @@ gimp_session_info_dock_from_widget (GimpDock *dock)
g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
dock_info = gimp_session_info_dock_new ();
dock_info = gimp_session_info_dock_new (GIMP_IS_TOOLBOX (dock) ?
"gimp-toolbox" :
"gimp-dock");
for (list = gimp_dock_get_dockbooks (dock); list; list = g_list_next (list))
{
......@@ -206,7 +221,6 @@ gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
GdkScreen *screen,
GimpDockWindow *dock_window)
{
gchar *dock_id = NULL;
GtkWidget *dock = NULL;
GList *iter = NULL;
GimpUIManager *ui_manager = NULL;
......@@ -215,18 +229,11 @@ gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
g_return_if_fail (GDK_IS_SCREEN (screen));
ui_manager = gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dock_window));
/* Create the dock. Always use the dock window factory for it (but
* we want to refactor away that hard-coding eventually) but the
* type of dock depends on the factory
*/
dock_id = g_strconcat ("gimp-", gimp_object_get_name (factory), NULL);
dock = gimp_dialog_factory_dialog_new (factory,
screen,
dock_id,
dock_info->identifier,
-1 /*view_size*/,
FALSE /*present*/);
g_free (dock_id);
g_return_if_fail (GIMP_IS_DOCK (dock));
......
......@@ -29,17 +29,21 @@
*/
struct _GimpSessionInfoDock
{
/* Identifier written to/read from sessionrc */
gchar *identifier;
/* list of GimpSessionInfoBook */
GList *books;
};
GimpSessionInfoDock * gimp_session_info_dock_new (void);
GimpSessionInfoDock * gimp_session_info_dock_new (const gchar *identifier);
void gimp_session_info_dock_free (GimpSessionInfoDock *dock_info);
void gimp_session_info_dock_serialize (GimpConfigWriter *writer,
GimpSessionInfoDock *dock);
GTokenType gimp_session_info_dock_deserialize (GScanner *scanner,
gint scope,
GimpSessionInfoDock **info);
GimpSessionInfoDock **info,
const gchar *identifier);
GimpSessionInfoDock * gimp_session_info_dock_from_widget (GimpDock *dock);
void gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
GimpDialogFactory *factory,
......
......@@ -282,15 +282,11 @@ gimp_session_info_dockable_restore (GimpSessionInfoDockable *info,
info->view_size > GIMP_VIEW_SIZE_GIGANTIC)
info->view_size = -1;
/* FIXME: Merge global_dock_factory and global_toolbox_factory
* somehow so we don't need this hack
*/
dockable = gimp_dialog_factory_dockable_new ((GIMP_IS_TOOLBOX (dock) ?
gimp_toolbox_get_dialog_factory (GIMP_TOOLBOX (dock)) :