forked from qt-creator/qt-creator
C++: handle case-insensitive file names in the WorkingCopy
... by keying on Utils::FileName Task-number: QTCREATORBUG-12390 Change-Id: Ia1a59d2e422b4f92300ac6a8e0e52dd7456a6e70 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
e3977de08e
commit
be4a030696
@@ -721,6 +721,11 @@ FileName &FileName::appendString(QChar str)
|
||||
return *this;
|
||||
}
|
||||
|
||||
QTextStream &operator<<(QTextStream &s, const FileName &fn)
|
||||
{
|
||||
return s << fn.toString();
|
||||
}
|
||||
|
||||
static bool isFileDrop(const QMimeData *d, QList<FileDropSupport::FileSpec> *files = 0)
|
||||
{
|
||||
// internal drop
|
||||
|
||||
@@ -102,6 +102,7 @@ private:
|
||||
FileName(const QString &string);
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QTextStream &operator<<(QTextStream &s, const FileName &fn);
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT FileUtils {
|
||||
public:
|
||||
|
||||
@@ -74,17 +74,17 @@ UnsavedFiles createUnsavedFiles(WorkingCopy workingCopy)
|
||||
// TODO: change the modelmanager to hold one working copy, and amend it every time we ask for one.
|
||||
// TODO: Reason: the UnsavedFile needs a QByteArray.
|
||||
|
||||
QSet<QString> modifiedFiles;
|
||||
QSet<::Utils::FileName> modifiedFiles;
|
||||
foreach (IDocument *doc, Core::DocumentManager::modifiedDocuments())
|
||||
modifiedFiles.insert(doc->filePath());
|
||||
modifiedFiles.insert(::Utils::FileName::fromString(doc->filePath()));
|
||||
|
||||
UnsavedFiles result;
|
||||
QHashIterator<QString, QPair<QByteArray, unsigned> > wcIter = workingCopy.iterator();
|
||||
QHashIterator<::Utils::FileName, QPair<QByteArray, unsigned> > wcIter = workingCopy.iterator();
|
||||
while (wcIter.hasNext()) {
|
||||
wcIter.next();
|
||||
const QString &fileName = wcIter.key();
|
||||
if (modifiedFiles.contains(fileName) && QFile(fileName).exists())
|
||||
result.insert(fileName, wcIter.value().first);
|
||||
const ::Utils::FileName &fileName = wcIter.key();
|
||||
if (modifiedFiles.contains(fileName) && QFile(fileName.toString()).exists())
|
||||
result.insert(fileName.toString(), wcIter.value().first);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -1087,10 +1087,11 @@ void WorkingCopyModel::configure(const WorkingCopy &workingCopy)
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
m_workingCopyList.clear();
|
||||
QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
m_workingCopyList << WorkingCopyEntry(it.key(), it.value().first, it.value().second);
|
||||
m_workingCopyList << WorkingCopyEntry(it.key().toString(), it.value().first,
|
||||
it.value().second);
|
||||
}
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
@@ -580,10 +580,10 @@ void Dumper::dumpWorkingCopy(const WorkingCopy &workingCopy)
|
||||
m_out << "Working Copy contains " << workingCopy.size() << " entries{{{1\n";
|
||||
|
||||
const QByteArray i1 = indent(1);
|
||||
QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
QHashIterator<::Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
const QString filePath = it.key();
|
||||
const ::Utils::FileName &filePath = it.key();
|
||||
unsigned sourcRevision = it.value().second;
|
||||
m_out << i1 << "rev=" << sourcRevision << ", " << filePath << "\n";
|
||||
}
|
||||
|
||||
@@ -684,10 +684,10 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
|
||||
QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h"
|
||||
|
||||
QStringList fileNamesInWorkinCopy;
|
||||
QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
fileNamesInWorkinCopy << QFileInfo(it.key()).fileName();
|
||||
fileNamesInWorkinCopy << QFileInfo(it.key().toString()).fileName();
|
||||
}
|
||||
fileNamesInWorkinCopy.sort();
|
||||
const QString expectedUiHeaderFileName = _("ui_mainwindow.h");
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QPair>
|
||||
@@ -45,28 +47,43 @@ public:
|
||||
WorkingCopy();
|
||||
|
||||
void insert(const QString &fileName, const QByteArray &source, unsigned revision = 0)
|
||||
{ insert(Utils::FileName::fromString(fileName), source, revision); }
|
||||
|
||||
void insert(const Utils::FileName &fileName, const QByteArray &source, unsigned revision = 0)
|
||||
{ _elements.insert(fileName, qMakePair(source, revision)); }
|
||||
|
||||
bool contains(const QString &fileName) const
|
||||
{ return contains(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
bool contains(const Utils::FileName &fileName) const
|
||||
{ return _elements.contains(fileName); }
|
||||
|
||||
QByteArray source(const QString &fileName) const
|
||||
{ return source(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
QByteArray source(const Utils::FileName &fileName) const
|
||||
{ return _elements.value(fileName).first; }
|
||||
|
||||
unsigned revision(const QString &fileName) const
|
||||
{ return revision(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
unsigned revision(const Utils::FileName &fileName) const
|
||||
{ return _elements.value(fileName).second; }
|
||||
|
||||
QPair<QByteArray, unsigned> get(const QString &fileName) const
|
||||
{ return get(Utils::FileName::fromString(fileName)); }
|
||||
|
||||
QPair<QByteArray, unsigned> get(const Utils::FileName &fileName) const
|
||||
{ return _elements.value(fileName); }
|
||||
|
||||
QHashIterator<QString, QPair<QByteArray, unsigned> > iterator() const
|
||||
{ return QHashIterator<QString, QPair<QByteArray, unsigned> >(_elements); }
|
||||
QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > iterator() const
|
||||
{ return QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> >(_elements); }
|
||||
|
||||
int size() const
|
||||
{ return _elements.size(); }
|
||||
|
||||
private:
|
||||
typedef QHash<QString, QPair<QByteArray, unsigned> > Table;
|
||||
typedef QHash<Utils::FileName, QPair<QByteArray, unsigned> > Table;
|
||||
Table _elements;
|
||||
};
|
||||
|
||||
|
||||
@@ -537,12 +537,14 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
||||
} else {
|
||||
const CppTools::WorkingCopy workingCopy =
|
||||
CppTools::CppModelManager::instance()->workingCopy();
|
||||
QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
const Utils::FileName configFileName =
|
||||
Utils::FileName::fromString(CppTools::CppModelManager::configurationFileName());
|
||||
QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
const QString fileName = it.key();
|
||||
if (fileName != CppTools::CppModelManager::configurationFileName())
|
||||
newDocTable.insert(docTable.document(fileName));
|
||||
const Utils::FileName &fileName = it.key();
|
||||
if (fileName != configFileName)
|
||||
newDocTable.insert(docTable.document(fileName.toString()));
|
||||
}
|
||||
}
|
||||
docTable = newDocTable;
|
||||
|
||||
Reference in New Issue
Block a user