mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
refine ViewWindow and FileOpenParameters
This commit is contained in:
parent
fe827e74f0
commit
0e41597798
@ -75,7 +75,7 @@ ViewWindow *Buffer::createViewWindow(const QSharedPointer<FileOpenParameters> &p
|
|||||||
{
|
{
|
||||||
auto window = createViewWindowInternal(p_paras, p_parent);
|
auto window = createViewWindowInternal(p_paras, p_parent);
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(window);
|
||||||
window->attachToBuffer(this);
|
window->attachToBuffer(this, p_paras);
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ MarkdownBuffer::MarkdownBuffer(const BufferParameters &p_parameters,
|
|||||||
|
|
||||||
ViewWindow *MarkdownBuffer::createViewWindowInternal(const QSharedPointer<FileOpenParameters> &p_paras, QWidget *p_parent)
|
ViewWindow *MarkdownBuffer::createViewWindowInternal(const QSharedPointer<FileOpenParameters> &p_paras, QWidget *p_parent)
|
||||||
{
|
{
|
||||||
return new MarkdownViewWindow(p_paras, p_parent);
|
Q_UNUSED(p_paras);
|
||||||
|
return new MarkdownViewWindow(p_parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MarkdownBuffer::insertImage(const QString &p_srcImagePath, const QString &p_imageFileName)
|
QString MarkdownBuffer::insertImage(const QString &p_srcImagePath, const QString &p_imageFileName)
|
||||||
|
@ -1,22 +1,15 @@
|
|||||||
#ifndef FILEOPENPARAMETERS_H
|
#ifndef FILEOPENPARAMETERS_H
|
||||||
#define FILEOPENPARAMETERS_H
|
#define FILEOPENPARAMETERS_H
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
namespace vnotex
|
namespace vnotex
|
||||||
{
|
{
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
struct FileOpenParameters
|
struct FileOpenParameters
|
||||||
{
|
{
|
||||||
// Some modes may be not supported by some editors.
|
ViewWindowMode m_mode = ViewWindowMode::Read;
|
||||||
enum Mode
|
|
||||||
{
|
|
||||||
Read,
|
|
||||||
Edit,
|
|
||||||
FullPreview,
|
|
||||||
FocusPreview
|
|
||||||
};
|
|
||||||
|
|
||||||
Mode m_mode = Mode::Read;
|
|
||||||
|
|
||||||
// Whether focus to the opened window.
|
// Whether focus to the opened window.
|
||||||
bool m_focus = true;
|
bool m_focus = true;
|
||||||
|
@ -89,6 +89,15 @@ namespace vnotex
|
|||||||
Center,
|
Center,
|
||||||
Right
|
Right
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ViewWindowMode
|
||||||
|
{
|
||||||
|
Read,
|
||||||
|
Edit,
|
||||||
|
FullPreview,
|
||||||
|
FocusPreview,
|
||||||
|
Invalid
|
||||||
|
};
|
||||||
} // ns vnotex
|
} // ns vnotex
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(vnotex::FindOptions);
|
Q_DECLARE_OPERATORS_FOR_FLAGS(vnotex::FindOptions);
|
||||||
|
@ -28,6 +28,7 @@ void WidgetConfig::init(const QJsonObject &p_app,
|
|||||||
m_nodeExplorerRecycleBinNodeVisible = READBOOL(QStringLiteral("node_explorer_recycle_bin_node_visible"));
|
m_nodeExplorerRecycleBinNodeVisible = READBOOL(QStringLiteral("node_explorer_recycle_bin_node_visible"));
|
||||||
m_nodeExplorerExternalFilesVisible = READBOOL(QStringLiteral("node_explorer_external_files_visible"));
|
m_nodeExplorerExternalFilesVisible = READBOOL(QStringLiteral("node_explorer_external_files_visible"));
|
||||||
m_nodeExplorerAutoImportExternalFilesEnabled = READBOOL(QStringLiteral("node_explorer_auto_import_external_files_enabled"));
|
m_nodeExplorerAutoImportExternalFilesEnabled = READBOOL(QStringLiteral("node_explorer_auto_import_external_files_enabled"));
|
||||||
|
m_searchPanelAdvancedSettingsVisible = READBOOL(QStringLiteral("search_panel_advanced_settings_visible"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject WidgetConfig::toJson() const
|
QJsonObject WidgetConfig::toJson() const
|
||||||
@ -39,6 +40,7 @@ QJsonObject WidgetConfig::toJson() const
|
|||||||
obj[QStringLiteral("node_explorer_recycle_bin_node_visible")] = m_nodeExplorerRecycleBinNodeVisible;
|
obj[QStringLiteral("node_explorer_recycle_bin_node_visible")] = m_nodeExplorerRecycleBinNodeVisible;
|
||||||
obj[QStringLiteral("node_explorer_external_files_visible")] = m_nodeExplorerExternalFilesVisible;
|
obj[QStringLiteral("node_explorer_external_files_visible")] = m_nodeExplorerExternalFilesVisible;
|
||||||
obj[QStringLiteral("node_explorer_auto_import_external_files_enabled")] = m_nodeExplorerAutoImportExternalFilesEnabled;
|
obj[QStringLiteral("node_explorer_auto_import_external_files_enabled")] = m_nodeExplorerAutoImportExternalFilesEnabled;
|
||||||
|
obj[QStringLiteral("search_panel_advanced_settings_visible")] = m_searchPanelAdvancedSettingsVisible;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,3 +103,13 @@ void WidgetConfig::setNodeExplorerAutoImportExternalFilesEnabled(bool p_enabled)
|
|||||||
{
|
{
|
||||||
updateConfig(m_nodeExplorerAutoImportExternalFilesEnabled, p_enabled, this);
|
updateConfig(m_nodeExplorerAutoImportExternalFilesEnabled, p_enabled, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WidgetConfig::isSearchPanelAdvancedSettingsVisible() const
|
||||||
|
{
|
||||||
|
return m_searchPanelAdvancedSettingsVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WidgetConfig::setSearchPanelAdvancedSettingsVisible(bool p_visible)
|
||||||
|
{
|
||||||
|
updateConfig(m_searchPanelAdvancedSettingsVisible, p_visible, this);
|
||||||
|
}
|
||||||
|
@ -36,6 +36,9 @@ namespace vnotex
|
|||||||
bool getNodeExplorerAutoImportExternalFilesEnabled() const;
|
bool getNodeExplorerAutoImportExternalFilesEnabled() const;
|
||||||
void setNodeExplorerAutoImportExternalFilesEnabled(bool p_enabled);
|
void setNodeExplorerAutoImportExternalFilesEnabled(bool p_enabled);
|
||||||
|
|
||||||
|
bool isSearchPanelAdvancedSettingsVisible() const;
|
||||||
|
void setSearchPanelAdvancedSettingsVisible(bool p_visible);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_outlineAutoExpandedLevel = 6;
|
int m_outlineAutoExpandedLevel = 6;
|
||||||
|
|
||||||
@ -48,6 +51,8 @@ namespace vnotex
|
|||||||
bool m_nodeExplorerExternalFilesVisible = true;
|
bool m_nodeExplorerExternalFilesVisible = true;
|
||||||
|
|
||||||
bool m_nodeExplorerAutoImportExternalFilesEnabled = true;
|
bool m_nodeExplorerAutoImportExternalFilesEnabled = true;
|
||||||
|
|
||||||
|
bool m_searchPanelAdvancedSettingsVisible = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<file>icons/import_notebook_of_vnote2.svg</file>
|
<file>icons/import_notebook_of_vnote2.svg</file>
|
||||||
<file>icons/new_notebook.svg</file>
|
<file>icons/new_notebook.svg</file>
|
||||||
<file>icons/notebook_menu.svg</file>
|
<file>icons/notebook_menu.svg</file>
|
||||||
|
<file>icons/advanced_settings.svg</file>
|
||||||
<file>icons/new_notebook_from_folder.svg</file>
|
<file>icons/new_notebook_from_folder.svg</file>
|
||||||
<file>icons/discard_editor.svg</file>
|
<file>icons/discard_editor.svg</file>
|
||||||
<file>icons/edit_editor.svg</file>
|
<file>icons/edit_editor.svg</file>
|
||||||
@ -35,6 +36,7 @@
|
|||||||
<file>icons/remove_notebook.svg</file>
|
<file>icons/remove_notebook.svg</file>
|
||||||
<file>icons/close_notebook.svg</file>
|
<file>icons/close_notebook.svg</file>
|
||||||
<file>icons/recycle_bin.svg</file>
|
<file>icons/recycle_bin.svg</file>
|
||||||
|
<file>icons/search_location_list.svg</file>
|
||||||
<file>icons/save_editor.svg</file>
|
<file>icons/save_editor.svg</file>
|
||||||
<file>icons/buffer.svg</file>
|
<file>icons/buffer.svg</file>
|
||||||
<file>icons/attachment_editor.svg</file>
|
<file>icons/attachment_editor.svg</file>
|
||||||
|
14
src/data/core/icons/advanced_settings.svg
Normal file
14
src/data/core/icons/advanced_settings.svg
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 16.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
|
||||||
|
<g>
|
||||||
|
<path style="fill:#000000" d="M32,376h283.35c6.186-14.112,20.281-24,36.65-24s30.465,9.888,36.65,24H480v32h-91.35c-6.186,14.112-20.281,24-36.65,24
|
||||||
|
s-30.465-9.888-36.65-24H32"/>
|
||||||
|
<path style="fill:#000000" d="M32,240h91.35c6.186-14.112,20.281-24,36.65-24s30.465,9.888,36.65,24H480v32H196.65c-6.186,14.112-20.281,24-36.65,24
|
||||||
|
s-30.465-9.888-36.65-24H32"/>
|
||||||
|
<path style="fill:#000000" d="M32,104h283.35c6.186-14.112,20.281-24,36.65-24s30.465,9.888,36.65,24H480v32h-91.35c-6.186,14.112-20.281,24-36.65,24
|
||||||
|
s-30.465-9.888-36.65-24H32"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1022 B |
1
src/data/core/icons/search_location_list.svg
Normal file
1
src/data/core/icons/search_location_list.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1618368321416" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2001" width="512" height="512" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css"></style></defs><path d="M128 256 64 256 64 192l64 0L128 256zM320 384 256 384l0 64 64 0L320 384zM320 576 256 576l0 64 64 0L320 576zM320 768 256 768l0 64 64 0L320 768zM896 224C896 206.336 881.664 192 864 192l-640 0C206.336 192 192 206.336 192 224l0 0C192 241.664 206.336 256 224 256l640 0C881.664 256 896 241.664 896 224L896 224zM896 416C896 398.336 881.664 384 864 384l-448 0C398.336 384 384 398.336 384 416l0 0C384 433.664 398.336 448 416 448l448 0C881.664 448 896 433.664 896 416L896 416zM896 608C896 590.336 881.664 576 864 576l-448 0C398.336 576 384 590.336 384 608l0 0C384 625.664 398.336 640 416 640l448 0C881.664 640 896 625.664 896 608L896 608zM896 800c0-17.664-14.336-32-32-32l-448 0C398.336 768 384 782.336 384 800l0 0C384 817.664 398.336 832 416 832l448 0C881.664 832 896 817.664 896 800L896 800z" p-id="2002" fill="#000000"></path></svg>
|
After Width: | Height: | Size: 1.2 KiB |
@ -301,6 +301,7 @@
|
|||||||
"node_explorer_view_order" : 0,
|
"node_explorer_view_order" : 0,
|
||||||
"node_explorer_recycle_bin_node_visible" : false,
|
"node_explorer_recycle_bin_node_visible" : false,
|
||||||
"node_explorer_external_files_visible" : true,
|
"node_explorer_external_files_visible" : true,
|
||||||
"node_explorer_auto_import_external_files_enabled" : true
|
"node_explorer_auto_import_external_files_enabled" : true,
|
||||||
|
"search_panel_advanced_settings_visible" : true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,11 @@ void MarkdownViewerAdapter::scrollToLine(int p_lineNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_viewerReady) {
|
if (!m_viewerReady) {
|
||||||
qWarning() << "Markdown viewer is not ready";
|
if (m_pendingData) {
|
||||||
|
m_pendingData->m_position = Position(p_lineNumber, QString());
|
||||||
|
} else {
|
||||||
|
qWarning() << "Markdown viewer is not ready";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,3 +748,9 @@ void MainWindow::setLocationListVisible(bool p_visible)
|
|||||||
m_docks[DockIndex::LocationListDock]->hide();
|
m_docks[DockIndex::LocationListDock]->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::toggleLocationListVisible()
|
||||||
|
{
|
||||||
|
bool visible = m_docks[DockIndex::LocationListDock]->isVisible();
|
||||||
|
setLocationListVisible(!visible);
|
||||||
|
}
|
||||||
|
@ -61,6 +61,8 @@ namespace vnotex
|
|||||||
|
|
||||||
void setLocationListVisible(bool p_visible);
|
void setLocationListVisible(bool p_visible);
|
||||||
|
|
||||||
|
void toggleLocationListVisible();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void mainWindowStarted();
|
void mainWindowStarted();
|
||||||
|
|
||||||
|
@ -32,9 +32,8 @@
|
|||||||
|
|
||||||
using namespace vnotex;
|
using namespace vnotex;
|
||||||
|
|
||||||
MarkdownViewWindow::MarkdownViewWindow(const QSharedPointer<FileOpenParameters> &p_paras, QWidget *p_parent)
|
MarkdownViewWindow::MarkdownViewWindow(QWidget *p_parent)
|
||||||
: ViewWindow(p_parent),
|
: ViewWindow(p_parent)
|
||||||
m_openParas(p_paras)
|
|
||||||
{
|
{
|
||||||
// Need to setup before setupUI() since the tool bar action will need the provider.
|
// Need to setup before setupUI() since the tool bar action will need the provider.
|
||||||
setupOutlineProvider();
|
setupOutlineProvider();
|
||||||
@ -42,10 +41,6 @@ MarkdownViewWindow::MarkdownViewWindow(const QSharedPointer<FileOpenParameters>
|
|||||||
setupUI();
|
setupUI();
|
||||||
|
|
||||||
m_previewHelper = new PreviewHelper(nullptr, this);
|
m_previewHelper = new PreviewHelper(nullptr, this);
|
||||||
|
|
||||||
setModeInternal(modeFromOpenParameters(*p_paras));
|
|
||||||
|
|
||||||
m_initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MarkdownViewWindow::~MarkdownViewWindow()
|
MarkdownViewWindow::~MarkdownViewWindow()
|
||||||
@ -86,16 +81,12 @@ void MarkdownViewWindow::setupUI()
|
|||||||
setupToolBar();
|
setupToolBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkdownViewWindow::setMode(Mode p_mode)
|
void MarkdownViewWindow::setMode(ViewWindowMode p_mode)
|
||||||
{
|
{
|
||||||
setModeInternal(p_mode);
|
setModeInternal(p_mode, true);
|
||||||
|
|
||||||
if (m_findAndReplace && m_findAndReplace->isVisible()) {
|
|
||||||
m_findAndReplace->setReplaceEnabled(m_mode != Mode::Read);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkdownViewWindow::setModeInternal(Mode p_mode)
|
void MarkdownViewWindow::setModeInternal(ViewWindowMode p_mode, bool p_syncBuffer)
|
||||||
{
|
{
|
||||||
if (p_mode == m_mode) {
|
if (p_mode == m_mode) {
|
||||||
return;
|
return;
|
||||||
@ -105,11 +96,11 @@ void MarkdownViewWindow::setModeInternal(Mode p_mode)
|
|||||||
m_mode = p_mode;
|
m_mode = p_mode;
|
||||||
|
|
||||||
switch (m_mode) {
|
switch (m_mode) {
|
||||||
case Mode::Read:
|
case ViewWindowMode::Read:
|
||||||
{
|
{
|
||||||
if (!m_viewer) {
|
if (!m_viewer) {
|
||||||
setupViewer();
|
setupViewer();
|
||||||
if (m_initialized) {
|
if (p_syncBuffer) {
|
||||||
syncViewerFromBuffer(true);
|
syncViewerFromBuffer(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +117,7 @@ void MarkdownViewWindow::setModeInternal(Mode p_mode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Mode::Edit:
|
case ViewWindowMode::Edit:
|
||||||
{
|
{
|
||||||
if (!m_editor) {
|
if (!m_editor) {
|
||||||
// We need viewer to preview.
|
// We need viewer to preview.
|
||||||
@ -136,7 +127,7 @@ void MarkdownViewWindow::setModeInternal(Mode p_mode)
|
|||||||
|
|
||||||
setupTextEditor();
|
setupTextEditor();
|
||||||
|
|
||||||
if (m_initialized) {
|
if (p_syncBuffer) {
|
||||||
syncTextEditorFromBuffer(true);
|
syncTextEditorFromBuffer(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,11 +151,15 @@ void MarkdownViewWindow::setModeInternal(Mode p_mode)
|
|||||||
// Let editor to show or scrollToLine will not work correctly.
|
// Let editor to show or scrollToLine will not work correctly.
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
if (m_initialized) {
|
if (p_syncBuffer) {
|
||||||
doSyncEditorFromBufferContent(true);
|
doSyncEditorFromBufferContent(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit modeChanged();
|
emit modeChanged();
|
||||||
|
|
||||||
|
if (m_findAndReplace && m_findAndReplace->isVisible()) {
|
||||||
|
m_findAndReplace->setReplaceEnabled(!isReadMode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkdownViewWindow::setModified(bool p_modified)
|
void MarkdownViewWindow::setModified(bool p_modified)
|
||||||
@ -219,11 +214,11 @@ void MarkdownViewWindow::doSyncEditorFromBufferContent(bool p_syncPosition)
|
|||||||
// case we will call editor or viewer to update its content.
|
// case we will call editor or viewer to update its content.
|
||||||
m_bufferRevision = buffer->getRevision();
|
m_bufferRevision = buffer->getRevision();
|
||||||
switch (m_mode) {
|
switch (m_mode) {
|
||||||
case Mode::Read:
|
case ViewWindowMode::Read:
|
||||||
syncViewerFromBufferContent(p_syncPosition);
|
syncViewerFromBufferContent(p_syncPosition);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Mode::Edit:
|
case ViewWindowMode::Edit:
|
||||||
syncTextEditorFromBufferContent(p_syncPosition);
|
syncTextEditorFromBufferContent(p_syncPosition);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -232,21 +227,16 @@ void MarkdownViewWindow::doSyncEditorFromBufferContent(bool p_syncPosition)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkdownViewWindow::handleBufferChangedInternal()
|
void MarkdownViewWindow::handleBufferChangedInternal(const QSharedPointer<FileOpenParameters> &p_paras)
|
||||||
{
|
{
|
||||||
TextViewWindowHelper::handleBufferChanged(this);
|
if (getBuffer()) {
|
||||||
|
// Will sync buffer right behind this.
|
||||||
auto buffer = getBuffer();
|
setModeInternal(p_paras ? p_paras->m_mode : ViewWindowMode::Read, false);
|
||||||
if (m_openParas && m_openParas->m_newFile) {
|
|
||||||
Q_ASSERT(m_mode != Mode::Read);
|
|
||||||
const auto &markdownEditorConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
|
|
||||||
if (markdownEditorConfig.getInsertFileNameAsTitle() && buffer->getContent().isEmpty()) {
|
|
||||||
const auto title = QString("# %1\n").arg(QFileInfo(buffer->getName()).completeBaseName());
|
|
||||||
m_editor->insertText(title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_openParas.clear();
|
TextViewWindowHelper::handleBufferChanged(this);
|
||||||
|
|
||||||
|
handleFileOpenParameters(p_paras);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkdownViewWindow::setupToolBar()
|
void MarkdownViewWindow::setupToolBar()
|
||||||
@ -329,14 +319,14 @@ void MarkdownViewWindow::setupTextEditor()
|
|||||||
// Connect outline pipeline.
|
// Connect outline pipeline.
|
||||||
connect(m_editor, &MarkdownEditor::headingsChanged,
|
connect(m_editor, &MarkdownEditor::headingsChanged,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
if (getMode() != Mode::Read) {
|
if (!isReadMode()) {
|
||||||
auto outline = headingsToOutline(m_editor->getHeadings());
|
auto outline = headingsToOutline(m_editor->getHeadings());
|
||||||
m_outlineProvider->setOutline(outline);
|
m_outlineProvider->setOutline(outline);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(m_editor, &MarkdownEditor::currentHeadingChanged,
|
connect(m_editor, &MarkdownEditor::currentHeadingChanged,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
if (getMode() != Mode::Read) {
|
if (!isReadMode()) {
|
||||||
m_outlineProvider->setCurrentHeadingIndex(m_editor->getCurrentHeadingIndex());
|
m_outlineProvider->setCurrentHeadingIndex(m_editor->getCurrentHeadingIndex());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -366,11 +356,11 @@ bool MarkdownViewWindow::eventFilter(QObject *p_obj, QEvent *p_event)
|
|||||||
void MarkdownViewWindow::focusEditor()
|
void MarkdownViewWindow::focusEditor()
|
||||||
{
|
{
|
||||||
switch (m_mode) {
|
switch (m_mode) {
|
||||||
case Mode::Read:
|
case ViewWindowMode::Read:
|
||||||
m_viewer->setFocus();
|
m_viewer->setFocus();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Mode::Edit:
|
case ViewWindowMode::Edit:
|
||||||
m_editor->setFocus();
|
m_editor->setFocus();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -430,14 +420,14 @@ void MarkdownViewWindow::setupViewer()
|
|||||||
// Connect outline pipeline.
|
// Connect outline pipeline.
|
||||||
connect(adapter, &MarkdownViewerAdapter::headingsChanged,
|
connect(adapter, &MarkdownViewerAdapter::headingsChanged,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
if (getMode() == Mode::Read) {
|
if (isReadMode()) {
|
||||||
auto outline = headingsToOutline(this->adapter()->getHeadings());
|
auto outline = headingsToOutline(this->adapter()->getHeadings());
|
||||||
m_outlineProvider->setOutline(outline);
|
m_outlineProvider->setOutline(outline);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(adapter, &MarkdownViewerAdapter::currentHeadingChanged,
|
connect(adapter, &MarkdownViewerAdapter::currentHeadingChanged,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
if (getMode() == Mode::Read) {
|
if (isReadMode()) {
|
||||||
m_outlineProvider->setCurrentHeadingIndex(this->adapter()->getCurrentHeadingIndex());
|
m_outlineProvider->setCurrentHeadingIndex(this->adapter()->getCurrentHeadingIndex());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -554,11 +544,11 @@ void MarkdownViewWindow::setBufferRevisionAfterInvalidation(int p_bufferRevision
|
|||||||
{
|
{
|
||||||
m_bufferRevision = p_bufferRevision;
|
m_bufferRevision = p_bufferRevision;
|
||||||
switch (m_mode) {
|
switch (m_mode) {
|
||||||
case Mode::Edit:
|
case ViewWindowMode::Edit:
|
||||||
m_textEditorBufferRevision = p_bufferRevision;
|
m_textEditorBufferRevision = p_bufferRevision;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Mode::Read:
|
case ViewWindowMode::Read:
|
||||||
m_viewerBufferRevision = p_bufferRevision;
|
m_viewerBufferRevision = p_bufferRevision;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -578,7 +568,7 @@ EditorMarkdownViewerAdapter *MarkdownViewWindow::adapter() const
|
|||||||
|
|
||||||
int MarkdownViewWindow::getEditLineNumber() const
|
int MarkdownViewWindow::getEditLineNumber() const
|
||||||
{
|
{
|
||||||
if (m_previousMode == Mode::Edit || m_previousMode == Mode::FocusPreview) {
|
if (m_previousMode == ViewWindowMode::Edit || m_previousMode == ViewWindowMode::FocusPreview) {
|
||||||
if (m_editor) {
|
if (m_editor) {
|
||||||
return m_editor->getTopLine();
|
return m_editor->getTopLine();
|
||||||
}
|
}
|
||||||
@ -589,7 +579,7 @@ int MarkdownViewWindow::getEditLineNumber() const
|
|||||||
|
|
||||||
int MarkdownViewWindow::getReadLineNumber() const
|
int MarkdownViewWindow::getReadLineNumber() const
|
||||||
{
|
{
|
||||||
if (m_previousMode == Mode::Read) {
|
if (m_previousMode == ViewWindowMode::Read) {
|
||||||
if (m_viewer) {
|
if (m_viewer) {
|
||||||
return adapter()->getTopLineNumber();
|
return adapter()->getTopLineNumber();
|
||||||
}
|
}
|
||||||
@ -693,7 +683,7 @@ void MarkdownViewWindow::handleTypeAction(TypeAction p_action)
|
|||||||
|
|
||||||
void MarkdownViewWindow::handleSectionNumberOverride(OverrideState p_state)
|
void MarkdownViewWindow::handleSectionNumberOverride(OverrideState p_state)
|
||||||
{
|
{
|
||||||
if (m_mode != Mode::Read) {
|
if (!isReadMode()) {
|
||||||
m_editor->overrideSectionNumber(p_state);
|
m_editor->overrideSectionNumber(p_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -772,7 +762,7 @@ void MarkdownViewWindow::setupOutlineProvider()
|
|||||||
connect(m_outlineProvider.data(), &OutlineProvider::headingClicked,
|
connect(m_outlineProvider.data(), &OutlineProvider::headingClicked,
|
||||||
this, [this](int p_idx) {
|
this, [this](int p_idx) {
|
||||||
switch (getMode()) {
|
switch (getMode()) {
|
||||||
case Mode::Read:
|
case ViewWindowMode::Read:
|
||||||
adapter()->scrollToHeading(p_idx);
|
adapter()->scrollToHeading(p_idx);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -796,7 +786,7 @@ QSharedPointer<vte::MarkdownEditorConfig> MarkdownViewWindow::createMarkdownEdit
|
|||||||
|
|
||||||
void MarkdownViewWindow::scrollUp()
|
void MarkdownViewWindow::scrollUp()
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Read) {
|
if (isReadMode()) {
|
||||||
adapter()->scroll(true);
|
adapter()->scroll(true);
|
||||||
} else {
|
} else {
|
||||||
QScrollBar *vbar = m_editor->getTextEdit()->verticalScrollBar();
|
QScrollBar *vbar = m_editor->getTextEdit()->verticalScrollBar();
|
||||||
@ -808,7 +798,7 @@ void MarkdownViewWindow::scrollUp()
|
|||||||
|
|
||||||
void MarkdownViewWindow::scrollDown()
|
void MarkdownViewWindow::scrollDown()
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Read) {
|
if (isReadMode()) {
|
||||||
adapter()->scroll(false);
|
adapter()->scroll(false);
|
||||||
} else {
|
} else {
|
||||||
QScrollBar *vbar = m_editor->getTextEdit()->verticalScrollBar();
|
QScrollBar *vbar = m_editor->getTextEdit()->verticalScrollBar();
|
||||||
@ -830,7 +820,7 @@ void MarkdownViewWindow::updateWebViewerConfig(const MarkdownEditorConfig &p_con
|
|||||||
void MarkdownViewWindow::zoom(bool p_zoomIn)
|
void MarkdownViewWindow::zoom(bool p_zoomIn)
|
||||||
{
|
{
|
||||||
// Only editor will receive the wheel event.
|
// Only editor will receive the wheel event.
|
||||||
Q_ASSERT(m_mode != Mode::Read);
|
Q_ASSERT(!isReadMode());
|
||||||
m_editor->zoom(m_editor->zoomDelta() + (p_zoomIn ? 1 : -1));
|
m_editor->zoom(m_editor->zoomDelta() + (p_zoomIn ? 1 : -1));
|
||||||
auto &textEditorConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig().getTextEditorConfig();
|
auto &textEditorConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig().getTextEditorConfig();
|
||||||
textEditorConfig.setZoomDelta(m_editor->zoomDelta());
|
textEditorConfig.setZoomDelta(m_editor->zoomDelta());
|
||||||
@ -839,7 +829,7 @@ void MarkdownViewWindow::zoom(bool p_zoomIn)
|
|||||||
|
|
||||||
void MarkdownViewWindow::handleFindTextChanged(const QString &p_text, FindOptions p_options)
|
void MarkdownViewWindow::handleFindTextChanged(const QString &p_text, FindOptions p_options)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Read) {
|
if (isReadMode()) {
|
||||||
if (p_options & FindOption::IncrementalSearch) {
|
if (p_options & FindOption::IncrementalSearch) {
|
||||||
adapter()->findText(p_text, p_options);
|
adapter()->findText(p_text, p_options);
|
||||||
}
|
}
|
||||||
@ -850,7 +840,7 @@ void MarkdownViewWindow::handleFindTextChanged(const QString &p_text, FindOption
|
|||||||
|
|
||||||
void MarkdownViewWindow::handleFindNext(const QString &p_text, FindOptions p_options)
|
void MarkdownViewWindow::handleFindNext(const QString &p_text, FindOptions p_options)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Read) {
|
if (isReadMode()) {
|
||||||
adapter()->findText(p_text, p_options);
|
adapter()->findText(p_text, p_options);
|
||||||
} else {
|
} else {
|
||||||
TextViewWindowHelper::handleFindNext(this, p_text, p_options);
|
TextViewWindowHelper::handleFindNext(this, p_text, p_options);
|
||||||
@ -859,7 +849,7 @@ void MarkdownViewWindow::handleFindNext(const QString &p_text, FindOptions p_opt
|
|||||||
|
|
||||||
void MarkdownViewWindow::handleReplace(const QString &p_text, FindOptions p_options, const QString &p_replaceText)
|
void MarkdownViewWindow::handleReplace(const QString &p_text, FindOptions p_options, const QString &p_replaceText)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Read) {
|
if (isReadMode()) {
|
||||||
VNoteX::getInst().showStatusMessageShort(tr("Replace is not supported in read mode"));
|
VNoteX::getInst().showStatusMessageShort(tr("Replace is not supported in read mode"));
|
||||||
} else {
|
} else {
|
||||||
TextViewWindowHelper::handleReplace(this, p_text, p_options, p_replaceText);
|
TextViewWindowHelper::handleReplace(this, p_text, p_options, p_replaceText);
|
||||||
@ -868,7 +858,7 @@ void MarkdownViewWindow::handleReplace(const QString &p_text, FindOptions p_opti
|
|||||||
|
|
||||||
void MarkdownViewWindow::handleReplaceAll(const QString &p_text, FindOptions p_options, const QString &p_replaceText)
|
void MarkdownViewWindow::handleReplaceAll(const QString &p_text, FindOptions p_options, const QString &p_replaceText)
|
||||||
{
|
{
|
||||||
if (m_mode == Mode::Read) {
|
if (isReadMode()) {
|
||||||
VNoteX::getInst().showStatusMessageShort(tr("Replace is not supported in read mode"));
|
VNoteX::getInst().showStatusMessageShort(tr("Replace is not supported in read mode"));
|
||||||
} else {
|
} else {
|
||||||
TextViewWindowHelper::handleReplaceAll(this, p_text, p_options, p_replaceText);
|
TextViewWindowHelper::handleReplaceAll(this, p_text, p_options, p_replaceText);
|
||||||
@ -887,5 +877,44 @@ void MarkdownViewWindow::handleFindAndReplaceWidgetClosed()
|
|||||||
void MarkdownViewWindow::handleFindAndReplaceWidgetOpened()
|
void MarkdownViewWindow::handleFindAndReplaceWidgetOpened()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_findAndReplace);
|
Q_ASSERT(m_findAndReplace);
|
||||||
m_findAndReplace->setReplaceEnabled(m_mode != Mode::Read);
|
m_findAndReplace->setReplaceEnabled(!isReadMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarkdownViewWindow::handleFileOpenParameters(const QSharedPointer<FileOpenParameters> &p_paras)
|
||||||
|
{
|
||||||
|
if (!p_paras) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto buffer = getBuffer();
|
||||||
|
if (p_paras->m_newFile) {
|
||||||
|
Q_ASSERT(!isReadMode());
|
||||||
|
const auto &markdownEditorConfig = ConfigMgr::getInst().getEditorConfig().getMarkdownEditorConfig();
|
||||||
|
if (markdownEditorConfig.getInsertFileNameAsTitle() && buffer->getContent().isEmpty()) {
|
||||||
|
const auto title = QString("# %1\n").arg(QFileInfo(buffer->getName()).completeBaseName());
|
||||||
|
m_editor->insertText(title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToLine(p_paras->m_lineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarkdownViewWindow::scrollToLine(int p_lineNumber)
|
||||||
|
{
|
||||||
|
if (p_lineNumber < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isReadMode()) {
|
||||||
|
Q_ASSERT(m_viewer);
|
||||||
|
adapter()->scrollToPosition(MarkdownViewerAdapter::Position(p_lineNumber, QString()));
|
||||||
|
} else {
|
||||||
|
Q_ASSERT(m_editor);
|
||||||
|
m_editor->scrollToLine(p_lineNumber, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MarkdownViewWindow::isReadMode() const
|
||||||
|
{
|
||||||
|
return m_mode == ViewWindowMode::Read;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ namespace vte
|
|||||||
|
|
||||||
namespace vnotex
|
namespace vnotex
|
||||||
{
|
{
|
||||||
struct FileOpenParameters;
|
|
||||||
class MarkdownEditor;
|
class MarkdownEditor;
|
||||||
class MarkdownViewer;
|
class MarkdownViewer;
|
||||||
class EditorMarkdownViewerAdapter;
|
class EditorMarkdownViewerAdapter;
|
||||||
@ -29,13 +28,13 @@ namespace vnotex
|
|||||||
public:
|
public:
|
||||||
friend class TextViewWindowHelper;
|
friend class TextViewWindowHelper;
|
||||||
|
|
||||||
MarkdownViewWindow(const QSharedPointer<FileOpenParameters> &p_paras, QWidget *p_parent = nullptr);
|
MarkdownViewWindow(QWidget *p_parent = nullptr);
|
||||||
|
|
||||||
~MarkdownViewWindow();
|
~MarkdownViewWindow();
|
||||||
|
|
||||||
QString getLatestContent() const Q_DECL_OVERRIDE;
|
QString getLatestContent() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void setMode(Mode p_mode) Q_DECL_OVERRIDE;
|
void setMode(ViewWindowMode p_mode) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
QSharedPointer<OutlineProvider> getOutlineProvider() Q_DECL_OVERRIDE;
|
QSharedPointer<OutlineProvider> getOutlineProvider() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ namespace vnotex
|
|||||||
protected slots:
|
protected slots:
|
||||||
void setModified(bool p_modified) Q_DECL_OVERRIDE;
|
void setModified(bool p_modified) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void handleBufferChangedInternal() Q_DECL_OVERRIDE;
|
void handleBufferChangedInternal(const QSharedPointer<FileOpenParameters> &p_paras) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void handleTypeAction(TypeAction p_action) Q_DECL_OVERRIDE;
|
void handleTypeAction(TypeAction p_action) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
@ -110,9 +109,6 @@ namespace vnotex
|
|||||||
|
|
||||||
EditorMarkdownViewerAdapter *adapter() const;
|
EditorMarkdownViewerAdapter *adapter() const;
|
||||||
|
|
||||||
// We need a non-virtual version for constructor.
|
|
||||||
void setModeInternal(Mode p_mode);
|
|
||||||
|
|
||||||
// Get the position to sync from editor.
|
// Get the position to sync from editor.
|
||||||
// Return -1 for an invalid position.
|
// Return -1 for an invalid position.
|
||||||
int getEditLineNumber() const;
|
int getEditLineNumber() const;
|
||||||
@ -127,13 +123,19 @@ namespace vnotex
|
|||||||
|
|
||||||
void updateWebViewerConfig(const MarkdownEditorConfig &p_config);
|
void updateWebViewerConfig(const MarkdownEditorConfig &p_config);
|
||||||
|
|
||||||
|
void setModeInternal(ViewWindowMode p_mode, bool p_syncBuffer);
|
||||||
|
|
||||||
|
void handleFileOpenParameters(const QSharedPointer<FileOpenParameters> &p_paras);
|
||||||
|
|
||||||
|
void scrollToLine(int p_lineNumber);
|
||||||
|
|
||||||
|
bool isReadMode() const;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
static QSharedPointer<Outline> headingsToOutline(const QVector<T> &p_headings);
|
static QSharedPointer<Outline> headingsToOutline(const QVector<T> &p_headings);
|
||||||
|
|
||||||
static QSharedPointer<vte::MarkdownEditorConfig> createMarkdownEditorConfig(const MarkdownEditorConfig &p_config);
|
static QSharedPointer<vte::MarkdownEditorConfig> createMarkdownEditorConfig(const MarkdownEditorConfig &p_config);
|
||||||
|
|
||||||
bool m_initialized = false;
|
|
||||||
|
|
||||||
// Splitter to hold editor and viewer.
|
// Splitter to hold editor and viewer.
|
||||||
QSplitter *m_splitter = nullptr;
|
QSplitter *m_splitter = nullptr;
|
||||||
|
|
||||||
@ -161,9 +163,7 @@ namespace vnotex
|
|||||||
|
|
||||||
int m_markdownEditorConfigRevision = 0;
|
int m_markdownEditorConfigRevision = 0;
|
||||||
|
|
||||||
Mode m_previousMode = Mode::Invalid;
|
ViewWindowMode m_previousMode = ViewWindowMode::Invalid;
|
||||||
|
|
||||||
QSharedPointer<FileOpenParameters> m_openParas;
|
|
||||||
|
|
||||||
QSharedPointer<OutlineProvider> m_outlineProvider;
|
QSharedPointer<OutlineProvider> m_outlineProvider;
|
||||||
};
|
};
|
||||||
|
@ -235,7 +235,7 @@ void NotebookExplorer::newNote()
|
|||||||
|
|
||||||
// Open it right now.
|
// Open it right now.
|
||||||
auto paras = QSharedPointer<FileOpenParameters>::create();
|
auto paras = QSharedPointer<FileOpenParameters>::create();
|
||||||
paras->m_mode = FileOpenParameters::Mode::Edit;
|
paras->m_mode = ViewWindowMode::Edit;
|
||||||
paras->m_newFile = true;
|
paras->m_newFile = true;
|
||||||
emit VNoteX::getInst().openNodeRequested(dialog.getNewNode().data(), paras);
|
emit VNoteX::getInst().openNodeRequested(dialog.getNewNode().data(), paras);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <core/configmgr.h>
|
#include <core/configmgr.h>
|
||||||
#include <core/sessionconfig.h>
|
#include <core/sessionconfig.h>
|
||||||
|
#include <core/widgetconfig.h>
|
||||||
#include <core/vnotex.h>
|
#include <core/vnotex.h>
|
||||||
#include <core/fileopenparameters.h>
|
#include <core/fileopenparameters.h>
|
||||||
#include <notebook/node.h>
|
#include <notebook/node.h>
|
||||||
@ -55,7 +56,7 @@ void SearchPanel::setupUI()
|
|||||||
mainLayout->addWidget(titleBar);
|
mainLayout->addWidget(titleBar);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto inputsLayout = new QFormLayout();
|
auto inputsLayout = WidgetsFactory::createFormLayout();
|
||||||
mainLayout->addLayout(inputsLayout);
|
mainLayout->addLayout(inputsLayout);
|
||||||
|
|
||||||
m_keywordComboBox = WidgetsFactory::createComboBox(this);
|
m_keywordComboBox = WidgetsFactory::createComboBox(this);
|
||||||
@ -77,21 +78,31 @@ void SearchPanel::setupUI()
|
|||||||
m_searchScopeComboBox->addItem(tr("All Notebooks"), static_cast<int>(SearchScope::AllNotebooks));
|
m_searchScopeComboBox->addItem(tr("All Notebooks"), static_cast<int>(SearchScope::AllNotebooks));
|
||||||
inputsLayout->addRow(tr("Scope:"), m_searchScopeComboBox);
|
inputsLayout->addRow(tr("Scope:"), m_searchScopeComboBox);
|
||||||
|
|
||||||
setupSearchObject(inputsLayout);
|
{
|
||||||
|
// Advanced settings.
|
||||||
|
m_advancedSettings = new QWidget(this);
|
||||||
|
inputsLayout->addRow(m_advancedSettings);
|
||||||
|
|
||||||
setupSearchTarget(inputsLayout);
|
auto advLayout = WidgetsFactory::createFormLayout(m_advancedSettings);
|
||||||
|
advLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
m_filePatternComboBox = WidgetsFactory::createComboBox(this);
|
setupSearchObject(advLayout);
|
||||||
m_filePatternComboBox->setEditable(true);
|
|
||||||
m_filePatternComboBox->setLineEdit(WidgetsFactory::createLineEdit(this));
|
|
||||||
m_filePatternComboBox->lineEdit()->setPlaceholderText(tr("Wildcard pattern of files and folders to search"));
|
|
||||||
m_filePatternComboBox->lineEdit()->setProperty(PropertyDefs::c_embeddedLineEdit, true);
|
|
||||||
m_filePatternComboBox->completer()->setCaseSensitivity(Qt::CaseSensitive);
|
|
||||||
inputsLayout->addRow(tr("File pattern:"), m_filePatternComboBox);
|
|
||||||
|
|
||||||
setupFindOption(inputsLayout);
|
setupSearchTarget(advLayout);
|
||||||
|
|
||||||
|
m_filePatternComboBox = WidgetsFactory::createComboBox(m_advancedSettings);
|
||||||
|
m_filePatternComboBox->setEditable(true);
|
||||||
|
m_filePatternComboBox->setLineEdit(WidgetsFactory::createLineEdit(m_advancedSettings));
|
||||||
|
m_filePatternComboBox->lineEdit()->setPlaceholderText(tr("Wildcard pattern of files to search"));
|
||||||
|
m_filePatternComboBox->lineEdit()->setProperty(PropertyDefs::c_embeddedLineEdit, true);
|
||||||
|
m_filePatternComboBox->completer()->setCaseSensitivity(Qt::CaseSensitive);
|
||||||
|
advLayout->addRow(tr("File pattern:"), m_filePatternComboBox);
|
||||||
|
|
||||||
|
setupFindOption(advLayout);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
// TODO: use a global progress bar.
|
||||||
m_progressBar = new QProgressBar(this);
|
m_progressBar = new QProgressBar(this);
|
||||||
m_progressBar->setRange(0, 0);
|
m_progressBar->setRange(0, 0);
|
||||||
m_progressBar->hide();
|
m_progressBar->hide();
|
||||||
@ -115,10 +126,17 @@ TitleBar *SearchPanel::setupTitleBar(const QString &p_title, QWidget *p_parent)
|
|||||||
connect(cancelBtn, &QToolButton::triggered,
|
connect(cancelBtn, &QToolButton::triggered,
|
||||||
this, &SearchPanel::stopSearch);
|
this, &SearchPanel::stopSearch);
|
||||||
|
|
||||||
auto closeLocationListBtn = titleBar->addActionButton(QStringLiteral("close.svg"), tr("Close Location List"));
|
auto toggleLocationListBtn = titleBar->addActionButton(QStringLiteral("search_location_list.svg"), tr("Toggle Location List"));
|
||||||
connect(closeLocationListBtn, &QToolButton::triggered,
|
connect(toggleLocationListBtn, &QToolButton::triggered,
|
||||||
this, [this]() {
|
this, [this]() {
|
||||||
|
VNoteX::getInst().getMainWindow()->toggleLocationListVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
m_advancedSettingsBtn = titleBar->addActionButton(QStringLiteral("advanced_settings.svg"), tr("Advanced Settings"));
|
||||||
|
m_advancedSettingsBtn->defaultAction()->setCheckable(true);
|
||||||
|
connect(m_advancedSettingsBtn, &QToolButton::triggered,
|
||||||
|
this, [this](QAction *p_act) {
|
||||||
|
m_advancedSettings->setVisible(p_act->isChecked());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +210,7 @@ void SearchPanel::setupFindOption(QFormLayout *p_layout)
|
|||||||
|
|
||||||
void SearchPanel::initOptions()
|
void SearchPanel::initOptions()
|
||||||
{
|
{
|
||||||
// Read it from config.
|
// Read search option from config.
|
||||||
m_option = QSharedPointer<SearchOption>::create(ConfigMgr::getInst().getSessionConfig().getSearchOption());
|
m_option = QSharedPointer<SearchOption>::create(ConfigMgr::getInst().getSessionConfig().getSearchOption());
|
||||||
|
|
||||||
connect(VNoteX::getInst().getMainWindow(), &MainWindow::mainWindowClosedOnQuit,
|
connect(VNoteX::getInst().getMainWindow(), &MainWindow::mainWindowClosedOnQuit,
|
||||||
@ -200,6 +218,10 @@ void SearchPanel::initOptions()
|
|||||||
saveFields(*m_option);
|
saveFields(*m_option);
|
||||||
ConfigMgr::getInst().getSessionConfig().setSearchOption(*m_option);
|
ConfigMgr::getInst().getSessionConfig().setSearchOption(*m_option);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Init layout.
|
||||||
|
const auto &widgetConfig = ConfigMgr::getInst().getWidgetConfig();
|
||||||
|
m_advancedSettingsBtn->defaultAction()->setChecked(widgetConfig.isSearchPanelAdvancedSettingsVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchPanel::restoreFields(const SearchOption &p_option)
|
void SearchPanel::restoreFields(const SearchOption &p_option)
|
||||||
@ -303,6 +325,7 @@ void SearchPanel::appendLog(const QString &p_text)
|
|||||||
if (!m_infoTextEdit) {
|
if (!m_infoTextEdit) {
|
||||||
m_infoTextEdit = WidgetsFactory::createPlainTextConsole(this);
|
m_infoTextEdit = WidgetsFactory::createPlainTextConsole(this);
|
||||||
m_infoTextEdit->setMaximumHeight(m_infoTextEdit->minimumSizeHint().height());
|
m_infoTextEdit->setMaximumHeight(m_infoTextEdit->minimumSizeHint().height());
|
||||||
|
// Before progress bar.
|
||||||
static_cast<QVBoxLayout *>(layout())->insertWidget(layout()->count() - 1, m_infoTextEdit);
|
static_cast<QVBoxLayout *>(layout())->insertWidget(layout()->count() - 1, m_infoTextEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ namespace vnotex
|
|||||||
|
|
||||||
QToolButton *m_searchBtn = nullptr;
|
QToolButton *m_searchBtn = nullptr;
|
||||||
|
|
||||||
|
QToolButton *m_advancedSettingsBtn = nullptr;
|
||||||
|
|
||||||
QComboBox *m_keywordComboBox = nullptr;
|
QComboBox *m_keywordComboBox = nullptr;
|
||||||
|
|
||||||
QComboBox *m_searchScopeComboBox = nullptr;
|
QComboBox *m_searchScopeComboBox = nullptr;
|
||||||
@ -127,6 +129,8 @@ namespace vnotex
|
|||||||
|
|
||||||
QRadioButton *m_regularExpressionRadioBtn = nullptr;
|
QRadioButton *m_regularExpressionRadioBtn = nullptr;
|
||||||
|
|
||||||
|
QWidget *m_advancedSettings = nullptr;
|
||||||
|
|
||||||
QProgressBar *m_progressBar = nullptr;
|
QProgressBar *m_progressBar = nullptr;
|
||||||
|
|
||||||
QPlainTextEdit *m_infoTextEdit = nullptr;
|
QPlainTextEdit *m_infoTextEdit = nullptr;
|
||||||
|
@ -20,7 +20,7 @@ using namespace vnotex;
|
|||||||
TextViewWindow::TextViewWindow(QWidget *p_parent)
|
TextViewWindow::TextViewWindow(QWidget *p_parent)
|
||||||
: ViewWindow(p_parent)
|
: ViewWindow(p_parent)
|
||||||
{
|
{
|
||||||
m_mode = Mode::Edit;
|
m_mode = ViewWindowMode::Edit;
|
||||||
setupUI();
|
setupUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,8 +72,9 @@ void TextViewWindow::setupToolBar()
|
|||||||
addAction(toolBar, ViewWindowToolBarHelper::FindAndReplace);
|
addAction(toolBar, ViewWindowToolBarHelper::FindAndReplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextViewWindow::handleBufferChangedInternal()
|
void TextViewWindow::handleBufferChangedInternal(const QSharedPointer<FileOpenParameters> &p_paras)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(p_paras);
|
||||||
TextViewWindowHelper::handleBufferChanged(this);
|
TextViewWindowHelper::handleBufferChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ void TextViewWindow::setBufferRevisionAfterInvalidation(int p_bufferRevision)
|
|||||||
m_bufferRevision = p_bufferRevision;
|
m_bufferRevision = p_bufferRevision;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextViewWindow::setMode(Mode p_mode)
|
void TextViewWindow::setMode(ViewWindowMode p_mode)
|
||||||
{
|
{
|
||||||
Q_UNUSED(p_mode);
|
Q_UNUSED(p_mode);
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
|
@ -23,7 +23,7 @@ namespace vnotex
|
|||||||
|
|
||||||
QString getLatestContent() const Q_DECL_OVERRIDE;
|
QString getLatestContent() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void setMode(Mode p_mode) Q_DECL_OVERRIDE;
|
void setMode(ViewWindowMode p_mode) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleEditorConfigChange() Q_DECL_OVERRIDE;
|
void handleEditorConfigChange() Q_DECL_OVERRIDE;
|
||||||
@ -31,7 +31,7 @@ namespace vnotex
|
|||||||
protected slots:
|
protected slots:
|
||||||
void setModified(bool p_modified) Q_DECL_OVERRIDE;
|
void setModified(bool p_modified) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void handleBufferChangedInternal() Q_DECL_OVERRIDE;
|
void handleBufferChangedInternal(const QSharedPointer<FileOpenParameters> &p_paras) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
void handleFindTextChanged(const QString &p_text, FindOptions p_options) Q_DECL_OVERRIDE;
|
void handleFindTextChanged(const QString &p_text, FindOptions p_options) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -70,30 +70,6 @@ ViewWindow::ViewWindow(QWidget *p_parent)
|
|||||||
syncEditorFromBufferContent();
|
syncEditorFromBufferContent();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &ViewWindow::bufferChanged,
|
|
||||||
this, [this]() {
|
|
||||||
auto buffer = getBuffer();
|
|
||||||
if (buffer) {
|
|
||||||
connect(buffer, &Buffer::modified,
|
|
||||||
this, &ViewWindow::statusChanged);
|
|
||||||
|
|
||||||
// To make it convenient to disconnect, do not connect directly to
|
|
||||||
// the timer.
|
|
||||||
connect(buffer, &Buffer::contentsChanged,
|
|
||||||
this, [this]() {
|
|
||||||
m_syncBufferContentTimer->start();
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(buffer, &Buffer::nameChanged,
|
|
||||||
this, &ViewWindow::nameChanged);
|
|
||||||
|
|
||||||
connect(buffer, &Buffer::attachmentChanged,
|
|
||||||
this, &ViewWindow::attachmentChanged);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleBufferChangedInternal();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewWindow::~ViewWindow()
|
ViewWindow::~ViewWindow()
|
||||||
@ -140,7 +116,33 @@ Buffer *ViewWindow::getBuffer() const
|
|||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewWindow::attachToBuffer(Buffer *p_buffer)
|
void ViewWindow::handleBufferChanged(const QSharedPointer<FileOpenParameters> &p_paras)
|
||||||
|
{
|
||||||
|
auto buffer = getBuffer();
|
||||||
|
if (buffer) {
|
||||||
|
connect(buffer, &Buffer::modified,
|
||||||
|
this, &ViewWindow::statusChanged);
|
||||||
|
|
||||||
|
// To make it convenient to disconnect, do not connect directly to
|
||||||
|
// the timer.
|
||||||
|
connect(buffer, &Buffer::contentsChanged,
|
||||||
|
this, [this]() {
|
||||||
|
m_syncBufferContentTimer->start();
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(buffer, &Buffer::nameChanged,
|
||||||
|
this, &ViewWindow::nameChanged);
|
||||||
|
|
||||||
|
connect(buffer, &Buffer::attachmentChanged,
|
||||||
|
this, &ViewWindow::attachmentChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBufferChangedInternal(p_paras);
|
||||||
|
|
||||||
|
emit bufferChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewWindow::attachToBuffer(Buffer *p_buffer, const QSharedPointer<FileOpenParameters> &p_paras)
|
||||||
{
|
{
|
||||||
Q_ASSERT(p_buffer);
|
Q_ASSERT(p_buffer);
|
||||||
Q_ASSERT(m_buffer != p_buffer);
|
Q_ASSERT(m_buffer != p_buffer);
|
||||||
@ -150,7 +152,7 @@ void ViewWindow::attachToBuffer(Buffer *p_buffer)
|
|||||||
m_buffer = p_buffer;
|
m_buffer = p_buffer;
|
||||||
m_buffer->attachViewWindow(this);
|
m_buffer->attachViewWindow(this);
|
||||||
|
|
||||||
emit bufferChanged();
|
handleBufferChanged(p_paras);
|
||||||
|
|
||||||
if (m_buffer->getAttachViewWindowCount() == 1) {
|
if (m_buffer->getAttachViewWindowCount() == 1) {
|
||||||
QTimer::singleShot(1000, this, &ViewWindow::checkBackupFileOfPreviousSession);
|
QTimer::singleShot(1000, this, &ViewWindow::checkBackupFileOfPreviousSession);
|
||||||
@ -172,7 +174,7 @@ void ViewWindow::detachFromBuffer(bool p_quiet)
|
|||||||
m_buffer = nullptr;
|
m_buffer = nullptr;
|
||||||
|
|
||||||
if (!p_quiet) {
|
if (!p_quiet) {
|
||||||
emit bufferChanged();
|
handleBufferChanged(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,20 +532,7 @@ bool ViewWindow::aboutToClose(bool p_force)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewWindow::Mode ViewWindow::modeFromOpenParameters(const FileOpenParameters &p_paras)
|
ViewWindowMode ViewWindow::getMode() const
|
||||||
{
|
|
||||||
switch (p_paras.m_mode) {
|
|
||||||
case FileOpenParameters::Mode::Edit:
|
|
||||||
return ViewWindow::Mode::Edit;
|
|
||||||
|
|
||||||
case FileOpenParameters::Mode::Read:
|
|
||||||
Q_FALLTHROUGH();
|
|
||||||
default:
|
|
||||||
return ViewWindow::Mode::Read;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewWindow::Mode ViewWindow::getMode() const
|
|
||||||
{
|
{
|
||||||
return m_mode;
|
return m_mode;
|
||||||
}
|
}
|
||||||
@ -595,12 +584,12 @@ void ViewWindow::discardChangesAndRead()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setMode(Mode::Read);
|
setMode(ViewWindowMode::Read);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewWindow::inModeCanInsert() const
|
bool ViewWindow::inModeCanInsert() const
|
||||||
{
|
{
|
||||||
return m_mode == Mode::Edit || m_mode == Mode::FocusPreview || m_mode == Mode::FullPreview;
|
return m_mode == ViewWindowMode::Edit || m_mode == ViewWindowMode::FocusPreview || m_mode == ViewWindowMode::FullPreview;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewWindow::handleTypeAction(TypeAction p_action)
|
void ViewWindow::handleTypeAction(TypeAction p_action)
|
||||||
@ -829,7 +818,7 @@ bool ViewWindow::save(bool p_force)
|
|||||||
void ViewWindow::updateEditReadDiscardActionState(EditReadDiscardAction *p_act)
|
void ViewWindow::updateEditReadDiscardActionState(EditReadDiscardAction *p_act)
|
||||||
{
|
{
|
||||||
switch (getMode()) {
|
switch (getMode()) {
|
||||||
case Mode::Read:
|
case ViewWindowMode::Read:
|
||||||
p_act->setState(BiAction::State::Default);
|
p_act->setState(BiAction::State::Default);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1057,7 +1046,7 @@ void ViewWindow::edit()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setMode(Mode::Edit);
|
setMode(ViewWindowMode::Edit);
|
||||||
setFocus();
|
setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,7 +1061,7 @@ void ViewWindow::read(bool p_save)
|
|||||||
|
|
||||||
if (p_save) {
|
if (p_save) {
|
||||||
if (save(false)) {
|
if (save(false)) {
|
||||||
setMode(Mode::Read);
|
setMode(ViewWindowMode::Read);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
discardChangesAndRead();
|
discardChangesAndRead();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
|
|
||||||
#include <buffer/buffer.h>
|
#include <buffer/buffer.h>
|
||||||
|
#include <core/global.h>
|
||||||
|
|
||||||
#include "viewwindowtoolbarhelper.h"
|
#include "viewwindowtoolbarhelper.h"
|
||||||
|
|
||||||
@ -28,22 +29,13 @@ namespace vnotex
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Mode
|
|
||||||
{
|
|
||||||
Read,
|
|
||||||
Edit,
|
|
||||||
FullPreview,
|
|
||||||
FocusPreview,
|
|
||||||
Invalid
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit ViewWindow(QWidget *p_parent = nullptr);
|
explicit ViewWindow(QWidget *p_parent = nullptr);
|
||||||
|
|
||||||
virtual ~ViewWindow();
|
virtual ~ViewWindow();
|
||||||
|
|
||||||
Buffer *getBuffer() const;
|
Buffer *getBuffer() const;
|
||||||
|
|
||||||
void attachToBuffer(Buffer *p_buffer);
|
void attachToBuffer(Buffer *p_buffer, const QSharedPointer<FileOpenParameters> &p_paras);
|
||||||
|
|
||||||
void detachFromBuffer(bool p_quiet = false);
|
void detachFromBuffer(bool p_quiet = false);
|
||||||
|
|
||||||
@ -68,8 +60,8 @@ namespace vnotex
|
|||||||
// Return true if it is OK to proceed.
|
// Return true if it is OK to proceed.
|
||||||
bool aboutToClose(bool p_force);
|
bool aboutToClose(bool p_force);
|
||||||
|
|
||||||
ViewWindow::Mode getMode() const;
|
ViewWindowMode getMode() const;
|
||||||
virtual void setMode(Mode p_mode) = 0;
|
virtual void setMode(ViewWindowMode p_mode) = 0;
|
||||||
|
|
||||||
virtual QSharedPointer<OutlineProvider> getOutlineProvider();
|
virtual QSharedPointer<OutlineProvider> getOutlineProvider();
|
||||||
|
|
||||||
@ -134,7 +126,7 @@ namespace vnotex
|
|||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Handle current buffer change.
|
// Handle current buffer change.
|
||||||
virtual void handleBufferChangedInternal() = 0;
|
virtual void handleBufferChangedInternal(const QSharedPointer<FileOpenParameters> &p_paras) = 0;
|
||||||
|
|
||||||
// Handle all kinds of type action.
|
// Handle all kinds of type action.
|
||||||
virtual void handleTypeAction(TypeAction p_action);
|
virtual void handleTypeAction(TypeAction p_action);
|
||||||
@ -218,8 +210,6 @@ namespace vnotex
|
|||||||
|
|
||||||
void read(bool p_save);
|
void read(bool p_save);
|
||||||
|
|
||||||
static ViewWindow::Mode modeFromOpenParameters(const FileOpenParameters &p_paras);
|
|
||||||
|
|
||||||
static QToolBar *createToolBar(QWidget *p_parent = nullptr);
|
static QToolBar *createToolBar(QWidget *p_parent = nullptr);
|
||||||
|
|
||||||
// The revision of the buffer of the last sync content.
|
// The revision of the buffer of the last sync content.
|
||||||
@ -229,7 +219,7 @@ namespace vnotex
|
|||||||
// Subclass should maintain it.
|
// Subclass should maintain it.
|
||||||
int m_editorConfigRevision = 0;
|
int m_editorConfigRevision = 0;
|
||||||
|
|
||||||
Mode m_mode = Mode::Invalid;
|
ViewWindowMode m_mode = ViewWindowMode::Invalid;
|
||||||
|
|
||||||
// Managed by QObject.
|
// Managed by QObject.
|
||||||
FindAndReplaceWidget *m_findAndReplace = nullptr;
|
FindAndReplaceWidget *m_findAndReplace = nullptr;
|
||||||
@ -282,6 +272,8 @@ namespace vnotex
|
|||||||
|
|
||||||
void findNextOnLastFind(bool p_forward = true);
|
void findNextOnLastFind(bool p_forward = true);
|
||||||
|
|
||||||
|
void handleBufferChanged(const QSharedPointer<FileOpenParameters> &p_paras);
|
||||||
|
|
||||||
static ViewWindow::TypeAction toolBarActionToTypeAction(ViewWindowToolBarHelper::Action p_action);
|
static ViewWindow::TypeAction toolBarActionToTypeAction(ViewWindowToolBarHelper::Action p_action);
|
||||||
|
|
||||||
Buffer *m_buffer = nullptr;
|
Buffer *m_buffer = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user