mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
export: support copying exported file's content
This commit is contained in:
parent
b355872c5f
commit
925833d590
@ -4,6 +4,9 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
|
|
||||||
#ifndef QT_NO_PRINTER
|
#ifndef QT_NO_PRINTER
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
@ -11,6 +14,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
|
#include "utils/vclipboardutils.h"
|
||||||
#include "vlineedit.h"
|
#include "vlineedit.h"
|
||||||
#include "vnotebook.h"
|
#include "vnotebook.h"
|
||||||
#include "vfile.h"
|
#include "vfile.h"
|
||||||
@ -127,7 +131,11 @@ void VExportDialog::setupUI()
|
|||||||
// Ok is the default button.
|
// Ok is the default button.
|
||||||
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Close);
|
||||||
m_exportBtn = m_btnBox->addButton(tr("Export"), QDialogButtonBox::ActionRole);
|
m_exportBtn = m_btnBox->addButton(tr("Export"), QDialogButtonBox::ActionRole);
|
||||||
m_openBtn = m_btnBox->addButton(tr("Open Output Directory"), QDialogButtonBox::ActionRole);
|
m_openBtn = m_btnBox->addButton(tr("Open Directory"), QDialogButtonBox::ActionRole);
|
||||||
|
m_openBtn->setToolTip(tr("Open output directory"));
|
||||||
|
m_copyBtn = m_btnBox->addButton(tr("Copy Content"), QDialogButtonBox::ActionRole);
|
||||||
|
m_copyBtn->setToolTip(tr("Copy the content of the exported file"));
|
||||||
|
m_copyBtn->setEnabled(false);
|
||||||
connect(m_btnBox, &QDialogButtonBox::rejected,
|
connect(m_btnBox, &QDialogButtonBox::rejected,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
if (m_inExport) {
|
if (m_inExport) {
|
||||||
@ -150,6 +158,28 @@ void VExportDialog::setupUI()
|
|||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(m_copyBtn, &QPushButton::clicked,
|
||||||
|
this, [this]() {
|
||||||
|
if (m_exportedFile.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ret = false;
|
||||||
|
QString content = VUtils::readFileFromDisk(m_exportedFile);
|
||||||
|
if (!content.isNull()) {
|
||||||
|
QMimeData *data = new QMimeData();
|
||||||
|
data->setText(content);
|
||||||
|
VClipboardUtils::setMimeDataToClipboard(QApplication::clipboard(), data, QClipboard::Clipboard);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
appendLogLine(tr("Copied content of file %1").arg(m_exportedFile));
|
||||||
|
} else {
|
||||||
|
appendLogLine(tr("Fail to copy content of file %1").arg(m_exportedFile));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Progress bar.
|
// Progress bar.
|
||||||
m_proBar = new QProgressBar();
|
m_proBar = new QProgressBar();
|
||||||
m_proBar->setRange(0, 0);
|
m_proBar->setRange(0, 0);
|
||||||
@ -524,6 +554,8 @@ void VExportDialog::startExport()
|
|||||||
m_askedToStop = false;
|
m_askedToStop = false;
|
||||||
m_exporter->setAskedToStop(false);
|
m_exporter->setAskedToStop(false);
|
||||||
m_inExport = true;
|
m_inExport = true;
|
||||||
|
m_exportedFile.clear();
|
||||||
|
m_copyBtn->setEnabled(false);
|
||||||
|
|
||||||
QString outputFolder = QDir::cleanPath(QDir(getOutputDirectory()).absolutePath());
|
QString outputFolder = QDir::cleanPath(QDir(getOutputDirectory()).absolutePath());
|
||||||
|
|
||||||
@ -655,8 +687,16 @@ void VExportDialog::startExport()
|
|||||||
} else {
|
} else {
|
||||||
switch (s_opt.m_source) {
|
switch (s_opt.m_source) {
|
||||||
case ExportSource::CurrentNote:
|
case ExportSource::CurrentNote:
|
||||||
ret = doExport(m_file, s_opt, outputFolder, &msg);
|
{
|
||||||
|
QStringList files;
|
||||||
|
ret = doExport(m_file, s_opt, outputFolder, &msg, &files);
|
||||||
|
if (ret == 1 && s_opt.m_format == ExportFormat::HTML) {
|
||||||
|
Q_ASSERT(files.size() == 1);
|
||||||
|
m_exportedFile = files.first();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ExportSource::CurrentFolder:
|
case ExportSource::CurrentFolder:
|
||||||
ret = doExport(m_directory, s_opt, outputFolder, &msg);
|
ret = doExport(m_directory, s_opt, outputFolder, &msg);
|
||||||
@ -698,6 +738,8 @@ exit:
|
|||||||
m_inExport = false;
|
m_inExport = false;
|
||||||
m_exportBtn->setEnabled(true);
|
m_exportBtn->setEnabled(true);
|
||||||
m_proBar->hide();
|
m_proBar->hide();
|
||||||
|
|
||||||
|
m_copyBtn->setEnabled(!m_exportedFile.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VExportDialog::getOutputDirectory() const
|
QString VExportDialog::getOutputDirectory() const
|
||||||
|
@ -417,6 +417,8 @@ private:
|
|||||||
|
|
||||||
QPushButton *m_exportBtn;
|
QPushButton *m_exportBtn;
|
||||||
|
|
||||||
|
QPushButton *m_copyBtn;
|
||||||
|
|
||||||
QLabel *m_layoutLabel;
|
QLabel *m_layoutLabel;
|
||||||
|
|
||||||
QCheckBox *m_wkhtmltopdfCB;
|
QCheckBox *m_wkhtmltopdfCB;
|
||||||
@ -480,6 +482,9 @@ private:
|
|||||||
// Exporter used to export PDF and HTML.
|
// Exporter used to export PDF and HTML.
|
||||||
VExporter *m_exporter;
|
VExporter *m_exporter;
|
||||||
|
|
||||||
|
// Last exproted file path.
|
||||||
|
QString m_exportedFile;
|
||||||
|
|
||||||
// Last output folder path.
|
// Last output folder path.
|
||||||
static QString s_lastOutputFolder;
|
static QString s_lastOutputFolder;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user