Initial checkin of Pika from heckimp

This commit is contained in:
2023-09-25 15:35:21 -07:00
commit 891e999216
6761 changed files with 5240685 additions and 0 deletions

38
app/menus/dockable-menu.c Normal file
View File

@ -0,0 +1,38 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "menus-types.h"
#include "dockable-menu.h"
#include "window-menu.h"
void
dockable_menu_setup (PikaUIManager *manager,
const gchar *ui_path)
{
window_menu_setup (manager, "dock", ui_path);
}

30
app/menus/dockable-menu.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __DOCKABLE_MENU_H__
#define __DOCKABLE_MENU_H__
void dockable_menu_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __DOCKABLE_MENU_H__ */

66
app/menus/file-menu.c Normal file
View File

@ -0,0 +1,66 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libpikathumb/pikathumb.h"
#include "menus-types.h"
#include "config/pikaguiconfig.h"
#include "core/pika.h"
#include "core/pikaviewable.h"
#include "widgets/pikaaction.h"
#include "widgets/pikaactionimpl.h"
#include "widgets/pikauimanager.h"
#include "file-menu.h"
void
file_menu_setup (PikaUIManager *manager,
const gchar *ui_path)
{
gint n_entries;
gint i;
g_return_if_fail (PIKA_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
n_entries = PIKA_GUI_CONFIG (manager->pika->config)->last_opened_size;
for (i = 0; i < n_entries; i++)
{
gchar *action_name;
action_name = g_strdup_printf ("file-open-recent-%02d", i + 1);
pika_ui_manager_add_ui (manager, "/File/Open Recent/[Files]",
action_name, FALSE);
g_free (action_name);
}
}

30
app/menus/file-menu.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __FILE_MENU_H__
#define __FILE_MENU_H__
void file_menu_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __FILE_MENU_H__ */

124
app/menus/filters-menu.c Normal file
View File

@ -0,0 +1,124 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gegl-plugin.h>
#include <gtk/gtk.h>
#include "menus-types.h"
#include "gegl/pika-gegl-utils.h"
#include "core/pika.h"
#include "core/pika-filter-history.h"
#include "widgets/pikaactiongroup.h"
#include "widgets/pikastringaction.h"
#include "widgets/pikauimanager.h"
#include "filters-menu.h"
/* public functions */
void
filters_menu_setup (PikaUIManager *manager,
const gchar *ui_path)
{
PikaActionGroup *group;
gchar **gegl_actions;
gint i;
g_return_if_fail (PIKA_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
for (i = 0; i < pika_filter_history_size (manager->pika); i++)
{
gchar *action_name;
action_name = g_strdup_printf ("filters-recent-%02d", i + 1);
pika_ui_manager_add_ui (manager, "/Filters/Recently Used/[Filters]",
action_name, FALSE);
g_free (action_name);
}
group = pika_ui_manager_get_action_group (manager, "filters");
gegl_actions = g_object_get_data (G_OBJECT (group), "filters-group-generated-gegl-actions");
g_return_if_fail (gegl_actions != NULL);
for (i = 0; i < g_strv_length (gegl_actions); i++)
{
PikaAction *action;
gchar *path;
gchar *root;
const gchar *op_name;
action = pika_action_group_get_action (group, gegl_actions[i]);
op_name = (const gchar *) PIKA_STRING_ACTION (action)->value;
path = (gchar *) gegl_operation_get_key (op_name, "pika:menu-path");
if (path == NULL)
continue;
path = g_strdup (path);
root = strstr (path, "/");
if (root == NULL || root == path)
{
g_printerr ("GEGL operation \"%s\" attempted to register a menu item "
"with an invalid value for key \"pika:menu-path\": \"%s\"\n"
"Expected format is \"<MenuName>/menu/submenu.\n",
gegl_actions[i], path);
}
else
{
GList *managers;
*root = '\0';
managers = pika_ui_managers_from_name (path);
if (managers == NULL)
{
g_printerr ("GEGL operation \"%s\" attempted to register an item in "
"the invalid menu \"%s\": use either \"<Image>\", "
"\"<Layers>\", \"<Channels>\", \"<Vectors>\", "
"\"<Colormap>\", \"<Brushes>\", \"<Dynamics>\", "
"\"<MyPaintBrushes>\", \"<Gradients>\", \"<Palettes>\", "
"\"<Patterns>\", \"<ToolPresets>\", \"<Fonts>\" "
"\"<Buffers>\" or \"<QuickMask>\".\n",
gegl_actions[i], path);
}
else
{
*root = '/';
for (GList *m = managers; m; m = m->next)
pika_ui_manager_add_ui (m->data, root, gegl_actions[i], FALSE);
}
}
g_free (path);
}
}

30
app/menus/filters-menu.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __FILTERS_MENU_H__
#define __FILTERS_MENU_H__
void filters_menu_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __FILTERS_MENU_H__ */

53
app/menus/image-menu.c Normal file
View File

@ -0,0 +1,53 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "menus-types.h"
#include "file-menu.h"
#include "filters-menu.h"
#include "image-menu.h"
#include "plug-in-menus.h"
#include "window-menu.h"
#include "windows-menu.h"
void
image_menu_setup (PikaUIManager *manager,
const gchar *ui_path)
{
gchar *path;
file_menu_setup (manager, ui_path);
windows_menu_setup (manager, ui_path);
plug_in_menus_setup (manager, ui_path);
filters_menu_setup (manager, ui_path);
path = g_strconcat (ui_path, "/View", NULL);
window_menu_setup (manager, "view", path);
g_free (path);
}

30
app/menus/image-menu.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __IMAGE_MENU_H__
#define __IMAGE_MENU_H__
void image_menu_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __IMAGE_MENU_H__ */

29
app/menus/menus-types.h Normal file
View File

@ -0,0 +1,29 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __MENUS_TYPES_H__
#define __MENUS_TYPES_H__
#include "actions/actions-types.h"
#endif /* __MENUS_TYPES_H__ */

548
app/menus/menus.c Normal file
View File

@ -0,0 +1,548 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libpikabase/pikabase.h"
#include "menus-types.h"
#include "actions/actions.h"
#include "config/pikaconfig-file.h"
#include "config/pikaguiconfig.h"
#include "core/pika.h"
#include "widgets/pikaaction.h"
#include "widgets/pikaactionfactory.h"
#include "widgets/pikadashboard.h"
#include "widgets/pikamenufactory.h"
#include "widgets/pikauimanager.h"
#include "dockable-menu.h"
#include "image-menu.h"
#include "menus.h"
#include "plug-in-menus.h"
#include "shortcuts-rc.h"
#include "tool-options-menu.h"
#include "pika-intl.h"
/* local function prototypes */
/* private variables */
static gboolean menurc_deleted = FALSE;
/* public functions */
void
menus_init (Pika *pika)
{
PikaMenuFactory *global_menu_factory = NULL;
g_return_if_fail (PIKA_IS_PIKA (pika));
/* We need to make sure the property is installed before using it */
g_type_class_ref (GTK_TYPE_MENU);
global_menu_factory = menus_get_global_menu_factory (pika);
pika_menu_factory_manager_register (global_menu_factory, "<Image>",
"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", image_menu_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<QuickMask>",
"quick-mask",
NULL,
"/quick-mask-popup",
"quick-mask-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<AppMenu>",
"file",
"dialogs",
NULL,
"/app-menu",
"app-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Toolbox>",
"file",
"context",
"help",
"edit",
"select",
"view",
"image",
"drawable",
"layers",
"channels",
"vectors",
"tools",
"windows",
"dialogs",
"plug-in",
"filters",
"quick-mask",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Dock>",
"file",
"context",
"edit",
"select",
"view",
"image",
"drawable",
"layers",
"channels",
"vectors",
"tools",
"windows",
"dialogs",
"plug-in",
"quick-mask",
"dock",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Layers>",
"layers",
"plug-in",
"filters",
NULL,
"/layers-popup",
"layers-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Channels>",
"channels",
"plug-in",
"filters",
NULL,
"/channels-popup",
"channels-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Vectors>",
"vectors",
"plug-in",
NULL,
"/vectors-popup",
"vectors-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<VectorToolPath>",
"vector-toolpath",
NULL,
"/vector-toolpath-popup",
"vector-toolpath-menu",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Colormap>",
"colormap",
"plug-in",
NULL,
"/colormap-popup",
"colormap-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Dockable>",
"dockable",
"dock",
NULL,
"/dockable-popup",
"dockable-menu", dockable_menu_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Brushes>",
"brushes",
"plug-in",
NULL,
"/brushes-popup",
"brushes-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Dynamics>",
"dynamics",
"plug-in",
NULL,
"/dynamics-popup",
"dynamics-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<MyPaintBrushes>",
"mypaint-brushes",
"plug-in",
NULL,
"/mypaint-brushes-popup",
"mypaint-brushes-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Patterns>",
"patterns",
"plug-in",
NULL,
"/patterns-popup",
"patterns-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Gradients>",
"gradients",
"plug-in",
NULL,
"/gradients-popup",
"gradients-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Palettes>",
"palettes",
"plug-in",
NULL,
"/palettes-popup",
"palettes-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<ToolPresets>",
"tool-presets",
"plug-in",
NULL,
"/tool-presets-popup",
"tool-presets-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Fonts>",
"fonts",
"plug-in",
NULL,
"/fonts-popup",
"fonts-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Buffers>",
"buffers",
"plug-in",
NULL,
"/buffers-popup",
"buffers-menu", plug_in_menus_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Documents>",
"documents",
NULL,
"/documents-popup",
"documents-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Templates>",
"templates",
NULL,
"/templates-popup",
"templates-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Images>",
"images",
NULL,
"/images-popup",
"images-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<BrushEditor>",
"brush-editor",
NULL,
"/brush-editor-popup",
"brush-editor-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<DynamicsEditor>",
"dynamics-editor",
NULL,
"/dynamics-editor-popup",
"dynamics-editor-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<GradientEditor>",
"gradient-editor",
NULL,
"/gradient-editor-popup",
"gradient-editor-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<PaletteEditor>",
"palette-editor",
NULL,
"/palette-editor-popup",
"palette-editor-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<ToolPresetEditor>",
"tool-preset-editor",
NULL,
"/tool-preset-editor-popup",
"tool-preset-editor-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Selection>",
"select",
"vectors",
NULL,
"/selection-popup",
"selection-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<NavigationEditor>",
"view",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Undo>",
"edit",
NULL,
"/undo-popup",
"undo-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<ErrorConsole>",
"error-console",
NULL,
"/error-console-popup",
"error-console-menu", NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<ToolOptions>",
"tool-options",
NULL,
"/tool-options-popup",
"tool-options-menu",
tool_options_menu_setup,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<TextEditor>",
"text-editor",
NULL,
"/text-editor-toolbar",
"text-editor-toolbar",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<TextTool>",
"text-tool",
NULL,
"/text-tool-popup",
"text-tool-menu",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<CursorInfo>",
"cursor-info",
NULL,
"/cursor-info-popup",
"cursor-info-menu",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<SamplePoints>",
"sample-points",
NULL,
"/sample-points-popup",
"sample-points-menu",
NULL,
NULL);
pika_menu_factory_manager_register (global_menu_factory, "<Dashboard>",
"dashboard",
NULL,
"/dashboard-popup",
"dashboard-menu", pika_dashboard_menu_setup,
NULL);
}
void
menus_exit (Pika *pika)
{
g_return_if_fail (PIKA_IS_PIKA (pika));
g_return_if_fail (menus_get_global_menu_factory (pika) != NULL);
g_object_unref (menus_get_global_menu_factory (pika));
}
void
menus_restore (Pika *pika)
{
GFile *file;
GError *error = NULL;
g_return_if_fail (PIKA_IS_PIKA (pika));
file = pika_directory_file ("shortcutsrc", NULL);
if (pika->be_verbose)
g_print ("Parsing '%s'\n", pika_file_get_utf8_name (file));
if (g_file_query_exists (file, NULL) &&
! shortcuts_rc_parse (GTK_APPLICATION (pika->app), file, &error))
g_printerr ("Failed reading '%s': %s\n",
g_file_peek_path (file), error->message);
g_object_unref (file);
}
void
menus_save (Pika *pika,
gboolean always_save)
{
GFile *file;
GError *error = NULL;
g_return_if_fail (PIKA_IS_PIKA (pika));
if (menurc_deleted && ! always_save)
return;
file = pika_directory_file ("shortcutsrc", NULL);
if (pika->be_verbose)
g_print ("Writing '%s'\n", pika_file_get_utf8_name (file));
if (! shortcuts_rc_write (GTK_APPLICATION (pika->app), file, &error))
g_printerr ("Failed writing to '%s': %s\n",
g_file_peek_path (file), error->message);
g_object_unref (file);
g_clear_error (&error);
menurc_deleted = FALSE;
}
gboolean
menus_clear (Pika *pika,
GError **error)
{
GFile *file;
gboolean success = TRUE;
GError *my_error = NULL;
g_return_val_if_fail (PIKA_IS_PIKA (pika), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
file = pika_directory_file ("shortcutsrc", NULL);
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"),
pika_file_get_utf8_name (file), my_error->message);
success = FALSE;
}
else
{
menurc_deleted = TRUE;
}
g_clear_error (&my_error);
g_object_unref (file);
return success;
}
void
menus_remove (Pika *pika)
{
gchar **actions;
g_return_if_fail (PIKA_IS_PIKA (pika));
actions = g_action_group_list_actions (G_ACTION_GROUP (pika->app));
for (gint i = 0; actions[i] != NULL; i++)
{
PikaAction *action;
action = (PikaAction *) g_action_map_lookup_action (G_ACTION_MAP (pika->app),
actions[i]);
pika_action_set_accels (action, (const gchar *[]) { NULL });
}
g_strfreev (actions);
}
PikaMenuFactory *
menus_get_global_menu_factory (Pika *pika)
{
static PikaMenuFactory *global_menu_factory = NULL;
static gboolean created = FALSE;
if (global_menu_factory == NULL && ! created)
{
g_set_weak_pointer (&global_menu_factory,
pika_menu_factory_new (pika, global_action_factory));
created = TRUE;
}
return global_menu_factory;
}
PikaUIManager *
menus_get_image_manager_singleton (Pika *pika)
{
static PikaUIManager *image_ui_manager = NULL;
if (image_ui_manager == NULL)
{
image_ui_manager = pika_menu_factory_get_manager (menus_get_global_menu_factory (pika),
"<Image>", pika);
image_ui_manager->store_action_paths = TRUE;
}
return image_ui_manager;
}

41
app/menus/menus.h Normal file
View File

@ -0,0 +1,41 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __MENUS_H__
#define __MENUS_H__
void menus_init (Pika *pika);
void menus_exit (Pika *pika);
void menus_restore (Pika *pika);
void menus_save (Pika *pika,
gboolean always_save);
gboolean menus_clear (Pika *pika,
GError **error);
void menus_remove (Pika *pika);
PikaMenuFactory * menus_get_global_menu_factory (Pika *pika);
PikaUIManager * menus_get_image_manager_singleton (Pika *pika);
#endif /* __MENUS_H__ */

21
app/menus/meson.build Normal file
View File

@ -0,0 +1,21 @@
libappmenus_sources = [
'dockable-menu.c',
'file-menu.c',
'filters-menu.c',
'image-menu.c',
'menus.c',
'plug-in-menus.c',
'shortcuts-rc.c',
'tool-options-menu.c',
'window-menu.c',
'windows-menu.c',
]
libappmenus = static_library('appmenus',
libappmenus_sources,
include_directories: [ rootInclude, rootAppInclude, ],
c_args: '-DG_LOG_DOMAIN="Pika-Menus"',
dependencies: [
gegl, gtk3
],
)

350
app/menus/plug-in-menus.c Normal file
View File

@ -0,0 +1,350 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#include <gegl.h>
#include "libpikabase/pikabase.h"
#include "menus-types.h"
#include "config/pikacoreconfig.h"
#include "core/pika.h"
#include "plug-in/pikapluginmanager.h"
#include "plug-in/pikapluginprocedure.h"
#include "widgets/pikauimanager.h"
#include "plug-in-menus.h"
#include "pika-log.h"
#include "pika-intl.h"
typedef struct _PlugInMenuEntry PlugInMenuEntry;
struct _PlugInMenuEntry
{
PikaPlugInProcedure *proc;
const gchar *menu_path;
};
/* local function prototypes */
static void plug_in_menus_register_procedure (PikaPDB *pdb,
PikaProcedure *procedure,
PikaUIManager *manager);
static void plug_in_menus_unregister_procedure (PikaPDB *pdb,
PikaProcedure *procedure,
PikaUIManager *manager);
static void plug_in_menus_menu_path_added (PikaPlugInProcedure *plug_in_proc,
const gchar *menu_path,
PikaUIManager *manager);
static void plug_in_menus_add_proc (PikaUIManager *manager,
const gchar *ui_path,
PikaPlugInProcedure *proc,
const gchar *menu_path);
static void plug_in_menus_tree_insert (GTree *entries,
const gchar * path,
PlugInMenuEntry *entry);
static gboolean plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,
PikaUIManager *manager);
static void plug_in_menu_entry_free (PlugInMenuEntry *entry);
/* public functions */
void
plug_in_menus_setup (PikaUIManager *manager,
const gchar *ui_path)
{
PikaPlugInManager *plug_in_manager;
GTree *menu_entries;
GSList *list;
g_return_if_fail (PIKA_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
plug_in_manager = manager->pika->plug_in_manager;
menu_entries = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
g_free,
(GDestroyNotify) plug_in_menu_entry_free);
for (list = plug_in_manager->plug_in_procedures;
list;
list = g_slist_next (list))
{
PikaPlugInProcedure *plug_in_proc = list->data;
if (! plug_in_proc->file)
continue;
g_signal_connect_object (plug_in_proc, "menu-path-added",
G_CALLBACK (plug_in_menus_menu_path_added),
manager, 0);
if (plug_in_proc->menu_label &&
! plug_in_proc->file_proc)
{
GList *path;
for (path = plug_in_proc->menu_paths; path; path = g_list_next (path))
{
if (g_str_has_prefix (path->data, manager->name))
{
PlugInMenuEntry *entry = g_slice_new0 (PlugInMenuEntry);
gchar *menu;
entry->proc = plug_in_proc;
entry->menu_path = path->data;
menu = g_strconcat (path->data, "/",
plug_in_proc->menu_label,
NULL);
plug_in_menus_tree_insert (menu_entries, menu, entry);
g_free (menu);
}
}
}
}
g_object_set_data (G_OBJECT (manager), "ui-path", (gpointer) ui_path);
g_tree_foreach (menu_entries,
(GTraverseFunc) plug_in_menus_tree_traverse,
manager);
g_object_set_data (G_OBJECT (manager), "ui-path", NULL);
g_tree_destroy (menu_entries);
g_signal_connect_object (manager->pika->pdb, "register-procedure",
G_CALLBACK (plug_in_menus_register_procedure),
manager, 0);
g_signal_connect_object (manager->pika->pdb, "unregister-procedure",
G_CALLBACK (plug_in_menus_unregister_procedure),
manager, 0);
}
/* private functions */
static void
plug_in_menus_register_procedure (PikaPDB *pdb,
PikaProcedure *procedure,
PikaUIManager *manager)
{
if (PIKA_IS_PLUG_IN_PROCEDURE (procedure))
{
PikaPlugInProcedure *plug_in_proc = PIKA_PLUG_IN_PROCEDURE (procedure);
g_signal_connect_object (plug_in_proc, "menu-path-added",
G_CALLBACK (plug_in_menus_menu_path_added),
manager, 0);
if (plug_in_proc->menu_label &&
! plug_in_proc->file_proc)
{
GList *list;
PIKA_LOG (MENUS, "register procedure: %s", pika_object_get_name (procedure));
for (list = plug_in_proc->menu_paths; list; list = g_list_next (list))
plug_in_menus_menu_path_added (plug_in_proc, list->data, manager);
}
}
}
static void
plug_in_menus_unregister_procedure (PikaPDB *pdb,
PikaProcedure *procedure,
PikaUIManager *manager)
{
if (PIKA_IS_PLUG_IN_PROCEDURE (procedure))
{
PikaPlugInProcedure *plug_in_proc = PIKA_PLUG_IN_PROCEDURE (procedure);
g_signal_handlers_disconnect_by_func (plug_in_proc,
plug_in_menus_menu_path_added,
manager);
if (plug_in_proc->menu_label && ! plug_in_proc->file_proc)
{
PIKA_LOG (MENUS, "unregister procedure: %s", pika_object_get_name (procedure));
pika_ui_manager_remove_ui (manager, pika_object_get_name (plug_in_proc));
}
}
}
static void
plug_in_menus_menu_path_added (PikaPlugInProcedure *plug_in_proc,
const gchar *menu_path,
PikaUIManager *manager)
{
PIKA_LOG (MENUS, "menu path added: %s (%s)",
pika_object_get_name (plug_in_proc), menu_path);
if (g_str_has_prefix (menu_path, manager->name))
{
if (! strcmp (manager->name, "<Image>"))
{
plug_in_menus_add_proc (manager, "/image-menubar", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Layers>"))
{
plug_in_menus_add_proc (manager, "/layers-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Channels>"))
{
plug_in_menus_add_proc (manager, "/channels-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Vectors>"))
{
plug_in_menus_add_proc (manager, "/vectors-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Colormap>"))
{
plug_in_menus_add_proc (manager, "/colormap-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Brushes>"))
{
plug_in_menus_add_proc (manager, "/brushes-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Dynamics>"))
{
plug_in_menus_add_proc (manager, "/dynamics-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<MyPaintBrushes>"))
{
plug_in_menus_add_proc (manager, "/mypaint-brushes-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Gradients>"))
{
plug_in_menus_add_proc (manager, "/gradients-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Palettes>"))
{
plug_in_menus_add_proc (manager, "/palettes-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Patterns>"))
{
plug_in_menus_add_proc (manager, "/patterns-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<ToolPresets>"))
{
plug_in_menus_add_proc (manager, "/tool-presets-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Fonts>"))
{
plug_in_menus_add_proc (manager, "/fonts-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
else if (! strcmp (manager->name, "<Buffers>"))
{
plug_in_menus_add_proc (manager, "/buffers-popup", plug_in_proc,
menu_path + strlen (manager->name));
}
}
}
static void
plug_in_menus_add_proc (PikaUIManager *manager,
const gchar *ui_path,
PikaPlugInProcedure *proc,
const gchar *menu_path)
{
g_return_if_fail (PIKA_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
g_return_if_fail (PIKA_IS_PLUG_IN_PROCEDURE (proc));
if (! proc->menu_label)
return;
PIKA_LOG (MENUS, "adding menu item for '%s' (@ %s)",
pika_object_get_name (proc), menu_path);
pika_ui_manager_add_ui (manager, menu_path,
pika_object_get_name (proc),
FALSE);
}
static void
plug_in_menus_tree_insert (GTree *entries,
const gchar *path,
PlugInMenuEntry *entry)
{
gchar *strip = pika_strip_uline (path);
gchar *key;
/* Append the procedure name to the menu path in order to get a unique
* key even if two procedures are installed to the same menu entry.
*/
key = g_strconcat (strip, pika_object_get_name (entry->proc), NULL);
g_tree_insert (entries, g_utf8_collate_key (key, -1), entry);
g_free (key);
g_free (strip);
}
static gboolean
plug_in_menus_tree_traverse (gpointer key,
PlugInMenuEntry *entry,
PikaUIManager *manager)
{
const gchar *ui_path = g_object_get_data (G_OBJECT (manager), "ui-path");
g_return_val_if_fail (g_str_has_prefix (entry->menu_path, manager->name), FALSE);
plug_in_menus_add_proc (manager, ui_path, entry->proc,
entry->menu_path + strlen (manager->name));
return FALSE;
}
static void
plug_in_menu_entry_free (PlugInMenuEntry *entry)
{
g_slice_free (PlugInMenuEntry, entry);
}

30
app/menus/plug-in-menus.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __PLUG_IN_MENUS_H__
#define __PLUG_IN_MENUS_H__
void plug_in_menus_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __PLUG_IN_MENUS_H__ */

350
app/menus/shortcuts-rc.c Normal file
View File

@ -0,0 +1,350 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* shortcuts-rc.c
* Copyright (C) 2023 Jehan
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libpikabase/pikabase.h"
#include "libpikabase/pikaprotocol.h"
#include "libpikaconfig/pikaconfig.h"
#include "menus-types.h"
#include "widgets/pikaaction.h"
#include "widgets/pikaradioaction.h"
#include "shortcuts-rc.h"
#include "pika-intl.h"
#define SHORTCUTS_RC_FILE_VERSION 1
/*
* All deserialize functions return G_TOKEN_LEFT_PAREN on success,
* or the GTokenType they would have expected but didn't get,
* or G_TOKEN_ERROR if the function already set an error itself.
*/
static GTokenType shortcuts_action_deserialize (GScanner *scanner,
GtkApplication *application);
enum
{
PROTOCOL_VERSION = 1,
FILE_VERSION,
ACTION,
};
gboolean
shortcuts_rc_parse (GtkApplication *application,
GFile *file,
GError **error)
{
GScanner *scanner;
gint protocol_version = PIKA_PROTOCOL_VERSION;
gint file_version = SHORTCUTS_RC_FILE_VERSION;
GTokenType token;
g_return_val_if_fail (GTK_IS_APPLICATION (application), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
scanner = pika_scanner_new_file (file, error);
if (! scanner)
return FALSE;
g_scanner_scope_add_symbol (scanner, 0,
"protocol-version",
GINT_TO_POINTER (PROTOCOL_VERSION));
g_scanner_scope_add_symbol (scanner, 0,
"file-version",
GINT_TO_POINTER (FILE_VERSION));
g_scanner_scope_add_symbol (scanner, 0,
"action", GINT_TO_POINTER (ACTION));
token = G_TOKEN_LEFT_PAREN;
while (protocol_version == PIKA_PROTOCOL_VERSION &&
file_version == SHORTCUTS_RC_FILE_VERSION &&
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 PROTOCOL_VERSION:
token = G_TOKEN_INT;
if (pika_scanner_parse_int (scanner, &protocol_version))
token = G_TOKEN_RIGHT_PAREN;
break;
case FILE_VERSION:
token = G_TOKEN_INT;
if (pika_scanner_parse_int (scanner, &file_version))
token = G_TOKEN_RIGHT_PAREN;
break;
case ACTION:
g_scanner_set_scope (scanner, ACTION);
token = shortcuts_action_deserialize (scanner, application);
g_scanner_set_scope (scanner, 0);
break;
default:
break;
}
break;
case G_TOKEN_RIGHT_PAREN:
token = G_TOKEN_LEFT_PAREN;
break;
default: /* do nothing */
break;
}
}
if (protocol_version != PIKA_PROTOCOL_VERSION ||
file_version != SHORTCUTS_RC_FILE_VERSION ||
token != G_TOKEN_LEFT_PAREN)
{
if (protocol_version != PIKA_PROTOCOL_VERSION)
{
g_set_error (error,
PIKA_CONFIG_ERROR, PIKA_CONFIG_ERROR_VERSION,
_("Skipping '%s': wrong PIKA protocol version."),
pika_file_get_utf8_name (file));
}
else if (file_version != SHORTCUTS_RC_FILE_VERSION)
{
g_set_error (error,
PIKA_CONFIG_ERROR, PIKA_CONFIG_ERROR_VERSION,
_("Skipping '%s': wrong shortcutsrc file format version."),
pika_file_get_utf8_name (file));
}
else if (token != G_TOKEN_ERROR)
{
g_scanner_get_next_token (scanner);
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
_("fatal parse error"), TRUE);
}
return FALSE;
}
pika_scanner_unref (scanner);
return TRUE;
}
gboolean
shortcuts_rc_write (GtkApplication *application,
GFile *file,
GError **error)
{
PikaConfigWriter *writer;
gchar **actions;
g_return_val_if_fail (GTK_IS_APPLICATION (application), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
writer = pika_config_writer_new_from_file (file,
FALSE,
"PIKA shortcutsrc\n\n"
"If you delete this file, all shortcuts "
"will be reset to defaults.",
error);
if (! writer)
return FALSE;
actions = g_action_group_list_actions (G_ACTION_GROUP (application));
pika_config_writer_open (writer, "protocol-version");
pika_config_writer_printf (writer, "%d", PIKA_PROTOCOL_VERSION);
pika_config_writer_close (writer);
pika_config_writer_open (writer, "file-version");
pika_config_writer_printf (writer, "%d", SHORTCUTS_RC_FILE_VERSION);
pika_config_writer_close (writer);
pika_config_writer_linefeed (writer);
for (gint i = 0; actions[i] != NULL; i++)
{
PikaAction *action;
gchar **accels;
gchar *detailed_name;
gboolean commented = FALSE;
action = (PikaAction *) g_action_map_lookup_action (G_ACTION_MAP (application), actions[i]);
if (PIKA_IS_RADIO_ACTION (action))
{
gint value;
g_object_get ((GObject *) action,
"value",
&value,
NULL);
detailed_name = g_strdup_printf ("app.%s(%i)", actions[i],
value);
}
else
{
detailed_name = g_strdup_printf ("app.%s", actions[i]);
}
accels = gtk_application_get_accels_for_action (application, detailed_name);
if (pika_action_use_default_accels (action))
commented = TRUE;
pika_config_writer_comment_mode (writer, commented);
pika_config_writer_open (writer, "action");
pika_config_writer_string (writer, actions[i]);
for (gint j = 0; accels[j]; j++)
pika_config_writer_string (writer, accels[j]);
pika_config_writer_close (writer);
pika_config_writer_comment_mode (writer, FALSE);
g_strfreev (accels);
g_free (detailed_name);
}
g_strfreev (actions);
return pika_config_writer_finish (writer, "end of shortcutsrc", error);
}
/* Private functions */
static GTokenType
shortcuts_action_deserialize (GScanner *scanner,
GtkApplication *application)
{
GStrvBuilder *builder;
gchar *action_name;
gchar *accel;
gchar **accels;
if (! pika_scanner_parse_string (scanner, &action_name))
return G_TOKEN_STRING;
builder = g_strv_builder_new ();
while (pika_scanner_parse_string (scanner, &accel))
{
gchar **dup_actions;
gboolean add_accel = TRUE;
dup_actions = gtk_application_get_actions_for_accel (application, accel);
for (gint i = 0; dup_actions[i] != NULL; i++)
{
PikaAction *conflict_action;
gchar *left_paren_ptr = strchr (dup_actions[i], '(');
if (left_paren_ptr)
*left_paren_ptr = '\0'; /* ignore target part of detailed name */
/* dup_actions[i] will be the detailed name prefixed with "app." */
if (g_strcmp0 (dup_actions[i] + 4, action_name) == 0)
continue;
conflict_action = (PikaAction *) g_action_map_lookup_action (G_ACTION_MAP (application),
dup_actions[i] + 4);
if (pika_action_use_default_accels (conflict_action))
{
/* We might simply not have scanned this action's accelerators yet
* in the shortcutsrc file. Just delete its current accelerators
* without any message.
*/
pika_action_set_accels (conflict_action, NULL);
}
else
{
g_printerr ("INFO: duplicate accelerator '%s' on '%s' and '%s'.\n"
" Removing the accelerator from '%s'.\n",
accel, action_name, dup_actions[i], action_name);
add_accel = FALSE;
break;
}
}
g_strfreev (dup_actions);
if (add_accel)
g_strv_builder_add (builder, accel);
g_free (accel);
}
accels = g_strv_builder_end (builder);
if (g_action_group_has_action (G_ACTION_GROUP (application), action_name))
{
PikaAction *action;
gchar *detailed_name;
action = (PikaAction *) g_action_map_lookup_action (G_ACTION_MAP (application),
action_name);
detailed_name = g_strdup_printf ("app.%s", action_name);
pika_action_set_accels (action, (const gchar **) accels);
g_free (detailed_name);
}
else
{
/* Don't set a breaking error, just output on stderr, so that we can make a
* notice while still loading other actions.
*/
g_printerr ("INFO: not existing action '%s' was ignored from the shortcutsrc file.\n",
action_name);
}
g_strv_builder_unref (builder);
g_free (action_name);
g_strfreev (accels);
if (! pika_scanner_parse_token (scanner, G_TOKEN_RIGHT_PAREN))
return G_TOKEN_RIGHT_PAREN;
return G_TOKEN_LEFT_PAREN;
}

37
app/menus/shortcuts-rc.h Normal file
View File

@ -0,0 +1,37 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* shortcuts-rc.h
* Copyright (C) 2023 Jehan
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __SHORTCUTS_RC_H__
#define __SHORTCUTS_RC_H__
gboolean shortcuts_rc_parse (GtkApplication *application,
GFile *file,
GError **error);
gboolean shortcuts_rc_write (GtkApplication *application,
GFile *file,
GError **error);
#endif /* __SHORTCUTS_RC_H__ */

View File

@ -0,0 +1,137 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "libpikawidgets/pikawidgets.h"
#include "menus-types.h"
#include "core/pika.h"
#include "core/pikacontext.h"
#include "core/pikalist.h"
#include "core/pikatoolinfo.h"
#include "widgets/pikahelp-ids.h"
#include "widgets/pikauimanager.h"
#include "tool-options-menu.h"
/* local function prototypes */
static void tool_options_menu_update (PikaUIManager *manager,
gpointer update_data,
const gchar *ui_path);
static void tool_options_menu_update_after (PikaUIManager *manager,
gpointer update_data,
const gchar *ui_path);
static void tool_options_menu_update_presets (PikaUIManager *manager,
const gchar *menu_path,
const gchar *which_action,
PikaContainer *presets);
/* public functions */
void
tool_options_menu_setup (PikaUIManager *manager,
const gchar *ui_path)
{
g_signal_connect (manager, "update",
G_CALLBACK (tool_options_menu_update),
(gpointer) ui_path);
g_signal_connect_after (manager, "update",
G_CALLBACK (tool_options_menu_update_after),
(gpointer) ui_path);
}
/* private functions */
static void
tool_options_menu_update (PikaUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
/* no-op. */
}
static void
tool_options_menu_update_after (PikaUIManager *manager,
gpointer update_data,
const gchar *ui_path)
{
PikaContext *context;
PikaToolInfo *tool_info;
context = pika_get_user_context (manager->pika);
tool_info = pika_context_get_tool (context);
if (! tool_info->presets)
return;
tool_options_menu_update_presets (manager, "Save Tool Preset",
"save", tool_info->presets);
tool_options_menu_update_presets (manager, "Restore Tool Preset",
"restore", tool_info->presets);
tool_options_menu_update_presets (manager, "Edit Tool Preset",
"edit", tool_info->presets);
tool_options_menu_update_presets (manager, "Delete Tool Preset",
"delete", tool_info->presets);
}
static void
tool_options_menu_update_presets (PikaUIManager *manager,
const gchar *menu_path,
const gchar *which_action,
PikaContainer *presets)
{
gchar *action_prefix;
gint n_children;
gint i;
action_prefix = g_strdup_printf ("tool-options-%s-preset-", which_action);
pika_ui_manager_remove_uis (manager, action_prefix);
n_children = pika_container_get_n_children (presets);
for (i = 0; i < n_children; i++)
{
gchar *action_name;
gchar *path;
action_name = g_strdup_printf ("%s%03d", action_prefix, i);
path = g_strdup_printf ("/Tool Options Menu/%s", menu_path);
pika_ui_manager_add_ui (manager, path, action_name, FALSE);
g_free (action_name);
g_free (path);
}
g_free (action_prefix);
}

View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __TOOL_OPTIONS_MENU_H__
#define __TOOL_OPTIONS_MENU_H__
void tool_options_menu_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __TOOL_OPTIONS_MENU_H__ */

144
app/menus/window-menu.c Normal file
View File

@ -0,0 +1,144 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gegl.h>
#include <gtk/gtk.h>
#include "menus-types.h"
#include "config/pikaguiconfig.h"
#include "core/pika.h"
#include "widgets/pikauimanager.h"
#include "widgets/pikawidgets-utils.h"
#include "window-menu.h"
/* private functions */
static void window_menu_display_opened (GdkDisplayManager *disp_manager,
GdkDisplay *display,
PikaUIManager *manager);
static void window_menu_display_closed (GdkDisplay *display,
gboolean is_error,
PikaUIManager *manager);
/* public functions */
void
window_menu_setup (PikaUIManager *manager,
const gchar *group_name,
const gchar *ui_path)
{
GdkDisplayManager *disp_manager = gdk_display_manager_get ();
GSList *displays;
GSList *list;
g_return_if_fail (PIKA_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
g_object_set_data_full (G_OBJECT (manager), "move-to-screen-group-name",
g_strdup (group_name),
(GDestroyNotify) g_free);
g_object_set_data_full (G_OBJECT (manager), "move-to-screen-ui-path",
g_strdup (ui_path),
(GDestroyNotify) g_free);
displays = gdk_display_manager_list_displays (disp_manager);
/* present displays in the order in which they were opened */
displays = g_slist_reverse (displays);
for (list = displays; list; list = g_slist_next (list))
{
window_menu_display_opened (disp_manager, list->data, manager);
}
g_slist_free (displays);
g_signal_connect_object (disp_manager, "display-opened",
G_CALLBACK (window_menu_display_opened),
G_OBJECT (manager), 0);
}
/* private functions */
static void
window_menu_display_opened (GdkDisplayManager *disp_manager,
GdkDisplay *display,
PikaUIManager *manager)
{
const gchar *group_name;
const gchar *ui_path;
const gchar *display_name;
gchar *action_name;
group_name = g_object_get_data (G_OBJECT (manager),
"move-to-screen-group-name");
ui_path = g_object_get_data (G_OBJECT (manager),
"move-to-screen-ui-path");
display_name = gdk_display_get_name (display);
if (! display_name)
display_name = "eek";
action_name = g_strdup_printf ("%s-move-to-screen-%s", group_name, display_name);
pika_make_valid_action_name (action_name);
/* TODO GMenu: there is also a case with the dockable menu, which is not yet
* using our new GAction/GMenu-based code. In such case, the ui_path is
* "/dockable-popup/Move to Screen".
*/
if (g_str_has_prefix (ui_path, "/image-menubar/"))
pika_ui_manager_add_ui (manager, "/View/Move to Screen", action_name, FALSE);
g_free (action_name);
g_signal_connect_object (display, "closed",
G_CALLBACK (window_menu_display_closed),
G_OBJECT (manager), 0);
}
static void
window_menu_display_closed (GdkDisplay *display,
gboolean is_error,
PikaUIManager *manager)
{
const gchar *group_name;
const gchar *display_name;
gchar *action_name;
group_name = g_object_get_data (G_OBJECT (manager), "move-to-screen-group-name");
display_name = gdk_display_get_name (display);
if (! display_name)
display_name = "eek";
action_name = g_strdup_printf ("%s-move-to-screen-%s", group_name, display_name);
pika_ui_manager_remove_ui (manager, action_name);
g_free (action_name);
}

31
app/menus/window-menu.h Normal file
View File

@ -0,0 +1,31 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __WINDOW_MENU_H__
#define __WINDOW_MENU_H__
void window_menu_setup (PikaUIManager *manager,
const gchar *group_name,
const gchar *ui_path);
#endif /* __WINDOW_MENU_H__ */

273
app/menus/windows-menu.c Normal file
View File

@ -0,0 +1,273 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libpikathumb/pikathumb.h"
#include "menus-types.h"
#include "config/pikaguiconfig.h"
#include "core/pika.h"
#include "core/pikaimage.h"
#include "core/pikalist.h"
#include "core/pikaviewable.h"
#include "widgets/pikaaction.h"
#include "widgets/pikaactionimpl.h"
#include "widgets/pikadialogfactory.h"
#include "widgets/pikadock.h"
#include "widgets/pikadockwindow.h"
#include "widgets/pikasessioninfo.h"
#include "widgets/pikauimanager.h"
#include "display/pikadisplay.h"
#include "dialogs/dialogs.h"
#include "actions/windows-actions.h"
#include "windows-menu.h"
static void windows_menu_display_add (PikaContainer *container,
PikaDisplay *display,
PikaUIManager *manager);
static void windows_menu_display_remove (PikaContainer *container,
PikaDisplay *display,
PikaUIManager *manager);
static void windows_menu_display_reorder (PikaContainer *container,
PikaDisplay *display,
gint new_index,
PikaUIManager *manager);
static void windows_menu_image_notify (PikaDisplay *display,
const GParamSpec *unused,
PikaUIManager *manager);
static void windows_menu_dock_window_added (PikaDialogFactory *factory,
PikaDockWindow *dock_window,
PikaUIManager *manager);
static void windows_menu_dock_window_removed (PikaDialogFactory *factory,
PikaDockWindow *dock_window,
PikaUIManager *manager);
static void windows_menu_recent_add (PikaContainer *container,
PikaSessionInfo *info,
PikaUIManager *manager);
static void windows_menu_recent_remove (PikaContainer *container,
PikaSessionInfo *info,
PikaUIManager *manager);
void
windows_menu_setup (PikaUIManager *manager,
const gchar *ui_path)
{
GList *list;
g_return_if_fail (PIKA_IS_UI_MANAGER (manager));
g_return_if_fail (ui_path != NULL);
g_object_set_data (G_OBJECT (manager), "image-menu-ui-path",
(gpointer) ui_path);
g_signal_connect_object (manager->pika->displays, "add",
G_CALLBACK (windows_menu_display_add),
manager, 0);
g_signal_connect_object (manager->pika->displays, "remove",
G_CALLBACK (windows_menu_display_remove),
manager, 0);
g_signal_connect_object (manager->pika->displays, "reorder",
G_CALLBACK (windows_menu_display_reorder),
manager, 0);
for (list = pika_get_display_iter (manager->pika);
list;
list = g_list_next (list))
{
PikaDisplay *display = list->data;
windows_menu_display_add (manager->pika->displays, display, manager);
}
g_signal_connect_object (pika_dialog_factory_get_singleton (), "dock-window-added",
G_CALLBACK (windows_menu_dock_window_added),
manager, 0);
g_signal_connect_object (pika_dialog_factory_get_singleton (), "dock-window-removed",
G_CALLBACK (windows_menu_dock_window_removed),
manager, 0);
for (list = pika_dialog_factory_get_open_dialogs (pika_dialog_factory_get_singleton ());
list;
list = g_list_next (list))
{
PikaDockWindow *dock_window = list->data;
if (PIKA_IS_DOCK_WINDOW (dock_window))
windows_menu_dock_window_added (pika_dialog_factory_get_singleton (),
dock_window,
manager);
}
g_signal_connect_object (global_recent_docks, "add",
G_CALLBACK (windows_menu_recent_add),
manager, 0);
g_signal_connect_object (global_recent_docks, "remove",
G_CALLBACK (windows_menu_recent_remove),
manager, 0);
for (list = g_list_last (PIKA_LIST (global_recent_docks)->queue->head);
list;
list = g_list_previous (list))
{
PikaSessionInfo *info = list->data;
windows_menu_recent_add (global_recent_docks, info, manager);
}
}
/* private functions */
static void
windows_menu_display_add (PikaContainer *container,
PikaDisplay *display,
PikaUIManager *manager)
{
g_signal_connect_object (display, "notify::image",
G_CALLBACK (windows_menu_image_notify),
manager, 0);
if (pika_display_get_image (display))
windows_menu_image_notify (display, NULL, manager);
}
static void
windows_menu_display_remove (PikaContainer *container,
PikaDisplay *display,
PikaUIManager *manager)
{
gchar *action_name;
action_name = pika_display_get_action_name (display);
pika_ui_manager_remove_ui (manager, action_name);
g_free (action_name);
}
static void
windows_menu_display_reorder (PikaContainer *container,
PikaDisplay *display,
gint new_index,
PikaUIManager *manager)
{
gint n_display = pika_container_get_n_children (container);
gint i;
for (i = new_index; i < n_display; i++)
{
PikaObject *d = pika_container_get_child_by_index (container, i);
windows_menu_display_remove (container, PIKA_DISPLAY (d), manager);
}
for (i = new_index; i < n_display; i++)
{
PikaObject *d = pika_container_get_child_by_index (container, i);
windows_menu_display_add (container, PIKA_DISPLAY (d), manager);
}
}
static void
windows_menu_image_notify (PikaDisplay *display,
const GParamSpec *unused,
PikaUIManager *manager)
{
windows_menu_display_remove (manager->pika->displays, display, manager);
if (pika_display_get_image (display))
{
gchar *action_name;
action_name = pika_display_get_action_name (display);
pika_ui_manager_add_ui (manager, "/Windows/[Images]", action_name, FALSE);
g_free (action_name);
}
}
static void
windows_menu_dock_window_added (PikaDialogFactory *factory,
PikaDockWindow *dock_window,
PikaUIManager *manager)
{
gchar *action_name;
action_name = windows_actions_dock_window_to_action_name (dock_window);
/* TODO GMenu: doesn't look like it's working, neither will old or new API. */
pika_ui_manager_add_ui (manager, "/Windows/[Docks]", action_name, FALSE);
g_free (action_name);
}
static void
windows_menu_dock_window_removed (PikaDialogFactory *factory,
PikaDockWindow *dock_window,
PikaUIManager *manager)
{
gchar *action_name;
action_name = windows_actions_dock_window_to_action_name (dock_window);
pika_ui_manager_remove_ui (manager, action_name);
g_free (action_name);
}
static void
windows_menu_recent_add (PikaContainer *container,
PikaSessionInfo *info,
PikaUIManager *manager)
{
gchar *action_name;
gint info_id;
info_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (info), "recent-action-id"));
action_name = g_strdup_printf ("windows-recent-%04d", info_id);
pika_ui_manager_add_ui (manager, "/Windows/Recently Closed Docks", action_name, TRUE);
g_free (action_name);
}
static void
windows_menu_recent_remove (PikaContainer *container,
PikaSessionInfo *info,
PikaUIManager *manager)
{
pika_ui_manager_remove_uis (manager, "windows-recent-");
}

30
app/menus/windows-menu.h Normal file
View File

@ -0,0 +1,30 @@
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef __WINDOWS_MENU_H__
#define __WINDOWS_MENU_H__
void windows_menu_setup (PikaUIManager *manager,
const gchar *ui_path);
#endif /* __WINDOWS_MENU_H__ */