diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 1b603567..ef47efe7 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -15,7 +15,7 @@ env: jobs: build-linux: name: Build On Ubuntu - runs-on: ubuntu-latest + runs-on: ubuntu-18.04 timeout-minutes: 120 steps: diff --git a/src/export/exportdata.h b/src/export/exportdata.h index 6f0732cd..ffb7148f 100644 --- a/src/export/exportdata.h +++ b/src/export/exportdata.h @@ -10,6 +10,7 @@ namespace vnotex enum class ExportSource { CurrentBuffer = 0, + CurrentNote, CurrentFolder, CurrentNotebook }; diff --git a/src/export/exporter.cpp b/src/export/exporter.cpp index acb4425c..c3d2acf1 100644 --- a/src/export/exporter.cpp +++ b/src/export/exporter.cpp @@ -93,7 +93,27 @@ void Exporter::exportAttachments(Node *p_node, } } -QStringList Exporter::doExport(const ExportOption &p_option, Node *p_folder) +QString Exporter::doExport(const ExportOption &p_option, Node *p_note) +{ + m_askedToStop = false; + + QString outputFile; + auto file = p_note->getContentFile(); + + // Make sure output folder exists. + if (!QDir().mkpath(p_option.m_outputDir)) { + emit logRequested(tr("Failed to create output folder %1.").arg(p_option.m_outputDir)); + return outputFile; + } + + outputFile = doExport(p_option, p_option.m_outputDir, file.data()); + + cleanUp(); + + return outputFile; +} + +QStringList Exporter::doExportFolder(const ExportOption &p_option, Node *p_folder) { m_askedToStop = false; diff --git a/src/export/exporter.h b/src/export/exporter.h index 949eb366..34c345ab 100644 --- a/src/export/exporter.h +++ b/src/export/exporter.h @@ -24,8 +24,11 @@ namespace vnotex // Return exported output file. QString doExport(const ExportOption &p_option, Buffer *p_buffer); + // Return exported output file. + QString doExport(const ExportOption &p_option, Node *p_note); + // Return exported output files. - QStringList doExport(const ExportOption &p_option, Node *p_folder); + QStringList doExportFolder(const ExportOption &p_option, Node *p_folder); QStringList doExport(const ExportOption &p_option, Notebook *p_notebook); diff --git a/src/widgets/dialogs/exportdialog.cpp b/src/widgets/dialogs/exportdialog.cpp index 13d679ff..cd1631a0 100644 --- a/src/widgets/dialogs/exportdialog.cpp +++ b/src/widgets/dialogs/exportdialog.cpp @@ -37,11 +37,13 @@ using namespace vnotex; ExportDialog::ExportDialog(Notebook *p_notebook, Node *p_folder, + Node *p_note, Buffer *p_buffer, QWidget *p_parent) : ScrollDialog(p_parent), m_notebook(p_notebook), m_folder(p_folder), + m_note(p_note), m_buffer(p_buffer) { setupUI(); @@ -94,6 +96,10 @@ QGroupBox *ExportDialog::setupSourceGroup(QWidget *p_parent) m_sourceComboBox->addItem(tr("Current Buffer (%1)").arg(m_buffer->getName()), static_cast(ExportSource::CurrentBuffer)); } + if (m_note && m_note->hasContent()) { + m_sourceComboBox->addItem(tr("Current Note (%1)").arg(m_note->getName()), + static_cast(ExportSource::CurrentNote)); + } if (m_folder && m_folder->isContainer()) { m_sourceComboBox->addItem(tr("Current Folder (%1)").arg(m_folder->getName()), static_cast(ExportSource::CurrentFolder)); @@ -431,10 +437,21 @@ int ExportDialog::doExport(ExportOption p_option) break; } + case ExportSource::CurrentNote: + { + Q_ASSERT(m_note); + const auto outputFile = getExporter()->doExport(p_option, m_note); + exportedFilesCount = outputFile.isEmpty() ? 0 : 1; + if (exportedFilesCount == 1 && p_option.m_targetFormat == ExportFormat::HTML) { + m_exportedFile = outputFile; + } + break; + } + case ExportSource::CurrentFolder: { Q_ASSERT(m_folder); - const auto outputFiles = getExporter()->doExport(p_option, m_folder); + const auto outputFiles = getExporter()->doExportFolder(p_option, m_folder); exportedFilesCount = outputFiles.size(); break; } diff --git a/src/widgets/dialogs/exportdialog.h b/src/widgets/dialogs/exportdialog.h index 2a743884..d18d6dc5 100644 --- a/src/widgets/dialogs/exportdialog.h +++ b/src/widgets/dialogs/exportdialog.h @@ -30,6 +30,7 @@ namespace vnotex // Current notebook/folder/buffer. ExportDialog(Notebook *p_notebook, Node *p_folder, + Node *p_note, Buffer *p_buffer, QWidget *p_parent = nullptr); @@ -104,6 +105,8 @@ namespace vnotex Node *m_folder = nullptr; + Node *m_note = nullptr; + Buffer *m_buffer = nullptr; // Last exported single file. diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index 10ed8de9..114fa1dd 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -632,8 +632,13 @@ void MainWindow::exportNotes() if (folderNode && (folderNode->isRoot() || currentNotebook->isRecycleBinNode(folderNode))) { folderNode = nullptr; } + auto noteNode = m_notebookExplorer->currentExploredNode(); + if (noteNode && !noteNode->hasContent()) { + noteNode = nullptr; + } ExportDialog dialog(currentNotebook, folderNode, + noteNode, viewWindow ? viewWindow->getBuffer() : nullptr, this); dialog.exec(); diff --git a/src/widgets/notebookexplorer.cpp b/src/widgets/notebookexplorer.cpp index 35622c0d..050c57c1 100644 --- a/src/widgets/notebookexplorer.cpp +++ b/src/widgets/notebookexplorer.cpp @@ -245,6 +245,11 @@ Node *NotebookExplorer::currentExploredFolderNode() const return m_nodeExplorer->currentExploredFolderNode(); } +Node *NotebookExplorer::currentExploredNode() const +{ + return m_nodeExplorer->currentExploredNode(); +} + Node *NotebookExplorer::checkNotebookAndGetCurrentExploredFolderNode() const { if (!m_currentNotebook) { diff --git a/src/widgets/notebookexplorer.h b/src/widgets/notebookexplorer.h index 7024a62f..1b6b761e 100644 --- a/src/widgets/notebookexplorer.h +++ b/src/widgets/notebookexplorer.h @@ -26,6 +26,8 @@ namespace vnotex Node *currentExploredFolderNode() const; + Node *currentExploredNode() const; + public slots: void newNotebook(); diff --git a/src/widgets/notebooknodeexplorer.cpp b/src/widgets/notebooknodeexplorer.cpp index 5aa59297..1d1caeb9 100644 --- a/src/widgets/notebooknodeexplorer.cpp +++ b/src/widgets/notebooknodeexplorer.cpp @@ -1738,6 +1738,15 @@ Node *NotebookNodeExplorer::currentExploredFolderNode() const return node; } +Node *NotebookNodeExplorer::currentExploredNode() const +{ + if (!m_notebook) { + return nullptr; + } + + return getCurrentNode(); +} + void NotebookNodeExplorer::setViewOrder(int p_order) { if (m_viewOrder == p_order) { diff --git a/src/widgets/notebooknodeexplorer.h b/src/widgets/notebooknodeexplorer.h index b50762f5..58e823ed 100644 --- a/src/widgets/notebooknodeexplorer.h +++ b/src/widgets/notebooknodeexplorer.h @@ -112,6 +112,8 @@ namespace vnotex Node *currentExploredFolderNode() const; + Node *currentExploredNode() const; + signals: void nodeActivated(Node *p_node, const QSharedPointer &p_paras);