forked from qt-creator/qt-creator
Core: Code cosmetics in saveitemsdialog.cpp
Including removing one use of QDir::toNativeSeparators() Change-Id: I5c1fe7733942d6161bd9dda94195a44c0cfded72 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -12,19 +12,16 @@
|
|||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QDebug>
|
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDir>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Core::IDocument*)
|
Q_DECLARE_METATYPE(Core::IDocument*)
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Core::Internal {
|
namespace Core::Internal {
|
||||||
|
|
||||||
SaveItemsDialog::SaveItemsDialog(QWidget *parent, const QList<IDocument *> &items)
|
SaveItemsDialog::SaveItemsDialog(QWidget *parent, const QList<IDocument *> &items)
|
||||||
@@ -46,7 +43,7 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent, const QList<IDocument *> &item
|
|||||||
m_treeWidget->setColumnCount(2);
|
m_treeWidget->setColumnCount(2);
|
||||||
|
|
||||||
// QDialogButtonBox's behavior for "destructive" is wrong, the "do not save" should be left-aligned
|
// QDialogButtonBox's behavior for "destructive" is wrong, the "do not save" should be left-aligned
|
||||||
const QDialogButtonBox::ButtonRole discardButtonRole = Utils::HostOsInfo::isMacHost()
|
const QDialogButtonBox::ButtonRole discardButtonRole = HostOsInfo::isMacHost()
|
||||||
? QDialogButtonBox::ResetRole
|
? QDialogButtonBox::ResetRole
|
||||||
: QDialogButtonBox::DestructiveRole;
|
: QDialogButtonBox::DestructiveRole;
|
||||||
if (DiffService::instance()) {
|
if (DiffService::instance()) {
|
||||||
@@ -71,26 +68,24 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent, const QList<IDocument *> &item
|
|||||||
|
|
||||||
for (IDocument *document : items) {
|
for (IDocument *document : items) {
|
||||||
QString visibleName;
|
QString visibleName;
|
||||||
QString directory;
|
FilePath directory;
|
||||||
Utils::FilePath filePath = document->filePath();
|
FilePath filePath = document->filePath();
|
||||||
if (filePath.isEmpty()) {
|
if (filePath.isEmpty()) {
|
||||||
visibleName = document->fallbackSaveAsFileName();
|
visibleName = document->fallbackSaveAsFileName();
|
||||||
} else {
|
} else {
|
||||||
directory = filePath.absolutePath().toUserOutput();
|
directory = filePath.absolutePath();
|
||||||
visibleName = filePath.fileName();
|
visibleName = filePath.fileName();
|
||||||
}
|
}
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(m_treeWidget,
|
QTreeWidgetItem *item = new QTreeWidgetItem(m_treeWidget,
|
||||||
QStringList()
|
QStringList{visibleName, directory.toUserOutput()});
|
||||||
<< visibleName
|
|
||||||
<< QDir::toNativeSeparators(directory));
|
|
||||||
if (!filePath.isEmpty())
|
if (!filePath.isEmpty())
|
||||||
item->setIcon(0, Utils::FileIconProvider::icon(filePath));
|
item->setIcon(0, FileIconProvider::icon(filePath));
|
||||||
item->setData(0, Qt::UserRole, QVariant::fromValue(document));
|
item->setData(0, Qt::UserRole, QVariant::fromValue(document));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_treeWidget->resizeColumnToContents(0);
|
m_treeWidget->resizeColumnToContents(0);
|
||||||
m_treeWidget->selectAll();
|
m_treeWidget->selectAll();
|
||||||
if (Utils::HostOsInfo::isMacHost())
|
if (HostOsInfo::isMacHost())
|
||||||
m_treeWidget->setAlternatingRowColors(true);
|
m_treeWidget->setAlternatingRowColors(true);
|
||||||
adjustButtonWidths();
|
adjustButtonWidths();
|
||||||
updateButtons();
|
updateButtons();
|
||||||
@@ -151,7 +146,7 @@ void SaveItemsDialog::adjustButtonWidths()
|
|||||||
if (hint > maxTextWidth)
|
if (hint > maxTextWidth)
|
||||||
maxTextWidth = hint;
|
maxTextWidth = hint;
|
||||||
}
|
}
|
||||||
if (Utils::HostOsInfo::isMacHost()) {
|
if (HostOsInfo::isMacHost()) {
|
||||||
QPushButton *cancelButton = m_buttonBox->button(QDialogButtonBox::Cancel);
|
QPushButton *cancelButton = m_buttonBox->button(QDialogButtonBox::Cancel);
|
||||||
int cancelButtonWidth = cancelButton->sizeHint().width();
|
int cancelButtonWidth = cancelButton->sizeHint().width();
|
||||||
if (cancelButtonWidth > maxTextWidth)
|
if (cancelButtonWidth > maxTextWidth)
|
||||||
|
Reference in New Issue
Block a user