support exporting current note besides current buffer

This commit is contained in:
Le Tan 2021-03-18 20:19:53 +08:00
parent a2d180ea12
commit 9c9983411f
11 changed files with 71 additions and 4 deletions

View File

@ -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:

View File

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

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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.

View File

@ -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();

View File

@ -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) {

View File

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

View File

@ -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) {

View File

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