This commit is contained in:
Le Tan 2021-01-04 15:01:19 -08:00 committed by GitHub
parent db341b5574
commit 9dd83a6f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 110 additions and 21 deletions

@ -1 +1 @@
Subproject commit 01fb4118f566ff7a71db67af72de1d586a0e9ee5
Subproject commit 5fe5d4be7191de58fd1c2411b1ff97bcbecfaa3d

View File

@ -212,7 +212,7 @@ Buffer::OperationCode Buffer::save(bool p_force)
try {
m_provider->write(m_content);
} catch (Exception &p_e) {
qWarning() << "failed to write the buffer content" << getPath();
qWarning() << "failed to write the buffer content" << getPath() << p_e.what();
return OperationCode::Failed;
}
@ -327,7 +327,7 @@ void Buffer::autoSave()
try {
writeBackupFile();
} catch (Exception &p_e) {
qWarning() << "AutoSave failed to write backup file, retry later";
qWarning() << "AutoSave failed to write backup file, retry later" << p_e.what();
}
break;
}

View File

@ -24,7 +24,7 @@
using namespace vnotex;
#ifndef QT_NO_DEBUG
#define VX_DEBUG_WEB
// #define VX_DEBUG_WEB
#endif
const QString ConfigMgr::c_orgName = "VNote";

View File

@ -24,6 +24,7 @@ QString WebGlobalOptions::toJavascriptObject() const
+ QString("htmlTagEnabled: %1,\n").arg(Utils::boolToString(m_htmlTagEnabled))
+ QString("autoBreakEnabled: %1,\n").arg(Utils::boolToString(m_autoBreakEnabled))
+ QString("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled))
+ QString("indentFirstLineEnabled: %1,\n").arg(Utils::boolToString(m_indentFirstLineEnabled))
+ QString("sectionNumberEnabled: %1\n").arg(Utils::boolToString(m_sectionNumberEnabled))
+ QStringLiteral("}");
}
@ -161,6 +162,7 @@ void HtmlTemplateHelper::updateMarkdownViewerTemplate(const MarkdownEditorConfig
opts.m_htmlTagEnabled = p_config.getHtmlTagEnabled();
opts.m_autoBreakEnabled = p_config.getAutoBreakEnabled();
opts.m_linkifyEnabled = p_config.getLinkifyEnabled();
opts.m_indentFirstLineEnabled = p_config.getIndentFirstLineEnabled();
fillGlobalOptions(s_markdownViewerTemplate.m_template, opts);
}

View File

@ -26,6 +26,8 @@ namespace vnotex
bool m_linkifyEnabled = true;
bool m_indentFirstLineEnabled = false;
QString toJavascriptObject() const;
};

View File

@ -117,5 +117,4 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
void MainConfig::doVersionSpecificOverride()
{
// In a new version, we may want to change one value by force.
m_coreConfig->setTheme(QStringLiteral("moonlight"));
}

View File

@ -46,6 +46,7 @@ void MarkdownEditorConfig::init(const QJsonObject &p_app, const QJsonObject &p_u
m_htmlTagEnabled = READBOOL(QStringLiteral("html_tag"));
m_autoBreakEnabled = READBOOL(QStringLiteral("auto_break"));
m_linkifyEnabled = READBOOL(QStringLiteral("linkify"));
m_indentFirstLineEnabled = READBOOL(QStringLiteral("indent_first_line"));
}
QJsonObject MarkdownEditorConfig::toJson() const
@ -69,6 +70,7 @@ QJsonObject MarkdownEditorConfig::toJson() const
obj[QStringLiteral("html_tag")] = m_htmlTagEnabled;
obj[QStringLiteral("auto_break")] = m_autoBreakEnabled;
obj[QStringLiteral("linkify")] = m_linkifyEnabled;
obj[QStringLiteral("indent_first_line")] = m_indentFirstLineEnabled;
return obj;
}
@ -229,6 +231,16 @@ void MarkdownEditorConfig::setLinkifyEnabled(bool p_enabled)
updateConfig(m_linkifyEnabled, p_enabled, this);
}
bool MarkdownEditorConfig::getIndentFirstLineEnabled() const
{
return m_indentFirstLineEnabled;
}
void MarkdownEditorConfig::setIndentFirstLineEnabled(bool p_enabled)
{
updateConfig(m_indentFirstLineEnabled, p_enabled, this);
}
QString MarkdownEditorConfig::sectionNumberModeToString(SectionNumberMode p_mode) const
{
switch (p_mode) {

View File

@ -81,6 +81,9 @@ namespace vnotex
bool getLinkifyEnabled() const;
void setLinkifyEnabled(bool p_enabled);
bool getIndentFirstLineEnabled() const;
void setIndentFirstLineEnabled(bool p_enabled);
private:
QString sectionNumberModeToString(SectionNumberMode p_mode) const;
SectionNumberMode stringToSectionNumberMode(const QString &p_str) const;
@ -131,6 +134,9 @@ namespace vnotex
// Whether convert URL-like text to links.
bool m_linkifyEnabled = true;
// Whether indent the first line of a paragraph.
bool m_indentFirstLineEnabled = false;
};
}

