/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "config.h"
#include
#include
#include "libgimpbase/gimpbase.h"
#include "menus-types.h"
#include "config/gimpconfig-file.h"
#include "config/gimpguiconfig.h"
#include "core/gimp.h"
#include "widgets/gimpactionfactory.h"
#include "widgets/gimpdashboard.h"
#include "widgets/gimpmenufactory.h"
#include "dockable-menu.h"
#include "image-menu.h"
#include "menus.h"
#include "plug-in-menus.h"
#include "tool-options-menu.h"
#include "gimp-intl.h"
/* local function prototypes */
static void menus_can_change_accels (GimpGuiConfig *config);
static void menus_remove_accels (gpointer data,
const gchar *accel_path,
guint accel_key,
GdkModifierType accel_mods,
gboolean changed);
/* global variables */
GimpMenuFactory * global_menu_factory = NULL;
/* private variables */
static gboolean menurc_deleted = FALSE;
/* public functions */
void
menus_init (Gimp *gimp,
GimpActionFactory *action_factory)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (GIMP_IS_ACTION_FACTORY (action_factory));
g_return_if_fail (global_menu_factory == NULL);
/* We need to make sure the property is installed before using it */
g_type_class_ref (GTK_TYPE_MENU);
menus_can_change_accels (GIMP_GUI_CONFIG (gimp->config));
g_signal_connect (gimp->config, "notify::can-change-accels",
G_CALLBACK (menus_can_change_accels), NULL);
global_menu_factory = gimp_menu_factory_new (gimp, action_factory);
gimp_menu_factory_manager_register (global_menu_factory, "",
"file",
"context",
"debug",
"help",
"edit",
"select",
"view",
"image",
"drawable",
"layers",
"channels",
"vectors",
"tools",
"dialogs",
"windows",
"plug-in",
"filters",
"quick-mask",
NULL,
"/image-menubar",
"image-menu.xml", image_menu_setup,
"/dummy-menubar",
"image-menu.xml", image_menu_setup,
"/quick-mask-popup",
"quick-mask-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"file",
"context",
"help",
"edit",
"select",
"view",
"image",
"drawable",
"layers",
"channels",
"vectors",
"tools",
"windows",
"dialogs",
"plug-in",
"filters",
"quick-mask",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"file",
"context",
"edit",
"select",
"view",
"image",
"drawable",
"layers",
"channels",
"vectors",
"tools",
"windows",
"dialogs",
"plug-in",
"quick-mask",
"dock",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"layers",
"plug-in",
"filters",
NULL,
"/layers-popup",
"layers-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"channels",
"plug-in",
"filters",
NULL,
"/channels-popup",
"channels-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"vectors",
"plug-in",
NULL,
"/vectors-popup",
"vectors-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"colormap",
"plug-in",
NULL,
"/colormap-popup",
"colormap-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"dockable",
"dock",
NULL,
"/dockable-popup",
"dockable-menu.xml", dockable_menu_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"brushes",
"plug-in",
NULL,
"/brushes-popup",
"brushes-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"dynamics",
"plug-in",
NULL,
"/dynamics-popup",
"dynamics-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"mypaint-brushes",
"plug-in",
NULL,
"/mypaint-brushes-popup",
"mypaint-brushes-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"patterns",
"plug-in",
NULL,
"/patterns-popup",
"patterns-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"gradients",
"plug-in",
NULL,
"/gradients-popup",
"gradients-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"palettes",
"plug-in",
NULL,
"/palettes-popup",
"palettes-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"tool-presets",
"plug-in",
NULL,
"/tool-presets-popup",
"tool-presets-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"fonts",
"plug-in",
NULL,
"/fonts-popup",
"fonts-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"buffers",
"plug-in",
NULL,
"/buffers-popup",
"buffers-menu.xml", plug_in_menus_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"documents",
NULL,
"/documents-popup",
"documents-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"templates",
NULL,
"/templates-popup",
"templates-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"images",
NULL,
"/images-popup",
"images-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"brush-editor",
NULL,
"/brush-editor-popup",
"brush-editor-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"dynamics-editor",
NULL,
"/dynamics-editor-popup",
"dynamics-editor-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"gradient-editor",
NULL,
"/gradient-editor-popup",
"gradient-editor-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"palette-editor",
NULL,
"/palette-editor-popup",
"palette-editor-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"tool-preset-editor",
NULL,
"/tool-preset-editor-popup",
"tool-preset-editor-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"select",
"vectors",
NULL,
"/selection-popup",
"selection-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"view",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"edit",
NULL,
"/undo-popup",
"undo-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"error-console",
NULL,
"/error-console-popup",
"error-console-menu.xml", NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"tool-options",
NULL,
"/tool-options-popup",
"tool-options-menu.xml",
tool_options_menu_setup,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"text-editor",
NULL,
"/text-editor-toolbar",
"text-editor-toolbar.xml",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"text-tool",
NULL,
"/text-tool-popup",
"text-tool-menu.xml",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"cursor-info",
NULL,
"/cursor-info-popup",
"cursor-info-menu.xml",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"sample-points",
NULL,
"/sample-points-popup",
"sample-points-menu.xml",
NULL,
NULL);
gimp_menu_factory_manager_register (global_menu_factory, "",
"dashboard",
NULL,
"/dashboard-popup",
"dashboard-menu.xml", gimp_dashboard_menu_setup,
NULL);
}
void
menus_exit (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (global_menu_factory != NULL);
g_object_unref (global_menu_factory);
global_menu_factory = NULL;
g_signal_handlers_disconnect_by_func (gimp->config,
menus_can_change_accels,
NULL);
}
void
menus_restore (Gimp *gimp)
{
GFile *file;
gchar *filename;
g_return_if_fail (GIMP_IS_GIMP (gimp));
file = gimp_directory_file ("menurc", NULL);
if (gimp->be_verbose)
g_print ("Parsing '%s'\n", gimp_file_get_utf8_name (file));
filename = g_file_get_path (file);
gtk_accel_map_load (filename);
g_free (filename);
g_object_unref (file);
}
void
menus_save (Gimp *gimp,
gboolean always_save)
{
GFile *file;
gchar *filename;
g_return_if_fail (GIMP_IS_GIMP (gimp));
if (menurc_deleted && ! always_save)
return;
file = gimp_directory_file ("menurc", NULL);
if (gimp->be_verbose)
g_print ("Writing '%s'\n", gimp_file_get_utf8_name (file));
filename = g_file_get_path (file);
gtk_accel_map_save (filename);
g_free (filename);
g_object_unref (file);
menurc_deleted = FALSE;
}
gboolean
menus_clear (Gimp *gimp,
GError **error)
{
GFile *file;
GFile *source;
gboolean success = TRUE;
GError *my_error = NULL;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
file = gimp_directory_file ("menurc", NULL);
source = gimp_sysconf_directory_file ("menurc", NULL);
if (g_file_copy (source, file, G_FILE_COPY_OVERWRITE,
NULL, NULL, NULL, NULL))
{
menurc_deleted = TRUE;
}
else if (! g_file_delete (file, NULL, &my_error) &&
my_error->code != G_IO_ERROR_NOT_FOUND)
{
g_set_error (error, my_error->domain, my_error->code,
_("Deleting \"%s\" failed: %s"),
gimp_file_get_utf8_name (file), my_error->message);
success = FALSE;
}
else
{
menurc_deleted = TRUE;
}
g_clear_error (&my_error);
g_object_unref (source);
g_object_unref (file);
return success;
}
void
menus_remove (Gimp *gimp)
{
g_return_if_fail (GIMP_IS_GIMP (gimp));
gtk_accel_map_foreach (gimp, menus_remove_accels);
}
/* private functions */
static void
menus_can_change_accels (GimpGuiConfig *config)
{
g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()),
"gtk-can-change-accels", config->can_change_accels,
NULL);
}
static void
menus_remove_accels (gpointer data,
const gchar *accel_path,
guint accel_key,
GdkModifierType accel_mods,
gboolean changed)
{
gtk_accel_map_change_entry (accel_path, 0, 0, TRUE);
}