Commit 202ce8ad authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Tobias Hunger
Browse files

Git: Improve Clean dialog



Check file iff it is not ignored

Change-Id: I16a489bdd772ea9b4df462b449a23324b5ef3b77
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 3b5c40ba
......@@ -1331,12 +1331,11 @@ bool GitClient::synchronousShow(const QString &workingDirectory, const QString &
}
// Retrieve list of files to be cleaned
bool GitClient::synchronousCleanList(const QString &workingDirectory,
QStringList *files, QString *errorMessage)
bool GitClient::cleanList(const QString &workingDirectory, const QString &flag, QStringList *files, QString *errorMessage)
{
files->clear();
QStringList args;
args << QLatin1String("clean") << QLatin1String("--dry-run") << QLatin1String("-dxf");
args << QLatin1String("clean") << QLatin1String("--dry-run") << flag;
QByteArray outputText;
QByteArray errorText;
const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText);
......@@ -1352,6 +1351,14 @@ bool GitClient::synchronousCleanList(const QString &workingDirectory,
return true;
}
bool GitClient::synchronousCleanList(const QString &workingDirectory, QStringList *files,
QStringList *ignoredFiles, QString *errorMessage)
{
bool res = cleanList(workingDirectory, QLatin1String("-df"), files, errorMessage);
res &= cleanList(workingDirectory, QLatin1String("-dXf"), ignoredFiles, errorMessage);
return res;
}
bool GitClient::synchronousApplyPatch(const QString &workingDirectory,
const QString &file, QString *errorMessage)
{
......
......@@ -122,7 +122,7 @@ public:
bool synchronousReset(const QString &workingDirectory,
const QStringList &files = QStringList(),
QString *errorMessage = 0);
bool synchronousCleanList(const QString &workingDirectory, QStringList *files, QString *errorMessage);
bool synchronousCleanList(const QString &workingDirectory, QStringList *files, QStringList *ignoredFiles, QString *errorMessage);
bool synchronousApplyPatch(const QString &workingDirectory, const QString &file, QString *errorMessage);
bool synchronousInit(const QString &workingDirectory);
bool synchronousCheckoutFiles(const QString &workingDirectory,
......@@ -289,6 +289,7 @@ private:
const QString &workingDirectory,
const QString &gitBinDirectory,
bool silent);
bool cleanList(const QString &workingDirectory, const QString &flag, QStringList *files, QString *errorMessage);
mutable QString m_gitVersionForBinary;
mutable unsigned m_cachedGitVersion;
......
......@@ -853,31 +853,25 @@ void GitPlugin::cleanRepository(const QString &directory)
// Find files to be deleted
QString errorMessage;
QStringList files;
QStringList ignoredFiles;
QApplication::setOverrideCursor(Qt::WaitCursor);
const bool gotFiles = m_gitClient->synchronousCleanList(directory, &files, &errorMessage);
const bool gotFiles = m_gitClient->synchronousCleanList(directory, &files, &ignoredFiles, &errorMessage);
QApplication::restoreOverrideCursor();
QWidget *parent = Core::ICore::mainWindow();
if (!gotFiles) {
QMessageBox::warning(parent, tr("Unable to retrieve file list"),
errorMessage);
QMessageBox::warning(parent, tr("Unable to retrieve file list"), errorMessage);
return;
}
if (files.isEmpty()) {
if (files.isEmpty() && ignoredFiles.isEmpty()) {
QMessageBox::information(parent, tr("Repository Clean"),
tr("The repository is clean."));
return;
}
// Clean the trailing slash of directories
const QChar slash = QLatin1Char('/');
const QStringList::iterator end = files.end();
for (QStringList::iterator it = files.begin(); it != end; ++it)
if (it->endsWith(slash))
it->truncate(it->size() - 1);
// Show in dialog
VcsBase::CleanDialog dialog(parent);
dialog.setFileList(directory, files);
dialog.setFileList(directory, files, ignoredFiles);
dialog.exec();
}
......
......@@ -180,7 +180,8 @@ CleanDialog::~CleanDialog()
delete d;
}
void CleanDialog::setFileList(const QString &workingDirectory, const QStringList &l)
void CleanDialog::setFileList(const QString &workingDirectory, const QStringList &files,
const QStringList &ignoredFiles)
{
d->m_workingDirectory = workingDirectory;
d->ui.groupBox->setTitle(tr("Repository: %1").
......@@ -188,40 +189,42 @@ void CleanDialog::setFileList(const QString &workingDirectory, const QStringList
if (const int oldRowCount = d->m_filesModel->rowCount())
d->m_filesModel->removeRows(0, oldRowCount);
foreach (const QString &fileName, files)
addFile(workingDirectory, fileName, true);
foreach (const QString &fileName, ignoredFiles)
addFile(workingDirectory, fileName, false);
for (int c = 0; c < d->m_filesModel->columnCount(); c++)
d->ui.filesTreeView->resizeColumnToContents(c);
}
void CleanDialog::addFile(const QString &workingDirectory, QString fileName, bool checked)
{
QStyle *style = QApplication::style();
const QIcon folderIcon = style->standardIcon(QStyle::SP_DirIcon);
const QIcon fileIcon = style->standardIcon(QStyle::SP_FileIcon);
const QString diffSuffix = QLatin1String(".diff");
const QString patchSuffix = QLatin1String(".patch");
const QString proUserSuffix = QLatin1String(".pro.user");
const QString qmlProUserSuffix = QLatin1String(".qmlproject.user");
const QChar slash = QLatin1Char('/');
// Do not initially check patches or 'pro.user' files for deletion.
foreach (const QString &fileName, l) {
const QFileInfo fi(workingDirectory + slash + fileName);
const bool isDir = fi.isDir();
QStandardItem *nameItem = new QStandardItem(QDir::toNativeSeparators(fileName));
nameItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
nameItem->setIcon(isDir ? folderIcon : fileIcon);
const bool saveFile = !isDir && (fileName.endsWith(diffSuffix)
|| fileName.endsWith(patchSuffix)
|| fileName.endsWith(proUserSuffix)
|| fileName.endsWith(qmlProUserSuffix));
nameItem->setCheckable(true);
nameItem->setCheckState(saveFile ? Qt::Unchecked : Qt::Checked);
nameItem->setData(QVariant(fi.absoluteFilePath()), Internal::fileNameRole);
nameItem->setData(QVariant(isDir), Internal::isDirectoryRole);
// Tooltip with size information
if (fi.isFile()) {
const QString lastModified = fi.lastModified().toString(Qt::DefaultLocaleShortDate);
nameItem->setToolTip(tr("%1 bytes, last modified %2")
.arg(fi.size()).arg(lastModified));
}
d->m_filesModel->appendRow(nameItem);
// Clean the trailing slash of directories
if (fileName.endsWith(slash))
fileName.chop(1);
QFileInfo fi(workingDirectory + slash + fileName);
bool isDir = fi.isDir();
if (isDir)
checked = false;
QStandardItem *nameItem = new QStandardItem(QDir::toNativeSeparators(fileName));
nameItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
nameItem->setIcon(isDir ? folderIcon : fileIcon);
nameItem->setCheckable(true);
nameItem->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
nameItem->setData(QVariant(fi.absoluteFilePath()), Internal::fileNameRole);
nameItem->setData(QVariant(isDir), Internal::isDirectoryRole);
// Tooltip with size information
if (fi.isFile()) {
const QString lastModified = fi.lastModified().toString(Qt::DefaultLocaleShortDate);
nameItem->setToolTip(tr("%1 bytes, last modified %2")
.arg(fi.size()).arg(lastModified));
}
for (int c = 0; c < d->m_filesModel->columnCount(); c++)
d->ui.filesTreeView->resizeColumnToContents(c);
d->m_filesModel->appendRow(nameItem);
}
QStringList CleanDialog::checkedFiles() const
......
......@@ -53,7 +53,7 @@ public:
explicit CleanDialog(QWidget *parent = 0);
~CleanDialog();
void setFileList(const QString &workingDirectory, const QStringList &);
void setFileList(const QString &workingDirectory, const QStringList &files, const QStringList &ignoredFiles);
public slots:
void accept();
......@@ -67,6 +67,7 @@ private slots:
private:
QStringList checkedFiles() const;
bool promptToDelete();
void addFile(const QString &workingDirectory, QString fileName, bool checked);
Internal::CleanDialogPrivate *const d;
};
......
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