diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-05-25 03:10:37 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-05-25 03:10:37 -0400 |
| commit | ebb855dc1421e89813a1f4a74a4963d76aba9747 (patch) | |
| tree | 83fddf2d4d62ac8d35930a7c04dcf4e02c194079 /src/organizercore.cpp | |
| parent | 9a014db4b3a64dc93450dff8afe980db3694c595 (diff) | |
ExploreFile() will select the file in explorer when the path is a file
replaced more ShellExecute() calls with ExploreFile()
Diffstat (limited to 'src/organizercore.cpp')
| -rw-r--r-- | src/organizercore.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 2542545f..d228dfe1 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -330,25 +330,59 @@ bool GetFileExecutionContext( } } -bool ExploreFile(const QString& path) + +bool ExploreDirectory(const QFileInfo& info) { - const auto ws = path.toStdWString(); + const auto path = QDir::toNativeSeparators(info.absoluteFilePath()); + const auto ws_path = path.toStdWString(); const auto h = ::ShellExecuteW( - nullptr, L"explore", ws.c_str(), nullptr, nullptr, SW_SHOWNORMAL); + nullptr, L"explore", ws_path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); // anything <= 32 is not an actual HINSTANCE and signals failure return (h > reinterpret_cast<HINSTANCE>(32)); } +bool ExploreFileInDirectory(const QFileInfo& info) +{ + const auto path = QDir::toNativeSeparators(info.absoluteFilePath()); + const auto params = "/select,\"" + path + "\""; + const auto ws_params = params.toStdWString(); + + const auto h = ::ShellExecuteW( + nullptr, nullptr, L"explorer", ws_params.c_str(), nullptr, SW_SHOWNORMAL); + + // anything <= 32 is not an actual HINSTANCE and signals failure + return (h > reinterpret_cast<HINSTANCE>(32)); +} + + bool ExploreFile(const QFileInfo& info) { - return ExploreFile(info.absolutePath()); + if (info.isFile()) { + return ExploreFileInDirectory(info); + } else if (info.isDir()) { + return ExploreDirectory(info); + } else { + // try the parent directory + const auto parent = info.dir(); + + if (parent.exists()) { + return ExploreDirectory(parent.absolutePath()); + } + } + + return false; +} + +bool ExploreFile(const QString& path) +{ + return ExploreFile(QFileInfo(path)); } bool ExploreFile(const QDir& dir) { - return ExploreFile(dir.absolutePath()); + return ExploreFile(QFileInfo(dir.absolutePath())); } |
