bugfix: update outline info after renaming

Update the filePath property in VToc after renaming the note.

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2017-01-11 21:26:46 +08:00
parent 3769ac5311
commit 62f2d39fbc
2 changed files with 21 additions and 0 deletions

View File

@ -400,6 +400,7 @@ void VEditTab::requestUpdateCurHeader()
void VEditTab::requestUpdateOutline() void VEditTab::requestUpdateOutline()
{ {
checkToc();
emit outlineChanged(tableOfContent); emit outlineChanged(tableOfContent);
} }
@ -427,6 +428,9 @@ void VEditTab::updateCurHeader(const QString &anchor)
} }
curHeader = VAnchor(m_file->retrivePath(), "#" + anchor, -1); curHeader = VAnchor(m_file->retrivePath(), "#" + anchor, -1);
if (!anchor.isEmpty()) { if (!anchor.isEmpty()) {
if (checkToc()) {
emit outlineChanged(tableOfContent);
}
const QVector<VHeader> &headers = tableOfContent.headers; const QVector<VHeader> &headers = tableOfContent.headers;
for (int i = 0; i < headers.size(); ++i) { for (int i = 0; i < headers.size(); ++i) {
if (headers[i].anchor == curHeader.anchor) { if (headers[i].anchor == curHeader.anchor) {
@ -443,6 +447,9 @@ void VEditTab::updateCurHeader(int p_lineNumber, int p_outlineIndex)
if (!isEditMode || curHeader.lineNumber == p_lineNumber) { if (!isEditMode || curHeader.lineNumber == p_lineNumber) {
return; return;
} }
if (checkToc()) {
emit outlineChanged(tableOfContent);
}
curHeader = VAnchor(m_file->retrivePath(), "", p_lineNumber); curHeader = VAnchor(m_file->retrivePath(), "", p_lineNumber);
curHeader.m_outlineIndex = p_outlineIndex; curHeader.m_outlineIndex = p_outlineIndex;
if (p_lineNumber > -1) { if (p_lineNumber > -1) {
@ -519,3 +526,14 @@ void VEditTab::clearFindSelectionInWebView()
webPreviewer->findText(""); webPreviewer->findText("");
} }
} }
bool VEditTab::checkToc()
{
bool ret = false;
if (tableOfContent.filePath != m_file->retrivePath()) {
tableOfContent.filePath = m_file->retrivePath();
ret = true;
}
return ret;
}

View File

@ -77,6 +77,9 @@ private:
void scrollPreviewToHeader(int p_outlineIndex); void scrollPreviewToHeader(int p_outlineIndex);
void findTextInWebView(const QString &p_text, uint p_options, bool p_peek, void findTextInWebView(const QString &p_text, uint p_options, bool p_peek,
bool p_forward); bool p_forward);
// Check if @tableOfContent is outdated (such as renaming the file).
// Return true if we need to update toc.
bool checkToc();
QPointer<VFile> m_file; QPointer<VFile> m_file;
bool isEditMode; bool isEditMode;