forked from qt-creator/qt-creator
Simpler "Save modified files" dialog.
This commit is contained in:
@@ -40,123 +40,47 @@
|
|||||||
#include <QtGui/QCheckBox>
|
#include <QtGui/QCheckBox>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Core::IFile*);
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
|
|
||||||
FileItem::FileItem(QTreeWidget *tree, bool supportOpen, bool open, const QString &text)
|
SaveItemsDialog::SaveItemsDialog(QWidget *parent,
|
||||||
: 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,
|
|
||||||
QMap<IFile*, QString> items)
|
QMap<IFile*, QString> items)
|
||||||
: QDialog(mainWindow)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
QPushButton *uncheckButton = m_ui.buttonBox->addButton(tr("Uncheck All"),
|
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Don't Save"), QDialogButtonBox::DestructiveRole);
|
||||||
QDialogButtonBox::ActionRole);
|
m_ui.buttonBox->button(QDialogButtonBox::Save)->setDefault(true);
|
||||||
QPushButton *discardButton = m_ui.buttonBox->addButton(tr("Discard All"),
|
m_ui.buttonBox->button(QDialogButtonBox::Save)->setFocus(Qt::TabFocusReason);
|
||||||
QDialogButtonBox::DestructiveRole);
|
m_ui.buttonBox->button(QDialogButtonBox::Save)->setMinimumWidth(130); // bad magic number to avoid resizing of button
|
||||||
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);
|
|
||||||
|
|
||||||
FileItem *itm;
|
|
||||||
QMap<IFile*, QString>::const_iterator it = items.constBegin();
|
QMap<IFile*, QString>::const_iterator it = items.constBegin();
|
||||||
while (it != items.constEnd()) {
|
while (it != items.constEnd()) {
|
||||||
QString directory = QFileInfo(it.key()->fileName()).absolutePath();
|
QString visibleName;
|
||||||
bool fileHasVersionControl = mainWindow->vcsManager()->findVersionControlForDirectory(directory) != 0;
|
QString directory;
|
||||||
itm = new FileItem(m_ui.treeWidget, fileHasVersionControl,
|
QString fileName = it.key()->fileName();
|
||||||
it.key()->isReadOnly(), it.value());
|
if (fileName.isEmpty()) {
|
||||||
m_itemMap.insert(itm, it.key());
|
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;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui.treeWidget->resizeColumnToContents(0);
|
m_ui.treeWidget->resizeColumnToContents(0);
|
||||||
if (hasVersionControl)
|
m_ui.treeWidget->selectAll();
|
||||||
m_ui.treeWidget->resizeColumnToContents(1);
|
updateSaveButton();
|
||||||
|
|
||||||
connect(m_ui.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
|
connect(m_ui.buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()),
|
||||||
this, SLOT(collectItemsToSave()));
|
this, SLOT(collectItemsToSave()));
|
||||||
connect(uncheckButton, SIGNAL(clicked()), this, SLOT(uncheckAll()));
|
|
||||||
connect(discardButton, SIGNAL(clicked()), this, SLOT(discardAll()));
|
connect(discardButton, SIGNAL(clicked()), this, SLOT(discardAll()));
|
||||||
|
connect(m_ui.treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(updateSaveButton()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveItemsDialog::setMessage(const QString &msg)
|
void SaveItemsDialog::setMessage(const QString &msg)
|
||||||
@@ -164,24 +88,34 @@ void SaveItemsDialog::setMessage(const QString &msg)
|
|||||||
m_ui.msgLabel->setText(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()
|
void SaveItemsDialog::collectItemsToSave()
|
||||||
{
|
{
|
||||||
m_itemsToSave.clear();
|
m_itemsToSave.clear();
|
||||||
m_itemsToOpen.clear();
|
foreach (QTreeWidgetItem *item, m_ui.treeWidget->selectedItems()) {
|
||||||
QMap<FileItem*, IFile*>::const_iterator it = m_itemMap.constBegin();
|
m_itemsToSave.append(item->data(0, Qt::UserRole).value<IFile*>());
|
||||||
while (it != m_itemMap.constEnd()) {
|
|
||||||
if (it.key()->shouldBeSaved())
|
|
||||||
m_itemsToSave << it.value();
|
|
||||||
if (it.key()->shouldBeOpened())
|
|
||||||
m_itemsToOpen.insert(it.value());
|
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveItemsDialog::discardAll()
|
void SaveItemsDialog::discardAll()
|
||||||
{
|
{
|
||||||
uncheckAll();
|
m_ui.treeWidget->clearSelection();
|
||||||
collectItemsToSave();
|
collectItemsToSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,15 +124,7 @@ QList<IFile*> SaveItemsDialog::itemsToSave() const
|
|||||||
return m_itemsToSave;
|
return m_itemsToSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<IFile*> SaveItemsDialog::itemsToOpen() const
|
QSet<IFile*> SaveItemsDialog::itemsToOpenWithVCS() const
|
||||||
{
|
{
|
||||||
return m_itemsToOpen;
|
return m_itemsToSave.toSet();
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,47 +48,26 @@ namespace Internal {
|
|||||||
|
|
||||||
class MainWindow;
|
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
|
class SaveItemsDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SaveItemsDialog(MainWindow *mainWindow,
|
SaveItemsDialog(QWidget *parent,
|
||||||
QMap<Core::IFile*, QString> items);
|
QMap<Core::IFile*, QString> items);
|
||||||
|
|
||||||
void setMessage(const QString &msg);
|
void setMessage(const QString &msg);
|
||||||
|
|
||||||
QList<Core::IFile*> itemsToSave() const;
|
QList<Core::IFile*> itemsToSave() const;
|
||||||
QSet<Core::IFile*> itemsToOpen() const;
|
QSet<Core::IFile*> itemsToOpenWithVCS() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void collectItemsToSave();
|
void collectItemsToSave();
|
||||||
void uncheckAll();
|
|
||||||
void discardAll();
|
void discardAll();
|
||||||
|
void updateSaveButton();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SaveItemsDialog m_ui;
|
Ui::SaveItemsDialog m_ui;
|
||||||
QMap<FileItem*, Core::IFile*> m_itemMap;
|
|
||||||
QList<Core::IFile*> m_itemsToSave;
|
QList<Core::IFile*> m_itemsToSave;
|
||||||
QSet<Core::IFile*> m_itemsToOpen;
|
QSet<Core::IFile*> m_itemsToOpen;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,41 +1,68 @@
|
|||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
<class>SaveItemsDialog</class>
|
<class>SaveItemsDialog</class>
|
||||||
<widget class="QDialog" name="SaveItemsDialog" >
|
<widget class="QDialog" name="SaveItemsDialog">
|
||||||
<property name="geometry" >
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>457</width>
|
||||||
<height>200</height>
|
<height>200</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>Save Changes</string>
|
<string>Save Changes</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout">
|
||||||
<property name="margin" >
|
|
||||||
<number>9</number>
|
|
||||||
</property>
|
|
||||||
<property name="spacing" >
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="msgLabel" >
|
<widget class="QLabel" name="msgLabel">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>Save the changes of the following items:</string>
|
<string>The following files have unsaved changes:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<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>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation" >
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons" >
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -52,11 +79,11 @@
|
|||||||
<receiver>SaveItemsDialog</receiver>
|
<receiver>SaveItemsDialog</receiver>
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel" >
|
<hint type="sourcelabel">
|
||||||
<x>199</x>
|
<x>199</x>
|
||||||
<y>174</y>
|
<y>174</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel" >
|
<hint type="destinationlabel">
|
||||||
<x>199</x>
|
<x>199</x>
|
||||||
<y>99</y>
|
<y>99</y>
|
||||||
</hint>
|
</hint>
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
|
|||||||
return notSaved;
|
return notSaved;
|
||||||
}
|
}
|
||||||
filesToSave = dia.itemsToSave();
|
filesToSave = dia.itemsToSave();
|
||||||
filesToOpen = dia.itemsToOpen();
|
filesToOpen = dia.itemsToOpenWithVCS();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool yestoall = false;
|
bool yestoall = false;
|
||||||
|
|||||||
@@ -1273,8 +1273,7 @@ bool ProjectExplorerPlugin::saveModifiedFiles(const QList<Project *> & projects)
|
|||||||
|
|
||||||
if (!filesToSave.isEmpty()) {
|
if (!filesToSave.isEmpty()) {
|
||||||
bool cancelled;
|
bool cancelled;
|
||||||
Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave, &cancelled,
|
Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave, &cancelled);
|
||||||
tr("The following dependencies are modified, do you want to save them?"));
|
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user