update current header in outline correctly

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-11-09 21:41:57 +08:00
parent 849fdf05bd
commit 454072c9ba
6 changed files with 63 additions and 48 deletions

View File

@ -165,17 +165,16 @@ void VEditArea::setCurrentWindow(int windowIndex, bool setFocus)
}
out:
// Update tab status
noticeTabStatus();
emit outlineChanged(getWindow(windowIndex)->getTabOutline());
// Update status
updateWindowStatus();
}
void VEditArea::noticeTabStatus()
void VEditArea::updateWindowStatus()
{
QString notebook, relativePath;
bool editMode, modifiable;
getWindow(curWindowIndex)->getTabStatus(notebook, relativePath, editMode, modifiable);
emit curTabStatusChanged(notebook, relativePath, editMode, modifiable);
VEditWindow *win = getWindow(curWindowIndex);
win->requestUpdateTabStatus();
win->requestUpdateOutline();
win->requestUpdateCurHeader();
}
void VEditArea::closeFile(QJsonObject fileJson)

View File

@ -60,7 +60,7 @@ private:
inline VEditWindow *getWindow(int windowIndex) const;
void insertSplitWindow(int idx);
void removeSplitWindow(VEditWindow *win);
void noticeTabStatus();
void updateWindowStatus();
VNote *vnote;
int curWindowIndex;

View File

@ -333,9 +333,14 @@ void VEditTab::parseTocLi(QXmlStreamReader &xml, QVector<VHeader> &headers, int
}
}
const VToc& VEditTab::getOutline() const
void VEditTab::requestUpdateCurHeader()
{
return tableOfContent;
emit curHeaderChanged(curHeader);
}
void VEditTab::requestUpdateOutline()
{
emit outlineChanged(tableOfContent);
}
void VEditTab::scrollToAnchor(const VAnchor &anchor)
@ -353,12 +358,12 @@ void VEditTab::scrollToAnchor(const VAnchor &anchor)
void VEditTab::updateCurHeader(const QString &anchor)
{
if (curHeader == anchor) {
if (curHeader.anchor.mid(1) == anchor) {
return;
}
curHeader = anchor;
curHeader = VAnchor(QDir::cleanPath(QDir(noteFile->basePath).filePath(noteFile->fileName)),
"#" + anchor, -1);
if (!anchor.isEmpty()) {
emit curHeaderChanged(VAnchor(QDir::cleanPath(QDir(noteFile->basePath).filePath(noteFile->fileName)),
"#" + anchor, -1));
emit curHeaderChanged(curHeader);
}
}

View File

@ -33,7 +33,8 @@ public:
inline bool getIsEditMode() const;
inline bool isModified() const;
void focusTab();
const VToc& getOutline() const;
void requestUpdateOutline();
void requestUpdateCurHeader();
void scrollToAnchor(const VAnchor& anchor);
signals:
@ -65,7 +66,7 @@ private:
VDocument document;
MarkdownConverterType mdConverterType;
VToc tableOfContent;
QString curHeader;
VAnchor curHeader;
};
inline bool VEditTab::getIsEditMode() const

View File

