working add items

This commit is contained in:
mappu 2017-05-21 17:59:27 +12:00
parent 4f1c48b55d
commit 7c62abb352
2 changed files with 34 additions and 16 deletions

View File

@ -282,6 +282,29 @@ void MainWindow::on_actionClear_selection_triggered()
} \ } \
auto *bdb = GET_BDB(top); auto *bdb = GET_BDB(top);
void MainWindow::openEditor(BoltDB *bdb, QStringList saveAs, QByteArray saveAsKey, QByteArray currentContent)
{
auto iw = new ItemWindow();
iw->ContentArea()->setPlainText(QString::fromUtf8(currentContent));
iw->setWindowTitle(QString::fromUtf8(saveAsKey));
iw->setWindowModality(Qt::ApplicationModal); // we need this - otherwise we'll refresh a possibly-changed area after saving
connect(iw, &ItemWindow::finished, iw, [=](int exitCode){
if (exitCode == ItemWindow::Accepted) {
QString err;
if (! bdb->setItem(saveAs, saveAsKey, iw->ContentArea()->toPlainText().toUtf8(), err)) {
QMessageBox qmb;
qmb.setText(tr("Error saving item content: %1").arg(err));
qmb.exec();
}
refreshData(bdb, saveAs);
}
iw->deleteLater();
});
iw->show();
}
void MainWindow::on_bucketData_doubleClicked(const QModelIndex &index) void MainWindow::on_bucketData_doubleClicked(const QModelIndex &index)
{ {
GET_ITM_TOP_BROWSE_BDB; GET_ITM_TOP_BROWSE_BDB;
@ -297,22 +320,7 @@ void MainWindow::on_bucketData_doubleClicked(const QModelIndex &index)
browse, browse,
key.toUtf8(), key.toUtf8(),
[=](QByteArray content) { [=](QByteArray content) {
auto iw = new ItemWindow(); openEditor(bdb, browse, key.toUtf8(), content);
iw->ContentArea()->setPlainText(QString::fromUtf8(content));
iw->setWindowTitle(key);
connect(iw, &ItemWindow::finished, iw, [=](int exitCode){
if (exitCode == ItemWindow::Accepted) {
QString err;
if (! bdb->setItem(browse, key.toUtf8(), iw->ContentArea()->toPlainText().toUtf8(), err)) {
QMessageBox qmb;
qmb.setText(tr("Error saving item content: %1").arg(err));
qmb.exec();
}
}
iw->deleteLater();
});
iw->show();
}, },
[=](QString error) { [=](QString error) {
QMessageBox qmb; QMessageBox qmb;
@ -378,7 +386,16 @@ void MainWindow::on_actionDelete_bucket_triggered()
void MainWindow::on_AddDataButton_clicked() void MainWindow::on_AddDataButton_clicked()
{ {
GET_ITM_TOP_BROWSE_BDB;
// Prompt for bucket name
QString name = QInputDialog::getText(this, tr("New item"), tr("Enter a key for the new item:"));
if (name.length() == 0) {
return;
}
openEditor(bdb, browse, name.toUtf8(), QByteArray());
} }
void MainWindow::on_DeleteDataButton_clicked() void MainWindow::on_DeleteDataButton_clicked()

View File

@ -55,6 +55,7 @@ protected:
void openDatabase(QString file); void openDatabase(QString file);
void refreshBucketTree(QTreeWidgetItem* top); void refreshBucketTree(QTreeWidgetItem* top);
void refreshData(BoltDB *bdb, QStringList browse); void refreshData(BoltDB *bdb, QStringList browse);
void openEditor(BoltDB *bdb, QStringList saveAs, QByteArray saveAsKey, QByteArray currentContent);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;