forked from qt-creator/qt-creator
Make it possible to set the external file browser on unix.
xdg-open is not available everywhere and fails when no DE is running. Reviewed-By: Oswald Buddenhagen
This commit is contained in:
99
src/libs/utils/unixutils.cpp
Normal file
99
src/libs/utils/unixutils.cpp
Normal file
@@ -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 <QtCore/QSettings>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
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",
|
||||
"<table border=1 cellspacing=0 cellpadding=3>"
|
||||
"<tr><th>Variable</th><th>Expands to</th></tr>"
|
||||
"<tr><td>%d</td><td>directory of current file</td></tr>"
|
||||
"<tr><td>%f</td><td>file name (with full path)</td></tr>"
|
||||
"<tr><td>%n</td><td>file name (without path)</td></tr>"
|
||||
"<tr><td>%%</td><td>%</td></tr>"
|
||||
"</table>");
|
||||
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;
|
||||
}
|
56
src/libs/utils/unixutils.h
Normal file
56
src/libs/utils/unixutils.h
Normal file
@@ -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 <QtCore/QString>
|
||||
|
||||
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
|
@@ -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 \
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include <utils/stylehelper.h>
|
||||
#include <utils/qtcolorbutton.h>
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <utils/unixutils.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
@@ -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
|
||||
|
@@ -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<QWidget> m_dialog;
|
||||
|
@@ -14,6 +14,9 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="rowWrapPolicy">
|
||||
<enum>QFormLayout::WrapLongRows</enum>
|
||||
</property>
|
||||
@@ -43,7 +46,7 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alphaAllowed">
|
||||
<property name="alphaAllowed" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -141,6 +144,13 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="externalFileBrowserLabel">
|
||||
<property name="text">
|
||||
<string>External file browser:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="modifiedLabel">
|
||||
<property name="text">
|
||||
<string>When files are externally modified:</string>
|
||||
@@ -150,7 +160,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="QComboBox" name="reloadBehavior">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
@@ -178,6 +188,38 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="externalFileBrowserEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="resetFileBrowserButton">
|
||||
<property name="toolTip">
|
||||
<string>Reset to default</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="core.qrc">
|
||||
<normaloff>:/core/images/reset.png</normaloff>:/core/images/reset.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="helpExternalFileBrowserButton">
|
||||
<property name="text">
|
||||
<string>?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@@ -86,6 +86,7 @@
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/parameteraction.h>
|
||||
#include <utils/unixutils.h>
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtCore/QDateTime>
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user