forked from qt-creator/qt-creator
Core: Reorganize ReadOnlyFilesDialog
Move exported class out of namespace Internal, but expose only a minimal interface. Use Qt 5 connections, adjust callers and surrounding code. Change-Id: I52b4156d78cd1ec42ec6c94994775ce74f24ebdc Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -52,10 +52,30 @@ namespace Internal {
|
|||||||
|
|
||||||
class ReadOnlyFilesDialogPrivate
|
class ReadOnlyFilesDialogPrivate
|
||||||
{
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(Core::ReadOnlyFilesDialog)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReadOnlyFilesDialogPrivate(IDocument *document = 0, bool useSaveAs = false);
|
ReadOnlyFilesDialogPrivate(ReadOnlyFilesDialog *parent, IDocument *document = 0, bool useSaveAs = false);
|
||||||
~ReadOnlyFilesDialogPrivate();
|
~ReadOnlyFilesDialogPrivate();
|
||||||
|
|
||||||
|
enum ReadOnlyFilesTreeColumn {
|
||||||
|
MakeWritable = ReadOnlyFilesDialog::MakeWritable,
|
||||||
|
OpenWithVCS = ReadOnlyFilesDialog::OpenWithVCS,
|
||||||
|
SaveAs = ReadOnlyFilesDialog::SaveAs,
|
||||||
|
FileName = ReadOnlyFilesDialog::FileName,
|
||||||
|
Folder = ReadOnlyFilesDialog::Folder,
|
||||||
|
NumberOfColumns
|
||||||
|
};
|
||||||
|
|
||||||
|
void initDialog(const QStringList &fileNames);
|
||||||
|
void promptFailWarning(const QStringList &files, ReadOnlyFilesDialog::ReadOnlyResult type) const;
|
||||||
|
QRadioButton *createRadioButtonForItem(QTreeWidgetItem *item, QButtonGroup *group, ReadOnlyFilesTreeColumn type);
|
||||||
|
|
||||||
|
void setAll(int index);
|
||||||
|
void updateSelectAll();
|
||||||
|
|
||||||
|
ReadOnlyFilesDialog *q;
|
||||||
|
|
||||||
// Buttongroups containing the operation for one file.
|
// Buttongroups containing the operation for one file.
|
||||||
struct ButtonGroupForFile
|
struct ButtonGroupForFile
|
||||||
{
|
{
|
||||||
@@ -85,17 +105,20 @@ public:
|
|||||||
QString makeWritableText;
|
QString makeWritableText;
|
||||||
QString versionControlOpenText;
|
QString versionControlOpenText;
|
||||||
const QString saveAsText;
|
const QString saveAsText;
|
||||||
|
|
||||||
|
Ui::ReadOnlyFilesDialog ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
ReadOnlyFilesDialogPrivate::ReadOnlyFilesDialogPrivate(IDocument *document, bool displaySaveAs)
|
ReadOnlyFilesDialogPrivate::ReadOnlyFilesDialogPrivate(ReadOnlyFilesDialog *parent, IDocument *document, bool displaySaveAs)
|
||||||
: useSaveAs(displaySaveAs)
|
: q(parent)
|
||||||
|
, useSaveAs(displaySaveAs)
|
||||||
, useVCS(false)
|
, useVCS(false)
|
||||||
, showWarnings(false)
|
, showWarnings(false)
|
||||||
, document(document)
|
, document(document)
|
||||||
, mixedText(ReadOnlyFilesDialog::tr("Mixed"))
|
, mixedText(tr("Mixed"))
|
||||||
, makeWritableText(ReadOnlyFilesDialog::tr("Make Writable"))
|
, makeWritableText(tr("Make Writable"))
|
||||||
, versionControlOpenText(ReadOnlyFilesDialog::tr("Open with VCS"))
|
, versionControlOpenText(tr("Open with VCS"))
|
||||||
, saveAsText(ReadOnlyFilesDialog::tr("Save As"))
|
, saveAsText(tr("Save As"))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate()
|
ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate()
|
||||||
@@ -104,6 +127,10 @@ ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate()
|
|||||||
delete groupForFile.group;
|
delete groupForFile.group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
|
||||||
|
using namespace Internal;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class ReadOnlyFilesDialog
|
* \class ReadOnlyFilesDialog
|
||||||
* \brief The ReadOnlyFilesDialog class implements a dialog to show a set of
|
* \brief The ReadOnlyFilesDialog class implements a dialog to show a set of
|
||||||
@@ -117,43 +144,38 @@ ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate()
|
|||||||
|
|
||||||
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QList<QString> &fileNames, QWidget *parent)
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QList<QString> &fileNames, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, d(new ReadOnlyFilesDialogPrivate)
|
, d(new ReadOnlyFilesDialogPrivate(this))
|
||||||
, ui(new Ui::ReadOnlyFilesDialog)
|
|
||||||
{
|
{
|
||||||
initDialog(fileNames);
|
d->initDialog(fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QString &fileName, QWidget *parent)
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QString &fileName, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, d(new ReadOnlyFilesDialogPrivate)
|
, d(new ReadOnlyFilesDialogPrivate(this))
|
||||||
, ui(new Ui::ReadOnlyFilesDialog)
|
|
||||||
{
|
{
|
||||||
initDialog(QStringList() << fileName);
|
d->initDialog(QStringList(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlyFilesDialog::ReadOnlyFilesDialog(IDocument *document, QWidget *parent,
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(IDocument *document, QWidget *parent,
|
||||||
bool displaySaveAs)
|
bool displaySaveAs)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, d(new ReadOnlyFilesDialogPrivate(document, displaySaveAs))
|
, d(new ReadOnlyFilesDialogPrivate(this, document, displaySaveAs))
|
||||||
, ui(new Ui::ReadOnlyFilesDialog)
|
|
||||||
{
|
{
|
||||||
initDialog(QStringList() << document->filePath());
|
d->initDialog(QStringList(document->filePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QList<IDocument *> &documents, QWidget *parent)
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QList<IDocument *> &documents, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, d(new ReadOnlyFilesDialogPrivate)
|
, d(new ReadOnlyFilesDialogPrivate(this))
|
||||||
, ui(new Ui::ReadOnlyFilesDialog)
|
|
||||||
{
|
{
|
||||||
QStringList files;
|
QStringList files;
|
||||||
foreach (IDocument *document, documents)
|
foreach (IDocument *document, documents)
|
||||||
files << document->filePath();
|
files << document->filePath();
|
||||||
initDialog(files);
|
d->initDialog(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlyFilesDialog::~ReadOnlyFilesDialog()
|
ReadOnlyFilesDialog::~ReadOnlyFilesDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +185,7 @@ ReadOnlyFilesDialog::~ReadOnlyFilesDialog()
|
|||||||
*/
|
*/
|
||||||
void ReadOnlyFilesDialog::setMessage(const QString &message)
|
void ReadOnlyFilesDialog::setMessage(const QString &message)
|
||||||
{
|
{
|
||||||
ui->msgLabel->setText(message);
|
d->ui.msgLabel->setText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -181,7 +203,7 @@ void ReadOnlyFilesDialog::setShowFailWarning(bool show, const QString &warning)
|
|||||||
* Opens a message box with an error description according to the type.
|
* Opens a message box with an error description according to the type.
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
void ReadOnlyFilesDialog::promptFailWarning(const QStringList &files, ReadOnlyResult type) const
|
void ReadOnlyFilesDialogPrivate::promptFailWarning(const QStringList &files, ReadOnlyFilesDialog::ReadOnlyResult type) const
|
||||||
{
|
{
|
||||||
if (files.isEmpty())
|
if (files.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -191,49 +213,48 @@ void ReadOnlyFilesDialog::promptFailWarning(const QStringList &files, ReadOnlyRe
|
|||||||
if (files.count() == 1) {
|
if (files.count() == 1) {
|
||||||
const QString file = files.first();
|
const QString file = files.first();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RO_OpenVCS: {
|
case ReadOnlyFilesDialog::RO_OpenVCS: {
|
||||||
if (IVersionControl *vc = d->versionControls[file]) {
|
if (IVersionControl *vc = versionControls[file]) {
|
||||||
const QString openText = vc->vcsOpenText().remove(QLatin1Char('&'));
|
const QString openText = vc->vcsOpenText().remove(QLatin1Char('&'));
|
||||||
title = tr("Failed to %1 File").arg(openText);
|
title = tr("Failed to %1 File").arg(openText);
|
||||||
message = tr("%1 file %2 from version control system %3 failed.")
|
message = tr("%1 file %2 from version control system %3 failed.")
|
||||||
.arg(openText)
|
.arg(openText)
|
||||||
.arg(QDir::toNativeSeparators(file))
|
.arg(QDir::toNativeSeparators(file))
|
||||||
.arg(vc->displayName());
|
.arg(vc->displayName())
|
||||||
message += QLatin1Char('\n');
|
+ QLatin1Char('\n')
|
||||||
message += d->failWarning;
|
+ failWarning;
|
||||||
} else {
|
} else {
|
||||||
title = tr("No Version Control System Found");
|
title = tr("No Version Control System Found");
|
||||||
message = tr("Cannot open file %1 from version control system.\n"
|
message = tr("Cannot open file %1 from version control system.\n"
|
||||||
"No version control system found.")
|
"No version control system found.")
|
||||||
.arg(QDir::toNativeSeparators(file));
|
.arg(QDir::toNativeSeparators(file))
|
||||||
message += QLatin1Char('\n');
|
+ QLatin1Char('\n')
|
||||||
message += d->failWarning;
|
+ failWarning;;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RO_MakeWritable:
|
case ReadOnlyFilesDialog::RO_MakeWritable:
|
||||||
title = tr("Cannot Set Permissions");
|
title = tr("Cannot Set Permissions");
|
||||||
message = tr("Cannot set permissions for %1 to writable.")
|
message = tr("Cannot set permissions for %1 to writable.")
|
||||||
.arg(QDir::toNativeSeparators(file));
|
.arg(QDir::toNativeSeparators(file))
|
||||||
message += QLatin1Char('\n');
|
+ QLatin1Char('\n')
|
||||||
message += d->failWarning;
|
+ failWarning;
|
||||||
break;
|
break;
|
||||||
case RO_SaveAs:
|
case ReadOnlyFilesDialog::RO_SaveAs:
|
||||||
title = tr("Cannot Save File");
|
title = tr("Cannot Save File");
|
||||||
message = tr("Cannot save file %1").arg(QDir::toNativeSeparators(file));
|
message = tr("Cannot save file %1").arg(QDir::toNativeSeparators(file))
|
||||||
message += QLatin1Char('\n');
|
+ QLatin1Char('\n')
|
||||||
message += d->failWarning;
|
+ failWarning;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
title = tr("Canceled Changing Permissions");
|
title = tr("Canceled Changing Permissions");
|
||||||
message = d->failWarning;
|
message = failWarning;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
title = tr("Could Not Change Permissions on Some Files");
|
title = tr("Could Not Change Permissions on Some Files");
|
||||||
message = d->failWarning;
|
message = failWarning + QLatin1Char('\n')
|
||||||
message += QLatin1Char('\n');
|
+ tr("See details for a complete list of files.");
|
||||||
message += tr("See details for a complete list of files.");
|
|
||||||
details = files.join(QLatin1Char('\n'));
|
details = files.join(QLatin1Char('\n'));
|
||||||
}
|
}
|
||||||
QMessageBox msgBox(QMessageBox::Warning, title, message,
|
QMessageBox msgBox(QMessageBox::Warning, title, message,
|
||||||
@@ -289,7 +310,7 @@ int ReadOnlyFilesDialog::exec()
|
|||||||
}
|
}
|
||||||
if (!failedToMakeWritable.isEmpty()) {
|
if (!failedToMakeWritable.isEmpty()) {
|
||||||
if (d->showWarnings)
|
if (d->showWarnings)
|
||||||
promptFailWarning(failedToMakeWritable, result);
|
d->promptFailWarning(failedToMakeWritable, result);
|
||||||
}
|
}
|
||||||
return failedToMakeWritable.isEmpty() ? result : RO_Cancel;
|
return failedToMakeWritable.isEmpty() ? result : RO_Cancel;
|
||||||
}
|
}
|
||||||
@@ -300,14 +321,14 @@ int ReadOnlyFilesDialog::exec()
|
|||||||
* Returns the created button.
|
* Returns the created button.
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
QRadioButton* ReadOnlyFilesDialog::createRadioButtonForItem(QTreeWidgetItem *item, QButtonGroup *group,
|
QRadioButton *ReadOnlyFilesDialogPrivate::createRadioButtonForItem(QTreeWidgetItem *item, QButtonGroup *group,
|
||||||
ReadOnlyFilesDialog::ReadOnlyFilesTreeColumn type)
|
ReadOnlyFilesTreeColumn type)
|
||||||
|
|
||||||
{
|
{
|
||||||
QRadioButton *radioButton = new QRadioButton(this);
|
QRadioButton *radioButton = new QRadioButton(q);
|
||||||
group->addButton(radioButton, type);
|
group->addButton(radioButton, type);
|
||||||
item->setTextAlignment(type, Qt::AlignHCenter);
|
item->setTextAlignment(type, Qt::AlignHCenter);
|
||||||
ui->treeWidget->setItemWidget(item, type, radioButton);
|
ui.treeWidget->setItemWidget(item, type, radioButton);
|
||||||
return radioButton;
|
return radioButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,23 +337,23 @@ QRadioButton* ReadOnlyFilesDialog::createRadioButtonForItem(QTreeWidgetItem *ite
|
|||||||
* per file accordingly.
|
* per file accordingly.
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
void ReadOnlyFilesDialog::setAll(int index)
|
void ReadOnlyFilesDialogPrivate::setAll(int index)
|
||||||
{
|
{
|
||||||
// If mixed is the current index, no need to change the user selection.
|
// If mixed is the current index, no need to change the user selection.
|
||||||
if (index == d->setAllIndexForOperation[-1/*mixed*/])
|
if (index == setAllIndexForOperation[-1/*mixed*/])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get the selected type from the select all combo box.
|
// Get the selected type from the select all combo box.
|
||||||
ReadOnlyFilesTreeColumn type = NumberOfColumns;
|
ReadOnlyFilesTreeColumn type = NumberOfColumns;
|
||||||
if (index == d->setAllIndexForOperation[MakeWritable])
|
if (index == setAllIndexForOperation[MakeWritable])
|
||||||
type = MakeWritable;
|
type = MakeWritable;
|
||||||
else if (index == d->setAllIndexForOperation[OpenWithVCS])
|
else if (index == setAllIndexForOperation[OpenWithVCS])
|
||||||
type = OpenWithVCS;
|
type = OpenWithVCS;
|
||||||
else if (index == d->setAllIndexForOperation[SaveAs])
|
else if (index == setAllIndexForOperation[SaveAs])
|
||||||
type = SaveAs;
|
type = SaveAs;
|
||||||
|
|
||||||
// Check for every file if the selected operation is available and change it to the operation.
|
// Check for every file if the selected operation is available and change it to the operation.
|
||||||
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, d->buttonGroups) {
|
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, buttonGroups) {
|
||||||
QRadioButton *radioButton = qobject_cast<QRadioButton*> (groupForFile.group->button(type));
|
QRadioButton *radioButton = qobject_cast<QRadioButton*> (groupForFile.group->button(type));
|
||||||
if (radioButton)
|
if (radioButton)
|
||||||
radioButton->setChecked(true);
|
radioButton->setChecked(true);
|
||||||
@@ -344,18 +365,18 @@ void ReadOnlyFilesDialog::setAll(int index)
|
|||||||
* the tree widget.
|
* the tree widget.
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
void ReadOnlyFilesDialog::updateSelectAll()
|
void ReadOnlyFilesDialogPrivate::updateSelectAll()
|
||||||
{
|
{
|
||||||
int selectedOperation = -1;
|
int selectedOperation = -1;
|
||||||
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, d->buttonGroups) {
|
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, buttonGroups) {
|
||||||
if (selectedOperation == -1) {
|
if (selectedOperation == -1) {
|
||||||
selectedOperation = groupForFile.group->checkedId();
|
selectedOperation = groupForFile.group->checkedId();
|
||||||
} else if (selectedOperation != groupForFile.group->checkedId()) {
|
} else if (selectedOperation != groupForFile.group->checkedId()) {
|
||||||
ui->setAll->setCurrentIndex(0);
|
ui.setAll->setCurrentIndex(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui->setAll->setCurrentIndex(d->setAllIndexForOperation[selectedOperation]);
|
ui.setAll->setCurrentIndex(setAllIndexForOperation[selectedOperation]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -365,11 +386,11 @@ void ReadOnlyFilesDialog::updateSelectAll()
|
|||||||
* dialog.
|
* dialog.
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
void ReadOnlyFilesDialog::initDialog(const QStringList &fileNames)
|
void ReadOnlyFilesDialogPrivate::initDialog(const QStringList &fileNames)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui.setupUi(q);
|
||||||
ui->buttonBox->addButton(tr("Change &Permission"), QDialogButtonBox::AcceptRole);
|
ui.buttonBox->addButton(tr("Change &Permission"), QDialogButtonBox::AcceptRole);
|
||||||
ui->buttonBox->addButton(QDialogButtonBox::Cancel);
|
ui.buttonBox->addButton(QDialogButtonBox::Cancel);
|
||||||
|
|
||||||
QString vcsOpenTextForAll;
|
QString vcsOpenTextForAll;
|
||||||
QString vcsMakeWritableTextForAll;
|
QString vcsMakeWritableTextForAll;
|
||||||
@@ -380,7 +401,7 @@ void ReadOnlyFilesDialog::initDialog(const QStringList &fileNames)
|
|||||||
const QString directory = info.absolutePath();
|
const QString directory = info.absolutePath();
|
||||||
|
|
||||||
// Setup a default entry with filename folder and make writable radio button.
|
// Setup a default entry with filename folder and make writable radio button.
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui.treeWidget);
|
||||||
item->setText(FileName, visibleName);
|
item->setText(FileName, visibleName);
|
||||||
item->setIcon(FileName, FileIconProvider::icon(fileName));
|
item->setIcon(FileName, FileIconProvider::icon(fileName));
|
||||||
item->setText(Folder, Utils::FileUtils::shortNativePath(Utils::FileName(QFileInfo(directory))));
|
item->setText(Folder, Utils::FileUtils::shortNativePath(Utils::FileName(QFileInfo(directory))));
|
||||||
@@ -397,10 +418,10 @@ void ReadOnlyFilesDialog::initDialog(const QStringList &fileNames)
|
|||||||
versionControlForFile->vcsOpenText().remove(QLatin1Char('&'));
|
versionControlForFile->vcsOpenText().remove(QLatin1Char('&'));
|
||||||
const QString vcsMakeWritableTextforFile =
|
const QString vcsMakeWritableTextforFile =
|
||||||
versionControlForFile->vcsMakeWritableText().remove(QLatin1Char('&'));
|
versionControlForFile->vcsMakeWritableText().remove(QLatin1Char('&'));
|
||||||
if (!d->useVCS) {
|
if (!useVCS) {
|
||||||
vcsOpenTextForAll = vcsOpenTextForFile;
|
vcsOpenTextForAll = vcsOpenTextForFile;
|
||||||
vcsMakeWritableTextForAll = vcsMakeWritableTextforFile;
|
vcsMakeWritableTextForAll = vcsMakeWritableTextforFile;
|
||||||
d->useVCS = true;
|
useVCS = true;
|
||||||
} else {
|
} else {
|
||||||
// If there are different open or make writable texts choose the default one.
|
// If there are different open or make writable texts choose the default one.
|
||||||
if (vcsOpenTextForFile != vcsOpenTextForAll)
|
if (vcsOpenTextForFile != vcsOpenTextForAll)
|
||||||
@@ -419,86 +440,87 @@ void ReadOnlyFilesDialog::initDialog(const QStringList &fileNames)
|
|||||||
createRadioButtonForItem(item, radioButtonGroup, MakeWritable)->setChecked(true);
|
createRadioButtonForItem(item, radioButtonGroup, MakeWritable)->setChecked(true);
|
||||||
}
|
}
|
||||||
// Add a Save As radio button if requested.
|
// Add a Save As radio button if requested.
|
||||||
if (d->useSaveAs)
|
if (useSaveAs)
|
||||||
createRadioButtonForItem(item, radioButtonGroup, SaveAs);
|
createRadioButtonForItem(item, radioButtonGroup, SaveAs);
|
||||||
// If the file is managed by a version control system save the vcs for this file.
|
// If the file is managed by a version control system save the vcs for this file.
|
||||||
d->versionControls[fileName] = fileManagedByVCS ? versionControlForFile : 0;
|
versionControls[fileName] = fileManagedByVCS ? versionControlForFile : 0;
|
||||||
|
|
||||||
// Also save the buttongroup for every file to get the result for each entry.
|
// Also save the buttongroup for every file to get the result for each entry.
|
||||||
ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile;
|
ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile;
|
||||||
groupForFile.fileName = fileName;
|
groupForFile.fileName = fileName;
|
||||||
groupForFile.group = radioButtonGroup;
|
groupForFile.group = radioButtonGroup;
|
||||||
d->buttonGroups.append(groupForFile);
|
buttonGroups.append(groupForFile);
|
||||||
connect(radioButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateSelectAll()));
|
QObject::connect(radioButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
|
||||||
|
[this](int) { updateSelectAll(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the Mac file dialog style.
|
// Apply the Mac file dialog style.
|
||||||
if (Utils::HostOsInfo::isMacHost())
|
if (Utils::HostOsInfo::isMacHost())
|
||||||
ui->treeWidget->setAlternatingRowColors(true);
|
ui.treeWidget->setAlternatingRowColors(true);
|
||||||
|
|
||||||
// Do not show any options to the user if he has no choice.
|
// Do not show any options to the user if he has no choice.
|
||||||
if (!d->useSaveAs && (!d->useVCS || !useMakeWritable)) {
|
if (!useSaveAs && (useVCS || !useMakeWritable)) {
|
||||||
ui->treeWidget->setColumnHidden(MakeWritable, true);
|
ui.treeWidget->setColumnHidden(MakeWritable, true);
|
||||||
ui->treeWidget->setColumnHidden(OpenWithVCS, true);
|
ui.treeWidget->setColumnHidden(OpenWithVCS, true);
|
||||||
ui->treeWidget->setColumnHidden(SaveAs, true);
|
ui.treeWidget->setColumnHidden(SaveAs, true);
|
||||||
ui->treeWidget->resizeColumnToContents(FileName);
|
ui.treeWidget->resizeColumnToContents(FileName);
|
||||||
ui->treeWidget->resizeColumnToContents(Folder);
|
ui.treeWidget->resizeColumnToContents(Folder);
|
||||||
ui->setAll->setVisible(false);
|
ui.setAll->setVisible(false);
|
||||||
ui->setAllLabel->setVisible(false);
|
ui.setAllLabel->setVisible(false);
|
||||||
ui->verticalLayout->removeItem(ui->setAllLayout);
|
ui.verticalLayout->removeItem(ui.setAllLayout);
|
||||||
if (d->useVCS)
|
if (useVCS)
|
||||||
ui->msgLabel->setText(tr("The following files are not checked out yet.\n"
|
ui.msgLabel->setText(tr("The following files are not checked out yet.\n"
|
||||||
"Do you want to check them out now?"));
|
"Do you want to check them out now?"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is just one file entry, there is no need to show the select all combo box
|
// If there is just one file entry, there is no need to show the select all combo box
|
||||||
if (fileNames.count() < 2) {
|
if (fileNames.count() < 2) {
|
||||||
ui->setAll->setVisible(false);
|
ui.setAll->setVisible(false);
|
||||||
ui->setAllLabel->setVisible(false);
|
ui.setAllLabel->setVisible(false);
|
||||||
ui->verticalLayout->removeItem(ui->setAllLayout);
|
ui.verticalLayout->removeItem(ui.setAllLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add items to the Set all combo box.
|
// Add items to the Set all combo box.
|
||||||
ui->setAll->addItem(d->mixedText);
|
ui.setAll->addItem(mixedText);
|
||||||
d->setAllIndexForOperation[-1/*mixed*/] = ui->setAll->count() - 1;
|
setAllIndexForOperation[-1/*mixed*/] = ui.setAll->count() - 1;
|
||||||
if (d->useVCS) {
|
if (useVCS) {
|
||||||
// If the files are managed by just one version control system, the Open and Make Writable
|
// If the files are managed by just one version control system, the Open and Make Writable
|
||||||
// text for the specific system is used.
|
// text for the specific system is used.
|
||||||
if (!vcsOpenTextForAll.isEmpty() && vcsOpenTextForAll != d->versionControlOpenText) {
|
if (!vcsOpenTextForAll.isEmpty() && vcsOpenTextForAll != versionControlOpenText) {
|
||||||
d->versionControlOpenText = vcsOpenTextForAll;
|
versionControlOpenText = vcsOpenTextForAll;
|
||||||
ui->treeWidget->headerItem()->setText(OpenWithVCS, d->versionControlOpenText);
|
ui.treeWidget->headerItem()->setText(OpenWithVCS, versionControlOpenText);
|
||||||
}
|
}
|
||||||
if (!vcsMakeWritableTextForAll.isEmpty() && vcsMakeWritableTextForAll != d->makeWritableText) {
|
if (!vcsMakeWritableTextForAll.isEmpty() && vcsMakeWritableTextForAll != makeWritableText) {
|
||||||
d->makeWritableText = vcsMakeWritableTextForAll;
|
makeWritableText = vcsMakeWritableTextForAll;
|
||||||
ui->treeWidget->headerItem()->setText(MakeWritable, d->makeWritableText);
|
ui.treeWidget->headerItem()->setText(MakeWritable, makeWritableText);
|
||||||
}
|
}
|
||||||
ui->setAll->addItem(d->versionControlOpenText);
|
ui.setAll->addItem(versionControlOpenText);
|
||||||
ui->setAll->setCurrentIndex(ui->setAll->count() - 1);
|
ui.setAll->setCurrentIndex(ui.setAll->count() - 1);
|
||||||
d->setAllIndexForOperation[OpenWithVCS] = ui->setAll->count() - 1;
|
setAllIndexForOperation[OpenWithVCS] = ui.setAll->count() - 1;
|
||||||
}
|
}
|
||||||
if (useMakeWritable) {
|
if (useMakeWritable) {
|
||||||
ui->setAll->addItem(d->makeWritableText);
|
ui.setAll->addItem(makeWritableText);
|
||||||
d->setAllIndexForOperation[MakeWritable] = ui->setAll->count() - 1;
|
setAllIndexForOperation[MakeWritable] = ui.setAll->count() - 1;
|
||||||
if (ui->setAll->currentIndex() == -1)
|
if (ui.setAll->currentIndex() == -1)
|
||||||
ui->setAll->setCurrentIndex(ui->setAll->count() - 1);
|
ui.setAll->setCurrentIndex(ui.setAll->count() - 1);
|
||||||
}
|
}
|
||||||
if (d->useSaveAs) {
|
if (useSaveAs) {
|
||||||
ui->setAll->addItem(d->saveAsText);
|
ui.setAll->addItem(saveAsText);
|
||||||
d->setAllIndexForOperation[SaveAs] = ui->setAll->count() - 1;
|
setAllIndexForOperation[SaveAs] = ui.setAll->count() - 1;
|
||||||
}
|
}
|
||||||
connect(ui->setAll, SIGNAL(activated(int)), this, SLOT(setAll(int)));
|
QObject::connect(ui.setAll, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
|
||||||
|
[this](int index) { setAll(index); });
|
||||||
|
|
||||||
// Filter which columns should be visible and resize them to content.
|
// Filter which columns should be visible and resize them to content.
|
||||||
for (int i = 0; i < NumberOfColumns; ++i) {
|
for (int i = 0; i < NumberOfColumns; ++i) {
|
||||||
if ((i == SaveAs && !d->useSaveAs) || (i == OpenWithVCS && !d->useVCS)
|
if ((i == SaveAs && !useSaveAs) || (i == OpenWithVCS && !useVCS)
|
||||||
|| (i == MakeWritable && !useMakeWritable)) {
|
|| (i == MakeWritable && !useMakeWritable)) {
|
||||||
ui->treeWidget->setColumnHidden(i, true);
|
ui.treeWidget->setColumnHidden(i, true);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ui->treeWidget->resizeColumnToContents(i);
|
ui.treeWidget->resizeColumnToContents(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace Internal
|
|
||||||
}// namespace Core
|
}// namespace Core
|
||||||
|
@@ -33,21 +33,12 @@
|
|||||||
#include <coreplugin/core_global.h>
|
#include <coreplugin/core_global.h>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QHash>
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QButtonGroup;
|
|
||||||
class QTreeWidgetItem;
|
|
||||||
class QRadioButton;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
class IVersionControl;
|
|
||||||
class IDocument;
|
class IDocument;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal { class ReadOnlyFilesDialogPrivate; }
|
||||||
|
|
||||||
namespace Ui { class ReadOnlyFilesDialog; }
|
|
||||||
|
|
||||||
class CORE_EXPORT ReadOnlyFilesDialog : public QDialog
|
class CORE_EXPORT ReadOnlyFilesDialog : public QDialog
|
||||||
{
|
{
|
||||||
@@ -89,21 +80,10 @@ public:
|
|||||||
int exec();
|
int exec();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initDialog(const QStringList &fileNames);
|
friend class Internal::ReadOnlyFilesDialogPrivate;
|
||||||
void promptFailWarning(const QStringList &files, ReadOnlyResult type) const;
|
Internal::ReadOnlyFilesDialogPrivate *d;
|
||||||
QRadioButton *createRadioButtonForItem(QTreeWidgetItem *item, QButtonGroup *group,
|
|
||||||
ReadOnlyFilesDialog::ReadOnlyFilesTreeColumn type);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void setAll(int index);
|
|
||||||
void updateSelectAll();
|
|
||||||
|
|
||||||
private:
|
|
||||||
class ReadOnlyFilesDialogPrivate *d;
|
|
||||||
Ui::ReadOnlyFilesDialog *ui;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
||||||
#endif // READONLYFILESDIALOG_H
|
#endif // READONLYFILESDIALOG_H
|
||||||
|
@@ -609,7 +609,7 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
|
|||||||
roDialog.setShowFailWarning(true, DocumentManager::tr(
|
roDialog.setShowFailWarning(true, DocumentManager::tr(
|
||||||
"Could not save the files.",
|
"Could not save the files.",
|
||||||
"error message"));
|
"error message"));
|
||||||
if (roDialog.exec() == Core::Internal::ReadOnlyFilesDialog::RO_Cancel) {
|
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel) {
|
||||||
if (cancelled)
|
if (cancelled)
|
||||||
(*cancelled) = true;
|
(*cancelled) = true;
|
||||||
if (failedToSave)
|
if (failedToSave)
|
||||||
|
@@ -71,6 +71,8 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <utils/QtConcurrentTools>
|
#include <utils/QtConcurrentTools>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
// Static cached data in struct QmakeNodeStaticData providing information and icons
|
// Static cached data in struct QmakeNodeStaticData providing information and icons
|
||||||
// for file types and the project. Do some magic via qAddPostRoutine()
|
// for file types and the project. Do some magic via qAddPostRoutine()
|
||||||
// to make sure the icons do not outlive QApplication, triggering warnings on X11.
|
// to make sure the icons do not outlive QApplication, triggering warnings on X11.
|
||||||
@@ -1072,9 +1074,9 @@ ProjectExplorer::FolderNode::AddNewInformation QmakePriFileNode::addNewInformati
|
|||||||
|
|
||||||
bool QmakePriFileNode::priFileWritable(const QString &path)
|
bool QmakePriFileNode::priFileWritable(const QString &path)
|
||||||
{
|
{
|
||||||
Core::Internal::ReadOnlyFilesDialog roDialog(path, Core::ICore::mainWindow());
|
ReadOnlyFilesDialog roDialog(path, ICore::mainWindow());
|
||||||
roDialog.setShowFailWarning(true);
|
roDialog.setShowFailWarning(true);
|
||||||
return roDialog.exec() != Core::Internal::ReadOnlyFilesDialog::RO_Cancel;
|
return roDialog.exec() != ReadOnlyFilesDialog::RO_Cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QmakePriFileNode::saveModifiedEditors()
|
bool QmakePriFileNode::saveModifiedEditors()
|
||||||
|
@@ -376,9 +376,9 @@ QStringList BaseFileFind::replaceAll(const QString &text,
|
|||||||
|
|
||||||
// Query the user for permissions
|
// Query the user for permissions
|
||||||
if (!roFiles.isEmpty()) {
|
if (!roFiles.isEmpty()) {
|
||||||
Core::Internal::ReadOnlyFilesDialog roDialog(roFiles.toList(), ICore::mainWindow());
|
ReadOnlyFilesDialog roDialog(roFiles.toList(), ICore::mainWindow());
|
||||||
roDialog.setShowFailWarning(true, tr("Aborting replace."));
|
roDialog.setShowFailWarning(true, tr("Aborting replace."));
|
||||||
if (roDialog.exec() == Core::Internal::ReadOnlyFilesDialog::RO_Cancel)
|
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel)
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,6 +43,9 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
RefactoringChanges::RefactoringChanges()
|
RefactoringChanges::RefactoringChanges()
|
||||||
@@ -93,8 +96,8 @@ bool RefactoringChanges::createFile(const QString &fileName, const QString &cont
|
|||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
|
|
||||||
// Write the file to disk:
|
// Write the file to disk:
|
||||||
Utils::TextFileFormat format;
|
TextFileFormat format;
|
||||||
format.codec = Core::EditorManager::defaultTextCodec();
|
format.codec = EditorManager::defaultTextCodec();
|
||||||
QString error;
|
QString error;
|
||||||
bool saveOk = format.writeFile(fileName, document->toPlainText(), &error);
|
bool saveOk = format.writeFile(fileName, document->toPlainText(), &error);
|
||||||
delete document;
|
delete document;
|
||||||
@@ -121,15 +124,14 @@ bool RefactoringChanges::removeFile(const QString &fileName) const
|
|||||||
|
|
||||||
BaseTextEditorWidget *RefactoringChanges::openEditor(const QString &fileName, bool activate, int line, int column)
|
BaseTextEditorWidget *RefactoringChanges::openEditor(const QString &fileName, bool activate, int line, int column)
|
||||||
{
|
{
|
||||||
Core::EditorManager::OpenEditorFlags flags = Core::EditorManager::IgnoreNavigationHistory;
|
EditorManager::OpenEditorFlags flags = EditorManager::IgnoreNavigationHistory;
|
||||||
if (!activate)
|
if (!activate)
|
||||||
flags |= Core::EditorManager::DoNotChangeCurrentEditor;
|
flags |= EditorManager::DoNotChangeCurrentEditor;
|
||||||
if (line != -1) {
|
if (line != -1) {
|
||||||
// openEditorAt uses a 1-based line and a 0-based column!
|
// openEditorAt uses a 1-based line and a 0-based column!
|
||||||
column -= 1;
|
column -= 1;
|
||||||
}
|
}
|
||||||
Core::IEditor *editor = Core::EditorManager::openEditorAt(
|
IEditor *editor = EditorManager::openEditorAt(fileName, line, column, Id(), flags);
|
||||||
fileName, line, column, Core::Id(), flags);
|
|
||||||
|
|
||||||
if (editor)
|
if (editor)
|
||||||
return qobject_cast<BaseTextEditorWidget *>(editor->widget());
|
return qobject_cast<BaseTextEditorWidget *>(editor->widget());
|
||||||
@@ -177,7 +179,7 @@ RefactoringFile::RefactoringFile(const QString &fileName, const QSharedPointer<R
|
|||||||
, m_editorCursorPosition(-1)
|
, m_editorCursorPosition(-1)
|
||||||
, m_appliedOnce(false)
|
, m_appliedOnce(false)
|
||||||
{
|
{
|
||||||
QList<Core::IEditor *> editors = Core::DocumentModel::editorsForFilePath(fileName);
|
QList<IEditor *> editors = DocumentModel::editorsForFilePath(fileName);
|
||||||
if (!editors.isEmpty())
|
if (!editors.isEmpty())
|
||||||
m_editor = qobject_cast<BaseTextEditorWidget *>(editors.first()->widget());
|
m_editor = qobject_cast<BaseTextEditorWidget *>(editors.first()->widget());
|
||||||
}
|
}
|
||||||
@@ -207,12 +209,12 @@ QTextDocument *RefactoringFile::mutableDocument() const
|
|||||||
QString fileContents;
|
QString fileContents;
|
||||||
if (!m_fileName.isEmpty()) {
|
if (!m_fileName.isEmpty()) {
|
||||||
QString error;
|
QString error;
|
||||||
QTextCodec *defaultCodec = Core::EditorManager::defaultTextCodec();
|
QTextCodec *defaultCodec = EditorManager::defaultTextCodec();
|
||||||
Utils::TextFileFormat::ReadResult result = Utils::TextFileFormat::readFile(
|
TextFileFormat::ReadResult result = TextFileFormat::readFile(
|
||||||
m_fileName, defaultCodec,
|
m_fileName, defaultCodec,
|
||||||
&fileContents, &m_textFileFormat,
|
&fileContents, &m_textFileFormat,
|
||||||
&error);
|
&error);
|
||||||
if (result != Utils::TextFileFormat::ReadSuccess) {
|
if (result != TextFileFormat::ReadSuccess) {
|
||||||
qWarning() << "Could not read " << m_fileName << ". Error: " << error;
|
qWarning() << "Could not read " << m_fileName << ". Error: " << error;
|
||||||
m_textFileFormat.codec = 0;
|
m_textFileFormat.codec = 0;
|
||||||
}
|
}
|
||||||
@@ -285,7 +287,7 @@ QString RefactoringFile::textOf(const Range &range) const
|
|||||||
return textOf(range.start, range.end);
|
return textOf(range.start, range.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RefactoringFile::setChangeSet(const Utils::ChangeSet &changeSet)
|
void RefactoringFile::setChangeSet(const ChangeSet &changeSet)
|
||||||
{
|
{
|
||||||
if (m_fileName.isEmpty())
|
if (m_fileName.isEmpty())
|
||||||
return;
|
return;
|
||||||
@@ -321,11 +323,11 @@ void RefactoringFile::apply()
|
|||||||
// test file permissions
|
// test file permissions
|
||||||
if (!QFileInfo(fileName()).isWritable()) {
|
if (!QFileInfo(fileName()).isWritable()) {
|
||||||
const QString &path = fileName();
|
const QString &path = fileName();
|
||||||
Core::Internal::ReadOnlyFilesDialog roDialog(path, Core::ICore::mainWindow());
|
ReadOnlyFilesDialog roDialog(path, ICore::mainWindow());
|
||||||
const QString &failDetailText = QApplication::translate("RefactoringFile::apply",
|
const QString &failDetailText = QApplication::translate("RefactoringFile::apply",
|
||||||
"Refactoring cannot be applied.");
|
"Refactoring cannot be applied.");
|
||||||
roDialog.setShowFailWarning(true, failDetailText);
|
roDialog.setShowFailWarning(true, failDetailText);
|
||||||
if (roDialog.exec() == Core::Internal::ReadOnlyFilesDialog::RO_Cancel)
|
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user