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 <core/thememgr.h>
|
||||
#include <core/vnotex.h>
|
||||
#include <core/exception.h>
|
||||
|
||||
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);
|
||||
try {
|
||||
styles += FileUtils::readTextFile(styleFile);
|
||||
} catch (Exception &p_e) {
|
||||
qWarning() << "failed to read global styles" << ele.m_name << styleFile << p_e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -138,6 +143,7 @@ static void fillResourcesByContent(QString &p_template, const WebResource &p_res
|
||||
|
||||
for (const auto &ele : p_resource.m_resources) {
|
||||
if (ele.m_enabled && !ele.isGlobal()) {
|
||||
try {
|
||||
// Styles.
|
||||
for (const auto &style : ele.m_styles) {
|
||||
auto styleFile = ConfigMgr::getInst().getUserOrAppFile(style);
|
||||
@ -149,6 +155,9 @@ static void fillResourcesByContent(QString &p_template, const WebResource &p_res
|
||||
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("<!-- 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);
|
||||
|
||||
private:
|
||||
static QString errorPage();
|
||||
|
||||
struct Template
|
||||
{
|
||||
int m_revision = -1;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -55,6 +55,8 @@ namespace vnotex
|
||||
|
||||
void locateNode(Node *p_node);
|
||||
|
||||
void manageNotebooks();
|
||||
|
||||
signals:
|
||||
void notebookActivated(ID p_notebookId);
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user