diff --git a/src/libs/utils/unixutils.cpp b/src/libs/utils/unixutils.cpp new file mode 100644 index 00000000000..2acbd163f29 --- /dev/null +++ b/src/libs/utils/unixutils.cpp @@ -0,0 +1,99 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + + +#include "unixutils.h" +#include +#include +#include +#include + +using namespace Utils; + +QString UnixUtils::defaultFileBrowser() +{ + return QLatin1String("xdg-open %d"); +} + +QString UnixUtils::fileBrowser(const QSettings *settings) +{ + const QString dflt = defaultFileBrowser(); + if (!settings) + return dflt; + return settings->value(QLatin1String("General/FileBrowser"), dflt).toString(); +} + +void UnixUtils::setFileBrowser(QSettings *settings, const QString &term) +{ + return settings->setValue(QLatin1String("General/FileBrowser"), term); +} + + +QString UnixUtils::fileBrowserHelpText() +{ + QString help = QCoreApplication::translate("Utils::UnixTools", + "" + "" + "" + "" + "" + "" + "
VariableExpands to
%ddirectory of current file
%ffile name (with full path)
%nfile name (without path)
%%%
"); + return help; +} + +QString UnixUtils::substituteFileBrowserParameters(const QString &pre, const QString &file) +{ + QString cmd; + for (int i = 0; i < pre.size(); ++i) { + QChar c = pre.at(i); + if (c == QLatin1Char('%') && i < pre.size()-1) { + c = pre.at(++i); + QString s; + if (c == QLatin1Char('d')) + s = QFileInfo(file).path(); + else if (c == QLatin1Char('f')) + s = file; + else if (c == QLatin1Char('n')) + s = QFileInfo(file).fileName(); + else if (c == QLatin1Char('%')) + s = c; + else { + s = QLatin1Char('%'); + s += c; + } + cmd += s; + continue; + + } + cmd += c; + } + + return cmd; +} diff --git a/src/libs/utils/unixutils.h b/src/libs/utils/unixutils.h new file mode 100644 index 00000000000..7deebc3c66a --- /dev/null +++ b/src/libs/utils/unixutils.h @@ -0,0 +1,56 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef UNIXUTILS_H +#define UNIXUTILS_H + +#include "utils_global.h" + +#include + +QT_BEGIN_NAMESPACE +class QSettings; +QT_END_NAMESPACE + +namespace Utils { + +class QTCREATOR_UTILS_EXPORT UnixUtils +{ +public: + static QString defaultFileBrowser(); + static QString fileBrowser(const QSettings *settings); + static void setFileBrowser(QSettings *settings, const QString &term); + static QString fileBrowserHelpText(); + static QString substituteFileBrowserParameters(const QString &command, + const QString &file); +}; + +}; + +#endif // UNIXUTILS_H diff --git a/src/libs/utils/utils.pro b/src/libs/utils/utils.pro index 61e5659451d..2c823cfd621 100644 --- a/src/libs/utils/utils.pro +++ b/src/libs/utils/utils.pro @@ -46,6 +46,11 @@ win32 { HEADERS += winutils.h } else:SOURCES += consoleprocess_unix.cpp + +unix:!macx { + HEADERS += unixutils.h + SOURCES += unixutils.cpp +} HEADERS += utils_global.h \ reloadpromptutils.h \ stringutils.h \ diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index 21123685cf0..97f9dc97fa1 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,7 @@ using namespace Utils; using namespace Core::Internal; + GeneralSettings::GeneralSettings(): m_dialog(0) { @@ -77,17 +79,26 @@ QWidget *GeneralSettings::createPage(QWidget *parent) QWidget *w = new QWidget(parent); m_page->setupUi(w); + QSettings* settings = Core::ICore::instance()->settings(); m_page->colorButton->setColor(StyleHelper::baseColor()); m_page->externalEditorEdit->setText(EditorManager::instance()->externalEditor()); m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadBehavior()); #ifdef Q_OS_UNIX - m_page->terminalEdit->setText(ConsoleProcess::terminalEmulator(Core::ICore::instance()->settings())); + m_page->terminalEdit->setText(ConsoleProcess::terminalEmulator(settings)); #else m_page->terminalLabel->hide(); m_page->terminalEdit->hide(); m_page->resetTerminalButton->hide(); #endif +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) + m_page->externalFileBrowserEdit->setText(UnixUtils::fileBrowser(settings)); +#else + m_page->externalFileBrowserLabel->hide(); + m_page->externalFileBrowserEdit->hide(); + m_page->resetFileBrowserButton->hide(); +#endif + connect(m_page->resetButton, SIGNAL(clicked()), this, SLOT(resetInterfaceColor())); connect(m_page->resetEditorButton, SIGNAL(clicked()), @@ -97,6 +108,12 @@ QWidget *GeneralSettings::createPage(QWidget *parent) #ifdef Q_OS_UNIX connect(m_page->resetTerminalButton, SIGNAL(clicked()), this, SLOT(resetTerminal())); +#ifndef Q_OS_MAC + connect(m_page->resetFileBrowserButton, SIGNAL(clicked()), + this, SLOT(resetFileBrowser())); + connect(m_page->helpExternalFileBrowserButton, SIGNAL(clicked()), + this, SLOT(showHelpForFileBrowser())); +#endif #endif if (m_searchKeywords.isEmpty()) { @@ -122,6 +139,9 @@ void GeneralSettings::apply() #ifdef Q_OS_UNIX ConsoleProcess::setTerminalEmulator(Core::ICore::instance()->settings(), m_page->terminalEdit->text()); +#ifndef Q_OS_MAC + Utils::UnixUtils::setFileBrowser(Core::ICore::instance()->settings(), m_page->externalFileBrowserEdit->text()); +#endif #endif } @@ -145,9 +165,17 @@ void GeneralSettings::resetTerminal() { m_page->terminalEdit->setText(ConsoleProcess::defaultTerminalEmulator() + QLatin1String(" -e")); } + +#ifndef Q_OS_MAC +void GeneralSettings::resetFileBrowser() +{ + m_page->externalFileBrowserEdit->setText(UnixUtils::defaultFileBrowser()); +} +#endif #endif -void GeneralSettings::showHelpForExternalEditor() + +void GeneralSettings::variableHelpDialogCreator(const QString& helpText) { if (m_dialog) { m_dialog->show(); @@ -157,10 +185,23 @@ void GeneralSettings::showHelpForExternalEditor() } QMessageBox *mb = new QMessageBox(QMessageBox::Information, tr("Variables"), - EditorManager::instance()->externalEditorHelpText(), - QMessageBox::Cancel, + helpText, + QMessageBox::Close, m_page->helpExternalEditorButton); mb->setWindowModality(Qt::NonModal); m_dialog = mb; mb->show(); } + + +void GeneralSettings::showHelpForExternalEditor() +{ + variableHelpDialogCreator(EditorManager::instance()->externalEditorHelpText()); +} + +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) +void GeneralSettings::showHelpForFileBrowser() +{ + variableHelpDialogCreator(UnixUtils::fileBrowserHelpText()); +} +#endif diff --git a/src/plugins/coreplugin/generalsettings.h b/src/plugins/coreplugin/generalsettings.h index 6c2e4ee45c1..fb13a88ed43 100644 --- a/src/plugins/coreplugin/generalsettings.h +++ b/src/plugins/coreplugin/generalsettings.h @@ -62,10 +62,15 @@ private slots: void resetExternalEditor(); void showHelpForExternalEditor(); #ifdef Q_OS_UNIX +# ifndef Q_OS_MAC + void showHelpForFileBrowser(); + void resetFileBrowser(); +# endif void resetTerminal(); #endif private: + void variableHelpDialogCreator(const QString& helpText); Ui::GeneralSettings *m_page; QString m_searchKeywords; QPointer m_dialog; diff --git a/src/plugins/coreplugin/generalsettings.ui b/src/plugins/coreplugin/generalsettings.ui index a128edbc155..fad3f5222ae 100644 --- a/src/plugins/coreplugin/generalsettings.ui +++ b/src/plugins/coreplugin/generalsettings.ui @@ -14,6 +14,9 @@ + + QFormLayout::AllNonFixedFieldsGrow + QFormLayout::WrapLongRows @@ -43,7 +46,7 @@ 0 - + false @@ -141,6 +144,13 @@ + + + External file browser: + + + + When files are externally modified: @@ -150,7 +160,7 @@ - + @@ -178,6 +188,38 @@ + + + + + + + + + + + Reset to default + + + R + + + + :/core/images/reset.png:/core/images/reset.png + + + + + + + ? + + + + + + + diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index fcb3fc9ee1a..7c05d2add4d 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -86,6 +86,7 @@ #include #include #include +#include #include #include @@ -1842,6 +1843,21 @@ void ProjectExplorerPlugin::openFile() em->ensureEditorManagerVisible(); } +void ProjectExplorerPlugin::graphicalShellHasError(const QString &app, const QString &error) +{ + QWidget *w = Core::ICore::instance()->mainWindow(); + QMessageBox mbox(w); + mbox.setIcon(QMessageBox::Warning); + mbox.setWindowTitle(tr("Launching a file browser failed")); + mbox.setText(tr("Unable to start the file manager:\n\n%1\n\n" + "Do you want to change the current file manager?").arg(app)); + if (!error.isEmpty()) { + mbox.setDetailedText(tr("'%1' returned the following error:\n\n%2").arg(app, error)); + } + if (mbox.exec() == QMessageBox::Accepted) + Core::ICore::instance()->showOptionsDialog("environment", QString(), w); +} + void ProjectExplorerPlugin::showInGraphicalShell() { QTC_ASSERT(d->m_currentNode, return) @@ -1865,14 +1881,14 @@ void ProjectExplorerPlugin::showInGraphicalShell() #else // we cannot select a file here, because no file browser really supports it... const QFileInfo fileInfo(d->m_currentNode->path()); - const QString xdgopen = Environment::systemEnvironment().searchInPath("xdg-open"); - if (xdgopen.isEmpty()) { - QMessageBox::warning(Core::ICore::instance()->mainWindow(), - tr("Launching a file explorer failed"), - tr("Could not find xdg-open to launch the native file explorer.")); - return; + QString app = Utils::UnixUtils::fileBrowser(Core::ICore::instance()->settings()); + QProcess browserProc; + bool success = browserProc.startDetached(Utils::UnixUtils::substituteFileBrowserParameters(app, fileInfo.filePath())); + QString error = QString::fromLocal8Bit(browserProc.readAllStandardError()); + success = success && error.isEmpty(); + if (!success) { + graphicalShellHasError(app, error); } - QProcess::startDetached(xdgopen, QStringList(fileInfo.path())); #endif } diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index 7b62bcfefd3..6f194f6335a 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -213,6 +213,7 @@ private slots: void currentModeChanged(Core::IMode *mode); private: + void graphicalShellHasError(const QString &app, const QString &error); void runProjectImpl(Project *pro, QString mode); void executeRunConfiguration(RunConfiguration *, const QString &mode); bool showBuildConfigDialog();