Show UnsavedDocumentsDialog when closing window or quitting application
so user can save and or discard docs more efficiently.
This commit is contained in:
parent
b97adced4c
commit
784ad68758
16 changed files with 544 additions and 164 deletions
48
pglab/querytool/UnsavedDocumentsDialog.h
Normal file
48
pglab/querytool/UnsavedDocumentsDialog.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef UNSAVEDDOCUMENTSDIALOG_H
|
||||
#define UNSAVEDDOCUMENTSDIALOG_H
|
||||
|
||||
#include "SqlDocument.h"
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
class QListWidget;
|
||||
|
||||
/** Lists modified documents with a checkbox per document. The user picks
|
||||
* whether the checked documents should be saved or discarded.
|
||||
*/
|
||||
class UnsavedDocumentsDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum class Choice {
|
||||
Cancel,
|
||||
Save,
|
||||
Discard
|
||||
};
|
||||
|
||||
UnsavedDocumentsDialog(const QList<std::shared_ptr<SqlDocument>> &docs, QWidget *parent = nullptr);
|
||||
|
||||
Choice choice() const { return m_choice; }
|
||||
QList<std::shared_ptr<SqlDocument>> checkedDocuments() const;
|
||||
QList<std::shared_ptr<SqlDocument>> uncheckedDocuments() const;
|
||||
|
||||
private:
|
||||
QList<std::shared_ptr<SqlDocument>> m_docs;
|
||||
QListWidget *m_list;
|
||||
Choice m_choice = Choice::Cancel;
|
||||
};
|
||||
|
||||
/** Selects the documents that are closed when every editor for which
|
||||
* isClosing returns true is closed. Only modified documents are returned.
|
||||
*/
|
||||
QList<std::shared_ptr<SqlDocument>> documentsClosedWith(const QList<std::shared_ptr<SqlDocument>> &docs,
|
||||
const std::function<bool(const QWidget*)> &isClosing);
|
||||
|
||||
/** Asks the user what to do with the modified documents. Returns true when
|
||||
* the close may continue, i.e. nothing was cancelled, no save failed and
|
||||
* every listed document was checked.
|
||||
*/
|
||||
bool confirmClose(QWidget *parent, const QList<std::shared_ptr<SqlDocument>> &docs);
|
||||
|
||||
#endif // UNSAVEDDOCUMENTSDIALOG_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue