Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Show note in file manager button doesn't respect system default #3132

Open
ArkitectNaut opened this issue Oct 21, 2024 · 2 comments
Open

Comments

@ArkitectNaut
Copy link

Expected behaviour

Open the user's prefered file manager app (in my case Directory Opus)

Actual behaviour

Opens the windows file explorer. This behaviour is also true for the right-click method menu.

Steps to reproduce

Have different system file manager, click 'Show note in file manager' button on the toolbar. Same behaviour with right-clicking the file and selecting the 'Show note in file manager' option

@pbek
Copy link
Owner

pbek commented Oct 22, 2024

So far, no better way to implement that on Windows crossed my path:

if (QFileInfo(path).exists()) {
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
// Dir separators MUST be win-style slashes
// QProcess::startDetached() has an obscure bug. If the path has
// no spaces and a comma(and maybe other special characters) it doesn't
// get wrapped in quotes. So explorer.exe can't find the correct path
// anddisplays the default one. If we wrap the path in quotes and pass
// it to QProcess::startDetached() explorer.exe still shows the default
// path. In this case QProcess::startDetached() probably puts its
// own quotes around ours.
STARTUPINFO startupInfo;
::ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
PROCESS_INFORMATION processInfo;
::ZeroMemory(&processInfo, sizeof(processInfo));
QString cmd = QStringLiteral("explorer.exe /select,\"%1\"")
.arg(QDir::toNativeSeparators(absolutePath));
LPWSTR lpCmd = new WCHAR[cmd.size() + 1];
cmd.toWCharArray(lpCmd);
lpCmd[cmd.size()] = 0;
bool ret = ::CreateProcessW(NULL, lpCmd, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo,
&processInfo);
delete[] lpCmd;
if (ret) {
::CloseHandle(processInfo.hProcess);
::CloseHandle(processInfo.hThread);
}
} else {
// If the item to select doesn't exist, try to open its parent
openPath(path.left(path.lastIndexOf("/")));
}

Suggestions and pull requests are welcome.

@pbek
Copy link
Owner

pbek commented Oct 22, 2024

But of course you also can write a script using a custom action and open any application with the path of the note, see https://www.qownnotes.org/scripting/methods-and-objects.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants