Commit bd2a163f authored by con's avatar con
Browse files

Simplify 'Save modified files' internals.

parent 87fdacba
......@@ -46,7 +46,7 @@ using namespace Core;
using namespace Core::Internal;
SaveItemsDialog::SaveItemsDialog(QWidget *parent,
QMap<IFile*, QString> items)
QList<IFile *> items)
: QDialog(parent)
{
m_ui.setupUi(this);
......@@ -55,13 +55,12 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
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
QMap<IFile*, QString>::const_iterator it = items.constBegin();
while (it != items.constEnd()) {
foreach (IFile *file, items) {
QString visibleName;
QString directory;
QString fileName = it.key()->fileName();
QString fileName = file->fileName();
if (fileName.isEmpty()) {
visibleName = it.key()->suggestedFileName();
visibleName = file->suggestedFileName();
} else {
QFileInfo info = QFileInfo(fileName);
directory = info.absolutePath();
......@@ -69,8 +68,7 @@ SaveItemsDialog::SaveItemsDialog(QWidget *parent,
}
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.treeWidget, QStringList()
<< visibleName << directory);
item->setData(0, Qt::UserRole, qVariantFromValue(it.key()));
++it;
item->setData(0, Qt::UserRole, qVariantFromValue(file));
}
m_ui.treeWidget->resizeColumnToContents(0);
......@@ -123,8 +121,3 @@ QList<IFile*> SaveItemsDialog::itemsToSave() const
{
return m_itemsToSave;
}
QSet<IFile*> SaveItemsDialog::itemsToOpenWithVCS() const
{
return m_itemsToSave.toSet();
}
......@@ -54,12 +54,11 @@ class SaveItemsDialog : public QDialog
public:
SaveItemsDialog(QWidget *parent,
QMap<Core::IFile*, QString> items);
QList<Core::IFile *> items);
void setMessage(const QString &msg);
QList<Core::IFile*> itemsToSave() const;
QSet<Core::IFile*> itemsToOpenWithVCS() const;
QList<Core::IFile *> itemsToSave() const;
private slots:
void collectItemsToSave();
......@@ -69,7 +68,6 @@ private slots:
private:
Ui::SaveItemsDialog m_ui;
QList<Core::IFile*> m_itemsToSave;
QSet<Core::IFile*> m_itemsToOpen;
};
} // namespace Internal
......
......@@ -36,7 +36,6 @@
#include "icore.h"
#include "iversioncontrol.h"
#include "mimedatabase.h"
#include "saveitemsdialog.h"
#include "tabpositionindicator.h"
#include "vcsmanager.h"
......
......@@ -314,7 +314,8 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
(*cancelled) = false;
QList<IFile *> notSaved;
QMap<IFile*, QString> modifiedFiles;
QMap<IFile *, QString> modifiedFilesMap;
QList<IFile *> modifiedFiles;
foreach (IFile *file, files) {
if (file->isModified()) {
......@@ -324,17 +325,16 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
// There can be several FileInterfaces pointing to the same file
// Select one that is not readonly.
if (!(modifiedFiles.values().contains(name)
if (!(modifiedFilesMap.values().contains(name)
&& file->isReadOnly()))
modifiedFiles.insert(file, name);
modifiedFilesMap.insert(file, name);
}
}
modifiedFiles = modifiedFilesMap.keys();
if (!modifiedFiles.isEmpty()) {
QList<IFile *> filesToSave;
QSet<IFile *> filesToOpen;
if (silently) {
filesToSave = modifiedFiles.keys();
filesToSave = modifiedFiles;
} else {
SaveItemsDialog dia(m_mainWindow, modifiedFiles);
if (!message.isEmpty())
......@@ -342,16 +342,15 @@ QList<IFile *> FileManager::saveModifiedFiles(const QList<IFile *> &files,
if (dia.exec() != QDialog::Accepted) {
if (cancelled)
(*cancelled) = true;
notSaved = modifiedFiles.keys();
notSaved = modifiedFiles;
return notSaved;
}
filesToSave = dia.itemsToSave();
filesToOpen = dia.itemsToOpenWithVCS();
}
bool yestoall = false;
foreach (IFile *file, filesToSave) {
if (file->isReadOnly() && filesToOpen.contains(file)) {
if (file->isReadOnly()) {
QString directory = QFileInfo(file->fileName()).absolutePath();
IVersionControl *versionControl = m_mainWindow->vcsManager()->findVersionControlForDirectory(directory);
if (versionControl)
......
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