screenshot: Use FileManager1 to show files

This commit is contained in:
Zander Brown 2023-12-27 20:27:08 +00:00
parent 1dda339395
commit 0a34cface1
No known key found for this signature in database
GPG key ID: 25EE3C36E31E5F84
3 changed files with 62 additions and 24 deletions

View file

@ -0,0 +1,33 @@
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"https://dbus.freedesktop.org/doc/introspect.dtd" >
<!--
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
-->
<node>
<interface name='org.freedesktop.FileManager1'>
<method name='ShowFolders'>
<arg type='as' name='URIs' direction='in'/>
<arg type='s' name='StartupId' direction='in'/>
</method>
<method name='ShowItems'>
<arg type='as' name='URIs' direction='in'/>
<arg type='s' name='StartupId' direction='in'/>
</method>
<method name='ShowItemProperties'>
<arg type='as' name='URIs' direction='in'/>
<arg type='s' name='StartupId' direction='in'/>
</method>
</interface>
</node>

View file

@ -10,6 +10,7 @@
<file preprocess="xml-stripblanks">org.freedesktop.bolt1.Device.xml</file>
<file preprocess="xml-stripblanks">org.freedesktop.bolt1.Manager.xml</file>
<file preprocess="xml-stripblanks">org.freedesktop.DBus.xml</file>
<file preprocess="xml-stripblanks">org.freedesktop.FileManager1.xml</file>
<file preprocess="xml-stripblanks">org.freedesktop.GeoClue2.Agent.xml</file>
<file preprocess="xml-stripblanks">org.freedesktop.GeoClue2.Manager.xml</file>
<file preprocess="xml-stripblanks">org.freedesktop.impl.portal.Access.xml</file>

View file

@ -33,6 +33,32 @@ const ScreenshotIface = loadInterfaceXML('org.gnome.Shell.Screenshot');
const ScreencastIface = loadInterfaceXML('org.gnome.Shell.Screencast');
const ScreencastProxy = Gio.DBusProxy.makeProxyWrapper(ScreencastIface);
const FileManagerIface = loadInterfaceXML('org.freedesktop.FileManager1');
const FileManagerProxy = Gio.DBusProxy.makeProxyWrapper(FileManagerIface);
function showInFiles(file) {
new FileManagerProxy(
Gio.DBus.session,
'org.freedesktop.FileManager1',
'/org/freedesktop/FileManager1',
(proxy, error) => {
if (error) {
Main.notifyError(
_('Unable to Show in Files'),
_('File manager encountered a problem'));
console.warn(error.message);
return;
}
proxy.ShowItemsAsync([file.get_uri()], '').catch(e => {
Main.notifyError(
_('Unable to Show in Files'),
_('File manager encountered a problem'));
console.warn(e.message);
});
});
}
const IconLabelButton = GObject.registerClass(
class IconLabelButton extends St.Button {
_init(iconName, label, params) {
@ -2034,18 +2060,7 @@ export const ScreenshotUI = GObject.registerClass({
_('Click here to view the video.')
);
// Translators: button on the screencast notification.
notification.addAction(_('Show in Files'), () => {
const app =
Gio.app_info_get_default_for_type('inode/directory', false);
if (app === null) {
// It may be null e.g. in a toolbox without nautilus.
log('Error showing in files: no default app set for inode/directory');
return;
}
app.launch([file], global.create_app_launch_context(0, -1));
});
notification.addAction(_('Show in Files'), () => showInFiles(file));
notification.connect('activated', () => {
try {
Gio.app_info_launch_default_for_uri(
@ -2275,18 +2290,7 @@ function _storeScreenshot(bytes, pixbuf) {
if (!disableSaveToDisk) {
// Translators: button on the screenshot notification.
notification.addAction(_('Show in Files'), () => {
const app =
Gio.app_info_get_default_for_type('inode/directory', false);
if (app === null) {
// It may be null e.g. in a toolbox without nautilus.
log('Error showing in files: no default app set for inode/directory');
return;
}
app.launch([file], global.create_app_launch_context(0, -1));
});
notification.addAction(_('Show in Files'), () => showInFiles(file));
notification.connect('activated', () => {
try {
Gio.app_info_launch_default_for_uri(