mirror of https://github.com/buggins/dlangui.git
Improved showInFileManager for linux
This commit is contained in:
parent
e5eb93102e
commit
d9af0b3b17
|
@ -1245,17 +1245,66 @@ class SDLPlatform : Platform {
|
||||||
wait(pid);
|
wait(pid);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// TODO: implement for POSIX
|
import std.exception;
|
||||||
if (normalized.isFile)
|
|
||||||
normalized = normalized.dirName;
|
/*
|
||||||
string exe = "xdg-open";
|
* Use xdg-mime to get default application for inode/directory.
|
||||||
string[] args;
|
* If application is known to be able to select the file, start it directly.
|
||||||
args ~= exe;
|
* Otherwise just open directory with xdg-open.
|
||||||
args ~= normalized;
|
*
|
||||||
Log.d("Executing ", args);
|
* So this relies on external tools like xdg-mime and xdg-open.
|
||||||
auto pid = spawnProcess(args);
|
* To make implementation free from external tools we need to implement
|
||||||
wait(pid);
|
* reading of mimeapps.list to find appropriate .desktop file,
|
||||||
return true;
|
* find it on the file system, parse its Exec value and run.
|
||||||
|
* That's basically what xdg-open is doing.
|
||||||
|
*
|
||||||
|
* We still will need to keep track of file managers capable of selecting file on opening,
|
||||||
|
* since there's no freedesktop specification on this feature.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static string[] getXdgOpen(string toOpen)
|
||||||
|
{
|
||||||
|
bool pathIsDir;
|
||||||
|
collectException(toOpen.isDir, pathIsDir);
|
||||||
|
if (!pathIsDir) {
|
||||||
|
toOpen = toOpen.dirName;
|
||||||
|
}
|
||||||
|
return ["xdg-open", toOpen];
|
||||||
|
}
|
||||||
|
|
||||||
|
string toOpen = normalized;
|
||||||
|
|
||||||
|
auto p = pipe();
|
||||||
|
spawnProcess(["xdg-mime", "query", "default", "inode/directory"], std.stdio.stdin, p.writeEnd);
|
||||||
|
auto fileManager = p.readEnd.readln().chomp();
|
||||||
|
p.close();
|
||||||
|
|
||||||
|
if (fileManager.length) {
|
||||||
|
string[] arguments;
|
||||||
|
|
||||||
|
switch(fileManager) {
|
||||||
|
//nautilus and nemo selects item if it's file
|
||||||
|
case "nautilus.desktop":
|
||||||
|
case "nautilus-classic.desktop":
|
||||||
|
arguments = ["nautilus", toOpen];
|
||||||
|
break;
|
||||||
|
case "nemo.desktop":
|
||||||
|
arguments = ["nemo", toOpen];
|
||||||
|
break;
|
||||||
|
//dolphin needs --select option
|
||||||
|
case "kde4-dolphin.desktop":
|
||||||
|
case "kde-dolphin.desktop":
|
||||||
|
arguments = ["dolphin", "--select", toOpen];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
arguments = getXdgOpen(toOpen);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
spawnProcess(arguments);
|
||||||
|
return true;
|
||||||
|
} else { //xdg-mime returned non-zero.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("showInFileManager -- exception while trying to open file browser");
|
Log.e("showInFileManager -- exception while trying to open file browser");
|
||||||
|
|
Loading…
Reference in New Issue