@ -93,7 +93,7 @@ int VEditWindow::insertTabWithData(int index, QWidget *page,
int idx = insertTab(index, page, label);
QTabBar *tabs = tabBar();
tabs->setTabData(idx, tabData);
noticeTabStatus(currentIndex());
noticeStatus(currentIndex());
return idx;
}
@ -116,7 +116,7 @@ out:
editFile();
}
focusWindow();
noticeTabStatus(idx);
noticeStatus(idx);
return idx;
}
@ -204,7 +204,7 @@ bool VEditWindow::handleTabCloseRequest(int index)
delete editor;
}
updateTabListMenu();
noticeTabStatus(currentIndex());
noticeStatus(currentIndex());
// User clicks the close button. We should make this window
// to be current window.
emit getFocused();
@ -216,14 +216,14 @@ void VEditWindow::readFile()
VEditTab *editor = getTab(currentIndex());
Q_ASSERT(editor);
editor->readFile();
noticeTabStatus(currentIndex());
noticeStatus(currentIndex());
}
void VEditWindow::saveAndReadFile()
{
saveFile();
readFile();
noticeTabStatus(currentIndex());
noticeStatus(currentIndex());
}
void VEditWindow::editFile()
@ -231,7 +231,7 @@ void VEditWindow::editFile()
VEditTab *editor = getTab(currentIndex());
Q_ASSERT(editor);
editor->editFile();
noticeTabStatus(currentIndex());
noticeStatus(currentIndex());
}
void VEditWindow::saveFile()
@ -275,33 +275,29 @@ void VEditWindow::noticeTabStatus(int index)
editMode, modifiable);
}
void VEditWindow::getTabStatus(QString &notebook, QString &relativePath,
bool &editMode, bool &modifiable) const
void VEditWindow::requestUpdateTabStatus()
{
int idx = currentIndex();
if (idx == -1) {
notebook = relativePath = "";
editMode = modifiable = false;
return;
}
QJsonObject tabJson = tabBar()->tabData(idx).toJsonObject();
Q_ASSERT(!tabJson.isEmpty());
notebook = tabJson["notebook"].toString();
relativePath = tabJson["relative_path"].toString();
VEditTab *editor = getTab(idx);
editMode = editor->getIsEditMode();
modifiable = tabJson["modifiable"].toBool();
noticeTabStatus(currentIndex());
}
VToc VEditWindow::getTabOutline() const
void VEditWindow::requestUpdateOutline()
{
int idx = currentIndex();
if (idx == -1) {
return VToc();
emit outlineChanged(VToc());
return;
}
getTab(idx)->requestUpdateOutline();
}
return getTab(idx)->getOutline();
void VEditWindow::requestUpdateCurHeader()
{
int idx = currentIndex();
if (idx == -1) {
emit curHeaderChanged(VAnchor());
return;
}
getTab(idx)->requestUpdateCurHeader();
}
void VEditWindow::focusWindow()
@ -318,8 +314,7 @@ void VEditWindow::handleTabbarClicked(int index)
{
// The child will emit getFocused here
focusWindow();
noticeTabStatus(index);
emit outlineChanged(getTab(index)->getOutline());
noticeStatus(index);
}
void VEditWindow::mousePressEvent(QMouseEvent *event)
@ -347,7 +342,7 @@ void VEditWindow::tabListJump(QAction *action)
tabJson["relative_path"].toString());
Q_ASSERT(idx >= 0);
setCurrentIndex(idx);
noticeTabStatus(idx);
noticeStatus(idx);
}
void VEditWindow::updateTabListMenu()
@ -412,3 +407,17 @@ void VEditWindow::scrollCurTab(const VAnchor &anchor)
getTab(idx)->scrollToAnchor(anchor);
}
}
void VEditWindow::noticeStatus(int index)
{
noticeTabStatus(index);
if (index == -1) {
emit outlineChanged(VToc());
emit curHeaderChanged(VAnchor());
} else {
VEditTab *tab = getTab(index);
tab->requestUpdateOutline();
tab->requestUpdateCurHeader();
}
}

View File

@ -32,9 +32,9 @@ public:
const QString &newName);
bool closeAllFiles();
void setRemoveSplitEnable(bool enabled);
void getTabStatus(QString &notebook, QString &relativePath,
bool &editMode, bool &modifiable) const;
VToc getTabOutline() const;
void requestUpdateTabStatus();
void requestUpdateOutline();
void requestUpdateCurHeader();
// Focus to current tab's editor
void focusWindow();
void scrollCurTab(const VAnchor &anchor);
@ -72,6 +72,7 @@ private:
inline VEditTab *getTab(int tabIndex) const;
void noticeTabStatus(int index);
void updateTabListMenu();
void noticeStatus(int index);
VNote *vnote;
// Button in the right corner