1
0
Эх сурвалжийг харах

support exporting current note besides current buffer

Le Tan 4 жил өмнө
parent
commit
9c9983411f

+ 1 - 1
.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:

+ 1 - 0
src/export/exportdata.h

@@ -10,6 +10,7 @@ namespace vnotex
     enum class ExportSource
     {
         CurrentBuffer = 0,
+        CurrentNote,
         CurrentFolder,
         CurrentNotebook
     };

+ 21 - 1
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;
 

+ 4 - 1
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);
 

+ 18 - 1
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<int>(ExportSource::CurrentBuffer));
         }
+        if (m_note && m_note->hasContent()) {
+            m_sourceComboBox->addItem(tr("Current Note (%1)").arg(m_note->getName()),
+                                      static_cast<int>(ExportSource::CurrentNote));
+        }
         if (m_folder && m_folder->isContainer()) {
             m_sourceComboBox->addItem(tr("Current Folder (%1)").arg(m_folder->getName()),
                                       static_cast<int>(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;
     }

+ 3 - 0
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.

+ 5 - 0
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();

+ 5 - 0
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) {

+ 2 - 0
src/widgets/notebookexplorer.h

@@ -26,6 +26,8 @@ namespace vnotex
 
         Node *currentExploredFolderNode() const;
 
+        Node *currentExploredNode() const;
+
     public slots:
         void newNotebook();
 

+ 9 - 0
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) {

+ 2 - 0
src/widgets/notebooknodeexplorer.h

@@ -112,6 +112,8 @@ namespace vnotex
 
         Node *currentExploredFolderNode() const;
 
+        Node *currentExploredNode() const;
+
     signals:
         void nodeActivated(Node *p_node, const QSharedPointer<FileOpenParameters> &p_paras);