Files
qt-creator/src/plugins/coreplugin/dialogs/saveitemsdialog.cpp

137 lines
4.4 KiB
C++
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +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"
#include <coreplugin/ifile.h>
2009-05-06 16:48:28 +02:00
#include <QtCore/QDir>
2008-12-02 12:01:29 +01:00
#include <QtCore/QFileInfo>
#include <QtGui/QPushButton>
#include <QtGui/QTreeWidget>
#include <QtGui/QHeaderView>
#include <QtGui/QCheckBox>
2009-03-24 12:27:58 +01:00
Q_DECLARE_METATYPE(Core::IFile*);
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,
QList<IFile *> items)
2009-03-24 12:27:58 +01:00
: QDialog(parent)
2008-12-02 12:01:29 +01:00
{
m_ui.setupUi(this);
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
m_ui.saveBeforeBuildCheckBox->setVisible(false);
foreach (IFile *file, items) {
2009-03-24 12:27:58 +01:00
QString visibleName;
QString directory;
QString fileName = file->fileName();
2009-03-24 12:27:58 +01:00
if (fileName.isEmpty()) {
visibleName = file->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()
<< visibleName << QDir::toNativeSeparators(directory));
item->setData(0, Qt::UserRole, qVariantFromValue(file));
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()) {
m_itemsToSave.append(item->data(0, Qt::UserRole).value<IFile*>());
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();
}
QList<IFile*> SaveItemsDialog::itemsToSave() const
{
return m_itemsToSave;
}
void SaveItemsDialog::setAlwaysSaveMessage(const QString &msg)
{
m_ui.saveBeforeBuildCheckBox->setText(msg);
m_ui.saveBeforeBuildCheckBox->setVisible(true);
}
bool SaveItemsDialog::alwaysSaveChecked()
{
return m_ui.saveBeforeBuildCheckBox->isChecked();
}