Commit 87fdacba authored by con's avatar con
Browse files

Simpler "Save modified files" dialog.

parent 60bb3616
......@@ -40,123 +40,47 @@
#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
Q_DECLARE_METATYPE(Core::IFile*);
using namespace Core;
using namespace Core::Internal;
FileItem::FileItem(QTreeWidget *tree, bool supportOpen, bool open, const QString &text)
: QTreeWidgetItem(tree)
{
m_saveCheckBox = createCheckBox(tree, 0);
m_saveCheckBox->setChecked(true);
QFileInfo fi(text);
QString name = fi.fileName();
if (open)
name.append(tr(" [ReadOnly]"));
if (supportOpen) {
m_sccCheckBox = createCheckBox(tree, 1);
m_sccCheckBox->setEnabled(open);
m_sccCheckBox->setChecked(open);
connect(m_saveCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(updateSCCCheckBox()));
setText(2, name);
setToolTip(2, text);
} else {
m_sccCheckBox = 0;
setText(2, name);
setToolTip(2, text);
}
}
QCheckBox *FileItem::createCheckBox(QTreeWidget *tree, int column)
{
QWidget *w = new QWidget();
QHBoxLayout *l = new QHBoxLayout(w);
l->setMargin(0);
l->setSpacing(0);
QCheckBox *box = new QCheckBox(w);
l->addWidget(box);
l->setAlignment(box, Qt::AlignCenter);
w->setLayout(l);
tree->setItemWidget(this, column, w);
return box;
}
void FileItem::updateSCCCheckBox()
{
if (!m_saveCheckBox->isChecked()) {
m_sccCheckBox->setEnabled(false);
m_sccCheckBox->setChecked(false);
} else {
m_sccCheckBox->setEnabled(true);
}
}
bool FileItem::shouldBeSaved() const
{
return m_saveCheckBox->isChecked();
}
void FileItem::setShouldBeSaved(bool s)
{
m_saveCheckBox->setChecked(s);
}
bool FileItem::shouldBeOpened() const
{
if (m_sccCheckBox)
return m_sccCheckBox->isChecked();
return false;
}
SaveItemsDialog::SaveItemsDialog(MainWindow *mainWindow,
SaveItemsDialog::SaveItemsDialog(QWidget *parent,
QMap<IFile*, QString> items)
: QDialog(mainWindow)
: QDialog(parent)
{
m_ui.setupUi(this);
QPushButton *uncheckButton = m_ui.buttonBox->addButton(tr("Uncheck All"),
QDialogButtonBox::ActionRole);
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Discard All"),
QDialogButtonBox::DestructiveRole);
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
m_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus(Qt::TabFocusReason);
m_ui.treeWidget->header()->setMovable(false);
m_ui.treeWidget->setRootIsDecorated(false);
m_ui.treeWidget->setColumnCount(2);
QStringList headers;
headers << tr("Save") << tr("File Name");
const bool hasVersionControl = true;
if (hasVersionControl) {
m_ui.treeWidget->setColumnCount(3);
headers.insert(1, tr("Open with SCC"));
}
m_ui.treeWidget->setHeaderLabels(headers);
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Don't Save"), QDialogButtonBox::DestructiveRole);
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
FileItem *itm;
QMap<IFile*, QString>::const_iterator it = items.constBegin();
while (it != items.constEnd()) {
QString directory = QFileInfo(it.key()->fileName()).absolutePath();
bool fileHasVersionControl = mainWindow->vcsManager()->findVersionControlForDirectory(directory) != 0;
itm = new FileItem(m_ui.treeWidget, fileHasVersionControl,
it.key()->isReadOnly(), it.value());
m_itemMap.insert(itm, it.key());
QString visibleName;
QString directory;
QString fileName = it.key()->fileName();
if (fileName.isEmpty()) {
visibleName = it.key()->suggestedFileName();
} else {
QFileInfo info = QFileInfo(fileName);
directory = info.absolutePath();
visibleName = info.fileName();
}
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
<< visibleName << directory);
item->setData(0, Qt::UserRole, qVariantFromValue(it.key()));
++it;
}
m_ui.treeWidget->resizeColumnToContents(0);
if (hasVersionControl)
m_ui.treeWidget->resizeColumnToContents(1);
m_ui.treeWidget->selectAll();
updateSaveButton();
connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
connect(m_ui.buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()),
this, SLOT(collectItemsToSave()));
connect(uncheckButton, SIGNAL(clicked()), this, SLOT(uncheckAll()));
connect(discardButton, SIGNAL(clicked()), this, SLOT(discardAll()));
connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(updateSaveButton()));
}
void SaveItemsDialog::setMessage(const QString &msg)
......@@ -164,24 +88,34 @@ void SaveItemsDialog::setMessage(const QString &msg)
m_ui.msgLabel->setText(msg);
}
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"));
}
}
void SaveItemsDialog::collectItemsToSave()
{
m_itemsToSave.clear();
m_itemsToOpen.clear();
QMap<FileItem*, IFile*>::const_iterator it = m_itemMap.constBegin();
while (it != m_itemMap.constEnd()) {
if (it.key()->shouldBeSaved())
m_itemsToSave << it.value();
if (it.key()->shouldBeOpened())
m_itemsToOpen.insert(it.value());
++it;
foreach (QTreeWidgetItem *item, m_ui.treeWidget->selectedItems()) {
m_itemsToSave.append(item->data(0, Qt::UserRole).value<IFile*>());
}
accept();
}
void SaveItemsDialog::discardAll()
{
uncheckAll();
m_ui.treeWidget->clearSelection();
collectItemsToSave();
}
......@@ -190,15 +124,7 @@ QList<IFile*> SaveItemsDialog::itemsToSave() const
return m_itemsToSave;
}
QSet<IFile*> SaveItemsDialog::itemsToOpen() const
QSet<IFile*> SaveItemsDialog::itemsToOpenWithVCS() const
{
return m_itemsToOpen;
}
void SaveItemsDialog::uncheckAll()
{
for (int i=0; i<m_ui.treeWidget->topLevelItemCount(); ++i) {
FileItem *item = static_cast<FileItem*>(m_ui.treeWidget->topLevelItem(i));
item->setShouldBeSaved(false);
}
return m_itemsToSave.toSet();
}
......@@ -48,47 +48,26 @@ namespace Internal {
class MainWindow;
class FileItem : public QObject, public QTreeWidgetItem
{
Q_OBJECT
public:
FileItem(QTreeWidget *tree, bool supportOpen,
bool open, const QString &text);
bool shouldBeSaved() const;
void setShouldBeSaved(bool s);
bool shouldBeOpened() const;
private slots:
void updateSCCCheckBox();
private:
QCheckBox *createCheckBox(QTreeWidget *tree, int column);
QCheckBox *m_saveCheckBox;
QCheckBox *m_sccCheckBox;
};
class SaveItemsDialog : public QDialog
{
Q_OBJECT
public:
SaveItemsDialog(MainWindow *mainWindow,
SaveItemsDialog(QWidget *parent,
QMap<Core::IFile*, QString> items);
void setMessage(const QString &msg);
QList<Core::IFile*> itemsToSave() const;
QSet<Core::IFile*> itemsToOpen() const;
QSet<Core::IFile*> itemsToOpenWithVCS() const;
private slots:
void collectItemsToSave();
void uncheckAll();
void discardAll();
void updateSaveButton();
private:
Ui::SaveItemsDialog m_ui;
QMap<FileItem*, Core::IFile*> m_itemMap;
QList<Core::IFile*> m_itemsToSave;
QSet<Core::IFile*> m_itemsToOpen;
};
......
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SaveItemsDialog</class>
<widget class="QDialog" name="SaveItemsDialog" >
<property name="geometry" >
<widget class="QDialog" name="SaveItemsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>457</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Save Changes</string>
</property>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="msgLabel" >
<property name="text" >
<string>Save the changes of the following items:</string>
<widget class="QLabel" name="msgLabel">
<property name="text">
<string>The following files have unsaved changes:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeWidget" />
<widget class="QTreeWidget" name="treeWidget">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideLeft</enum>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">2</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
......@@ -52,11 +79,11 @@
<receiver>SaveItemsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>199</x>
<y>174</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>199</x>
<y>99</y>
</hint>
......
......@@ -346,7 +346,7 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
return notSaved;
}
filesToSave = dia.itemsToSave();
filesToOpen = dia.itemsToOpen();
filesToOpen = dia.itemsToOpenWithVCS();
}
bool yestoall = false;
......
......@@ -1273,8 +1273,7 @@ bool ProjectExplorerPlugin::saveModifiedFiles(const QList<Project *> & projects)
if (!filesToSave.isEmpty()) {
bool cancelled;
Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave, &cancelled,
tr("The following dependencies are modified, do you want to save them?"));
Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave, &cancelled);
if (cancelled) {
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment