forked from qt-creator/qt-creator
CMakeToolManager: Add static readFirstParagraphs()
Reuse it in CMakeEditor and CMakeFileCompletionAssistProvider.
Amends d04585b519
Change-Id: I8dbd59c815e017404ff215ca1ff68740d6653e91
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
committed by
Cristian Adam
parent
cbc6809b28
commit
4e90ca1b59
@@ -9,7 +9,6 @@
|
|||||||
#include "cmakefilecompletionassist.h"
|
#include "cmakefilecompletionassist.h"
|
||||||
#include "cmakeindenter.h"
|
#include "cmakeindenter.h"
|
||||||
#include "cmakekitaspect.h"
|
#include "cmakekitaspect.h"
|
||||||
#include "cmakeproject.h"
|
|
||||||
#include "cmakeprojectconstants.h"
|
#include "cmakeprojectconstants.h"
|
||||||
|
|
||||||
#include "3rdparty/cmake/cmListFileCache.h"
|
#include "3rdparty/cmake/cmListFileCache.h"
|
||||||
@@ -347,8 +346,6 @@ const CMakeKeywords &CMakeHoverHandler::keywords() const
|
|||||||
return m_keywords;
|
return m_keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString readFirstParagraphs(const QString &element, const FilePath &helpFile);
|
|
||||||
|
|
||||||
void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||||
int pos,
|
int pos,
|
||||||
ReportPriority report)
|
ReportPriority report)
|
||||||
@@ -377,7 +374,7 @@ void CMakeHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget
|
|||||||
}
|
}
|
||||||
m_helpToolTip.clear();
|
m_helpToolTip.clear();
|
||||||
if (!helpFile.isEmpty())
|
if (!helpFile.isEmpty())
|
||||||
m_helpToolTip = readFirstParagraphs(word, helpFile);
|
m_helpToolTip = CMakeToolManager::readFirstParagraphs(helpFile);
|
||||||
|
|
||||||
setPriority(m_helpToolTip.isEmpty() ? Priority_Tooltip : Priority_None);
|
setPriority(m_helpToolTip.isEmpty() ? Priority_Tooltip : Priority_None);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,20 +153,6 @@ static QList<AssistProposalItemInterface *> generateList(const T &words, const Q
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString readFirstParagraphs(const FilePath &helpFile)
|
|
||||||
{
|
|
||||||
static QMap<FilePath, QString> map;
|
|
||||||
if (map.contains(helpFile))
|
|
||||||
return map.value(helpFile);
|
|
||||||
|
|
||||||
auto content = helpFile.fileContents(1024).value_or(QByteArray());
|
|
||||||
const QString firstParagraphs
|
|
||||||
= QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n"))));
|
|
||||||
|
|
||||||
map[helpFile] = firstParagraphs;
|
|
||||||
return firstParagraphs;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QList<AssistProposalItemInterface *> generateList(const QMap<QString, FilePath> &words,
|
static QList<AssistProposalItemInterface *> generateList(const QMap<QString, FilePath> &words,
|
||||||
const QIcon &icon)
|
const QIcon &icon)
|
||||||
{
|
{
|
||||||
@@ -180,7 +166,7 @@ static QList<AssistProposalItemInterface *> generateList(const QMap<QString, Fil
|
|||||||
MarkDownAssitProposalItem *item = new MarkDownAssitProposalItem();
|
MarkDownAssitProposalItem *item = new MarkDownAssitProposalItem();
|
||||||
item->setText(it.key());
|
item->setText(it.key());
|
||||||
if (!it.value().isEmpty())
|
if (!it.value().isEmpty())
|
||||||
item->setDetail(readFirstParagraphs(it.value()));
|
item->setDetail(CMakeToolManager::readFirstParagraphs(it.value()));
|
||||||
item->setIcon(icon);
|
item->setIcon(icon);
|
||||||
list << item;
|
list << item;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -167,6 +167,21 @@ void CMakeToolManager::updateDocumentation()
|
|||||||
Core::HelpManager::registerDocumentation(docs);
|
Core::HelpManager::registerDocumentation(docs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CMakeToolManager::readFirstParagraphs(const FilePath &helpFile)
|
||||||
|
{
|
||||||
|
static QMap<FilePath, QString> map;
|
||||||
|
if (map.contains(helpFile))
|
||||||
|
return map.value(helpFile);
|
||||||
|
|
||||||
|
auto content = helpFile.fileContents(1024).value_or(QByteArray());
|
||||||
|
const QString firstParagraphs
|
||||||
|
= QString("```\n%1\n```").arg(QString::fromUtf8(content.left(content.lastIndexOf("\n"))));
|
||||||
|
|
||||||
|
map[helpFile] = firstParagraphs;
|
||||||
|
return firstParagraphs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<Id> CMakeToolManager::autoDetectCMakeForDevice(const FilePaths &searchPaths,
|
QList<Id> CMakeToolManager::autoDetectCMakeForDevice(const FilePaths &searchPaths,
|
||||||
const QString &detectionSource,
|
const QString &detectionSource,
|
||||||
QString *logMessage)
|
QString *logMessage)
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ public:
|
|||||||
|
|
||||||
static void updateDocumentation();
|
static void updateDocumentation();
|
||||||
|
|
||||||
|
static QString readFirstParagraphs(const Utils::FilePath &helpFile);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QList<Utils::Id> autoDetectCMakeForDevice(const Utils::FilePaths &searchPaths,
|
QList<Utils::Id> autoDetectCMakeForDevice(const Utils::FilePaths &searchPaths,
|
||||||
const QString &detectionSource,
|
const QString &detectionSource,
|
||||||
|
|||||||
Reference in New Issue
Block a user