Commit 041e8c89 authored by Kåre Särs's avatar Kåre Särs

BP: Add caseFixed() function to fix path casing on Windows

MSVC sometimes prints all lowercase filenames in compile output, so to
not end up with duplicate files in Kate we have to fix the case of the
url before opening it.
parent 69c962f2
......@@ -395,7 +395,36 @@ void KateBuildView::slotPrev()
}
}
#ifdef Q_OS_WIN
/******************************************************************/
QString KateBuildView::caseFixed(const QString &path)
{
QStringList paths = path.split(QLatin1Char('/'));
if (paths.isEmpty()) { return path; }
qDebug() << "PATH=" << paths;
QString result = paths[0].toUpper() + QLatin1Char('/');
for (int i=1; i<paths.count(); ++i) {
QDir curDir(result);
const QStringList items = curDir.entryList();
int j;
for (j=0; j<items.size(); ++j) {
if (items[j].compare(paths[i], Qt::CaseInsensitive) == 0) {
qDebug() << "adding" << items[j];
result += items[j];
if (i < paths.count()-1) {
result += QLatin1Char('/');
}
break;
}
}
if (j==items.size()) { return path; }
}
return result;
}
#endif
void KateBuildView::slotErrorSelected(QTreeWidgetItem *item)
{
// any view active?
......@@ -415,7 +444,7 @@ void KateBuildView::slotErrorSelected(QTreeWidgetItem *item)
}
// get stuff
const QString filename = item->data(0, Qt::UserRole).toString();
QString filename = item->data(0, Qt::UserRole).toString();
if (filename.isEmpty()) {
return;
}
......@@ -429,6 +458,10 @@ void KateBuildView::slotErrorSelected(QTreeWidgetItem *item)
column = data.cursor->column();
}
#ifdef Q_OS_WIN
filename = caseFixed(filename);
#endif
// open file (if needed, otherwise, this will activate only the right view...)
m_win->openUrl(QUrl::fromLocalFile(filename));
......@@ -1026,7 +1059,12 @@ void KateBuildView::processLine(const QString &line)
const QString line_n = match.captured(3);
const QString msg = match.captured(4);
// qDebug() << "File Name:"<<filename<< " msg:"<< msg;
#ifdef Q_OS_WIN
// convert '\' to '/' so the concatenation works
filename = QFileInfo(filename).filePath();
#endif
//qDebug() << "File Name:"<<m_make_dir << filename << " msg:"<< msg;
// add path to file
if (QFile::exists(m_make_dir + QLatin1Char('/') + filename)) {
filename = m_make_dir + QLatin1Char('/') + filename;
......
......@@ -117,6 +117,9 @@ protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
private:
#ifdef Q_OS_WIN
QString caseFixed(const QString &path);
#endif
void processLine(const QString &);
void addError(const QString &filename, const QString &line, const QString &column, const QString &message);
bool startProcess(const QString &dir, const QString &command);
......
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