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
|
|
@ -20,10 +20,13 @@
|
|||
#include <QStandardPaths>
|
||||
#include <QStatusBar>
|
||||
#include <QTableView>
|
||||
#include <QApplication>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "EditTableWidget.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "querytool/QueryTool.h"
|
||||
#include "querytool/UnsavedDocumentsDialog.h"
|
||||
#include <serverinspector/ServerInspector.h>
|
||||
|
||||
namespace pg = Pgsql;
|
||||
|
|
@ -91,12 +94,18 @@ void DatabaseWindow::closeEvent(QCloseEvent *event)
|
|||
{
|
||||
for (int idx = 0; idx < ui->mainTabs->count(); ++idx)
|
||||
{
|
||||
if (!canCloseTab(idx))
|
||||
auto mp = dynamic_cast<ManagedPage*>(ui->mainTabs->widget(idx));
|
||||
if (mp && !dynamic_cast<QueryTool*>(mp) && !mp->CanClose(true))
|
||||
{
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto docs = documentsClosedWith(m_masterController->sqlDocumentRegistry().modifiedDocuments(),
|
||||
[this](const QWidget *editor) { return editor->window() == this; });
|
||||
if (!confirmClose(this, docs))
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void DatabaseWindow::setConfig(const ConnectionConfig &config)
|
||||
|
|
@ -199,14 +208,14 @@ void DatabaseWindow::openSqlFile(QString file_name)
|
|||
{
|
||||
if (!file_name.isEmpty())
|
||||
{
|
||||
auto *ct = new QueryTool(this, this);
|
||||
if (ct->load(file_name))
|
||||
auto document = std::make_shared<SqlDocument>();
|
||||
if (document->load(file_name))
|
||||
{
|
||||
m_masterController->sqlDocumentRegistry().add(document);
|
||||
auto *ct = new QueryTool(this, document, this);
|
||||
ct->addAction(ui->actionExecute_query);
|
||||
addPage(ct, ct->title());
|
||||
}
|
||||
else
|
||||
delete ct;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -391,13 +400,53 @@ void DatabaseWindow::on_actionInspect_server_triggered()
|
|||
newServerInspectorPage();
|
||||
}
|
||||
|
||||
void DatabaseWindow::openSharedSqlDocument(std::shared_ptr<SqlDocument> document)
|
||||
{
|
||||
auto *ct = new QueryTool(this, std::move(document), this);
|
||||
ct->addAction(ui->actionExecute_query);
|
||||
addPage(ct, ct->title());
|
||||
ct->updateTitle();
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionNew_Query_triggered()
|
||||
{
|
||||
auto *ct = new QueryTool(this, this);
|
||||
auto document = std::make_shared<SqlDocument>();
|
||||
m_masterController->sqlDocumentRegistry().add(document);
|
||||
auto *ct = new QueryTool(this, document, this);
|
||||
ct->addAction(ui->actionExecute_query);
|
||||
addPage(ct, "new");
|
||||
ct->newdoc();
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionOpen_in_other_window_triggered()
|
||||
{
|
||||
auto ct = dynamic_cast<QueryTool*>(ui->mainTabs->currentWidget());
|
||||
if (!ct)
|
||||
return;
|
||||
|
||||
QList<DatabaseWindow*> others;
|
||||
for (auto *widget : QApplication::topLevelWidgets()) {
|
||||
auto dw = qobject_cast<DatabaseWindow*>(widget);
|
||||
if (dw && dw != this && dw->isVisible())
|
||||
others.append(dw);
|
||||
}
|
||||
|
||||
if (others.isEmpty()) {
|
||||
QMessageBox::information(this, "pglab", tr("No other window is open."));
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList names;
|
||||
for (int i = 0; i < others.size(); ++i)
|
||||
names.append(QString("%1 (%2)").arg(others[i]->windowTitle()).arg(i + 1));
|
||||
|
||||
bool ok = false;
|
||||
QString selected = QInputDialog::getItem(this, tr("Open in other window"),
|
||||
tr("Select window:"), names, 0, false, &ok);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
auto target = others[names.indexOf(selected)];
|
||||
target->openSharedSqlDocument(ct->document());
|
||||
}
|
||||
|
||||
void DatabaseWindow::on_actionOpen_Query_triggered()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue