widgets, actions: Allow multi-select in Document History

This patch enables multiple selections in
the GimpDocumentView widget and dockable.
It also updates the "documents-open" and
"documents-remove" actions to check if the
GimpContainerView has more than
one selection, and if so, tries to load/remove
all of those images. The action wording is
slightly edited to indicate multiple
images can now be opened/removed.
This commit is contained in:
Alx Sa 2025-10-29 14:40:19 +00:00
parent 94c9d225c8
commit 4812fddc5c
3 changed files with 41 additions and 14 deletions

View file

@ -39,8 +39,8 @@
static const GimpActionEntry documents_actions[] =
{
{ "documents-open", GIMP_ICON_DOCUMENT_OPEN,
NC_("documents-action", "_Open Image"), NULL, { NULL },
NC_("documents-action", "Open the selected entry"),
NC_("documents-action", "_Open Images"), NULL, { NULL },
NC_("documents-action", "Open the selected entries"),
documents_open_cmd_callback,
GIMP_HELP_DOCUMENT_OPEN },
@ -69,8 +69,8 @@ static const GimpActionEntry documents_actions[] =
GIMP_HELP_DOCUMENT_SHOW_IN_FILE_MANAGER },
{ "documents-remove", GIMP_ICON_LIST_REMOVE,
NC_("documents-action", "Remove _Entry"), NULL, { NULL },
NC_("documents-action", "Remove the selected entry"),
NC_("documents-action", "Remove _Entries"), NULL, { NULL },
NC_("documents-action", "Remove the selected entries"),
documents_remove_cmd_callback,
GIMP_HELP_DOCUMENT_REMOVE },

View file

@ -84,20 +84,35 @@ documents_open_cmd_callback (GimpAction *action,
GimpContext *context;
GimpContainer *container;
GimpImagefile *imagefile;
GList *images = NULL;
GList *list;
context = gimp_container_view_get_context (editor->view);
container = gimp_container_view_get_container (editor->view);
imagefile = gimp_context_get_imagefile (context);
if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile)))
if (gimp_container_view_get_selected (editor->view, &images) > 1)
{
documents_open_image (GTK_WIDGET (editor), context, imagefile);
for (list = images; list; list = list->next)
documents_open_image (GTK_WIDGET (editor), context,
GIMP_IMAGEFILE (list->data));
g_list_free (list);
}
else
{
file_file_open_dialog (context->gimp, NULL, GTK_WIDGET (editor));
if (imagefile && gimp_container_have (container, GIMP_OBJECT (imagefile)))
{
documents_open_image (GTK_WIDGET (editor), context, imagefile);
}
else
{
file_file_open_dialog (context->gimp, NULL, GTK_WIDGET (editor));
}
}
if (images)
g_list_free (images);
}
void
@ -206,16 +221,26 @@ documents_remove_cmd_callback (GimpAction *action,
GVariant *value,
gpointer data)
{
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
GimpContext *context = gimp_container_view_get_context (editor->view);
GimpImagefile *imagefile = gimp_context_get_imagefile (context);
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
const gchar *uri;
GList *images = NULL;
GList *list;
uri = gimp_object_get_name (imagefile);
if (gimp_container_view_get_selected (editor->view, &images) > 1)
{
for (list = images; list; list = list->next)
{
uri = gimp_object_get_name (GIMP_IMAGEFILE (list->data));
gtk_recent_manager_remove_item (gtk_recent_manager_get_default (), uri, NULL);
gimp_container_view_remove_active (editor->view);
gtk_recent_manager_remove_item (gtk_recent_manager_get_default (),
uri, NULL);
gimp_container_view_set_1_selected (editor->view,
GIMP_VIEWABLE (list->data));
gimp_container_view_remove_active (editor->view);
}
g_list_free (list);
g_list_free (images);
}
}
void

View file

@ -106,6 +106,8 @@ gimp_document_view_new (GimpViewType view_type,
editor = GIMP_CONTAINER_EDITOR (document_view);
gimp_container_editor_set_selection_mode (editor, GTK_SELECTION_MULTIPLE);
document_view->open_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "documents",
"documents-open",