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);
void cleanCommitMessageFile();
void cleanRepository(const FilePath &directory);
void applyPatch(const FilePath &workingDirectory, QString file = QString());
void applyPatch(const FilePath &workingDirectory, QString file = {});
void updateVersionWarning();
@@ -1055,9 +1055,8 @@ void GitPluginPrivate::blameFile()
}
}
}
VcsBaseEditorWidget *editor = m_gitClient.annotate(
state.currentFileTopLevel(), state.relativeCurrentFile(), QString(),
lineNumber, extraOptions);
VcsBaseEditorWidget *editor = m_gitClient.annotate(state.currentFileTopLevel(),
state.relativeCurrentFile(), {}, lineNumber, extraOptions);
if (firstLine > 0)
editor->setFirstLineNumber(firstLine);
}
@@ -1133,7 +1132,7 @@ void GitPluginPrivate::resetRepository()
LogChangeDialog dialog(true, ICore::dialogParent());
ResetItemDelegate delegate(dialog.widget());
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());
}
@@ -1152,7 +1151,7 @@ void GitPluginPrivate::startRebase()
QTC_ASSERT(state.hasTopLevel(), return);
const FilePath topLevel = state.topLevel();
startRebaseFromCommit(topLevel, QString());
startRebaseFromCommit(topLevel, {});
}
void GitPluginPrivate::startRebaseFromCommit(const FilePath &workingDirectory, QString commit)
@@ -1453,7 +1452,7 @@ bool GitPluginPrivate::submitEditorAboutToClose()
void GitPluginPrivate::fetch()
{
m_gitClient.fetch(currentState().topLevel(), QString());
m_gitClient.fetch(currentState().topLevel(), {});
}
void GitPluginPrivate::pull()
@@ -1514,7 +1513,8 @@ void GitPluginPrivate::cleanRepository(const FilePath &directory)
QStringList files;
QStringList ignoredFiles;
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();
if (!gotFiles) {
@@ -1529,7 +1529,7 @@ void GitPluginPrivate::cleanRepository(const FilePath &directory)
// Show in dialog
CleanDialog dialog(ICore::dialogParent());
dialog.setFileList(directory.toString(), files, ignoredFiles);
dialog.setFileList(directory, files, ignoredFiles);
dialog.exec();
}
@@ -1561,7 +1561,7 @@ void GitPluginPrivate::promptApplyPatch()
{
const VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
applyPatch(state.topLevel(), QString());
applyPatch(state.topLevel(), {});
}
void GitPluginPrivate::applyPatch(const FilePath &workingDirectory, QString file)
@@ -1572,7 +1572,7 @@ void GitPluginPrivate::applyPatch(const FilePath &workingDirectory, QString file
// Prompt for file
if (file.isEmpty()) {
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()) {
m_gitClient.endStashScope(workingDirectory);
return;
@@ -1601,7 +1601,7 @@ void GitPluginPrivate::stash(bool unstagedOnly)
QTC_ASSERT(state.hasTopLevel(), return);
const FilePath topLevel = state.topLevel();
m_gitClient.executeSynchronousStash(topLevel, QString(), unstagedOnly);
m_gitClient.executeSynchronousStash(topLevel, {}, unstagedOnly);
if (m_stashDialog)
m_stashDialog->refresh(topLevel, true);
}
@@ -1616,7 +1616,7 @@ void GitPluginPrivate::stashSnapshot()
// Prompt for description, restore immediately and keep on working.
const VcsBasePluginState state = currentState();
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);
if (!id.isEmpty() && m_stashDialog)
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)
{
m_gitClient.annotate(filePath.absolutePath(), filePath.fileName(), QString(), line);
m_gitClient.annotate(filePath.absolutePath(), filePath.fileName(), {}, line);
}
void GitPlugin::emitFilesChanged(const QStringList &l)

View File

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

View File

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