mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
small fixes
This commit is contained in:
parent
2740983308
commit
bb1598dde2
@ -10,6 +10,7 @@
|
|||||||
#include <utils/htmlutils.h>
|
#include <utils/htmlutils.h>
|
||||||
#include <core/thememgr.h>
|
#include <core/thememgr.h>
|
||||||
#include <core/vnotex.h>
|
#include <core/vnotex.h>
|
||||||
|
#include <core/exception.h>
|
||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
@ -48,7 +49,11 @@ static void fillGlobalStyles(QString &p_template, const WebResource &p_resource,
|
|||||||
for (const auto &style : ele.m_styles) {
|
for (const auto &style : ele.m_styles) {
|
||||||
// Read the style file content.
|
// Read the style file content.
|
||||||
auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style);
|
auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style);
|
||||||
styles += FileUtils::readTextFile(styleFile);
|
try {
|
||||||
|
styles += FileUtils::readTextFile(styleFile);
|
||||||
|
} catch (Exception &p_e) {
|
||||||
|
qWarning() << "failed to read global styles" << ele.m_name << styleFile << p_e.what();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -138,16 +143,20 @@ static void fillResourcesByContent(QString &p_template, const WebResource &p_res
|
|||||||
|
|
||||||
for (const auto &ele : p_resource.m_resources) {
|
for (const auto &ele : p_resource.m_resources) {
|
||||||
if (ele.m_enabled && !ele.isGlobal()) {
|
if (ele.m_enabled && !ele.isGlobal()) {
|
||||||
// Styles.
|
try {
|
||||||
for (const auto &style : ele.m_styles) {
|
// Styles.
|
||||||
auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style);
|
for (const auto &style : ele.m_styles) {
|
||||||
styles += FileUtils::readTextFile(styleFile);
|
auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style);
|
||||||
}
|
styles += FileUtils::readTextFile(styleFile);
|
||||||
|
}
|
||||||
|
|
||||||
// Scripts.
|
// Scripts.
|
||||||
for (const auto &script : ele.m_scripts) {
|
for (const auto &script : ele.m_scripts) {
|
||||||
auto scriptFile = ConfigMgr::getInst().getUserOrAppFile(script);
|
auto scriptFile = ConfigMgr::getInst().getUserOrAppFile(script);
|
||||||
scripts += FileUtils::readTextFile(scriptFile);
|
scripts += FileUtils::readTextFile(scriptFile);
|
||||||
|
}
|
||||||
|
} catch (Exception &p_e) {
|
||||||
|
qWarning() << "failed to read resource" << ele.m_name << p_e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,7 +195,13 @@ QString HtmlTemplateHelper::generateMarkdownViewerTemplate(const MarkdownEditorC
|
|||||||
{
|
{
|
||||||
const auto &viewerResource = p_config.getViewerResource();
|
const auto &viewerResource = p_config.getViewerResource();
|
||||||
const auto templateFile = ConfigMgr::getInst().getUserOrAppFile(viewerResource.m_template);
|
const auto templateFile = ConfigMgr::getInst().getUserOrAppFile(viewerResource.m_template);
|
||||||
auto htmlTemplate = FileUtils::readTextFile(templateFile);
|
QString htmlTemplate;
|
||||||
|
try {
|
||||||
|
htmlTemplate = FileUtils::readTextFile(templateFile);
|
||||||
|
} catch (Exception &p_e) {
|
||||||
|
qWarning() << "failed to read HTML template" << templateFile << p_e.what();
|
||||||
|
return errorPage();
|
||||||
|
}
|
||||||
|
|
||||||
fillGlobalStyles(htmlTemplate, viewerResource, "");
|
fillGlobalStyles(htmlTemplate, viewerResource, "");
|
||||||
|
|
||||||
@ -224,7 +239,13 @@ QString HtmlTemplateHelper::generateExportTemplate(const MarkdownEditorConfig &p
|
|||||||
{
|
{
|
||||||
auto exportResource = p_config.getExportResource();
|
auto exportResource = p_config.getExportResource();
|
||||||
const auto templateFile = ConfigMgr::getInst().getUserOrAppFile(exportResource.m_template);
|
const auto templateFile = ConfigMgr::getInst().getUserOrAppFile(exportResource.m_template);
|
||||||
auto htmlTemplate = FileUtils::readTextFile(templateFile);
|
QString htmlTemplate;
|
||||||
|
try {
|
||||||
|
htmlTemplate = FileUtils::readTextFile(templateFile);
|
||||||
|
} catch (Exception &p_e) {
|
||||||
|
qWarning() << "failed to read export HTML template" << templateFile << p_e.what();
|
||||||
|
return errorPage();
|
||||||
|
}
|
||||||
|
|
||||||
fillGlobalStyles(htmlTemplate, exportResource, "");
|
fillGlobalStyles(htmlTemplate, exportResource, "");
|
||||||
|
|
||||||
@ -287,3 +308,9 @@ void HtmlTemplateHelper::fillBodyClassList(QString &p_template, const QString &p
|
|||||||
{
|
{
|
||||||
p_template.replace("<!-- VX_BODY_CLASS_LIST_PLACEHOLDER -->", p_classList);
|
p_template.replace("<!-- VX_BODY_CLASS_LIST_PLACEHOLDER -->", p_classList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString HtmlTemplateHelper::errorPage()
|
||||||
|
{
|
||||||
|
return VNoteX::tr("Failed to load HTML template. Check the logs for details. "
|
||||||
|
"Try deleting the user configuration file and the default configuration file.");
|
||||||
|
}
|
||||||
|
@ -103,6 +103,8 @@ namespace vnotex
|
|||||||
static void fillOutlinePanel(QString &p_template, WebResource &p_exportResource, bool p_addOutlinePanel);
|
static void fillOutlinePanel(QString &p_template, WebResource &p_exportResource, bool p_addOutlinePanel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static QString errorPage();
|
||||||
|
|
||||||
struct Template
|
struct Template
|
||||||
{
|
{
|
||||||
int m_revision = -1;
|
int m_revision = -1;
|
||||||
|
@ -64,6 +64,8 @@ namespace vnotex
|
|||||||
// Requested to import a legacy notebook from VNote 2.0.
|
// Requested to import a legacy notebook from VNote 2.0.
|
||||||
void importLegacyNotebookRequested();
|
void importLegacyNotebookRequested();
|
||||||
|
|
||||||
|
void manageNotebooksRequested();
|
||||||
|
|
||||||
// Requested to import files.
|
// Requested to import files.
|
||||||
void importFileRequested();
|
void importFileRequested();
|
||||||
|
|
||||||
|
@ -295,6 +295,8 @@ void MainWindow::setupNotebookExplorer(QWidget *p_parent)
|
|||||||
m_notebookExplorer, &NotebookExplorer::importFolder);
|
m_notebookExplorer, &NotebookExplorer::importFolder);
|
||||||
connect(&VNoteX::getInst(), &VNoteX::importLegacyNotebookRequested,
|
connect(&VNoteX::getInst(), &VNoteX::importLegacyNotebookRequested,
|
||||||
m_notebookExplorer, &NotebookExplorer::importLegacyNotebook);
|
m_notebookExplorer, &NotebookExplorer::importLegacyNotebook);
|
||||||
|
connect(&VNoteX::getInst(), &VNoteX::manageNotebooksRequested,
|
||||||
|
m_notebookExplorer, &NotebookExplorer::manageNotebooks);
|
||||||
connect(&VNoteX::getInst(), &VNoteX::locateNodeRequested,
|
connect(&VNoteX::getInst(), &VNoteX::locateNodeRequested,
|
||||||
this, [this](Node *p_node) {
|
this, [this](Node *p_node) {
|
||||||
m_dockWidgetHelper.activateDock(DockWidgetHelper::NavigationDock);
|
m_dockWidgetHelper.activateDock(DockWidgetHelper::NavigationDock);
|
||||||
|
@ -164,16 +164,11 @@ TitleBar *NotebookExplorer::setupTitleBar(QWidget *p_parent)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
titleBar->addMenuAction(QStringLiteral("manage_notebooks.svg"),
|
{
|
||||||
tr("&Manage Notebooks"),
|
auto btn = titleBar->addActionButton(QStringLiteral("manage_notebooks.svg"), tr("Manage Notebooks"));
|
||||||
titleBar,
|
connect(btn, &QToolButton::clicked,
|
||||||
[this]() {
|
this, &NotebookExplorer::manageNotebooks);
|
||||||
ManageNotebooksDialog dialog(m_currentNotebook.data(),
|
}
|
||||||
VNoteX::getInst().getMainWindow());
|
|
||||||
dialog.exec();
|
|
||||||
});
|
|
||||||
|
|
||||||
titleBar->addMenuSeparator();
|
|
||||||
|
|
||||||
// External Files menu.
|
// External Files menu.
|
||||||
{
|
{
|
||||||
@ -404,6 +399,12 @@ void NotebookExplorer::importLegacyNotebook()
|
|||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotebookExplorer::manageNotebooks()
|
||||||
|
{
|
||||||
|
ManageNotebooksDialog dialog(m_currentNotebook.data(), VNoteX::getInst().getMainWindow());
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
|
||||||
void NotebookExplorer::locateNode(Node *p_node)
|
void NotebookExplorer::locateNode(Node *p_node)
|
||||||
{
|
{
|
||||||
Q_ASSERT(p_node);
|
Q_ASSERT(p_node);
|
||||||
|
@ -55,6 +55,8 @@ namespace vnotex
|
|||||||
|
|
||||||
void locateNode(Node *p_node);
|
void locateNode(Node *p_node);
|
||||||
|
|
||||||
|
void manageNotebooks();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void notebookActivated(ID p_notebookId);
|
void notebookActivated(ID p_notebookId);
|
||||||
|
|
||||||
|
@ -96,6 +96,16 @@ QToolBar *ToolBarHelper::setupFileToolBar(MainWindow *p_win, QToolBar *p_toolBar
|
|||||||
[]() {
|
[]() {
|
||||||
emit VNoteX::getInst().importLegacyNotebookRequested();
|
emit VNoteX::getInst().importLegacyNotebookRequested();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
btnMenu->addSeparator();
|
||||||
|
|
||||||
|
// Manage notebook.
|
||||||
|
btnMenu->addAction(generateIcon("manage_notebooks.svg"),
|
||||||
|
MainWindow::tr("Manage Notebooks"),
|
||||||
|
btnMenu,
|
||||||
|
[]() {
|
||||||
|
emit VNoteX::getInst().manageNotebooksRequested();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// New Note.
|
// New Note.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user