2012-10-15 11:53:22 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "readonlyfilesdialog.h"
|
|
|
|
|
#include "ui_readonlyfilesdialog.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
2012-10-15 11:53:22 +02:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/idocument.h>
|
|
|
|
|
#include <coreplugin/iversioncontrol.h>
|
|
|
|
|
#include <coreplugin/vcsmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QRadioButton>
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class ReadOnlyFilesDialogPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ReadOnlyFilesDialogPrivate(IDocument *document = 0, bool useSaveAs = false);
|
|
|
|
|
~ReadOnlyFilesDialogPrivate();
|
|
|
|
|
|
|
|
|
|
// Buttongroups containing the operation for one file.
|
|
|
|
|
struct ButtonGroupForFile
|
|
|
|
|
{
|
|
|
|
|
QString fileName;
|
|
|
|
|
QButtonGroup *group;
|
|
|
|
|
};
|
|
|
|
|
QList <ButtonGroupForFile> buttonGroups;
|
|
|
|
|
|
|
|
|
|
QMap <int, int> setAllIndexForOperation;
|
|
|
|
|
// The version control systems for every file, if the file isn't in VCS the value is 0.
|
|
|
|
|
QHash <QString, IVersionControl*> versionControls;
|
|
|
|
|
|
|
|
|
|
// Define if some specific operations should be allowed to make the files writable.
|
|
|
|
|
const bool useSaveAs;
|
|
|
|
|
bool useVCS;
|
|
|
|
|
|
|
|
|
|
// Define if an error should be displayed when an operation fails.
|
|
|
|
|
bool showWarnings;
|
|
|
|
|
QString failWarning;
|
|
|
|
|
|
|
|
|
|
// The document is necessary for the Save As operation.
|
|
|
|
|
IDocument *document;
|
|
|
|
|
|
|
|
|
|
// Operation text for the tree widget header and combo box entries for
|
|
|
|
|
// modifying operations for all files.
|
|
|
|
|
const QString mixedText;
|
|
|
|
|
QString makeWritableText;
|
|
|
|
|
QString versionControlOpenText;
|
|
|
|
|
const QString saveAsText;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialogPrivate::ReadOnlyFilesDialogPrivate(IDocument *document, bool displaySaveAs)
|
|
|
|
|
: useSaveAs(displaySaveAs)
|
|
|
|
|
, useVCS(false)
|
|
|
|
|
, showWarnings(false)
|
|
|
|
|
, document(document)
|
2013-04-15 13:43:16 +02:00
|
|
|
, mixedText(ReadOnlyFilesDialog::tr("Mixed"))
|
|
|
|
|
, makeWritableText(ReadOnlyFilesDialog::tr("Make Writable"))
|
2013-05-14 16:13:29 +02:00
|
|
|
, versionControlOpenText(ReadOnlyFilesDialog::tr("Open with VCS"))
|
2013-04-15 13:43:16 +02:00
|
|
|
, saveAsText(ReadOnlyFilesDialog::tr("Save As"))
|
2012-10-15 11:53:22 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialogPrivate::~ReadOnlyFilesDialogPrivate()
|
|
|
|
|
{
|
|
|
|
|
foreach (const ButtonGroupForFile &groupForFile, buttonGroups)
|
|
|
|
|
delete groupForFile.group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \class ReadOnlyFilesDialog
|
2013-06-05 14:29:24 +02:00
|
|
|
* \brief The ReadOnlyFilesDialog class implements a dialog to show a set of
|
|
|
|
|
* files that are classified as not writable.
|
2012-10-15 11:53:22 +02:00
|
|
|
*
|
|
|
|
|
* Automatically checks which operations are allowed to make the file writable. These operations
|
|
|
|
|
* are Make Writable which tries to set the file permissions in the file system,
|
|
|
|
|
* Open With Version Control System if the open operation is allowed by the version control system
|
|
|
|
|
* and Save As which is used to save the changes to a document in another file.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QList<QString> &fileNames, QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, d(new ReadOnlyFilesDialogPrivate)
|
|
|
|
|
, ui(new Ui::ReadOnlyFilesDialog)
|
|
|
|
|
{
|
|
|
|
|
initDialog(fileNames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QString &fileName, QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, d(new ReadOnlyFilesDialogPrivate)
|
|
|
|
|
, ui(new Ui::ReadOnlyFilesDialog)
|
|
|
|
|
{
|
|
|
|
|
initDialog(QStringList() << fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(IDocument *document, QWidget *parent,
|
|
|
|
|
bool displaySaveAs)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, d(new ReadOnlyFilesDialogPrivate(document, displaySaveAs))
|
|
|
|
|
, ui(new Ui::ReadOnlyFilesDialog)
|
|
|
|
|
{
|
2013-07-04 13:30:26 +02:00
|
|
|
initDialog(QStringList() << document->filePath());
|
2012-10-15 11:53:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialog::ReadOnlyFilesDialog(const QList<IDocument *> documents, QWidget *parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
, d(new ReadOnlyFilesDialogPrivate)
|
|
|
|
|
, ui(new Ui::ReadOnlyFilesDialog)
|
|
|
|
|
{
|
|
|
|
|
QStringList files;
|
|
|
|
|
foreach (IDocument *document, documents)
|
2013-07-04 13:30:26 +02:00
|
|
|
files << document->filePath();
|
2012-10-15 11:53:22 +02:00
|
|
|
initDialog(files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReadOnlyFilesDialog::~ReadOnlyFilesDialog()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Sets a user defined message in the dialog.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
void ReadOnlyFilesDialog::setMessage(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
ui->msgLabel->setText(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Enables the error output to the user via a message box. \a warning should
|
|
|
|
|
* show the possible consequences if the file is still read only.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
void ReadOnlyFilesDialog::setShowFailWarning(bool show, const QString &warning)
|
|
|
|
|
{
|
|
|
|
|
d->showWarnings = show;
|
|
|
|
|
d->failWarning = warning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Opens a message box with an error description according to the type.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
void ReadOnlyFilesDialog::promptFailWarning(const QStringList &files, ReadOnlyResult type) const
|
|
|
|
|
{
|
|
|
|
|
if (files.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
QString title;
|
|
|
|
|
QString message;
|
|
|
|
|
QString details;
|
|
|
|
|
if (files.count() == 1) {
|
|
|
|
|
const QString file = files.first();
|
|
|
|
|
switch (type) {
|
|
|
|
|
case RO_OpenVCS: {
|
|
|
|
|
if (IVersionControl *vc = d->versionControls[file]) {
|
|
|
|
|
const QString openText = vc->vcsOpenText().remove(QLatin1Char('&'));
|
2013-05-14 16:13:29 +02:00
|
|
|
title = tr("Failed to %1 File").arg(openText);
|
2013-10-17 13:48:04 +02:00
|
|
|
message = tr("%1 file %2 from version control system %3 failed.")
|
2012-10-15 11:53:22 +02:00
|
|
|
.arg(openText)
|
|
|
|
|
.arg(QDir::toNativeSeparators(file))
|
|
|
|
|
.arg(vc->displayName());
|
2013-10-17 13:48:04 +02:00
|
|
|
message += QLatin1Char('\n');
|
2012-10-15 11:53:22 +02:00
|
|
|
message += d->failWarning;
|
|
|
|
|
} else {
|
|
|
|
|
title = tr("No Version Control System Found");
|
|
|
|
|
message = tr("Cannot open file %1 from version control system.\n"
|
2013-10-17 13:48:04 +02:00
|
|
|
"No version control system found.")
|
2012-10-15 11:53:22 +02:00
|
|
|
.arg(QDir::toNativeSeparators(file));
|
2013-10-17 13:48:04 +02:00
|
|
|
message += QLatin1Char('\n');
|
2012-10-15 11:53:22 +02:00
|
|
|
message += d->failWarning;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case RO_MakeWritable:
|
|
|
|
|
title = tr("Cannot Set Permissions");
|
2013-10-17 13:48:04 +02:00
|
|
|
message = tr("Cannot set permissions for %1 to writable.")
|
2012-10-15 11:53:22 +02:00
|
|
|
.arg(QDir::toNativeSeparators(file));
|
2013-10-17 13:48:04 +02:00
|
|
|
message += QLatin1Char('\n');
|
2012-10-15 11:53:22 +02:00
|
|
|
message += d->failWarning;
|
|
|
|
|
break;
|
|
|
|
|
case RO_SaveAs:
|
|
|
|
|
title = tr("Cannot Save File");
|
2013-10-17 13:48:04 +02:00
|
|
|
message = tr("Cannot save file %1").arg(QDir::toNativeSeparators(file));
|
|
|
|
|
message += QLatin1Char('\n');
|
2012-10-15 11:53:22 +02:00
|
|
|
message += d->failWarning;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2013-04-15 13:43:16 +02:00
|
|
|
title = tr("Canceled Changing Permissions");
|
2012-10-15 11:53:22 +02:00
|
|
|
message = d->failWarning;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-05-14 16:13:29 +02:00
|
|
|
title = tr("Could Not Change Permissions on Some Files");
|
2012-10-15 11:53:22 +02:00
|
|
|
message = d->failWarning;
|
|
|
|
|
message += tr("\nSee details for a complete list of files.");
|
|
|
|
|
details = files.join(QLatin1String("\n"));
|
|
|
|
|
}
|
|
|
|
|
QMessageBox msgBox(QMessageBox::Warning, title, message);
|
|
|
|
|
msgBox.setDetailedText(details);
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Executes the ReadOnlyFilesDialog dialog.
|
|
|
|
|
* Returns ReadOnlyResult to provide information about the operation that was
|
|
|
|
|
* used to make the files writable.
|
2013-10-17 13:48:04 +02:00
|
|
|
*
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*
|
2013-09-06 16:38:53 +02:00
|
|
|
* Also displays an error dialog when some operations cannot be executed and the
|
|
|
|
|
* function \c setShowFailWarning() was called.
|
2012-10-15 11:53:22 +02:00
|
|
|
*/
|
|
|
|
|
int ReadOnlyFilesDialog::exec()
|
|
|
|
|
{
|
|
|
|
|
if (QDialog::exec() != QDialog::Accepted)
|
|
|
|
|
return RO_Cancel;
|
|
|
|
|
|
2013-05-29 08:45:13 +02:00
|
|
|
ReadOnlyResult result = RO_Cancel;
|
2012-10-15 11:53:22 +02:00
|
|
|
QStringList failedToMakeWritable;
|
|
|
|
|
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile buttengroup, d->buttonGroups) {
|
|
|
|
|
result = static_cast<ReadOnlyResult>(buttengroup.group->checkedId());
|
|
|
|
|
switch (result) {
|
|
|
|
|
case RO_MakeWritable:
|
|
|
|
|
if (!Utils::FileUtils::makeWritable(Utils::FileName(QFileInfo(buttengroup.fileName)))) {
|
|
|
|
|
failedToMakeWritable << buttengroup.fileName;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case RO_OpenVCS:
|
|
|
|
|
if (!d->versionControls[buttengroup.fileName]->vcsOpen(buttengroup.fileName)) {
|
|
|
|
|
failedToMakeWritable << buttengroup.fileName;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case RO_SaveAs:
|
2013-08-29 15:46:04 +02:00
|
|
|
if (!EditorManager::saveDocumentAs(d->document)) {
|
2012-10-15 11:53:22 +02:00
|
|
|
failedToMakeWritable << buttengroup.fileName;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
failedToMakeWritable << buttengroup.fileName;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!QFileInfo(buttengroup.fileName).isWritable())
|
|
|
|
|
failedToMakeWritable << buttengroup.fileName;
|
|
|
|
|
}
|
|
|
|
|
if (!failedToMakeWritable.isEmpty()) {
|
|
|
|
|
if (d->showWarnings)
|
|
|
|
|
promptFailWarning(failedToMakeWritable, result);
|
|
|
|
|
}
|
|
|
|
|
return failedToMakeWritable.isEmpty() ? result : RO_Cancel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Creates a radio button in the group \a group and in the column specified by
|
|
|
|
|
* \a type.
|
|
|
|
|
* Returns the created button.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
QRadioButton* ReadOnlyFilesDialog::createRadioButtonForItem(QTreeWidgetItem *item, QButtonGroup *group,
|
|
|
|
|
ReadOnlyFilesDialog::ReadOnlyFilesTreeColumn type)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QRadioButton *radioButton = new QRadioButton(this);
|
|
|
|
|
group->addButton(radioButton, type);
|
|
|
|
|
item->setTextAlignment(type, Qt::AlignHCenter);
|
|
|
|
|
ui->treeWidget->setItemWidget(item, type, radioButton);
|
|
|
|
|
return radioButton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Checks the type of the select all combo box and changes the user selection
|
|
|
|
|
* per file accordingly.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
void ReadOnlyFilesDialog::setAll(int index)
|
|
|
|
|
{
|
|
|
|
|
// If mixed is the current index, no need to change the user selection.
|
|
|
|
|
if (index == d->setAllIndexForOperation[-1/*mixed*/])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Get the selected type from the select all combo box.
|
2013-05-29 08:45:13 +02:00
|
|
|
ReadOnlyFilesTreeColumn type = NumberOfColumns;
|
2012-10-15 11:53:22 +02:00
|
|
|
if (index == d->setAllIndexForOperation[MakeWritable])
|
|
|
|
|
type = MakeWritable;
|
|
|
|
|
else if (index == d->setAllIndexForOperation[OpenWithVCS])
|
|
|
|
|
type = OpenWithVCS;
|
|
|
|
|
else if (index == d->setAllIndexForOperation[SaveAs])
|
|
|
|
|
type = SaveAs;
|
|
|
|
|
|
|
|
|
|
// Check for every file if the selected operation is available and change it to the operation.
|
|
|
|
|
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, d->buttonGroups) {
|
|
|
|
|
QRadioButton *radioButton = qobject_cast<QRadioButton*> (groupForFile.group->button(type));
|
|
|
|
|
if (radioButton)
|
|
|
|
|
radioButton->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Updates the select all combo box depending on the selection the user made in
|
|
|
|
|
* the tree widget.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
void ReadOnlyFilesDialog::updateSelectAll()
|
|
|
|
|
{
|
|
|
|
|
int selectedOperation = -1;
|
|
|
|
|
foreach (ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile, d->buttonGroups) {
|
|
|
|
|
if (selectedOperation == -1) {
|
|
|
|
|
selectedOperation = groupForFile.group->checkedId();
|
|
|
|
|
} else if (selectedOperation != groupForFile.group->checkedId()) {
|
|
|
|
|
ui->setAll->setCurrentIndex(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ui->setAll->setCurrentIndex(d->setAllIndexForOperation[selectedOperation]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-06 16:38:53 +02:00
|
|
|
* Adds files to the dialog and checks for a possible operation to make the file
|
|
|
|
|
* writable.
|
|
|
|
|
* \a fileNames contains the list of the files that should be added to the
|
|
|
|
|
* dialog.
|
2012-10-15 11:53:22 +02:00
|
|
|
* \internal
|
|
|
|
|
*/
|
|
|
|
|
void ReadOnlyFilesDialog::initDialog(const QStringList &fileNames)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
ui->buttonBox->addButton(tr("&Change Permission"), QDialogButtonBox::AcceptRole);
|
|
|
|
|
ui->buttonBox->addButton(QDialogButtonBox::Cancel);
|
|
|
|
|
|
|
|
|
|
QString vcsOpenTextForAll;
|
|
|
|
|
QString vcsMakeWritableTextForAll;
|
|
|
|
|
bool useMakeWritable = false;
|
|
|
|
|
foreach (const QString &fileName, fileNames) {
|
|
|
|
|
const QFileInfo info = QFileInfo(fileName);
|
|
|
|
|
const QString visibleName = info.fileName();
|
|
|
|
|
const QString directory = info.absolutePath();
|
|
|
|
|
|
|
|
|
|
// Setup a default entry with filename folder and make writable radio button.
|
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
|
|
|
|
|
item->setText(FileName, visibleName);
|
2013-09-12 16:06:33 +02:00
|
|
|
item->setIcon(FileName, FileIconProvider::icon(fileName));
|
2012-10-15 11:53:22 +02:00
|
|
|
item->setText(Folder, Utils::FileUtils::shortNativePath(Utils::FileName(QFileInfo(directory))));
|
|
|
|
|
QButtonGroup *radioButtonGroup = new QButtonGroup;
|
|
|
|
|
|
|
|
|
|
// Add a button for opening the file with a version control system
|
|
|
|
|
// if the file is managed by an version control system which allows opening files.
|
|
|
|
|
IVersionControl *versionControlForFile =
|
2013-08-30 17:13:29 +02:00
|
|
|
VcsManager::findVersionControlForDirectory(directory);
|
2012-10-15 11:53:22 +02:00
|
|
|
const bool fileManagedByVCS = versionControlForFile
|
2013-11-07 12:31:22 +01:00
|
|
|
&& versionControlForFile->openSupportMode(fileName) != IVersionControl::NoOpen;
|
2012-10-15 11:53:22 +02:00
|
|
|
if (fileManagedByVCS) {
|
|
|
|
|
const QString vcsOpenTextForFile =
|
|
|
|
|
versionControlForFile->vcsOpenText().remove(QLatin1Char('&'));
|
|
|
|
|
const QString vcsMakeWritableTextforFile =
|
|
|
|
|
versionControlForFile->vcsMakeWritableText().remove(QLatin1Char('&'));
|
|
|
|
|
if (!d->useVCS) {
|
|
|
|
|
vcsOpenTextForAll = vcsOpenTextForFile;
|
|
|
|
|
vcsMakeWritableTextForAll = vcsMakeWritableTextforFile;
|
|
|
|
|
d->useVCS = true;
|
|
|
|
|
} else {
|
|
|
|
|
// If there are different open or make writable texts choose the default one.
|
|
|
|
|
if (vcsOpenTextForFile != vcsOpenTextForAll)
|
|
|
|
|
vcsOpenTextForAll.clear();
|
|
|
|
|
if (vcsMakeWritableTextforFile != vcsMakeWritableTextForAll)
|
|
|
|
|
vcsMakeWritableTextForAll.clear();
|
|
|
|
|
}
|
|
|
|
|
// Add make writable if it is supported by the reposetory.
|
2013-11-07 12:31:22 +01:00
|
|
|
if (versionControlForFile->openSupportMode(fileName) == IVersionControl::OpenOptional) {
|
2012-10-15 11:53:22 +02:00
|
|
|
useMakeWritable = true;
|
|
|
|
|
createRadioButtonForItem(item, radioButtonGroup, MakeWritable);
|
|
|
|
|
}
|
|
|
|
|
createRadioButtonForItem(item, radioButtonGroup, OpenWithVCS)->setChecked(true);
|
|
|
|
|
} else {
|
|
|
|
|
useMakeWritable = true;
|
|
|
|
|
createRadioButtonForItem(item, radioButtonGroup, MakeWritable)->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
// Add a Save As radio button if requested.
|
|
|
|
|
if (d->useSaveAs)
|
|
|
|
|
createRadioButtonForItem(item, radioButtonGroup, SaveAs);
|
|
|
|
|
// If the file is managed by a version control system save the vcs for this file.
|
|
|
|
|
d->versionControls[fileName] = fileManagedByVCS ? versionControlForFile : 0;
|
|
|
|
|
|
|
|
|
|
// Also save the buttongroup for every file to get the result for each entry.
|
|
|
|
|
ReadOnlyFilesDialogPrivate::ButtonGroupForFile groupForFile;
|
|
|
|
|
groupForFile.fileName = fileName;
|
|
|
|
|
groupForFile.group = radioButtonGroup;
|
|
|
|
|
d->buttonGroups.append(groupForFile);
|
|
|
|
|
connect(radioButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(updateSelectAll()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Apply the Mac file dialog style.
|
|
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
|
ui->treeWidget->setAlternatingRowColors(true);
|
|
|
|
|
|
|
|
|
|
// Do not show any options to the user if he has no choice.
|
|
|
|
|
if (!d->useSaveAs && (!d->useVCS || !useMakeWritable)) {
|
|
|
|
|
ui->treeWidget->setColumnHidden(MakeWritable, true);
|
|
|
|
|
ui->treeWidget->setColumnHidden(OpenWithVCS, true);
|
|
|
|
|
ui->treeWidget->setColumnHidden(SaveAs, true);
|
|
|
|
|
ui->treeWidget->resizeColumnToContents(FileName);
|
|
|
|
|
ui->treeWidget->resizeColumnToContents(Folder);
|
|
|
|
|
ui->setAll->setVisible(false);
|
|
|
|
|
ui->setAllLabel->setVisible(false);
|
|
|
|
|
ui->verticalLayout->removeItem(ui->setAllLayout);
|
|
|
|
|
if (d->useVCS)
|
2013-05-14 16:13:29 +02:00
|
|
|
ui->msgLabel->setText(tr("The following files are not checked out yet.\n"
|
|
|
|
|
"Do you want to check them out now?"));
|
2012-10-15 11:53:22 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there is just one file entry, there is no need to show the select all combo box
|
|
|
|
|
if (fileNames.count() < 2) {
|
|
|
|
|
ui->setAll->setVisible(false);
|
|
|
|
|
ui->setAllLabel->setVisible(false);
|
|
|
|
|
ui->verticalLayout->removeItem(ui->setAllLayout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add items to the Set all combo box.
|
|
|
|
|
ui->setAll->addItem(d->mixedText);
|
|
|
|
|
d->setAllIndexForOperation[-1/*mixed*/] = ui->setAll->count() - 1;
|
|
|
|
|
if (d->useVCS) {
|
|
|
|
|
// If the files are managed by just one version control system, the Open and Make Writable
|
|
|
|
|
// text for the specific system is used.
|
|
|
|
|
if (!vcsOpenTextForAll.isEmpty() && vcsOpenTextForAll != d->versionControlOpenText) {
|
|
|
|
|
d->versionControlOpenText = vcsOpenTextForAll;
|
|
|
|
|
ui->treeWidget->headerItem()->setText(OpenWithVCS, d->versionControlOpenText);
|
|
|
|
|
}
|
|
|
|
|
if (!vcsMakeWritableTextForAll.isEmpty() && vcsMakeWritableTextForAll != d->makeWritableText) {
|
|
|
|
|
d->makeWritableText = vcsMakeWritableTextForAll;
|
|
|
|
|
ui->treeWidget->headerItem()->setText(MakeWritable, d->makeWritableText);
|
|
|
|
|
}
|
|
|
|
|
ui->setAll->addItem(d->versionControlOpenText);
|
|
|
|
|
ui->setAll->setCurrentIndex(ui->setAll->count() - 1);
|
|
|
|
|
d->setAllIndexForOperation[OpenWithVCS] = ui->setAll->count() - 1;
|
|
|
|
|
}
|
|
|
|
|
if (useMakeWritable) {
|
|
|
|
|
ui->setAll->addItem(d->makeWritableText);
|
|
|
|
|
d->setAllIndexForOperation[MakeWritable] = ui->setAll->count() - 1;
|
|
|
|
|
if (ui->setAll->currentIndex() == -1)
|
|
|
|
|
ui->setAll->setCurrentIndex(ui->setAll->count() - 1);
|
|
|
|
|
}
|
|
|
|
|
if (d->useSaveAs) {
|
|
|
|
|
ui->setAll->addItem(d->saveAsText);
|
|
|
|
|
d->setAllIndexForOperation[SaveAs] = ui->setAll->count() - 1;
|
|
|
|
|
}
|
|
|
|
|
connect(ui->setAll, SIGNAL(activated(int)), this, SLOT(setAll(int)));
|
|
|
|
|
|
|
|
|
|
// Filter which columns should be visible and resize them to content.
|
|
|
|
|
for (int i = 0; i < NumberOfColumns; ++i) {
|
|
|
|
|
if ((i == SaveAs && !d->useSaveAs) || (i == OpenWithVCS && !d->useVCS)
|
|
|
|
|
|| (i == MakeWritable && !useMakeWritable)) {
|
|
|
|
|
ui->treeWidget->setColumnHidden(i, true);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ui->treeWidget->resizeColumnToContents(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}// namespace Internal
|
|
|
|
|
}// namespace Core
|