From ea3bee369dbe10ddf6327b57ebe7301232e03075 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon, 11 Jul 2022 14:20:05 -0700 Subject: [PATCH] app: implement export option --- app/mainwindow.cpp | 22 ++++++++++++++++++++++ app/mainwindow.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index b2377f4..7928e89 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -96,6 +96,7 @@ void MainWindow::InitializeMenuBar() file_menu->addSeparator(); auto export_action = file_menu->addAction(tr("&Export")); + connect(export_action, &QAction::triggered, this, &MainWindow::ExportFile); file_menu->addSeparator(); @@ -123,6 +124,12 @@ void MainWindow::ExtractObject(si::Object *obj) if (filename.isEmpty()) { filename = QString::fromStdString(obj->name()); filename.append(QStringLiteral(".bin")); + } else { + // Strip off directory + int index = filename.lastIndexOf('\\'); + if (index != -1) { + filename = filename.mid(index+1); + } } QString s = QFileDialog::getSaveFileName(this, tr("Export Object"), filename); @@ -146,6 +153,21 @@ void MainWindow::OpenFile() } } +void MainWindow::ExportFile() +{ + Chunk *c = interleaf_.Export(); + SIViewDialog d(SIViewDialog::Export, c, this); + if (d.exec() == QDialog::Accepted) { + QString s = QFileDialog::getSaveFileName(this); + if (!s.isEmpty()) { + if (!c->Write(s.toStdString())) { + QMessageBox::critical(this, QString(), tr("Failed to write SI file.")); + } + } + } + delete c; +} + void MainWindow::SelectionChanged(const QModelIndex &index) { Panel *p = panel_blank_; diff --git a/app/mainwindow.h b/app/mainwindow.h index 2c2b1b9..83af820 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -52,6 +52,8 @@ private slots: //bool SaveFile(); //bool SaveFileAs(); + void ExportFile(); + void SelectionChanged(const QModelIndex &index); void ShowContextMenu(const QPoint &p);