QString GwtCallback::getOpenFileName(const QString& caption, const QString& dir, const QString& filter) { QString resolvedDir = resolveAliasedPath(dir); QString result = QFileDialog::getOpenFileName(pOwnerWindow_, caption, resolvedDir, filter); webView()->page()->mainFrame()->setFocus(); return createAliasedPath(result); }
void GwtCallback::showFolder(QString path) { if (path.isNull() || path.isEmpty()) return; path = resolveAliasedPath(path); QDir dir(path); if (dir.exists()) { QDesktopServices::openUrl(QUrl::fromLocalFile(dir.absolutePath())); } }
QString GwtCallback::getSaveFileName(const QString& caption, const QString& dir, const QString& defaultExtension, bool forceDefaultExtension) { QString resolvedDir = resolveAliasedPath(dir); while (true) { QString result = QFileDialog::getSaveFileName(pOwnerWindow_, caption, resolvedDir); webView()->page()->mainFrame()->setFocus(); if (result.isEmpty()) return result; if (!defaultExtension.isEmpty()) { FilePath fp(result.toUtf8().constData()); if (fp.extension().empty() || (forceDefaultExtension && (fp.extension() != defaultExtension.toStdString()))) { result += defaultExtension; FilePath newExtPath(result.toUtf8().constData()); if (newExtPath.exists()) { std::string message = "\"" + newExtPath.filename() + "\" already " "exists. Do you want to overwrite it?"; if (QMessageBox::Cancel == QMessageBox::warning(pOwnerWindow_, QString::fromUtf8("Save File"), QString::fromUtf8(message.c_str()), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok)) { resolvedDir = result; continue; } } } } return createAliasedPath(result); } }
QString GwtCallback::getExistingDirectory(const QString& caption, const QString& dir) { QString resolvedDir = resolveAliasedPath(dir); QString result; #ifdef _WIN32 if (dir.isNull()) { // Bug wchar_t szDir[MAX_PATH]; BROWSEINFOW bi; bi.hwndOwner = pOwnerWindow_->winId(); bi.pidlRoot = NULL; bi.pszDisplayName = szDir; bi.lpszTitle = L"Select a folder:"; bi.ulFlags = BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lpfn = 0; bi.iImage = -1; LPITEMIDLIST pidl = SHBrowseForFolderW(&bi); if (!pidl || !SHGetPathFromIDListW(pidl, szDir)) result = QString(); else result = QString::fromWCharArray(szDir); } else { result = QFileDialog::getExistingDirectory(pOwnerWindow_, caption, resolvedDir); } #else result = QFileDialog::getExistingDirectory(pOwnerWindow_, caption, resolvedDir); #endif webView()->page()->mainFrame()->setFocus(); return createAliasedPath(result); }
void GwtCallback::openProjectInNewWindow(QString projectFilePath) { launchProjectInNewInstance(resolveAliasedPath(projectFilePath)); }
QString GwtCallback::getUriForPath(QString path) { return QUrl::fromLocalFile(resolveAliasedPath(path)).toString(); }
void GwtCallback::openTerminal(QString terminalPath, QString workingDirectory, QString extraPathEntries) { // append extra path entries to our path before launching std::string path = core::system::getenv("PATH"); std::string previousPath = path; core::system::addToPath(&path, extraPathEntries.toStdString()); core::system::setenv("PATH", path); #if defined(Q_WS_MACX) // call Terminal.app with an applescript that navigates it // to the specified directory. note we don't reference the // passed terminalPath because this setting isn't respected // on the Mac (we always use Terminal.app) FilePath macTermScriptFilePath = desktop::options().scriptsPath().complete("mac-terminal"); QString macTermScriptPath = QString::fromUtf8( macTermScriptFilePath.absolutePath().c_str()); QStringList args; args.append(resolveAliasedPath(workingDirectory)); QProcess::startDetached(macTermScriptPath, args); #elif defined(Q_WS_WIN) // git bash if (terminalPath.length() > 0) { QStringList args; args.append(QString::fromAscii("--login")); args.append(QString::fromAscii("-i")); QProcess::startDetached(terminalPath, args, resolveAliasedPath(workingDirectory)); } else { // set HOME to USERPROFILE so msys ssh can find our keys std::string previousHome = core::system::getenv("HOME"); std::string userProfile = core::system::getenv("USERPROFILE"); core::system::setenv("HOME", userProfile); // run the process QProcess::startDetached(QString::fromAscii("cmd.exe"), QStringList(), resolveAliasedPath(workingDirectory)); // revert to previous home core::system::setenv("HOME", previousHome); } #elif defined(Q_WS_X11) // start the auto-detected terminal (or user-specified override) if (!terminalPath.length() == 0) { QStringList args; QProcess::startDetached(terminalPath, args, resolveAliasedPath(workingDirectory)); } else { desktop::showWarning( NULL, QString::fromAscii("Terminal Not Found"), QString::fromAscii( "Unable to find a compatible terminal program to launch")); } #endif // restore previous path core::system::setenv("PATH", previousPath); }