Commit be4a0306 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

C++: handle case-insensitive file names in the WorkingCopy

... by keying on Utils::FileName

Task-number: QTCREATORBUG-12390
Change-Id: Ia1a59d2e422b4f92300ac6a8e0e52dd7456a6e70
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent e3977de0
...@@ -721,6 +721,11 @@ FileName &FileName::appendString(QChar str) ...@@ -721,6 +721,11 @@ FileName &FileName::appendString(QChar str)
return *this; return *this;
} }
QTextStream &operator<<(QTextStream &s, const FileName &fn)
{
return s << fn.toString();
}
static bool isFileDrop(const QMimeData *d, QList<FileDropSupport::FileSpec> *files = 0) static bool isFileDrop(const QMimeData *d, QList<FileDropSupport::FileSpec> *files = 0)
{ {
// internal drop // internal drop
......
...@@ -102,6 +102,7 @@ private: ...@@ -102,6 +102,7 @@ private:
FileName(const QString &string); FileName(const QString &string);
}; };
QTCREATOR_UTILS_EXPORT QTextStream &operator<<(QTextStream &s, const FileName &fn);
class QTCREATOR_UTILS_EXPORT FileUtils { class QTCREATOR_UTILS_EXPORT FileUtils {
public: public:
......
...@@ -74,17 +74,17 @@ UnsavedFiles createUnsavedFiles(WorkingCopy workingCopy) ...@@ -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: change the modelmanager to hold one working copy, and amend it every time we ask for one.
// TODO: Reason: the UnsavedFile needs a QByteArray. // TODO: Reason: the UnsavedFile needs a QByteArray.
QSet<QString> modifiedFiles; QSet<::Utils::FileName> modifiedFiles;
foreach (IDocument *doc, Core::DocumentManager::modifiedDocuments()) foreach (IDocument *doc, Core::DocumentManager::modifiedDocuments())
modifiedFiles.insert(doc->filePath()); modifiedFiles.insert(::Utils::FileName::fromString(doc->filePath()));
UnsavedFiles result; UnsavedFiles result;
QHashIterator<QString, QPair<QByteArray, unsigned> > wcIter = workingCopy.iterator(); QHashIterator<::Utils::FileName, QPair<QByteArray, unsigned> > wcIter = workingCopy.iterator();
while (wcIter.hasNext()) { while (wcIter.hasNext()) {
wcIter.next(); wcIter.next();
const QString &fileName = wcIter.key(); const ::Utils::FileName &fileName = wcIter.key();
if (modifiedFiles.contains(fileName) && QFile(fileName).exists()) if (modifiedFiles.contains(fileName) && QFile(fileName.toString()).exists())
result.insert(fileName, wcIter.value().first); result.insert(fileName.toString(), wcIter.value().first);
} }
return result; return result;
......
...@@ -1087,10 +1087,11 @@ void WorkingCopyModel::configure(const WorkingCopy &workingCopy) ...@@ -1087,10 +1087,11 @@ void WorkingCopyModel::configure(const WorkingCopy &workingCopy)
{ {
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
m_workingCopyList.clear(); m_workingCopyList.clear();
QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
while (it.hasNext()) { while (it.hasNext()) {
it.next(); 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(); emit layoutChanged();
} }
......
...@@ -580,10 +580,10 @@ void Dumper::dumpWorkingCopy(const WorkingCopy &workingCopy) ...@@ -580,10 +580,10 @@ void Dumper::dumpWorkingCopy(const WorkingCopy &workingCopy)
m_out << "Working Copy contains " << workingCopy.size() << " entries{{{1\n"; m_out << "Working Copy contains " << workingCopy.size() << " entries{{{1\n";
const QByteArray i1 = indent(1); 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()) { while (it.hasNext()) {
it.next(); it.next();
const QString filePath = it.key(); const ::Utils::FileName &filePath = it.key();
unsigned sourcRevision = it.value().second; unsigned sourcRevision = it.value().second;
m_out << i1 << "rev=" << sourcRevision << ", " << filePath << "\n"; m_out << i1 << "rev=" << sourcRevision << ", " << filePath << "\n";
} }
......
...@@ -684,10 +684,10 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles() ...@@ -684,10 +684,10 @@ void CppToolsPlugin::test_modelmanager_extraeditorsupport_uiFiles()
QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h" QCOMPARE(workingCopy.size(), 2); // mm->configurationFileName() and "ui_*.h"
QStringList fileNamesInWorkinCopy; QStringList fileNamesInWorkinCopy;
QHashIterator<QString, QPair<QByteArray, unsigned> > it = workingCopy.iterator(); QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > it = workingCopy.iterator();
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
fileNamesInWorkinCopy << QFileInfo(it.key()).fileName(); fileNamesInWorkinCopy << QFileInfo(it.key().toString()).fileName();
} }
fileNamesInWorkinCopy.sort(); fileNamesInWorkinCopy.sort();
const QString expectedUiHeaderFileName = _("ui_mainwindow.h"); const QString expectedUiHeaderFileName = _("ui_mainwindow.h");
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "cpptools_global.h" #include "cpptools_global.h"
#include <utils/fileutils.h>
#include <QHash> #include <QHash>
#include <QString> #include <QString>
#include <QPair> #include <QPair>
...@@ -45,28 +47,43 @@ public: ...@@ -45,28 +47,43 @@ public:
WorkingCopy(); WorkingCopy();
void insert(const QString &fileName, const QByteArray &source, unsigned revision = 0) 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)); } { _elements.insert(fileName, qMakePair(source, revision)); }
bool contains(const QString &fileName) const bool contains(const QString &fileName) const
{ return contains(Utils::FileName::fromString(fileName)); }
bool contains(const Utils::FileName &fileName) const
{ return _elements.contains(fileName); } { return _elements.contains(fileName); }
QByteArray source(const QString &fileName) const QByteArray source(const QString &fileName) const
{ return source(Utils::FileName::fromString(fileName)); }
QByteArray source(const Utils::FileName &fileName) const
{ return _elements.value(fileName).first; } { return _elements.value(fileName).first; }
unsigned revision(const QString &fileName) const unsigned revision(const QString &fileName) const
{ return revision(Utils::FileName::fromString(fileName)); }
unsigned revision(const Utils::FileName &fileName) const
{ return _elements.value(fileName).second; } { return _elements.value(fileName).second; }
QPair<QByteArray, unsigned> get(const QString &fileName) const 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); } { return _elements.value(fileName); }
QHashIterator<QString, QPair<QByteArray, unsigned> > iterator() const QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> > iterator() const
{ return QHashIterator<QString, QPair<QByteArray, unsigned> >(_elements); } { return QHashIterator<Utils::FileName, QPair<QByteArray, unsigned> >(_elements); }
int size() const int size() const
{ return _elements.size(); } { return _elements.size(); }
private: private:
typedef QHash<QString, QPair<QByteArray, unsigned> > Table; typedef QHash<Utils::FileName, QPair<QByteArray, unsigned> > Table;
Table _elements; Table _elements;
}; };
......
...@@ -537,12 +537,14 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName, ...@@ -537,12 +537,14 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
} else { } else {
const CppTools::WorkingCopy workingCopy = const CppTools::WorkingCopy workingCopy =
CppTools::CppModelManager::instance()->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()) { while (it.hasNext()) {
it.next(); it.next();
const QString fileName = it.key(); const Utils::FileName &fileName = it.key();
if (fileName != CppTools::CppModelManager::configurationFileName()) if (fileName != configFileName)
newDocTable.insert(docTable.document(fileName)); newDocTable.insert(docTable.document(fileName.toString()));
} }
} }
docTable = newDocTable; docTable = newDocTable;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment