CleanDialog: Use more FilePath

Change-Id: Id545b8c412d55d8e1976cbe0bbdad36e22eb93a0
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-09-30 17:05:32 +02:00
parent f5c725cf23
commit 604730f14d
3 changed files with 40 additions and 43 deletions

View File

@@ -350,7 +350,7 @@ public:
IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd); IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd);
void cleanCommitMessageFile(); void cleanCommitMessageFile();
void cleanRepository(const FilePath &directory); void cleanRepository(const FilePath &directory);
void applyPatch(const FilePath &workingDirectory, QString file = QString()); void applyPatch(const FilePath &workingDirectory, QString file = {});
void updateVersionWarning(); void updateVersionWarning();
@@ -1055,9 +1055,8 @@ void GitPluginPrivate::blameFile()
} }
} }
} }
VcsBaseEditorWidget *editor = m_gitClient.annotate( VcsBaseEditorWidget *editor = m_gitClient.annotate(state.currentFileTopLevel(),
state.currentFileTopLevel(), state.relativeCurrentFile(), QString(), state.relativeCurrentFile(), {}, lineNumber, extraOptions);
lineNumber, extraOptions);
if (firstLine > 0) if (firstLine > 0)
editor->setFirstLineNumber(firstLine); editor->setFirstLineNumber(firstLine);
} }
@@ -1133,7 +1132,7 @@ void GitPluginPrivate::resetRepository()
LogChangeDialog dialog(true, ICore::dialogParent()); LogChangeDialog dialog(true, ICore::dialogParent());
ResetItemDelegate delegate(dialog.widget()); ResetItemDelegate delegate(dialog.widget());
dialog.setWindowTitle(tr("Undo Changes to %1").arg(topLevel.toUserOutput())); dialog.setWindowTitle(tr("Undo Changes to %1").arg(topLevel.toUserOutput()));
if (dialog.runDialog(topLevel, QString(), LogChangeWidget::IncludeRemotes)) if (dialog.runDialog(topLevel, {}, LogChangeWidget::IncludeRemotes))
m_gitClient.reset(topLevel, dialog.resetFlag(), dialog.commit()); m_gitClient.reset(topLevel, dialog.resetFlag(), dialog.commit());
} }
@@ -1152,7 +1151,7 @@ void GitPluginPrivate::startRebase()
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
const FilePath topLevel = state.topLevel(); const FilePath topLevel = state.topLevel();
startRebaseFromCommit(topLevel, QString()); startRebaseFromCommit(topLevel, {});
} }
void GitPluginPrivate::startRebaseFromCommit(const FilePath &workingDirectory, QString commit) void GitPluginPrivate::startRebaseFromCommit(const FilePath &workingDirectory, QString commit)
@@ -1453,7 +1452,7 @@ bool GitPluginPrivate::submitEditorAboutToClose()
void GitPluginPrivate::fetch() void GitPluginPrivate::fetch()
{ {
m_gitClient.fetch(currentState().topLevel(), QString()); m_gitClient.fetch(currentState().topLevel(), {});
} }
void GitPluginPrivate::pull() void GitPluginPrivate::pull()
@@ -1514,7 +1513,8 @@ void GitPluginPrivate::cleanRepository(const FilePath &directory)
QStringList files; QStringList files;
QStringList ignoredFiles; QStringList ignoredFiles;
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
const bool gotFiles = m_gitClient.synchronousCleanList(directory, QString(), &files, &ignoredFiles, &errorMessage); const bool gotFiles = m_gitClient.synchronousCleanList(directory, {}, &files, &ignoredFiles,
&errorMessage);
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
if (!gotFiles) { if (!gotFiles) {
@@ -1529,7 +1529,7 @@ void GitPluginPrivate::cleanRepository(const FilePath &directory)
// Show in dialog // Show in dialog
CleanDialog dialog(ICore::dialogParent()); CleanDialog dialog(ICore::dialogParent());
dialog.setFileList(directory.toString(), files, ignoredFiles); dialog.setFileList(directory, files, ignoredFiles);
dialog.exec(); dialog.exec();
} }
@@ -1561,7 +1561,7 @@ void GitPluginPrivate::promptApplyPatch()
{ {
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
applyPatch(state.topLevel(), QString()); applyPatch(state.topLevel(), {});
} }
void GitPluginPrivate::applyPatch(const FilePath &workingDirectory, QString file) void GitPluginPrivate::applyPatch(const FilePath &workingDirectory, QString file)
@@ -1572,7 +1572,7 @@ void GitPluginPrivate::applyPatch(const FilePath &workingDirectory, QString file
// Prompt for file // Prompt for file
if (file.isEmpty()) { if (file.isEmpty()) {
const QString filter = tr("Patches (*.patch *.diff)"); const QString filter = tr("Patches (*.patch *.diff)");
file = QFileDialog::getOpenFileName(ICore::dialogParent(), tr("Choose Patch"), QString(), filter); file = QFileDialog::getOpenFileName(ICore::dialogParent(), tr("Choose Patch"), {}, filter);
if (file.isEmpty()) { if (file.isEmpty()) {
m_gitClient.endStashScope(workingDirectory); m_gitClient.endStashScope(workingDirectory);
return; return;
@@ -1601,7 +1601,7 @@ void GitPluginPrivate::stash(bool unstagedOnly)
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
const FilePath topLevel = state.topLevel(); const FilePath topLevel = state.topLevel();
m_gitClient.executeSynchronousStash(topLevel, QString(), unstagedOnly); m_gitClient.executeSynchronousStash(topLevel, {}, unstagedOnly);
if (m_stashDialog) if (m_stashDialog)
m_stashDialog->refresh(topLevel, true); m_stashDialog->refresh(topLevel, true);
} }
@@ -1616,7 +1616,7 @@ void GitPluginPrivate::stashSnapshot()
// Prompt for description, restore immediately and keep on working. // Prompt for description, restore immediately and keep on working.
const VcsBasePluginState state = currentState(); const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return); QTC_ASSERT(state.hasTopLevel(), return);
const QString id = m_gitClient.synchronousStash(state.topLevel(), QString(), const QString id = m_gitClient.synchronousStash(state.topLevel(), {},
GitClient::StashImmediateRestore | GitClient::StashPromptDescription); GitClient::StashImmediateRestore | GitClient::StashPromptDescription);
if (!id.isEmpty() && m_stashDialog) if (!id.isEmpty() && m_stashDialog)
m_stashDialog->refresh(state.topLevel(), true); m_stashDialog->refresh(state.topLevel(), true);
@@ -1906,7 +1906,7 @@ FilePaths GitPluginPrivate::unmanagedFiles(const FilePaths &filePaths) const
void GitPluginPrivate::vcsAnnotate(const FilePath &filePath, int line) void GitPluginPrivate::vcsAnnotate(const FilePath &filePath, int line)
{ {
m_gitClient.annotate(filePath.absolutePath(), filePath.fileName(), QString(), line); m_gitClient.annotate(filePath.absolutePath(), filePath.fileName(), {}, line);
} }
void GitPlugin::emitFilesChanged(const QStringList &l) void GitPlugin::emitFilesChanged(const QStringList &l)

View File

@@ -28,6 +28,8 @@
#include <QTimer> #include <QTimer>
#include <QTreeView> #include <QTreeView>
using namespace Utils;
namespace VcsBase { namespace VcsBase {
namespace Internal { namespace Internal {
@@ -65,7 +67,7 @@ static void removeFileRecursion(QFutureInterface<void> &futureInterface,
// Cleaning files in the background // Cleaning files in the background
static void runCleanFiles(QFutureInterface<void> &futureInterface, static void runCleanFiles(QFutureInterface<void> &futureInterface,
const QString &repository, const QStringList &files, const FilePath &repository, const QStringList &files,
const std::function<void(const QString&)> &errorHandler) const std::function<void(const QString&)> &errorHandler)
{ {
QString errorMessage; QString errorMessage;
@@ -80,7 +82,7 @@ static void runCleanFiles(QFutureInterface<void> &futureInterface,
if (!errorMessage.isEmpty()) { if (!errorMessage.isEmpty()) {
// Format and emit error. // Format and emit error.
const QString msg = CleanDialog::tr("There were errors when cleaning the repository %1:"). const QString msg = CleanDialog::tr("There were errors when cleaning the repository %1:").
arg(QDir::toNativeSeparators(repository)); arg(repository.toUserOutput());
errorMessage.insert(0, QLatin1Char('\n')); errorMessage.insert(0, QLatin1Char('\n'));
errorMessage.insert(0, msg); errorMessage.insert(0, msg);
errorHandler(errorMessage); errorHandler(errorMessage);
@@ -108,7 +110,7 @@ public:
QTreeView *m_filesTreeView; QTreeView *m_filesTreeView;
QStandardItemModel *m_filesModel; QStandardItemModel *m_filesModel;
QString m_workingDirectory; FilePath m_workingDirectory;
}; };
@@ -150,7 +152,7 @@ CleanDialog::CleanDialog(QWidget *parent) :
d->m_filesTreeView->setAllColumnsShowFocus(true); d->m_filesTreeView->setAllColumnsShowFocus(true);
d->m_filesTreeView->setRootIsDecorated(false); d->m_filesTreeView->setRootIsDecorated(false);
using namespace Utils::Layouting; using namespace Layouting;
Column { Column {
d->m_selectAllCheckBox, d->m_selectAllCheckBox,
@@ -178,12 +180,11 @@ CleanDialog::~CleanDialog()
delete d; delete d;
} }
void CleanDialog::setFileList(const QString &workingDirectory, const QStringList &files, void CleanDialog::setFileList(const FilePath &workingDirectory, const QStringList &files,
const QStringList &ignoredFiles) const QStringList &ignoredFiles)
{ {
d->m_workingDirectory = workingDirectory; d->m_workingDirectory = workingDirectory;
d->m_groupBox->setTitle(tr("Repository: %1"). d->m_groupBox->setTitle(tr("Repository: %1").arg(workingDirectory.toUserOutput()));
arg(QDir::toNativeSeparators(workingDirectory)));
if (const int oldRowCount = d->m_filesModel->rowCount()) if (const int oldRowCount = d->m_filesModel->rowCount())
d->m_filesModel->removeRows(0, oldRowCount); d->m_filesModel->removeRows(0, oldRowCount);
@@ -199,32 +200,27 @@ void CleanDialog::setFileList(const QString &workingDirectory, const QStringList
d->m_selectAllCheckBox->setChecked(true); d->m_selectAllCheckBox->setChecked(true);
} }
void CleanDialog::addFile(const QString &workingDirectory, QString fileName, bool checked) void CleanDialog::addFile(const FilePath &workingDirectory, const QString &fileName, bool checked)
{ {
QStyle *style = QApplication::style(); QStyle *style = QApplication::style();
const QIcon folderIcon = style->standardIcon(QStyle::SP_DirIcon); const QIcon folderIcon = style->standardIcon(QStyle::SP_DirIcon);
const QIcon fileIcon = style->standardIcon(QStyle::SP_FileIcon); const QIcon fileIcon = style->standardIcon(QStyle::SP_FileIcon);
const QChar slash = QLatin1Char('/'); const FilePath fullPath = workingDirectory.pathAppended(fileName);
// Clean the trailing slash of directories const bool isDir = fullPath.isDir();
if (fileName.endsWith(slash)) const bool isChecked = checked && !isDir;
fileName.chop(1);
QFileInfo fi(workingDirectory + slash + fileName);
bool isDir = fi.isDir();
if (isDir)
checked = false;
auto nameItem = new QStandardItem(QDir::toNativeSeparators(fileName)); auto nameItem = new QStandardItem(QDir::toNativeSeparators(fileName));
nameItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled); nameItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
nameItem->setIcon(isDir ? folderIcon : fileIcon); nameItem->setIcon(isDir ? folderIcon : fileIcon);
nameItem->setCheckable(true); nameItem->setCheckable(true);
nameItem->setCheckState(checked ? Qt::Checked : Qt::Unchecked); nameItem->setCheckState(isChecked ? Qt::Checked : Qt::Unchecked);
nameItem->setData(QVariant(fi.absoluteFilePath()), Internal::fileNameRole); nameItem->setData(fullPath.absoluteFilePath().toVariant(), Internal::fileNameRole);
nameItem->setData(QVariant(isDir), Internal::isDirectoryRole); nameItem->setData(QVariant(isDir), Internal::isDirectoryRole);
// Tooltip with size information // Tooltip with size information
if (fi.isFile()) { if (fullPath.isFile()) {
const QString lastModified = const QString lastModified = QLocale::system().toString(fullPath.lastModified(),
QLocale::system().toString(fi.lastModified(), QLocale::ShortFormat); QLocale::ShortFormat);
nameItem->setToolTip(tr("%n bytes, last modified %1.", nullptr, nameItem->setToolTip(tr("%n bytes, last modified %1.", nullptr,
fi.size()).arg(lastModified)); fullPath.fileSize()).arg(lastModified));
} }
d->m_filesModel->appendRow(nameItem); d->m_filesModel->appendRow(nameItem);
} }
@@ -261,11 +257,10 @@ bool CleanDialog::promptToDelete()
return false; return false;
// Remove in background // Remove in background
QFuture<void> task = Utils::runAsync(Internal::runCleanFiles, d->m_workingDirectory, QFuture<void> task = runAsync(Internal::runCleanFiles, d->m_workingDirectory,
selectedFiles, Internal::handleError); selectedFiles, Internal::handleError);
const QString taskName = tr("Cleaning \"%1\""). const QString taskName = tr("Cleaning \"%1\"").arg(d->m_workingDirectory.toUserOutput());
arg(QDir::toNativeSeparators(d->m_workingDirectory));
Core::ProgressManager::addTask(task, taskName, "VcsBase.cleanRepository"); Core::ProgressManager::addTask(task, taskName, "VcsBase.cleanRepository");
return true; return true;
} }
@@ -275,7 +270,7 @@ void CleanDialog::slotDoubleClicked(const QModelIndex &index)
// Open file on doubleclick // Open file on doubleclick
if (const QStandardItem *item = d->m_filesModel->itemFromIndex(index)) if (const QStandardItem *item = d->m_filesModel->itemFromIndex(index))
if (!item->data(Internal::isDirectoryRole).toBool()) { if (!item->data(Internal::isDirectoryRole).toBool()) {
const auto fname = Utils::FilePath::fromVariant(item->data(Internal::fileNameRole)); const auto fname = FilePath::fromVariant(item->data(Internal::fileNameRole));
Core::EditorManager::openEditor(fname); Core::EditorManager::openEditor(fname);
} }
} }

View File

@@ -11,6 +11,8 @@ QT_BEGIN_NAMESPACE
class QModelIndex; class QModelIndex;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { class FilePath; }
namespace VcsBase { namespace VcsBase {
namespace Internal { class CleanDialogPrivate; } namespace Internal { class CleanDialogPrivate; }
@@ -23,7 +25,7 @@ public:
explicit CleanDialog(QWidget *parent = nullptr); explicit CleanDialog(QWidget *parent = nullptr);
~CleanDialog() override; ~CleanDialog() override;
void setFileList(const QString &workingDirectory, const QStringList &files, void setFileList(const Utils::FilePath &workingDirectory, const QStringList &files,
const QStringList &ignoredFiles); const QStringList &ignoredFiles);
public slots: public slots:
@@ -36,7 +38,7 @@ private:
QStringList checkedFiles() const; QStringList checkedFiles() const;
bool promptToDelete(); bool promptToDelete();
void addFile(const QString &workingDirectory, QString fileName, bool checked); void addFile(const Utils::FilePath &workingDirectory, const QString &fileName, bool checked);
Internal::CleanDialogPrivate *const d; Internal::CleanDialogPrivate *const d;
}; };