From 2c4faf01db772b642ccc068383df96ee5633321b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 13 Jan 2022 14:10:58 +0200 Subject: Showing files using `dbus-send` under Freedesktop D-Bus command line tools can be called to make method calls to reveal a file's location in the file manager. --- src/app.c | 40 ++++++++++++++++++++++++++++++++-------- src/ui/certlistwidget.c | 3 +++ src/ui/documentwidget.c | 8 ++++++++ src/ui/mediaui.c | 6 ++++++ 4 files changed, 49 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 0a17a665..65f6fde6 100644 --- a/src/app.c +++ b/src/app.c @@ -3404,28 +3404,52 @@ void openInDefaultBrowser_App(const iString *url) { "xdg-open", cstr_String(url), #elif defined (iPlatformMsys) - concatPath_CStr(cstr_String(execPath_App()), "../urlopen.bat"), - cstr_String(url), + concatPath_CStr(cstr_String(execPath_App()), "../urlopen.bat"), + cstr_String(url), /* TODO: The prompt window is shown momentarily... */ #endif NULL)) ); start_Process(proc); - waitForFinished_Process(proc); /* TODO: test on Windows */ + waitForFinished_Process(proc); iRelease(proc); } +#include + void revealPath_App(const iString *path) { #if defined (iPlatformAppleDesktop) - iProcess *proc = new_Process(); - setArguments_Process( + iProcess *proc = new_Process(); + setArguments_Process( proc, iClob(newStringsCStr_StringList("/usr/bin/open", "-R", cstr_String(path), NULL))); - start_Process(proc); - iRelease(proc); + start_Process(proc); + iRelease(proc); #elif defined (iPlatformAppleMobile) /* Use a share sheet. */ openFileActivityView_iOS(path); #elif defined (iPlatformLinux) || defined (iPlatformHaiku) + iProcess *proc = NULL; + /* Try with `dbus-send` first. */ { + proc = new_Process(); + setArguments_Process( + proc, + iClob(newStringsCStr_StringList( + "/usr/bin/dbus-send", + "--print-reply", + "--dest=org.freedesktop.FileManager1", + "/org/freedesktop/FileManager1", + "org.freedesktop.FileManager1.ShowItems", + format_CStr("array:string:%s", makeFileUrl_CStr(cstr_String(path))), + "string:", + NULL))); + start_Process(proc); + waitForFinished_Process(proc); + const iBool dbusDidSucceed = (exitStatus_Process(proc) == 0); + iRelease(proc); + if (dbusDidSucceed) { + return; + } + } iFileInfo *inf = iClob(new_FileInfo(path)); iRangecc target; if (isDirectory_FileInfo(inf)) { @@ -3434,7 +3458,7 @@ void revealPath_App(const iString *path) { else { target = dirName_Path(path); } - iProcess *proc = new_Process(); + proc = new_Process(); setArguments_Process( proc, iClob(newStringsCStr_StringList("/usr/bin/env", "xdg-open", cstr_Rangecc(target), NULL))); start_Process(proc); diff --git a/src/ui/certlistwidget.c b/src/ui/certlistwidget.c index 5a1c481b..2a7562d8 100644 --- a/src/ui/certlistwidget.c +++ b/src/ui/certlistwidget.c @@ -106,6 +106,9 @@ static void updateContextMenu_CertListWidget_(iCertListWidget *d) { { "${ident.fingerprint}", 0, 0, "ident.fingerprint" }, #if defined (iPlatformAppleDesktop) { magnifyingGlass_Icon " ${menu.reveal.macos}", 0, 0, "ident.reveal" }, +#endif +#if defined (iPlatformLinux) + { magnifyingGlass_Icon " ${menu.reveal.filemgr}", 0, 0, "ident.reveal" }, #endif { export_Icon " ${ident.export}", 0, 0, "ident.export" }, { "---", 0, 0, NULL }, diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 2ea0a4b7..58e6a11e 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -5031,6 +5031,14 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e 0, format_CStr("!reveal url:%s", cstr_String(linkUrl)) }); +#endif +#if defined (iPlatformLinux) + pushBack_Array(&items, + &(iMenuItem){ "${menu.reveal.filemgr}", + 0, + 0, + format_CStr("!reveal url:%s", + cstr_String(linkUrl)) }); #endif } } diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c index ab88c94a..f0070688 100644 --- a/src/ui/mediaui.c +++ b/src/ui/mediaui.c @@ -268,6 +268,12 @@ iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { 0, 0, format_CStr("!reveal path:%s", cstr_String(path)) }, +#endif +#if defined (iPlatformLinux) + { "${menu.reveal.filemgr}", + 0, + 0, + format_CStr("!reveal path:%s", cstr_String(path)) }, #endif { "---" }, /* Generic items */ -- cgit v1.2.3