MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / handlePluginEditorRequest

Method handlePluginEditorRequest

src/jsplugin/JSPluginManager.cpp:290–350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290void JSPluginManager::handlePluginEditorRequest(const WIZDOCUMENTDATA &doc, const QString &guid)
291{
292 WizDatabaseManager *dbMgr = WizDatabaseManager::instance();
293 WizDatabase &db = dbMgr->db(doc.strKbGUID);
294 QString strDocumentFileName = db.getDocumentFileName(doc.strGUID);
295
296 QFileInfo docZiwFile(strDocumentFileName);
297 if (!docZiwFile.exists()) {
298 qWarning() << tr("Document data does not exist: ") + doc.strTitle;
299 return;
300 }
301
302 QString strHtmlFile;
303 if (!db.documentToTempHtmlFile(doc, strHtmlFile)) {
304 qWarning() << tr("Can't unzip note data: ") + doc.strTitle;
305 return;
306 }
307
308 QString htmlContent;
309 if (!WizLoadUnicodeTextFromFile(strHtmlFile, htmlContent)) {
310 qWarning() << tr("Can't read html file: ") + doc.strTitle;
311 return;
312 }
313
314 // Insert JavaScript and CSS files
315 JSPluginModule *module = moduleByGUID(guid);
316 QStringList scriptFiles = module->spec()->scriptFiles();
317 QStringList styleFiles = module->spec()->styleFiles();
318 QString insertion;
319 for (auto &cssFile : styleFiles) {
320 insertion += QString(
321 "<link rel='stylesheet' type='text/css' href='%1' name='wiz_inner_style' wiz_style='unsave' charset='utf-8'>")
322 .arg(QUrl::fromLocalFile(cssFile).toString());
323 }
324 for (auto &jsFile : scriptFiles) {
325 insertion += QString(
326 "<script type='text/javascript' src='%1' name='wiz_inner_script' wiz_style='unsave' charset='utf-8'></script>")
327 .arg(QUrl::fromLocalFile(jsFile).toString());
328 }
329
330 htmlContent = Utils::WizHtmlInsertText(htmlContent, insertion, "beforeend", "head");
331
332 // Save to temp file
333 if (!WizSaveUnicodeTextToUtf8File(strHtmlFile, htmlContent, true)) {
334 qWarning() << tr("Can't write html file: ") + doc.strTitle;
335 return;
336 }
337
338 QString indexFileUrl = QUrl::fromLocalFile(strHtmlFile).toString() + "?guid=" + doc.strGUID + "&kbguid=" + doc.strKbGUID;
339 WizWebEngineInjectObjectCollection objects = {
340 {"JSPlugin", module->parentPlugin()},
341 {"JSPluginModule", module},
342 {"WizExplorerApp", m_mainWindow->publicAPIsObject()}
343 };
344 // Ownership of page is passed on to the QTabWidget.
345 WizWebEngineView *webView = new WizWebEngineView(objects, nullptr);
346 WizWebsiteView *websiteView = new WizWebsiteView(webView, *m_mainWindow);
347 websiteView->viewHtml(indexFileUrl);

Callers

nothing calls this directly

Calls 15

WizHtmlInsertTextFunction · 0.85
getDocumentFileNameMethod · 0.80
scriptFilesMethod · 0.80
styleFilesMethod · 0.80
parentPluginMethod · 0.80
viewHtmlMethod · 0.80
mainTabViewMethod · 0.80
createTabMethod · 0.80
QStringClass · 0.50

Tested by

no test coverage detected