initial support for showInFileBrowser - #151

This commit is contained in:
Vadim Lopatin 2016-01-25 15:22:34 +03:00
parent 7eee173a55
commit c5eeec6ea5
3 changed files with 61 additions and 17 deletions

View File

@ -385,3 +385,4 @@ string findExecutablePath(string executableName) {
} }
return null; return null;
} }

View File

@ -1169,20 +1169,66 @@ class SDLPlatform : Platform {
/// show directory or file in OS file manager (explorer, finder, etc...) /// show directory or file in OS file manager (explorer, finder, etc...)
override bool showInFileManager(string pathName) { override bool showInFileManager(string pathName) {
import std.process; import std.process;
import std.path;
import std.file;
string normalized = buildNormalizedPath(pathName); string normalized = buildNormalizedPath(pathName);
version (OSX) { if (!normalized.exists) {
Log.e("showInFileManager failed - file or directory does not exist");
return false;
}
import std.string;
try {
version (Windows) {
Log.i("showInFileManager(", pathName, ")");
import win32.windows;
import dlangui.core.files;
string explorerPath = findExecutablePath("explorer.exe");
if (!explorerPath.length) {
Log.e("showInFileManager failed - cannot find explorer.exe");
return false;
}
string arg = "/select,\"" ~ normalized ~ "\"";
STARTUPINFO si;
si.cb = si.sizeof;
PROCESS_INFORMATION pi;
Log.d("showInFileManager: ", explorerPath, " ", arg);
arg = "\"" ~ explorerPath ~ "\" " ~ arg;
auto res = CreateProcessW(null, //explorerPath.toUTF16z,
cast(wchar*)arg.toUTF16z,
null, null, false, DETACHED_PROCESS,
null, null, &si, &pi);
if (!res) {
Log.e("showInFileManager failed to run explorer.exe");
return false;
}
return true;
} else version (OSX) {
string exe = "/usr/bin/osascript"; string exe = "/usr/bin/osascript";
string[] args; string[] args;
args ~= exe;
args ~= "-e"; args ~= "-e";
args ~= "tell application \"Finder\" to reveal POSIX file \" ~ normalized ~ \""; args ~= "tell application \"Finder\" to reveal POSIX file \" ~ normalized ~ \"";
auto pid = spawnProcess(exe, args, Config.none); auto pid = spawnProcess(args);
wait(pid); wait(pid);
args[1] = "tell application \"Finder\" to activate"; args[2] = "tell application \"Finder\" to activate";
pid = spawnProcess(exe, args, Config.none); pid = spawnProcess(args);
wait(pid); wait(pid);
return true; return true;
} else { } else {
// TODO: implement for POSIX // TODO: implement for POSIX
if (normalized.isFile)
normalized = normalized.basePath;
string exe = "xdg-open";
string[] args;
args ~= exe;
args ~= normalized;
auto pid = spawnProcess(args);
wait(pid);
return true;
}
} catch (Exception e) {
Log.e("showInFileManager -- exception while trying to open file browser");
} }
return false; return false;
} }

View File

@ -867,7 +867,6 @@ class Win32Platform : Platform {
override bool showInFileManager(string pathName) { override bool showInFileManager(string pathName) {
Log.i("showInFileManager(", pathName, ")"); Log.i("showInFileManager(", pathName, ")");
import dlangui.core.files; import dlangui.core.files;
//import std.process;
import std.path; import std.path;
import std.string; import std.string;
@ -881,7 +880,7 @@ class Win32Platform : Platform {
STARTUPINFO si; STARTUPINFO si;
si.cb = si.sizeof; si.cb = si.sizeof;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
Log.i("showInFileManager: ", explorerPath, " ", arg); Log.d("showInFileManager: ", explorerPath, " ", arg);
arg = "\"" ~ explorerPath ~ "\" " ~ arg; arg = "\"" ~ explorerPath ~ "\" " ~ arg;
auto res = CreateProcessW(null, //explorerPath.toUTF16z, auto res = CreateProcessW(null, //explorerPath.toUTF16z,
cast(wchar*)arg.toUTF16z, cast(wchar*)arg.toUTF16z,
@ -891,8 +890,6 @@ class Win32Platform : Platform {
Log.e("showInFileManager failed to run explorer.exe"); Log.e("showInFileManager failed to run explorer.exe");
return false; return false;
} }
//auto pid = spawnProcess(explorerPath, [arg], );
return true; return true;
} }