// Indicates that an item was activated and appropriate action should be taken. Returns error message, if any FileOperationResultCode CController::itemActivated(qulonglong itemHash, Panel p) { const auto item = panel(p).itemByHash(itemHash); if (item.isDir()) { // Attempting to enter this dir const FileOperationResultCode result = setPath(p, item.fullAbsolutePath(), item.isCdUp() ? refreshCauseCdUp : refreshCauseForwardNavigation); return result; } else if (item.isFile()) { if (item.isExecutable()) // Attempting to launch this exe from the current directory return QProcess::startDetached(toPosixSeparators(item.fullAbsolutePath()), QStringList(), toPosixSeparators(item.parentDirPath())) ? rcOk : rcFail; else // It's probably not a binary file, try opening with openUrl return QDesktopServices::openUrl(QUrl::fromLocalFile(toPosixSeparators(item.fullAbsolutePath()))) ? rcOk : rcFail; } return rcFail; }
DISABLE_COMPILER_WARNINGS #include <QDateTime> #include <QDebug> RESTORE_COMPILER_WARNINGS #include <assert.h> #include <errno.h> #if defined __linux__ || defined __APPLE__ #include <unistd.h> #include <sys/stat.h> #include <wordexp.h> #elif defined _WIN32 #include "windows/windowsutils.h" #include <Windows.h> #include <Shlwapi.h> #pragma comment(lib, "Shlwapi.lib") // This lib would have to be added not just to the top level application, but every plugin as well, so using #pragma instead #endif static inline QString expandEnvironmentVariables(const QString& string) { #ifdef _WIN32 if (!string.contains('%')) return string; static WCHAR result[16384 + 1]; if (ExpandEnvironmentStringsW((WCHAR*)string.utf16(), result, sizeof(result) / sizeof(result[0])) != 0) return toPosixSeparators(QString::fromUtf16((char16_t*)result)); else return string; #else QString result = string; if (result.startsWith('~')) result.replace(0, 1, getenv("HOME")); if (result.contains('$')) { wordexp_t p; wordexp("$HOME/bin", &p, 0); const auto w = p.we_wordv; if (p.we_wordc > 0) result = w[0]; wordfree(&p); } return result; #endif }
bool CController::createFolder(const QString &parentFolder, const QString &name) { QDir parentDir(parentFolder); if (!parentDir.exists()) return false; const QString posixName = toPosixSeparators(name); if (parentDir.mkpath(posixName)) { if (parentDir.absolutePath() == activePanel().currentDirObject().qDir().absolutePath()) { const int slashPosition = posixName.indexOf('/'); const QString newFolderPath = parentDir.absolutePath() + "/" + (slashPosition > 0 ? posixName.left(posixName.indexOf('/')) : posixName); // This is required for the UI to know to set the cursor at the new folder setCursorPositionForCurrentFolder(CFileSystemObject(newFolderPath).hash()); } return true; } else return false; }