mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
change VEditor to VEditTab
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
d8aa464653
commit
29a41e8285
@ -22,7 +22,6 @@ SOURCES += main.cpp\
|
||||
vfilelist.cpp \
|
||||
dialog/vnewfiledialog.cpp \
|
||||
vedit.cpp \
|
||||
veditor.cpp \
|
||||
vnotefile.cpp \
|
||||
vdocument.cpp \
|
||||
utils/vutils.cpp \
|
||||
@ -41,7 +40,8 @@ SOURCES += main.cpp\
|
||||
dialog/vinsertimagedialog.cpp \
|
||||
vdownloader.cpp \
|
||||
veditarea.cpp \
|
||||
veditwindow.cpp
|
||||
veditwindow.cpp \
|
||||
vedittab.cpp
|
||||
|
||||
HEADERS += vmainwindow.h \
|
||||
vdirectorytree.h \
|
||||
@ -52,7 +52,6 @@ HEADERS += vmainwindow.h \
|
||||
vfilelist.h \
|
||||
dialog/vnewfiledialog.h \
|
||||
vedit.h \
|
||||
veditor.h \
|
||||
vconstants.h \
|
||||
vnotefile.h \
|
||||
vdocument.h \
|
||||
@ -73,7 +72,8 @@ HEADERS += vmainwindow.h \
|
||||
dialog/vinsertimagedialog.h \
|
||||
vdownloader.h \
|
||||
veditarea.h \
|
||||
veditwindow.h
|
||||
veditwindow.h \
|
||||
vedittab.h
|
||||
|
||||
RESOURCES += \
|
||||
vnote.qrc
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QtWidgets>
|
||||
#include "veditarea.h"
|
||||
#include "veditwindow.h"
|
||||
#include "veditor.h"
|
||||
#include "vedittab.h"
|
||||
#include "vnote.h"
|
||||
#include "vconfigmanager.h"
|
||||
|
||||
@ -143,16 +143,16 @@ int VEditArea::openFileInWindow(int windowIndex, const QString ¬ebook, const
|
||||
|
||||
void VEditArea::setCurrentTab(int windowIndex, int tabIndex, bool setFocus)
|
||||
{
|
||||
setCurrentWindow(windowIndex, setFocus);
|
||||
|
||||
VEditWindow *win = getWindow(windowIndex);
|
||||
win->setCurrentIndex(tabIndex);
|
||||
|
||||
setCurrentWindow(windowIndex, setFocus);
|
||||
}
|
||||
|
||||
void VEditArea::setCurrentWindow(int windowIndex, bool setFocus)
|
||||
{
|
||||
if (curWindowIndex == windowIndex) {
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
qDebug() << "current window" << windowIndex;
|
||||
curWindowIndex = windowIndex;
|
||||
@ -160,7 +160,13 @@ void VEditArea::setCurrentWindow(int windowIndex, bool setFocus)
|
||||
getWindow(windowIndex)->focusWindow();
|
||||
}
|
||||
|
||||
out:
|
||||
// Update tab status
|
||||
noticeTabStatus();
|
||||
}
|
||||
|
||||
void VEditArea::noticeTabStatus()
|
||||
{
|
||||
QString notebook, relativePath;
|
||||
bool editMode, modifiable;
|
||||
getWindow(curWindowIndex)->getTabStatus(notebook, relativePath, editMode, modifiable);
|
||||
|
@ -54,6 +54,7 @@ private:
|
||||
inline VEditWindow *getWindow(int windowIndex) const;
|
||||
void insertSplitWindow(int idx);
|
||||
void removeSplitWindow(VEditWindow *win);
|
||||
void noticeTabStatus();
|
||||
|
||||
VNote *vnote;
|
||||
int curWindowIndex;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <QWebChannel>
|
||||
#include <QWebEngineView>
|
||||
#include <QFileInfo>
|
||||
#include "veditor.h"
|
||||
#include "vedittab.h"
|
||||
#include "vedit.h"
|
||||
#include "vdocument.h"
|
||||
#include "vnote.h"
|
||||
@ -16,13 +16,13 @@
|
||||
|
||||
extern VConfigManager vconfig;
|
||||
|
||||
VEditor::VEditor(const QString &path, bool modifiable, QWidget *parent)
|
||||
VEditTab::VEditTab(const QString &path, bool modifiable, QWidget *parent)
|
||||
: QStackedWidget(parent), mdConverterType(vconfig.getMdConverterType())
|
||||
{
|
||||
DocType docType = isMarkdown(path) ? DocType::Markdown : DocType::Html;
|
||||
QString basePath = QFileInfo(path).path();
|
||||
QString fileName = QFileInfo(path).fileName();
|
||||
qDebug() << "VEditor basePath" << basePath << "file" << fileName;
|
||||
qDebug() << "VEditTab basePath" << basePath << "file" << fileName;
|
||||
QString fileText = VUtils::readFileFromDisk(path);
|
||||
noteFile = new VNoteFile(basePath, fileName, fileText,
|
||||
docType, modifiable);
|
||||
@ -34,17 +34,17 @@ VEditor::VEditor(const QString &path, bool modifiable, QWidget *parent)
|
||||
showFileReadMode();
|
||||
|
||||
connect(qApp, &QApplication::focusChanged,
|
||||
this, &VEditor::handleFocusChanged);
|
||||
this, &VEditTab::handleFocusChanged);
|
||||
}
|
||||
|
||||
VEditor::~VEditor()
|
||||
VEditTab::~VEditTab()
|
||||
{
|
||||
if (noteFile) {
|
||||
delete noteFile;
|
||||
}
|
||||
}
|
||||
|
||||
void VEditor::setupUI()
|
||||
void VEditTab::setupUI()
|
||||
{
|
||||
textEditor = new VEdit(noteFile);
|
||||
addWidget(textEditor);
|
||||
@ -67,7 +67,7 @@ void VEditor::setupUI()
|
||||
}
|
||||
}
|
||||
|
||||
bool VEditor::isMarkdown(const QString &name)
|
||||
bool VEditTab::isMarkdown(const QString &name)
|
||||
{
|
||||
const QVector<QString> mdPostfix({"md", "markdown", "mkd"});
|
||||
|
||||
@ -84,7 +84,7 @@ bool VEditor::isMarkdown(const QString &name)
|
||||
return false;
|
||||
}
|
||||
|
||||
void VEditor::showFileReadMode()
|
||||
void VEditTab::showFileReadMode()
|
||||
{
|
||||
isEditMode = false;
|
||||
switch (noteFile->docType) {
|
||||
@ -107,7 +107,7 @@ void VEditor::showFileReadMode()
|
||||
}
|
||||
}
|
||||
|
||||
void VEditor::previewByConverter()
|
||||
void VEditTab::previewByConverter()
|
||||
{
|
||||
VMarkdownConverter mdConverter;
|
||||
QString content = noteFile->content;
|
||||
@ -119,7 +119,7 @@ void VEditor::previewByConverter()
|
||||
webPreviewer->setHtml(completeHtml, QUrl::fromLocalFile(noteFile->basePath + QDir::separator()));
|
||||
}
|
||||
|
||||
void VEditor::showFileEditMode()
|
||||
void VEditTab::showFileEditMode()
|
||||
{
|
||||
isEditMode = true;
|
||||
textEditor->beginEdit();
|
||||
@ -127,13 +127,13 @@ void VEditor::showFileEditMode()
|
||||
textEditor->setFocus();
|
||||
}
|
||||
|
||||
bool VEditor::requestClose()
|
||||
bool VEditTab::requestClose()
|
||||
{
|
||||
readFile();
|
||||
return !isEditMode;
|
||||
}
|
||||
|
||||
void VEditor::editFile()
|
||||
void VEditTab::editFile()
|
||||
{
|
||||
if (isEditMode || !noteFile->modifiable) {
|
||||
return;
|
||||
@ -142,7 +142,7 @@ void VEditor::editFile()
|
||||
showFileEditMode();
|
||||
}
|
||||
|
||||
void VEditor::readFile()
|
||||
void VEditTab::readFile()
|
||||
{
|
||||
if (!isEditMode) {
|
||||
return;
|
||||
@ -176,7 +176,7 @@ void VEditor::readFile()
|
||||
showFileReadMode();
|
||||
}
|
||||
|
||||
bool VEditor::saveFile()
|
||||
bool VEditTab::saveFile()
|
||||
{
|
||||
if (!isEditMode || !noteFile->modifiable || !textEditor->isModified()) {
|
||||
return true;
|
||||
@ -207,7 +207,7 @@ bool VEditor::saveFile()
|
||||
return true;
|
||||
}
|
||||
|
||||
void VEditor::setupMarkdownPreview()
|
||||
void VEditTab::setupMarkdownPreview()
|
||||
{
|
||||
webPreviewer = new QWebEngineView(this);
|
||||
VPreviewPage *page = new VPreviewPage(this);
|
||||
@ -224,12 +224,12 @@ void VEditor::setupMarkdownPreview()
|
||||
addWidget(webPreviewer);
|
||||
}
|
||||
|
||||
void VEditor::focusTab()
|
||||
void VEditTab::focusTab()
|
||||
{
|
||||
currentWidget()->setFocus();
|
||||
}
|
||||
|
||||
void VEditor::handleFocusChanged(QWidget *old, QWidget *now)
|
||||
void VEditTab::handleFocusChanged(QWidget *old, QWidget *now)
|
||||
{
|
||||
if (isChild(now)) {
|
||||
emit getFocused();
|
@ -1,5 +1,5 @@
|
||||
#ifndef VEDITOR_H
|
||||
#define VEDITOR_H
|
||||
#ifndef VEDITTAB_H
|
||||
#define VEDITTAB_H
|
||||
|
||||
#include <QStackedWidget>
|
||||
#include <QString>
|
||||
@ -14,12 +14,12 @@ class QTextBrowser;
|
||||
class QWebEngineView;
|
||||
class VNote;
|
||||
|
||||
class VEditor : public QStackedWidget
|
||||
class VEditTab : public QStackedWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
VEditor(const QString &path, bool modifiable, QWidget *parent = 0);
|
||||
~VEditor();
|
||||
VEditTab(const QString &path, bool modifiable, QWidget *parent = 0);
|
||||
~VEditTab();
|
||||
bool requestClose();
|
||||
// Enter edit mode
|
||||
void editFile();
|
||||
@ -56,17 +56,17 @@ private:
|
||||
MarkdownConverterType mdConverterType;
|
||||
};
|
||||
|
||||
inline bool VEditor::getIsEditMode() const
|
||||
inline bool VEditTab::getIsEditMode() const
|
||||
{
|
||||
return isEditMode;
|
||||
}
|
||||
|
||||
inline bool VEditor::isModified() const
|
||||
inline bool VEditTab::isModified() const
|
||||
{
|
||||
return textEditor->isModified();
|
||||
}
|
||||
|
||||
inline bool VEditor::isChild(QObject *obj)
|
||||
inline bool VEditTab::isChild(QObject *obj)
|
||||
{
|
||||
while (obj) {
|
||||
if (obj == this) {
|
||||
@ -77,4 +77,4 @@ inline bool VEditor::isChild(QObject *obj)
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif // VEDITOR_H
|
||||
#endif // VEDITTAB_H
|
@ -1,7 +1,7 @@
|
||||
#include <QtWidgets>
|
||||
#include <QtDebug>
|
||||
#include "veditwindow.h"
|
||||
#include "veditor.h"
|
||||
#include "vedittab.h"
|
||||
#include "vnote.h"
|
||||
#include "vconfigmanager.h"
|
||||
|
||||
@ -107,6 +107,7 @@ out:
|
||||
editFile();
|
||||
}
|
||||
focusWindow();
|
||||
noticeTabStatus(idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
@ -119,7 +120,7 @@ void VEditWindow::closeFile(const QString ¬ebook, const QString &relativePath
|
||||
}
|
||||
|
||||
// Do not check if modified
|
||||
VEditor *editor = getTab(idx);
|
||||
VEditTab *editor = getTab(idx);
|
||||
Q_ASSERT(editor);
|
||||
removeTab(idx);
|
||||
delete editor;
|
||||
@ -149,9 +150,9 @@ int VEditWindow::openFileInTab(const QString ¬ebook, const QString &relativeP
|
||||
}
|
||||
}
|
||||
|
||||
VEditor *editor = new VEditor(QDir::cleanPath(QDir(rootPath).filePath(relativePath)),
|
||||
modifiable);
|
||||
connect(editor, &VEditor::getFocused,
|
||||
VEditTab *editor = new VEditTab(QDir::cleanPath(QDir(rootPath).filePath(relativePath)),
|
||||
modifiable);
|
||||
connect(editor, &VEditTab::getFocused,
|
||||
this, &VEditWindow::getFocused);
|
||||
|
||||
QJsonObject tabJson;
|
||||
@ -178,7 +179,7 @@ int VEditWindow::findTabByFile(const QString ¬ebook, const QString &relativeP
|
||||
bool VEditWindow::handleTabCloseRequest(int index)
|
||||
{
|
||||
qDebug() << "request closing tab" << index;
|
||||
VEditor *editor = getTab(index);
|
||||
VEditTab *editor = getTab(index);
|
||||
Q_ASSERT(editor);
|
||||
bool ok = editor->requestClose();
|
||||
if (ok) {
|
||||
@ -194,7 +195,7 @@ bool VEditWindow::handleTabCloseRequest(int index)
|
||||
|
||||
void VEditWindow::readFile()
|
||||
{
|
||||
VEditor *editor = getTab(currentIndex());
|
||||
VEditTab *editor = getTab(currentIndex());
|
||||
Q_ASSERT(editor);
|
||||
editor->readFile();
|
||||
noticeTabStatus(currentIndex());
|
||||
@ -209,7 +210,7 @@ void VEditWindow::saveAndReadFile()
|
||||
|
||||
void VEditWindow::editFile()
|
||||
{
|
||||
VEditor *editor = getTab(currentIndex());
|
||||
VEditTab *editor = getTab(currentIndex());
|
||||
Q_ASSERT(editor);
|
||||
editor->editFile();
|
||||
noticeTabStatus(currentIndex());
|
||||
@ -217,7 +218,7 @@ void VEditWindow::editFile()
|
||||
|
||||
void VEditWindow::saveFile()
|
||||
{
|
||||
VEditor *editor = getTab(currentIndex());
|
||||
VEditTab *editor = getTab(currentIndex());
|
||||
Q_ASSERT(editor);
|
||||
editor->saveFile();
|
||||
}
|
||||
@ -248,7 +249,7 @@ void VEditWindow::noticeTabStatus(int index)
|
||||
|
||||
QString notebook = tabJson["notebook"].toString();
|
||||
QString relativePath = tabJson["relative_path"].toString();
|
||||
VEditor *editor = getTab(index);
|
||||
VEditTab *editor = getTab(index);
|
||||
bool editMode = editor->getIsEditMode();
|
||||
bool modifiable = tabJson["modifiable"].toBool();
|
||||
|
||||
@ -270,7 +271,7 @@ void VEditWindow::getTabStatus(QString ¬ebook, QString &relativePath,
|
||||
Q_ASSERT(!tabJson.isEmpty());
|
||||
notebook = tabJson["notebook"].toString();
|
||||
relativePath = tabJson["relative_path"].toString();
|
||||
VEditor *editor = getTab(idx);
|
||||
VEditTab *editor = getTab(idx);
|
||||
editMode = editor->getIsEditMode();
|
||||
modifiable = tabJson["modifiable"].toBool();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include "vnotebook.h"
|
||||
#include "veditor.h"
|
||||
#include "vedittab.h"
|
||||
|
||||
class VNote;
|
||||
class QPushButton;
|
||||
@ -60,7 +60,7 @@ private:
|
||||
int appendTabWithData(QWidget *page, const QJsonObject &tabData);
|
||||
int openFileInTab(const QString ¬ebook, const QString &relativePath, bool modifiable);
|
||||
inline QString getFileName(const QString &relativePath) const;
|
||||
inline VEditor *getTab(int tabIndex) const;
|
||||
inline VEditTab *getTab(int tabIndex) const;
|
||||
void noticeTabStatus(int index);
|
||||
|
||||
VNote *vnote;
|
||||
@ -77,9 +77,9 @@ inline QString VEditWindow::getFileName(const QString &path) const
|
||||
return QFileInfo(QDir::cleanPath(path)).fileName();
|
||||
}
|
||||
|
||||
inline VEditor* VEditWindow::getTab(int tabIndex) const
|
||||
inline VEditTab* VEditWindow::getTab(int tabIndex) const
|
||||
{
|
||||
return dynamic_cast<VEditor *>(widget(tabIndex));
|
||||
return dynamic_cast<VEditTab *>(widget(tabIndex));
|
||||
}
|
||||
|
||||
#endif // VEDITWINDOW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user