diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-07-03 10:16:25 +0200 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-07-03 10:16:25 +0200 |
commit | 9cef3efa2251833883e0f1fcf47138776e2a45aa (patch) | |
tree | 6ab8bb8eeb3163cc5bdf138d953ee5841187aea2 /qtmips_gui/mainwindow.cpp | |
parent | 9f4c221eb9767adec56f57c2479be5fa38049397 (diff) | |
download | qtmips-9cef3efa2251833883e0f1fcf47138776e2a45aa.tar.gz qtmips-9cef3efa2251833883e0f1fcf47138776e2a45aa.tar.bz2 qtmips-9cef3efa2251833883e0f1fcf47138776e2a45aa.zip |
Implement file save for emscripten build.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/mainwindow.cpp')
-rw-r--r-- | qtmips_gui/mainwindow.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index d0338cc..f300b5e 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -555,6 +555,7 @@ void MainWindow::open_source() { void MainWindow::save_source_as() { if (current_srceditor == nullptr) return; +#ifndef __EMSCRIPTEN__ QFileDialog fileDialog(this, tr("Save as...")); fileDialog.setAcceptMode(QFileDialog::AcceptSave); fileDialog.setDefaultSuffix("s"); @@ -568,6 +569,17 @@ void MainWindow::save_source_as() { } else { QMessageBox::critical(this, "QtMips Error", tr("Cannot save file '%1'.").arg(fn)); } +#else + bool ok; + QString text = QInputDialog::getText(this, tr("Select file name"), + tr("File name:"), QLineEdit::Normal, + "unknow.s", &ok); + if (ok && !text.isEmpty()) { + current_srceditor->setFileName(text); + if (!current_srceditor->filename().isEmpty()) + save_source(); + } +#endif update_open_file_list(); } @@ -576,9 +588,14 @@ void MainWindow::save_source() { return; if (current_srceditor->filename().isEmpty()) return save_source_as(); +#ifndef __EMSCRIPTEN__ if (!current_srceditor->saveFile()) { QMessageBox::critical(this, "QtMips Error", tr("Cannot save file '%1'.").arg(current_srceditor->filename())); } +#else + QHtml5File::save(current_srceditor->document()->toPlainText().toUtf8(), + current_srceditor->filename()); +#endif } void MainWindow::close_source() { |