static void
set_window (PlumaDocumentsPanel *panel,
	    PlumaWindow         *window)
{
	g_return_if_fail (panel->priv->window == NULL);
	g_return_if_fail (PLUMA_IS_WINDOW (window));

	panel->priv->window = g_object_ref (window);

	g_signal_connect (window,
			  "tab_added",
			  G_CALLBACK (window_tab_added),
			  panel);
	g_signal_connect (window,
			  "tab_removed",
			  G_CALLBACK (window_tab_removed),
			  panel);
	g_signal_connect (window,
			  "tabs_reordered",
			  G_CALLBACK (window_tabs_reordered),
			  panel);
	g_signal_connect (window,
			  "active_tab_changed",
			  G_CALLBACK (window_active_tab_changed),
			  panel);
}
void
pluma_plugins_engine_deactivate_plugins (PlumaPluginsEngine *engine,
					  PlumaWindow        *window)
{
	GList *pl;

	pluma_debug (DEBUG_PLUGINS);

	g_return_if_fail (PLUMA_IS_PLUGINS_ENGINE (engine));
	g_return_if_fail (PLUMA_IS_WINDOW (window));

	for (pl = engine->priv->plugin_list; pl; pl = pl->next)
	{
		PlumaPluginInfo *info = (PlumaPluginInfo*)pl->data;

		/* check if the plugin is actually active */
		if (!pluma_plugin_info_is_active (info))
			continue;

		/* call deactivate for the plugin for this window */
		pluma_plugin_deactivate (info->plugin, window);
	}

	pluma_debug_message (DEBUG_PLUGINS, "End");
}
static PlumaNotebook *
find_notebook_at_pointer (gint abs_x, gint abs_y)
{
	GdkWindow *win_at_pointer;
	GdkWindow *toplevel_win;
	gpointer toplevel = NULL;
	gint x, y;

	/* FIXME multi-head */
	win_at_pointer = gdk_window_at_pointer (&x, &y);
	if (win_at_pointer == NULL)
	{
		/* We are outside all windows of the same application */
		return NULL;
	}

	toplevel_win = gdk_window_get_toplevel (win_at_pointer);

	/* get the GtkWidget which owns the toplevel GdkWindow */
	gdk_window_get_user_data (toplevel_win, &toplevel);

	/* toplevel should be an PlumaWindow */
	if ((toplevel != NULL) && 
	    PLUMA_IS_WINDOW (toplevel))
	{
		return PLUMA_NOTEBOOK (_pluma_window_get_notebook
						(PLUMA_WINDOW (toplevel)));
	}

	/* We are outside all windows containing a notebook */
	return NULL;
}
GtkWidget *
pluma_documents_panel_new (PlumaWindow *window)
{
	g_return_val_if_fail (PLUMA_IS_WINDOW (window), NULL);

	return GTK_WIDGET (g_object_new (PLUMA_TYPE_DOCUMENTS_PANEL,
					 "window", window,
					 NULL));
}
void
pluma_plugins_engine_activate_plugins (PlumaPluginsEngine *engine,
					PlumaWindow        *window)
{
	GSList *active_plugins = NULL;
	GList *pl;

	pluma_debug (DEBUG_PLUGINS);

	g_return_if_fail (PLUMA_IS_PLUGINS_ENGINE (engine));
	g_return_if_fail (PLUMA_IS_WINDOW (window));

	/* the first time, we get the 'active' plugins from mateconf */
	if (engine->priv->activate_from_prefs)
	{
		active_plugins = pluma_prefs_manager_get_active_plugins ();
	}

	for (pl = engine->priv->plugin_list; pl; pl = pl->next)
	{
		PlumaPluginInfo *info = (PlumaPluginInfo*)pl->data;

		if (engine->priv->activate_from_prefs &&
		    g_slist_find_custom (active_plugins,
					 pluma_plugin_info_get_module_name (info),
					 (GCompareFunc)strcmp) == NULL)
			continue;

		/* If plugin is not active, don't try to activate/load it */
		if (!engine->priv->activate_from_prefs &&
		    !pluma_plugin_info_is_active (info))
			continue;

		if (load_plugin (engine, info))
			pluma_plugin_activate (info->plugin,
					       window);
	}

	if (engine->priv->activate_from_prefs)
	{
		g_slist_foreach (active_plugins, (GFunc) g_free, NULL);
		g_slist_free (active_plugins);
		engine->priv->activate_from_prefs = FALSE;
	}

	pluma_debug_message (DEBUG_PLUGINS, "End");

	/* also call update_ui after activation */
	pluma_plugins_engine_update_plugins_ui (engine, window);
}
void
pluma_plugins_engine_update_plugins_ui (PlumaPluginsEngine *engine,
					 PlumaWindow        *window)
{
	GList *pl;

	pluma_debug (DEBUG_PLUGINS);

	g_return_if_fail (PLUMA_IS_PLUGINS_ENGINE (engine));
	g_return_if_fail (PLUMA_IS_WINDOW (window));

	/* call update_ui for all active plugins */
	for (pl = engine->priv->plugin_list; pl; pl = pl->next)
	{
		PlumaPluginInfo *info = (PlumaPluginInfo*)pl->data;

		if (!pluma_plugin_info_is_active (info))
			continue;

	       	pluma_debug_message (DEBUG_PLUGINS, "Updating UI of %s", info->name);
		pluma_plugin_update_ui (info->plugin, window);
	}
}