Skip to content

Commit f6b37b6

Browse files
committed
Add NemoSelectionProvider extension interface
Adds a new NemoSelectionProvider interface to libnemo-extension that allows extensions to be notified when the file selection changes. - Add nemo-selection-provider.h/.c with the new interface - Call nemo_view_notify_selection_providers() from nemo_view_notify_selection_changed() to notify all registered selection provider extensions
1 parent 1337cf0 commit f6b37b6

4 files changed

Lines changed: 156 additions & 0 deletions

File tree

libnemo-extension/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nemo_extension_sources = [
1818
'nemo-property-page-provider.c',
1919
'nemo-property-page.c',
2020
'nemo-menu.c',
21+
'nemo-selection-provider.c',
2122
'nemo-simple-button.c',
2223
]
2324

@@ -35,6 +36,7 @@ nemo_extension_headers = [
3536
'nemo-property-page-provider.h',
3637
'nemo-property-page.h',
3738
'nemo-menu.h',
39+
'nemo-selection-provider.h',
3840
'nemo-simple-button.h',
3941
]
4042

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* nemo-selection-provider.c - Interface for Nemo extensions that
3+
* want to be notified when the file
4+
* selection changes.
5+
*
6+
* Copyright (C) 2026
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Library General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Library General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Library General Public
19+
* License along with this library; if not, write to the Free
20+
* Software Foundation, Inc., 51 Franklin Street, Suite 500, MA 02110-1335, USA.
21+
*/
22+
23+
#include <config.h>
24+
#include "nemo-selection-provider.h"
25+
#include <glib-object.h>
26+
27+
/**
28+
* SECTION:nemo-selection-provider
29+
* @Title: NemoSelectionProvider
30+
* @Short_description: Notifies extensions when the file selection changes.
31+
*
32+
* Extensions implementing this interface will have their selection_changed
33+
* method called whenever the user changes the file selection in Nemo.
34+
**/
35+
36+
G_DEFINE_INTERFACE (NemoSelectionProvider, nemo_selection_provider, G_TYPE_OBJECT)
37+
38+
static void
39+
nemo_selection_provider_default_init (NemoSelectionProviderInterface *klass)
40+
{
41+
/* No signals needed — Nemo calls selection_changed() directly */
42+
}
43+
44+
/**
45+
* nemo_selection_provider_selection_changed:
46+
* @provider: a #NemoSelectionProvider
47+
* @window: the parent #GtkWidget window
48+
* @files: (element-type NemoFileInfo): a list of currently selected #NemoFileInfo
49+
*
50+
* Called by Nemo when the file selection changes. Dispatches to the
51+
* extension's selection_changed() implementation.
52+
*/
53+
void
54+
nemo_selection_provider_selection_changed (NemoSelectionProvider *provider,
55+
GtkWidget *window,
56+
GList *files)
57+
{
58+
g_return_if_fail (NEMO_IS_SELECTION_PROVIDER (provider));
59+
60+
if (NEMO_SELECTION_PROVIDER_GET_IFACE (provider)->selection_changed) {
61+
NEMO_SELECTION_PROVIDER_GET_IFACE (provider)->selection_changed
62+
(provider, window, files);
63+
}
64+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* nemo-selection-provider.h - Interface for Nemo extensions that
3+
* want to be notified when the file
4+
* selection changes.
5+
*
6+
* Copyright (C) 2026
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Library General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Library General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Library General Public
19+
* License along with this library; if not, write to the Free
20+
* Software Foundation, Inc., 51 Franklin Street, Suite 500, MA 02110-1335, USA.
21+
*/
22+
23+
/* This interface is implemented by Nemo extensions that want to
24+
* be notified when the user's file selection changes. Extensions
25+
* receive a list of NemoFileInfo objects representing the current
26+
* selection, and the GtkWidget of the parent window. */
27+
28+
#ifndef NEMO_SELECTION_PROVIDER_H
29+
#define NEMO_SELECTION_PROVIDER_H
30+
31+
#include <glib-object.h>
32+
#include <gtk/gtk.h>
33+
#include "nemo-extension-types.h"
34+
#include "nemo-file-info.h"
35+
36+
G_BEGIN_DECLS
37+
38+
#define NEMO_TYPE_SELECTION_PROVIDER (nemo_selection_provider_get_type ())
39+
40+
G_DECLARE_INTERFACE (NemoSelectionProvider, nemo_selection_provider,
41+
NEMO, SELECTION_PROVIDER,
42+
GObject)
43+
44+
typedef NemoSelectionProviderInterface NemoSelectionProviderIface;
45+
46+
struct _NemoSelectionProviderInterface {
47+
GTypeInterface g_iface;
48+
49+
void (*selection_changed) (NemoSelectionProvider *provider,
50+
GtkWidget *window,
51+
GList *files);
52+
};
53+
54+
/* Called by Nemo when the selection changes. files is a list of NemoFileInfo. */
55+
void nemo_selection_provider_selection_changed (NemoSelectionProvider *provider,
56+
GtkWidget *window,
57+
GList *files);
58+
59+
G_END_DECLS
60+
61+
#endif /* NEMO_SELECTION_PROVIDER_H */

src/nemo-view.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <eel/eel-vfs-extensions.h>
6262

6363
#include <libnemo-extension/nemo-menu-provider.h>
64+
#include <libnemo-extension/nemo-selection-provider.h>
6465
#include <libnemo-private/nemo-bookmark.h>
6566
#include <libnemo-private/nemo-clipboard.h>
6667
#include <libnemo-private/nemo-clipboard-monitor.h>
@@ -10310,6 +10311,33 @@ schedule_update_status (NemoView *view)
1031010311
}
1031110312
}
1031210313

10314+
static void
10315+
nemo_view_notify_selection_providers (NemoView *view)
10316+
{
10317+
GList *providers, *l, *selection, *file_infos;
10318+
GtkWidget *window;
10319+
10320+
providers = nemo_module_get_extensions_for_type (NEMO_TYPE_SELECTION_PROVIDER);
10321+
if (providers == NULL)
10322+
return;
10323+
10324+
selection = nemo_view_get_selection (view);
10325+
window = GTK_WIDGET (nemo_view_get_containing_window (view));
10326+
10327+
file_infos = NULL;
10328+
for (l = selection; l != NULL; l = l->next)
10329+
file_infos = g_list_prepend (file_infos, NEMO_FILE_INFO (l->data));
10330+
file_infos = g_list_reverse (file_infos);
10331+
10332+
for (l = providers; l != NULL; l = l->next)
10333+
nemo_selection_provider_selection_changed (NEMO_SELECTION_PROVIDER (l->data),
10334+
window, file_infos);
10335+
10336+
g_list_free (file_infos);
10337+
nemo_file_list_free (selection);
10338+
nemo_module_extension_list_free (providers);
10339+
}
10340+
1031310341
/**
1031410342
* nemo_view_notify_selection_changed:
1031510343
*
@@ -10359,6 +10387,7 @@ nemo_view_notify_selection_changed (NemoView *view)
1035910387
/* Schedule an update of menu item states to match selection */
1036010388
selection_changed_schedule_update_menus (view);
1036110389
}
10390+
nemo_view_notify_selection_providers (view);
1036210391
}
1036310392

1036410393
static void

0 commit comments

Comments
 (0)