Locator on Linux/Mac: Show ~ instead of $HOME in paths.

With this, you will see more of the "relevant" path.

Change-Id: I03c4c7bd2bdaa9148c70a68678306e259f9c7204
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Nikolai Kosjar
2012-08-24 15:00:44 +02:00
parent ce9b7bf123
commit 9483408fec
6 changed files with 36 additions and 6 deletions

View File

@@ -205,6 +205,24 @@ FileName FileUtils::resolveSymlinks(const FileName &path)
return FileName::fromString(f.filePath()); return FileName::fromString(f.filePath());
} }
/*!
Like QDir::toNativeSeparators(), but use prefix '~' instead of $HOME on unix systems when an
absolute path is given.
return Possibly shortened path with native separators.
*/
QString FileUtils::shortNativePath(const FileName &path)
{
if (HostOsInfo::isAnyUnixHost()) {
const FileName home = FileName::fromString(QDir::cleanPath(QDir::homePath()));
if (path.isChildOf(home)) {
return QLatin1Char('~') + QDir::separator()
+ QDir::toNativeSeparators(path.relativeChildPath(home).toString());
}
}
return path.toUserOutput();
}
QByteArray FileReader::fetchQrc(const QString &fileName) QByteArray FileReader::fetchQrc(const QString &fileName)
{ {
QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray()); QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray());

View File

@@ -96,6 +96,7 @@ public:
QString *error = 0); QString *error = 0);
static bool isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp); static bool isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp);
static FileName resolveSymlinks(const FileName &path); static FileName resolveSymlinks(const FileName &path);
static QString shortNativePath(const FileName &path);
}; };
class QTCREATOR_UTILS_EXPORT FileReader class QTCREATOR_UTILS_EXPORT FileReader

View File

@@ -37,10 +37,12 @@
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/buildsteplist.h> #include <projectexplorer/buildsteplist.h>
#include <utils/fileutils.h>
using namespace CMakeProjectManager; using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal; using namespace CMakeProjectManager::Internal;
using namespace Utils;
CMakeLocatorFilter::CMakeLocatorFilter() CMakeLocatorFilter::CMakeLocatorFilter()
{ {
@@ -74,7 +76,8 @@ QList<Locator::FilterEntry> CMakeLocatorFilter::matchesFor(QFutureInterface<Loca
foreach (CMakeBuildTarget ct, cmakeProject->buildTargets()) { foreach (CMakeBuildTarget ct, cmakeProject->buildTargets()) {
if (ct.title.contains(entry)) { if (ct.title.contains(entry)) {
Locator::FilterEntry entry(this, ct.title, cmakeProject->document()->fileName()); Locator::FilterEntry entry(this, ct.title, cmakeProject->document()->fileName());
entry.extraInfo = cmakeProject->document()->fileName(); entry.extraInfo = FileUtils::shortNativePath(
FileName::fromString(cmakeProject->document()->fileName()));
result.append(entry); result.append(entry);
} }
} }

View File

@@ -33,10 +33,12 @@
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <utils/fileutils.h>
#include <QStringMatcher> #include <QStringMatcher>
using namespace CppTools::Internal; using namespace CppTools::Internal;
using namespace Utils;
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager) CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
: m_manager(manager), : m_manager(manager),
@@ -103,10 +105,12 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
QVariant id = qVariantFromValue(info); QVariant id = qVariantFromValue(info);
Locator::FilterEntry filterEntry(this, info.symbolName, id, info.icon); Locator::FilterEntry filterEntry(this, info.symbolName, id, info.icon);
if (! info.symbolType.isEmpty()) if (! info.symbolType.isEmpty()) {
filterEntry.extraInfo = info.symbolType; filterEntry.extraInfo = info.symbolType;
else } else {
filterEntry.extraInfo = info.fileName; filterEntry.extraInfo = FileUtils::shortNativePath(
FileName::fromString(info.fileName));
}
if (info.symbolName.startsWith(entry)) if (info.symbolName.startsWith(entry))
betterEntries.append(filterEntry); betterEntries.append(filterEntry);

View File

@@ -31,12 +31,14 @@
#include "basefilefilter.h" #include "basefilefilter.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <utils/fileutils.h>
#include <QDir> #include <QDir>
#include <QStringMatcher> #include <QStringMatcher>
using namespace Core; using namespace Core;
using namespace Locator; using namespace Locator;
using namespace Utils;
BaseFileFilter::BaseFileFilter() BaseFileFilter::BaseFileFilter()
: m_forceNewSearchList(false) : m_forceNewSearchList(false)
@@ -81,7 +83,7 @@ QList<FilterEntry> BaseFileFilter::matchesFor(QFutureInterface<Locator::FilterEn
|| (!hasWildcard && matcher.indexIn(name) != -1)) { || (!hasWildcard && matcher.indexIn(name) != -1)) {
QFileInfo fi(path); QFileInfo fi(path);
FilterEntry entry(this, fi.fileName(), QString(path + lineNoSuffix)); FilterEntry entry(this, fi.fileName(), QString(path + lineNoSuffix));
entry.extraInfo = QDir::toNativeSeparators(fi.path()); entry.extraInfo = FileUtils::shortNativePath(FileName(fi));
entry.resolveFileIcon = true; entry.resolveFileIcon = true;
if (name.startsWith(needle)) if (name.startsWith(needle))
matches.append(entry); matches.append(entry);

View File

@@ -32,6 +32,7 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h> #include <coreplugin/editormanager/ieditor.h>
#include <utils/fileutils.h>
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
@@ -39,6 +40,7 @@
using namespace Core; using namespace Core;
using namespace Locator; using namespace Locator;
using namespace Locator::Internal; using namespace Locator::Internal;
using namespace Utils;
OpenDocumentsFilter::OpenDocumentsFilter(EditorManager *editorManager) : OpenDocumentsFilter::OpenDocumentsFilter(EditorManager *editorManager) :
m_editorManager(editorManager) m_editorManager(editorManager)
@@ -72,7 +74,7 @@ QList<FilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locator::Fil
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
QFileInfo fi(fileName); QFileInfo fi(fileName);
FilterEntry fiEntry(this, fi.fileName(), QString(fileName + lineNoSuffix)); FilterEntry fiEntry(this, fi.fileName(), QString(fileName + lineNoSuffix));
fiEntry.extraInfo = QDir::toNativeSeparators(fi.path()); fiEntry.extraInfo = FileUtils::shortNativePath(FileName(fi));
fiEntry.resolveFileIcon = true; fiEntry.resolveFileIcon = true;
value.append(fiEntry); value.append(fiEntry);
} }