Commit 7cbbada3 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Wizards: Improve list of files displayed.

Extract the common root directory and display in separate
line. Use the routine from
the cvs plugin for that, moving it to stringutils.h.
parent efdd8cea
......@@ -27,9 +27,12 @@
**
**************************************************************************/
#include "settingsutils.h"
#include "stringutils.h"
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <limits.h>
namespace Utils {
......@@ -46,4 +49,53 @@ QTCREATOR_UTILS_EXPORT QString settingsKey(const QString &category)
return rc;
}
// Figure out length of common start of string ("C:\a", "c:\b" -> "c:\"
static inline int commonPartSize(const QString &s1, const QString &s2)
{
const int size = qMin(s1.size(), s2.size());
for (int i = 0; i < size; i++)
if (s1.at(i) != s2.at(i))
return i;
return size;
}
QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings)
{
switch (strings.size()) {
case 0:
return QString();
case 1:
return strings.front();
default:
break;
}
// Figure out common string part: "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo\bar"
int commonLength = INT_MAX;
const int last = strings.size() - 1;
for (int i = 0; i < last; i++)
commonLength = qMin(commonLength, commonPartSize(strings.at(i), strings.at(i + 1)));
if (!commonLength)
return QString();
return strings.at(0).left(commonLength);
}
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files)
{
QString common = commonPrefix(files);
// Find common directory part: "C:\foo\bar" -> "C:\foo"
int lastSeparatorPos = common.lastIndexOf(QLatin1Char('/'));
if (lastSeparatorPos == -1)
lastSeparatorPos = common.lastIndexOf(QLatin1Char('\\'));
if (lastSeparatorPos == -1)
return QString();
if (lastSeparatorPos == -1)
return QString();
#ifdef Q_OS_UNIX
if (lastSeparatorPos == 0) // Unix: "/a", "/b" -> '/'
lastSeparatorPos = 1;
#endif
common.truncate(lastSeparatorPos);
return common;
}
} // namespace Utils
......@@ -32,12 +32,24 @@
#include "utils_global.h"
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
namespace Utils {
// Create a usable settings key from a category,
// for example Editor|C++ -> Editor_C__
QTCREATOR_UTILS_EXPORT QString settingsKey(const QString &category);
// Return the common prefix part of a string list:
// "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo\bar"
QTCREATOR_UTILS_EXPORT QString commonPrefix(const QStringList &strings);
// Return the common path of a list of files:
// "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo"
QTCREATOR_UTILS_EXPORT QString commonPath(const QStringList &files);
} // namespace Utils
#endif // SETTINGSTUTILS_H
......@@ -5,7 +5,7 @@ QT += gui \
DEFINES += QTCREATOR_UTILS_LIB
include(../../qtcreatorlibrary.pri)
SOURCES += reloadpromptutils.cpp \
settingsutils.cpp \
stringutils.cpp \
filesearch.cpp \
pathchooser.cpp \
pathlisteditor.cpp \
......@@ -47,7 +47,7 @@ win32 {
else:SOURCES += consoleprocess_unix.cpp
HEADERS += utils_global.h \
reloadpromptutils.h \
settingsutils.h \
stringutils.h \
filesearch.h \
listutils.h \
pathchooser.h \
......
......@@ -54,6 +54,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/vcsmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <utils/stringutils.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
......@@ -68,8 +69,6 @@
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
#include <limits.h>
namespace CVS {
namespace Internal {
......@@ -963,13 +962,6 @@ static inline QString processStdErr(QProcess &proc)
return QString::fromLocal8Bit(proc.readAllStandardError()).remove(QLatin1Char('\r'));
}
static inline QString processStdOut(QProcess &proc, QTextCodec *outputCodec = 0)
{
const QByteArray stdOutData = proc.readAllStandardOutput();
QString stdOut = outputCodec ? outputCodec->toUnicode(stdOutData) : QString::fromLocal8Bit(stdOutData);
return stdOut.remove(QLatin1Char('\r'));
}
/* Tortoise CVS does not allow for absolute path names
* (which it claims to be CVS standard behaviour).
* So, try to figure out the common root of the file arguments,
......@@ -980,16 +972,6 @@ static inline QString processStdOut(QProcess &proc, QTextCodec *outputCodec = 0)
* Usually, there is only one file argument, which is not
* problematic; it is just split using QFileInfo. */
// Figure out length of common start of string ("C:\a", "c:\b" -> "c:\"
static inline int commonPartSize(const QString &s1, const QString &s2)
{
const int size = qMin(s1.size(), s2.size());
for (int i = 0; i < size; i++)
if (s1.at(i) != s2.at(i))
return i;
return size;
}
static inline QString fixFileArgs(QStringList *files)
{
switch (files->size()) {
......@@ -1003,27 +985,10 @@ static inline QString fixFileArgs(QStringList *files)
default:
break;
}
// Figure out common string part: "C:\foo\bar1" "C:\foo\bar2" -> "C:\foo\bar"
int commonLength = INT_MAX;
const int last = files->size() - 1;
for (int i = 0; i < last; i++)
commonLength = qMin(commonLength, commonPartSize(files->at(i), files->at(i + 1)));
if (!commonLength)
return QString();
// Find directory part: "C:\foo\bar" -> "C:\foo"
QString common = files->at(0).left(commonLength);
int lastSlashPos = common.lastIndexOf(QLatin1Char('/'));
if (lastSlashPos == -1)
lastSlashPos = common.lastIndexOf(QLatin1Char('\\'));
if (lastSlashPos == -1)
return QString();
#ifdef Q_OS_UNIX
if (lastSlashPos == 0) // leave "/a", "/b" untouched
return QString();
#endif
common.truncate(lastSlashPos);
// Find common directory part: "C:\foo\bar" -> "C:\foo"
const QString common = Utils::commonPath(*files);
// remove up until slash from the files
commonLength = lastSlashPos + 1;
const int commonLength = common.size() + 1;
const QStringList::iterator end = files->end();
for (QStringList::iterator it = files->begin(); it != end; ++it) {
it->remove(0, commonLength);
......
......@@ -31,6 +31,8 @@
#include "ui_projectwizardpage.h"
#include "projectnodes.h"
#include <utils/stringutils.h>
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QTextStream>
......@@ -134,13 +136,21 @@ void ProjectWizardPage::setVCSDisplay(const QString &vcsName)
void ProjectWizardPage::setFilesDisplay(const QStringList &files)
{
QString fileMessage;
const QString commonPath = Utils::commonPath(files);
{
QTextStream str(&fileMessage);
str << "<qt>" << tr("Files to be added:");
str << "<pre>";
const QStringList::const_iterator cend = files.constEnd();
for (QStringList::const_iterator it = files.constBegin(); it != cend; ++it)
str << *it << '\n';
str << "<qt>"
<< (commonPath.isEmpty() ? tr("Files to be added:") : tr("Files to be added in"))
<< "<pre>";
if (commonPath.isEmpty()) {
foreach(const QString &f, files)
str << f << '\n';
} else {
str << commonPath << ":\n\n";
const int prefixSize = commonPath.size() + 1;
foreach(const QString &f, files)
str << f.right(f.size() - prefixSize) << '\n';
}
str << "</pre>";
}
m_ui->filesLabel->setText(fileMessage);
......
......@@ -35,7 +35,7 @@
#include "ui_fontsettingspage.h"
#include <coreplugin/icore.h>
#include <utils/settingsutils.h>
#include <utils/stringutils.h>
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
......
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