diff --git a/src/main.cpp b/src/main.cpp index 69387544..c564d28e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -223,13 +223,7 @@ int main(int argc, char *argv[]) w.show(); - w.checkNotebooks(); - - w.promptNewNotebookIfEmpty(); - - w.openStartupPages(); - - w.openFiles(filePaths); + w.kickOffStartUpTimer(filePaths); return app.exec(); } diff --git a/src/veditarea.cpp b/src/veditarea.cpp index abaac1a0..c1fef62e 100644 --- a/src/veditarea.cpp +++ b/src/veditarea.cpp @@ -811,7 +811,7 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed) return ret; } -int VEditArea::openFiles(const QVector &p_files) +int VEditArea::openFiles(const QVector &p_files, bool p_oneByOne) { VFile *curFile = NULL; int nrOpened = 0; @@ -838,6 +838,10 @@ int VEditArea::openFiles(const QVector &p_files) info.toEditTabInfo(&tabInfo); tab->tryRestoreFromTabInfo(tabInfo); + + if (p_oneByOne) { + QCoreApplication::sendPostedEvents(); + } } if (curFile) { diff --git a/src/veditarea.h b/src/veditarea.h index 1ac09943..49c2bf6f 100644 --- a/src/veditarea.h +++ b/src/veditarea.h @@ -79,7 +79,7 @@ public: bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE; // Open files @p_files. - int openFiles(const QVector &p_files); + int openFiles(const QVector &p_files, bool p_oneByOne = false); // Record a closed file in the stack. void recordClosedFile(const VFileSessionInfo &p_file); diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index d851c08e..a988d084 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -2637,7 +2637,8 @@ bool VMainWindow::tryOpenInternalFile(const QString &p_filePath) void VMainWindow::openFiles(const QStringList &p_files, bool p_forceOrphan, OpenFileMode p_mode, - bool p_forceMode) + bool p_forceMode, + bool p_oneByOne) { for (int i = 0; i < p_files.size(); ++i) { VFile *file = NULL; @@ -2650,6 +2651,9 @@ void VMainWindow::openFiles(const QStringList &p_files, } m_editArea->openFile(file, p_mode, p_forceMode); + if (p_oneByOne) { + QCoreApplication::sendPostedEvents(); + } } } @@ -2744,7 +2748,7 @@ void VMainWindow::openStartupPages() { QVector files = g_config->getLastOpenedFiles(); qDebug() << "open" << files.size() << "last opened files"; - m_editArea->openFiles(files); + m_editArea->openFiles(files, true); break; } @@ -2752,7 +2756,7 @@ void VMainWindow::openStartupPages() { QStringList pagesToOpen = VUtils::filterFilePathsToOpen(g_config->getStartupPages()); qDebug() << "open startup pages" << pagesToOpen; - openFiles(pagesToOpen); + openFiles(pagesToOpen, false, OpenFileMode::Read, false, true); break; } @@ -3403,3 +3407,15 @@ void VMainWindow::postChangePanelView() m_mainSplitter->setSizes(sizes); } } + +void VMainWindow::kickOffStartUpTimer(const QStringList &p_files) +{ + QTimer::singleShot(300, [this, p_files]() { + checkNotebooks(); + QCoreApplication::sendPostedEvents(); + promptNewNotebookIfEmpty(); + QCoreApplication::sendPostedEvents(); + openStartupPages(); + openFiles(p_files, false, OpenFileMode::Read, false, true); + }); +} diff --git a/src/vmainwindow.h b/src/vmainwindow.h index 8d63cfc4..d94cc870 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -89,7 +89,8 @@ public: void openFiles(const QStringList &p_files, bool p_forceOrphan = false, OpenFileMode p_mode = OpenFileMode::Read, - bool p_forceMode = false); + bool p_forceMode = false, + bool p_oneByOne = false); // Try to open @p_filePath as internal note. bool tryOpenInternalFile(const QString &p_filePath); @@ -114,6 +115,9 @@ public: VNotebook *getCurrentNotebook() const; + // Kick off timer to do things after start. + void kickOffStartUpTimer(const QStringList &p_files); + signals: // Emit when editor related configurations were changed by user. void editorConfigUpdated(); diff --git a/src/vmathjaxinplacepreviewhelper.cpp b/src/vmathjaxinplacepreviewhelper.cpp index 3643bf19..184e6e98 100644 --- a/src/vmathjaxinplacepreviewhelper.cpp +++ b/src/vmathjaxinplacepreviewhelper.cpp @@ -153,27 +153,23 @@ void VMathJaxInplacePreviewHelper::processForInplacePreview(int p_idx) if (vmb.m_text.isEmpty()) { updateInplacePreview(); } else { - textToHtmlViaWebView(vmb.m_text, p_idx, m_timeStamp); + if (!textToHtmlViaWebView(vmb.m_text, p_idx, m_timeStamp)) { + updateInplacePreview(); + } } } -void VMathJaxInplacePreviewHelper::textToHtmlViaWebView(const QString &p_text, +bool VMathJaxInplacePreviewHelper::textToHtmlViaWebView(const QString &p_text, int p_id, int p_timeStamp) { - int maxRetry = 50; - while (!m_document->isReadyToTextToHtml() && maxRetry > 0) { - qDebug() << "wait for web side ready to convert text to HTML"; - VUtils::sleepWait(100); - --maxRetry; - } - - if (maxRetry == 0) { - qWarning() << "web side is not ready to convert text to HTML"; - return; + if (!m_document->isReadyToTextToHtml()) { + qDebug() << "web side is not ready to convert text to HTML"; + return false; } m_document->textToHtmlAsync(m_documentID, p_id, p_timeStamp, p_text, false); + return true; } void VMathJaxInplacePreviewHelper::updateInplacePreview() diff --git a/src/vmathjaxinplacepreviewhelper.h b/src/vmathjaxinplacepreviewhelper.h index d5a13db5..174ee258 100644 --- a/src/vmathjaxinplacepreviewhelper.h +++ b/src/vmathjaxinplacepreviewhelper.h @@ -118,7 +118,7 @@ private: // Emit signal to update inplace preview. void updateInplacePreview(); - void textToHtmlViaWebView(const QString &p_text, + bool textToHtmlViaWebView(const QString &p_text, int p_id, int p_timeStamp);