void GolangSymbol::updateModel() { m_matchCase = m_liteApp->settings()->value(GOLANGAST_QUICKOPEN_SYMBOL_MATCHCASE,false).toBool()?Qt::CaseSensitive:Qt::CaseInsensitive; m_importPath = m_liteApp->settings()->value(GOLANGAST_QUICKOPNE_SYMBOL_IMPORTPATH,true).toBool(); m_model->clear(); m_proxy->setFilterCaseSensitivity(m_matchCase); LiteApi::IEditor *editor = m_liteApp->editorManager()->currentEditor(); if (!editor) { return; } QString filePath = editor->filePath(); if (filePath.isEmpty()) { return; } QFileInfo info(filePath); QString cmd = LiteApi::getGotools(m_liteApp); QStringList args; args << "astview"; args << info.fileName(); m_process->setWorkingDirectory(info.path()); m_process->setEnvironment(LiteApi::getGoEnvironment(m_liteApp).toStringList()); m_process->start(cmd,args); }
void LiteDoc::openUrlFile(const QUrl &url) { QFileInfo info(url.toLocalFile()); if (!info.exists()) { info.setFile(url.path()); } QString ext = info.suffix().toLower(); if (ext == "html") { QFile file(info.filePath()); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = file.readAll(); file.close(); if (info.fileName().compare("docs.html",Qt::CaseInsensitive) == 0) { updateHtmlDoc(url,ba,QString(),false); } else { updateHtmlDoc(url,ba); } } } else if (ext == "md") { QFile file(info.filePath()); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = mdtohtml(file.readAll()); updateHtmlDoc(url,ba); } } else if (ext == "go") { LiteApi::IEditor *editor = m_liteApp->fileManager()->openEditor(info.filePath()); if (editor) { editor->setReadOnly(true); QPlainTextEdit *ed = LiteApi::findExtensionObject<QPlainTextEdit*>(editor,"LiteApi.QPlainTextEdit"); if (ed && url.hasQueryItem("s")) { QStringList pos = url.queryItemValue("s").split(":"); if (pos.length() == 2) { bool ok = false; int begin = pos.at(0).toInt(&ok); if (ok) { QTextCursor cur = ed->textCursor(); cur.setPosition(begin); ed->setTextCursor(cur); ed->centerCursor(); } } } } } else if (ext == "pdf") { QDesktopServices::openUrl(info.filePath()); } else { QFile file(info.filePath()); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = file.readAll(); updateTextDoc(url,ba,info.fileName()); } } }
void GolangCodePlugin::currentEditorChanged(LiteApi::IEditor *editor) { if (editor) { if (editor->mimeType() == "text/x-gosrc") { LiteApi::ICompleter *completer = LiteApi::findExtensionObject<LiteApi::ICompleter*>(editor,"LiteApi.ICompleter"); m_code->setCompleter(completer); return; } else if (editor->mimeType() == "browser/goplay") { LiteApi::IEditor* editor = LiteApi::findExtensionObject<LiteApi::IEditor*>(m_liteApp->extension(),"LiteApi.Goplay.IEditor"); if (editor && editor->mimeType() == "text/x-gosrc") { LiteApi::ICompleter *completer = LiteApi::findExtensionObject<LiteApi::ICompleter*>(editor,"LiteApi.ICompleter"); m_code->setCompleter(completer); return; } } } m_code->setCompleter(0); }
void LiteDoc::openUrlFile(const QUrl &url) { QFileInfo info(url.toLocalFile()); if (!info.exists()) { info.setFile(url.path()); } QString ext = info.suffix().toLower(); if (ext == "html") { QFile file(info.filePath()); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = file.readAll(); file.close(); if (info.fileName().compare("docs.html",Qt::CaseInsensitive) == 0) { updateHtmlDoc(url,ba,QString(),false); } else { updateHtmlDoc(url,ba); } } } else if (ext == "md") { QFile file(info.filePath()); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = md2html(file.readAll()); updateHtmlDoc(url,ba); } } else if (ext == "go") { LiteApi::IEditor *editor = m_liteApp->fileManager()->openEditor(info.filePath()); if (editor) { editor->setReadOnly(true); QPlainTextEdit *ed = LiteApi::findExtensionObject<QPlainTextEdit*>(editor,"LiteApi.QPlainTextEdit"); #if QT_VERSION >= 0x050000 if (ed && QUrlQuery(url).hasQueryItem("s")) { QStringList pos = QUrlQuery(url).queryItemValue("s").split(":"); #else if (ed && url.hasQueryItem("s")) { QStringList pos = url.queryItemValue("s").split(":"); #endif if (pos.length() == 2) { bool ok = false; int begin = pos.at(0).toInt(&ok); if (ok) { QTextCursor cur = ed->textCursor(); cur.setPosition(begin); ed->setTextCursor(cur); ed->centerCursor(); } } } } } else if (ext == "pdf") { QDesktopServices::openUrl(info.filePath()); } else { QFile file(info.filePath()); if (file.open(QIODevice::ReadOnly)) { QByteArray ba = file.readAll(); updateTextDoc(url,ba,info.fileName()); } } } void LiteDoc::updateTextDoc(const QUrl &url, const QByteArray &ba, const QString &header) { m_lastUrl = url; QTextCodec *codec = QTextCodec::codecForUtfText(ba,QTextCodec::codecForName("utf-8")); #if QT_VERSION >= 0x050000 QString html = codec->toUnicode(ba).toHtmlEscaped(); #else QString html = Qt::escape(codec->toUnicode(ba)); #endif QString data = m_templateData; data.replace("{header}",header); data.replace("{nav}",""); data.replace("{content}",QString("<pre>%1</pre>").arg(html)); m_docBrowser->setUrlHtml(url,data); }