diff --git a/src/core/htmltemplatehelper.cpp b/src/core/htmltemplatehelper.cpp index 8bb809ee..e2ef4650 100644 --- a/src/core/htmltemplatehelper.cpp +++ b/src/core/htmltemplatehelper.cpp @@ -10,6 +10,7 @@ #include #include #include +#include using namespace vnotex; @@ -48,7 +49,11 @@ static void fillGlobalStyles(QString &p_template, const WebResource &p_resource, for (const auto &style : ele.m_styles) { // Read the style file content. 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; @@ -138,16 +143,20 @@ static void fillResourcesByContent(QString &p_template, const WebResource &p_res for (const auto &ele : p_resource.m_resources) { if (ele.m_enabled && !ele.isGlobal()) { - // Styles. - for (const auto &style : ele.m_styles) { - auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style); - styles += FileUtils::readTextFile(styleFile); - } + try { + // Styles. + for (const auto &style : ele.m_styles) { + auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style); + styles += FileUtils::readTextFile(styleFile); + } - // Scripts. - for (const auto &script : ele.m_scripts) { - auto scriptFile = ConfigMgr::getInst().getUserOrAppFile(script); - scripts += FileUtils::readTextFile(scriptFile); + // Scripts. + for (const auto &script : ele.m_scripts) { + auto scriptFile = ConfigMgr::getInst().getUserOrAppFile(script); + 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 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, ""); @@ -224,7 +239,13 @@ QString HtmlTemplateHelper::generateExportTemplate(const MarkdownEditorConfig &p { auto exportResource = p_config.getExportResource(); 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, ""); @@ -287,3 +308,9 @@ void HtmlTemplateHelper::fillBodyClassList(QString &p_template, const QString &p { p_template.replace("", 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."); +} diff --git a/src/core/htmltemplatehelper.h b/src/core/htmltemplatehelper.h index e49e2847..6f91ff29 100644 --- a/src/core/htmltemplatehelper.h +++ b/src/core/htmltemplatehelper.h @@ -103,6 +103,8 @@ namespace vnotex static void fillOutlinePanel(QString &p_template, WebResource &p_exportResource, bool p_addOutlinePanel); private: + static QString errorPage(); + struct Template { int m_revision = -1; diff --git a/src/core/vnotex.h b/src/core/vnotex.h index 8ab5cbe5..87fe08ba 100644 --- a/src/core/vnotex.h +++ b/src/core/vnotex.h @@ -64,6 +64,8 @@ namespace vnotex // Requested to import a legacy notebook from VNote 2.0. void importLegacyNotebookRequested(); + void manageNotebooksRequested(); + // Requested to import files. void importFileRequested(); diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index a25b1c3b..a2ca46b7 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -295,6 +295,8 @@ void MainWindow::setupNotebookExplorer(QWidget *p_parent) m_notebookExplorer, &NotebookExplorer::importFolder); connect(&VNoteX::getInst(), &VNoteX::importLegacyNotebookRequested, m_notebookExplorer, &NotebookExplorer::importLegacyNotebook); + connect(&VNoteX::getInst(), &VNoteX::manageNotebooksRequested, + m_notebookExplorer, &NotebookExplorer::manageNotebooks); connect(&VNoteX::getInst(), &VNoteX::locateNodeRequested, this, [this](Node *p_node) { m_dockWidgetHelper.activateDock(DockWidgetHelper::NavigationDock); diff --git a/src/widgets/notebookexplorer.cpp b/src/widgets/notebookexplorer.cpp index 0920e3cf..d2fd712b 100644 --- a/src/widgets/notebookexplorer.cpp +++ b/src/widgets/notebookexplorer.cpp @@ -164,16 +164,11 @@ TitleBar *NotebookExplorer::setupTitleBar(QWidget *p_parent) }); } - titleBar->addMenuAction(QStringLiteral("manage_notebooks.svg"), - tr("&Manage Notebooks"), - titleBar, - [this]() { - ManageNotebooksDialog dialog(m_currentNotebook.data(), - VNoteX::getInst().getMainWindow()); - dialog.exec(); - }); - - titleBar->addMenuSeparator(); + { + auto btn = titleBar->addActionButton(QStringLiteral("manage_notebooks.svg"), tr("Manage Notebooks")); + connect(btn, &QToolButton::clicked, + this, &NotebookExplorer::manageNotebooks); + } // External Files menu. { @@ -404,6 +399,12 @@ void NotebookExplorer::importLegacyNotebook() dialog.exec(); } +void NotebookExplorer::manageNotebooks() +{ + ManageNotebooksDialog dialog(m_currentNotebook.data(), VNoteX::getInst().getMainWindow()); + dialog.exec(); +} + void NotebookExplorer::locateNode(Node *p_node) { Q_ASSERT(p_node); diff --git a/src/widgets/notebookexplorer.h b/src/widgets/notebookexplorer.h index 61f047eb..b9f345cd 100644 --- a/src/widgets/notebookexplorer.h +++ b/src/widgets/notebookexplorer.h @@ -55,6 +55,8 @@ namespace vnotex void locateNode(Node *p_node); + void manageNotebooks(); + signals: void notebookActivated(ID p_notebookId); diff --git a/src/widgets/toolbarhelper.cpp b/src/widgets/toolbarhelper.cpp index 2af23ab2..b2b6ac35 100644 --- a/src/widgets/toolbarhelper.cpp +++ b/src/widgets/toolbarhelper.cpp @@ -96,6 +96,16 @@ QToolBar *ToolBarHelper::setupFileToolBar(MainWindow *p_win, QToolBar *p_toolBar []() { 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.