View File

@ -2,6 +2,22 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>vnote.icns</string>
<key>CFBundleTypeName</key>
<string>VNote Document</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>public.plain-text</string>
<string>net.daringfireball.markdown</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>vnote</string>
<key>CFBundleShortVersionString</key>

View File

@ -245,7 +245,9 @@
"//comment" : "Whether auto break a line with '\\n'",
"auto_break" : false,
"//comment" : "Whether convert URL-like text to links",
"linkify" : true
"linkify" : true,
"//comment" : "Whether add indentation to the first line of paragraph",
"indent_first_line" : false
}
},
"widget" : {

View File

@ -897,6 +897,11 @@ QAbstractSpinBox {
selection-background-color: @widgets#qspinbox#selection#bg;
}
QAbstractSpinBox:disabled {
color: @widgets#qspinbox#disabled#fg;
background-color: @widgets#qspinbox#disabled#bg;
}
QAbstractSpinBox:focus {
border: 2px solid @widgets#qspinbox#focus#border;
background-color: @widgets#qspinbox#focus#bg;

View File

@ -516,6 +516,10 @@
"border" : "@base#content#border",
"fg" : "@base#content#fg",
"bg" : "@base#content#bg",
"disabled" : {
"fg" : "@base#content#disabled#fg",
"bg" : "@base#content#disabled#bg"
},
"selection" : {
"fg" : "@base#content#selection#fg",
"bg" : "@base#content#selection#bg"

View File

@ -81,3 +81,7 @@
visibility: visible;
vertical-align: middle;
}
#vx-content.vx-indent-first-line p {
text-indent: 2em;
}

View File

@ -240,6 +240,10 @@ class MarkdownIt extends VxWorker {
}
registerInternal() {
this.vnotex.on('ready', () => {
this.setConstrainImageWidthEnabled(window.vxOptions.constrainImageWidthEnabled);
this.setIndentFirstLineEnabled(window.vxOptions.indentFirstLineEnabled);
});
this.vnotex.on('markdownTextUpdated', (p_text) => {
this.render(this.vnotex.contentContainer,
p_text,
@ -247,6 +251,24 @@ class MarkdownIt extends VxWorker {
});
}
setConstrainImageWidthEnabled(p_enabled) {
let constrainClass = 'vx-constrain-image-width';
if (p_enabled) {
this.vnotex.contentContainer.classList.add(constrainClass);
} else {
this.vnotex.contentContainer.classList.remove(constrainClass);
}
}
setIndentFirstLineEnabled(p_enabled) {
let constrainClass = 'vx-indent-first-line';
if (p_enabled) {
this.vnotex.contentContainer.classList.add(constrainClass);
} else {
this.vnotex.contentContainer.classList.remove(constrainClass);
}
}
// Render Markdown @p_text to HTML in @p_node.
// @p_finishCbStr will be called after finishing loading new content nodes.
// This could prevent Mermaid Gantt from negative width error.

View File

@ -111,6 +111,6 @@ class Utils {
}
static headingSequenceRegExp() {
return /^\d(?:\.\d)*\.? /;
return /^\d{1,3}(?:\.\d+)*\.? /;
}
}

View File

@ -136,7 +136,6 @@ class VNoteX extends EventEmitter {
}
setBasicMarkdownRendered() {
this.setConstrainImageWidthEnabled(window.vxOptions.constrainImageWidthEnabled);
this.emit('basicMarkdownRendered');
}
@ -210,15 +209,6 @@ class VNoteX extends EventEmitter {
}
}
setConstrainImageWidthEnabled(p_enabled) {
let constrainClass = 'vx-constrain-image-width';
if (p_enabled) {
this.contentContainer.classList.add(constrainClass);
} else {
this.contentContainer.classList.remove(constrainClass);
}
}
scroll(p_up) {
EasyAccess.scroll(p_up);
}

View File

@ -76,6 +76,10 @@ QDialogButtonBox *Dialog::getDialogButtonBox() const
void Dialog::setInformationText(const QString &p_text, InformationLevel p_level)
{
if (!m_infoTextEdit) {
if (p_text.isEmpty()) {
return;
}
m_infoTextEdit = new QPlainTextEdit(this);
m_infoTextEdit->setReadOnly(true);
m_infoTextEdit->setMaximumHeight(m_infoTextEdit->minimumSizeHint().height());
@ -83,7 +87,10 @@ void Dialog::setInformationText(const QString &p_text, InformationLevel p_level)
}
m_infoTextEdit->setPlainText(p_text);
m_infoTextEdit->setVisible(!p_text.isEmpty());
const bool visible = !p_text.isEmpty();
const bool needResize = visible != m_infoTextEdit->isVisible();
m_infoTextEdit->setVisible(visible);
// Change the style.
const char *level = "";
@ -102,8 +109,10 @@ void Dialog::setInformationText(const QString &p_text, InformationLevel p_level)
}
WidgetUtils::setPropertyDynamically(m_infoTextEdit, PropertyDefs::s_state, level);
if (needResize) {
WidgetUtils::updateSize(this);
}
}
void Dialog::acceptedButtonClicked()
{

View File

@ -66,6 +66,8 @@ void MarkdownEditorPage::loadInternal()
m_autoBreakCheckBox->setChecked(markdownConfig.getAutoBreakEnabled());
m_linkifyCheckBox->setChecked(markdownConfig.getLinkifyEnabled());
m_indentFirstLineCheckBox->setChecked(markdownConfig.getIndentFirstLineEnabled());
}
void MarkdownEditorPage::saveInternal()
@ -97,6 +99,8 @@ void MarkdownEditorPage::saveInternal()
markdownConfig.setLinkifyEnabled(m_linkifyCheckBox->isChecked());
markdownConfig.setIndentFirstLineEnabled(m_indentFirstLineCheckBox->isChecked());
EditorPage::notifyEditorConfigChange();
}
@ -164,6 +168,16 @@ QGroupBox *MarkdownEditorPage::setupReadGroup()
this, &MarkdownEditorPage::pageIsChanged);
}
{
const QString label(tr("Indent first line"));
m_indentFirstLineCheckBox = WidgetsFactory::createCheckBox(label, box);
m_indentFirstLineCheckBox->setToolTip(tr("Indent the first line of each paragraph"));
layout->addRow(m_indentFirstLineCheckBox);
addSearchItem(label, m_indentFirstLineCheckBox->toolTip(), m_indentFirstLineCheckBox);
connect(m_indentFirstLineCheckBox, &QCheckBox::stateChanged,
this, &MarkdownEditorPage::pageIsChanged);
}
return box;
}

View File

@ -47,6 +47,8 @@ namespace vnotex
QCheckBox *m_linkifyCheckBox = nullptr;
QCheckBox *m_indentFirstLineCheckBox = nullptr;
QDoubleSpinBox *m_zoomFactorSpinBox = nullptr;
QComboBox *m_sectionNumberComboBox = nullptr;

View File

@ -187,7 +187,7 @@ namespace vnotex
QTimer *m_sectionNumberTimer = nullptr;
// Used to detect the config change and do a clean up.
bool m_sectionNumberEnabled = true;
bool m_sectionNumberEnabled = false;
OverrideState m_overriddenSectionNumber = OverrideState::NoOverride;
};

View File

@ -399,7 +399,7 @@ void MarkdownViewWindow::setupViewer()
// Status widget.
{
// TODO: implement a real status widget for viewer.
auto label = new QLabel(tr("Markdown Web Viewer"), this);
auto label = new QLabel(tr("Markdown Viewer"), this);
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_viewerStatusWidget.reset(label);
getMainStatusWidget()->addWidget(m_viewerStatusWidget.get());