forked from qt-creator/qt-creator
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:
@@ -205,6 +205,24 @@ FileName FileUtils::resolveSymlinks(const FileName &path)
|
||||
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)
|
||||
{
|
||||
QTC_ASSERT(fileName.startsWith(QLatin1Char(':')), return QByteArray());
|
||||
|
||||
@@ -96,6 +96,7 @@ public:
|
||||
QString *error = 0);
|
||||
static bool isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp);
|
||||
static FileName resolveSymlinks(const FileName &path);
|
||||
static QString shortNativePath(const FileName &path);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT FileReader
|
||||
|
||||
@@ -37,10 +37,12 @@
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
|
||||
using namespace CMakeProjectManager;
|
||||
using namespace CMakeProjectManager::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
CMakeLocatorFilter::CMakeLocatorFilter()
|
||||
{
|
||||
@@ -74,7 +76,8 @@ QList<Locator::FilterEntry> CMakeLocatorFilter::matchesFor(QFutureInterface<Loca
|
||||
foreach (CMakeBuildTarget ct, cmakeProject->buildTargets()) {
|
||||
if (ct.title.contains(entry)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,12 @@
|
||||
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QStringMatcher>
|
||||
|
||||
using namespace CppTools::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
CppLocatorFilter::CppLocatorFilter(CppModelManager *manager)
|
||||
: m_manager(manager),
|
||||
@@ -103,10 +105,12 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(QFutureInterface<Locato
|
||||
|
||||
QVariant id = qVariantFromValue(info);
|
||||
Locator::FilterEntry filterEntry(this, info.symbolName, id, info.icon);
|
||||
if (! info.symbolType.isEmpty())
|
||||
if (! info.symbolType.isEmpty()) {
|
||||
filterEntry.extraInfo = info.symbolType;
|
||||
else
|
||||
filterEntry.extraInfo = info.fileName;
|
||||
} else {
|
||||
filterEntry.extraInfo = FileUtils::shortNativePath(
|
||||
FileName::fromString(info.fileName));
|
||||
}
|
||||
|
||||
if (info.symbolName.startsWith(entry))
|
||||
betterEntries.append(filterEntry);
|
||||
|
||||
@@ -31,12 +31,14 @@
|
||||
#include "basefilefilter.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QStringMatcher>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Locator;
|
||||
using namespace Utils;
|
||||
|
||||
BaseFileFilter::BaseFileFilter()
|
||||
: m_forceNewSearchList(false)
|
||||
@@ -81,7 +83,7 @@ QList<FilterEntry> BaseFileFilter::matchesFor(QFutureInterface<Locator::FilterEn
|
||||
|| (!hasWildcard && matcher.indexIn(name) != -1)) {
|
||||
QFileInfo fi(path);
|
||||
FilterEntry entry(this, fi.fileName(), QString(path + lineNoSuffix));
|
||||
entry.extraInfo = QDir::toNativeSeparators(fi.path());
|
||||
entry.extraInfo = FileUtils::shortNativePath(FileName(fi));
|
||||
entry.resolveFileIcon = true;
|
||||
if (name.startsWith(needle))
|
||||
matches.append(entry);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
@@ -39,6 +40,7 @@
|
||||
using namespace Core;
|
||||
using namespace Locator;
|
||||
using namespace Locator::Internal;
|
||||
using namespace Utils;
|
||||
|
||||
OpenDocumentsFilter::OpenDocumentsFilter(EditorManager *editorManager) :
|
||||
m_editorManager(editorManager)
|
||||
@@ -72,7 +74,7 @@ QList<FilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<Locator::Fil
|
||||
if (!fileName.isEmpty()) {
|
||||
QFileInfo fi(fileName);
|
||||
FilterEntry fiEntry(this, fi.fileName(), QString(fileName + lineNoSuffix));
|
||||
fiEntry.extraInfo = QDir::toNativeSeparators(fi.path());
|
||||
fiEntry.extraInfo = FileUtils::shortNativePath(FileName(fi));
|
||||
fiEntry.resolveFileIcon = true;
|
||||
value.append(fiEntry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user