2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "saveitemsdialog.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "vcsmanager.h"
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QCheckBox>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::IDocument*)
|
2009-03-24 12:27:58 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core;
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
2009-03-24 12:27:58 +01:00
|
|
|
SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
2012-02-14 16:43:51 +01:00
|
|
|
QList<IDocument *> items)
|
2009-03-24 12:27:58 +01:00
|
|
|
: QDialog(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
m_ui.setupUi(this);
|
2011-04-15 11:43:09 +02:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2009-09-29 12:17:37 +02:00
|
|
|
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Do not Save"), QDialogButtonBox::DestructiveRole);
|
2009-03-24 12:27:58 +01:00
|
|
|
m_ui.buttonBox->button(QDialogButtonBox::Save)->setDefault(true);
|
|
|
|
m_ui.buttonBox->button(QDialogButtonBox::Save)->setFocus(Qt::TabFocusReason);
|
|
|
|
m_ui.buttonBox->button(QDialogButtonBox::Save)->setMinimumWidth(130); // bad magic number to avoid resizing of button
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-06 11:55:21 +02:00
|
|
|
m_ui.saveBeforeBuildCheckBox->setVisible(false);
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
foreach (IDocument *document, items) {
|
2009-03-24 12:27:58 +01:00
|
|
|
QString visibleName;
|
|
|
|
QString directory;
|
2012-02-14 16:43:51 +01:00
|
|
|
QString fileName = document->fileName();
|
2009-03-24 12:27:58 +01:00
|
|
|
if (fileName.isEmpty()) {
|
2012-02-14 16:43:51 +01:00
|
|
|
visibleName = document->suggestedFileName();
|
2009-03-24 12:27:58 +01:00
|
|
|
} else {
|
|
|
|
QFileInfo info = QFileInfo(fileName);
|
|
|
|
directory = info.absolutePath();
|
|
|
|
visibleName = info.fileName();
|
|
|
|
}
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
|
2009-05-06 16:26:32 +02:00
|
|
|
<< visibleName << QDir::toNativeSeparators(directory));
|
2012-02-14 16:43:51 +01:00
|
|
|
item->setData(0, Qt::UserRole, qVariantFromValue(document));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_ui.treeWidget->resizeColumnToContents(0);
|
2009-03-24 12:27:58 +01:00
|
|
|
m_ui.treeWidget->selectAll();
|
|
|
|
updateSaveButton();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-24 12:27:58 +01:00
|
|
|
connect(m_ui.buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()),
|
2008-12-02 12:01:29 +01:00
|
|
|
this, SLOT(collectItemsToSave()));
|
|
|
|
connect(discardButton, SIGNAL(clicked()), this, SLOT(discardAll()));
|
2009-03-24 12:27:58 +01:00
|
|
|
connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(updateSaveButton()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveItemsDialog::setMessage(const QString &msg)
|
|
|
|
{
|
|
|
|
m_ui.msgLabel->setText(msg);
|
|
|
|
}
|
|
|
|
|
2009-03-24 12:27:58 +01:00
|
|
|
void SaveItemsDialog::updateSaveButton()
|
|
|
|
{
|
|
|
|
int count = m_ui.treeWidget->selectedItems().count();
|
|
|
|
QPushButton *button = m_ui.buttonBox->button(QDialogButtonBox::Save);
|
|
|
|
if (count == m_ui.treeWidget->topLevelItemCount()) {
|
|
|
|
button->setEnabled(true);
|
|
|
|
button->setText(tr("Save All"));
|
|
|
|
} else if (count == 0) {
|
|
|
|
button->setEnabled(false);
|
|
|
|
button->setText(tr("Save"));
|
|
|
|
} else {
|
|
|
|
button->setEnabled(true);
|
|
|
|
button->setText(tr("Save Selected"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void SaveItemsDialog::collectItemsToSave()
|
|
|
|
{
|
|
|
|
m_itemsToSave.clear();
|
2009-03-24 12:27:58 +01:00
|
|
|
foreach (QTreeWidgetItem *item, m_ui.treeWidget->selectedItems()) {
|
2012-02-14 16:43:51 +01:00
|
|
|
m_itemsToSave.append(item->data(0, Qt::UserRole).value<IDocument*>());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveItemsDialog::discardAll()
|
|
|
|
{
|
2009-03-24 12:27:58 +01:00
|
|
|
m_ui.treeWidget->clearSelection();
|
2008-12-02 12:01:29 +01:00
|
|
|
collectItemsToSave();
|
|
|
|
}
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
QList<IDocument*> SaveItemsDialog::itemsToSave() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
return m_itemsToSave;
|
|
|
|
}
|
2009-05-06 11:55:21 +02:00
|
|
|
|
|
|
|
void SaveItemsDialog::setAlwaysSaveMessage(const QString &msg)
|
|
|
|
{
|
|
|
|
m_ui.saveBeforeBuildCheckBox->setText(msg);
|
|
|
|
m_ui.saveBeforeBuildCheckBox->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SaveItemsDialog::alwaysSaveChecked()
|
|
|
|
{
|
|
|
|
return m_ui.saveBeforeBuildCheckBox->isChecked();
|
|
|
|
}
|