forked from qt-creator/qt-creator
On Linux/Mac, show home path as ~ in recent projects.
Reviewed-by: Daniel Molkentin
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QtCore/QDir>
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
@@ -100,4 +102,21 @@ QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
|
|||||||
return common;
|
return common;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
QString outPath = path;
|
||||||
|
#else
|
||||||
|
static const QString homePath = QDir::homePath();
|
||||||
|
|
||||||
|
QFileInfo fi(QDir::cleanPath(path));
|
||||||
|
QString outPath = fi.absoluteFilePath();
|
||||||
|
if (outPath.startsWith(homePath))
|
||||||
|
outPath = QLatin1Char('~') + outPath.mid(homePath.size());
|
||||||
|
else
|
||||||
|
outPath = path;
|
||||||
|
#endif
|
||||||
|
return outPath;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings);
|
|||||||
// "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo"
|
// "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo"
|
||||||
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files);
|
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files);
|
||||||
|
|
||||||
|
// On Linux/Mac replace user's home path with ~
|
||||||
|
// Uses cleaned path and tries to use absolute path of "path" if possible
|
||||||
|
// If path is not sub of home path, or when running on Windows, returns the input
|
||||||
|
QTCREATOR_UTILS_EXPORT QString withTildeHomePath(const QString &path);
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
#endif // SETTINGSTUTILS_H
|
#endif // SETTINGSTUTILS_H
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
#include <coreplugin/settingsdatabase.h>
|
#include <coreplugin/settingsdatabase.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
#include <utils/stylehelper.h>
|
#include <utils/stylehelper.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
@@ -1253,7 +1254,8 @@ void MainWindow::aboutToShowRecentFiles()
|
|||||||
bool hasRecentFiles = false;
|
bool hasRecentFiles = false;
|
||||||
foreach (const QString &fileName, m_fileManager->recentFiles()) {
|
foreach (const QString &fileName, m_fileManager->recentFiles()) {
|
||||||
hasRecentFiles = true;
|
hasRecentFiles = true;
|
||||||
QAction *action = aci->menu()->addAction(fileName);
|
QAction *action = aci->menu()->addAction(
|
||||||
|
Utils::withTildeHomePath(fileName));
|
||||||
action->setData(fileName);
|
action->setData(fileName);
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
|
connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
#include <utils/consoleprocess.h>
|
#include <utils/consoleprocess.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/parameteraction.h>
|
#include <utils/parameteraction.h>
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
@@ -1998,7 +1999,7 @@ void ProjectExplorerPlugin::updateRecentProjectMenu()
|
|||||||
const QPair<QString, QString> &s = *it;
|
const QPair<QString, QString> &s = *it;
|
||||||
if (s.first.endsWith(QLatin1String(".qws")))
|
if (s.first.endsWith(QLatin1String(".qws")))
|
||||||
continue;
|
continue;
|
||||||
QAction *action = menu->addAction(s.first);
|
QAction *action = menu->addAction(Utils::withTildeHomePath(s.first));
|
||||||
action->setData(s.first);
|
action->setData(s.first);
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(openRecentProject()));
|
connect(action, SIGNAL(triggered()), this, SLOT(openRecentProject()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
#include <coreplugin/mainwindow.h>
|
#include <coreplugin/mainwindow.h>
|
||||||
#include <coreplugin/filemanager.h>
|
#include <coreplugin/filemanager.h>
|
||||||
|
|
||||||
|
#include <utils/stringutils.h>
|
||||||
|
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QPair>
|
#include <QtCore/QPair>
|
||||||
@@ -146,8 +148,9 @@ void ProjectWelcomePageWidget::updateWelcomePage(const WelcomePageData &welcomeP
|
|||||||
break;
|
break;
|
||||||
const QFileInfo fi(it.first);
|
const QFileInfo fi(it.first);
|
||||||
QString label = "<b>" + it.second +
|
QString label = "<b>" + it.second +
|
||||||
"</b><br><font color=gray>" +
|
"</b><br><font color=gray>" +
|
||||||
fm.elidedText(it.first, Qt::ElideMiddle, 250);
|
fm.elidedText(QDir::toNativeSeparators(Utils::withTildeHomePath(it.first)),
|
||||||
|
Qt::ElideMiddle, 250);
|
||||||
ui->projTreeWidget->addItem(label, it.first,
|
ui->projTreeWidget->addItem(label, it.first,
|
||||||
QDir::toNativeSeparators(fi.absolutePath()));
|
QDir::toNativeSeparators(fi.absolutePath()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ SUBDIRS += \
|
|||||||
aggregation \
|
aggregation \
|
||||||
changeset \
|
changeset \
|
||||||
# icheckbuild \
|
# icheckbuild \
|
||||||
generichighlighter
|
generichighlighter \
|
||||||
|
utils_stringutils
|
||||||
|
|
||||||
contains (QT_CONFIG, declarative) {
|
contains (QT_CONFIG, declarative) {
|
||||||
SUBDIRS += qml
|
SUBDIRS += qml
|
||||||
|
|||||||
76
tests/auto/utils_stringutils/tst_stringutils.cpp
Normal file
76
tests/auto/utils_stringutils/tst_stringutils.cpp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2010 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 <stringutils.h>
|
||||||
|
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
class tst_StringUtils : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void testWithTildeHomePath();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_StringUtils::testWithTildeHomePath()
|
||||||
|
{
|
||||||
|
#ifndef Q_OS_WIN
|
||||||
|
// home path itself
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath()), QLatin1String("~"));
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1Char('/')),
|
||||||
|
QLatin1String("~"));
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QLatin1String("/unclean/..") + QDir::homePath()),
|
||||||
|
QLatin1String("~"));
|
||||||
|
// sub of home path
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/foo")),
|
||||||
|
QLatin1String("~/foo"));
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/foo/")),
|
||||||
|
QLatin1String("~/foo"));
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/some/path/file.txt")),
|
||||||
|
QLatin1String("~/some/path/file.txt"));
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/some/unclean/../path/file.txt")),
|
||||||
|
QLatin1String("~/some/path/file.txt"));
|
||||||
|
// not sub of home path
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/../foo")),
|
||||||
|
QDir::homePath() + QLatin1String("/../foo"));
|
||||||
|
#else
|
||||||
|
// windows: should return same as input
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath()), QDir::homePath());
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/foo")),
|
||||||
|
QDir::homePath() + QLatin1String("/foo"));
|
||||||
|
QCOMPARE(Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/../foo")),
|
||||||
|
Utils::withTildeHomePath(QDir::homePath() + QLatin1String("/../foo")));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_StringUtils)
|
||||||
|
|
||||||
|
#include "tst_stringutils.moc"
|
||||||
15
tests/auto/utils_stringutils/utils_stringutils.pro
Normal file
15
tests/auto/utils_stringutils/utils_stringutils.pro
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
CONFIG += qtestlib testcase
|
||||||
|
TEMPLATE = app
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
DEFINES += QTCREATOR_UTILS_LIB
|
||||||
|
|
||||||
|
UTILS_PATH = ../../../src/libs/utils
|
||||||
|
|
||||||
|
INCLUDEPATH += $$UTILS_PATH
|
||||||
|
# Input
|
||||||
|
SOURCES += tst_stringutils.cpp \
|
||||||
|
$$UTILS_PATH/stringutils.cpp
|
||||||
|
HEADERS += $$UTILS_PATH/stringutils.h \
|
||||||
|
$$UTILS_PATH/utils_global.h
|
||||||
|
|
||||||
|
TARGET=tst_$$TARGET
|
||||||
Reference in New Issue
Block a user