Changeset View
Changeset View
Standalone View
Standalone View
projectmanagers/cmake/cmakedocumentation.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | 44 | | |||
45 | K_PLUGIN_FACTORY_WITH_JSON(CMakeSupportDocFactory, "kdevcmakedocumentation.json", registerPlugin<CMakeDocumentation>(); ) | 45 | K_PLUGIN_FACTORY_WITH_JSON(CMakeSupportDocFactory, "kdevcmakedocumentation.json", registerPlugin<CMakeDocumentation>(); ) | ||
46 | 46 | | |||
47 | CMakeDocumentation* CMakeDoc::s_provider=nullptr; | 47 | CMakeDocumentation* CMakeDoc::s_provider=nullptr; | ||
48 | KDevelop::IDocumentationProvider* CMakeDoc::provider() const { return s_provider; } | 48 | KDevelop::IDocumentationProvider* CMakeDoc::provider() const { return s_provider; } | ||
49 | 49 | | |||
50 | CMakeDocumentation::CMakeDocumentation(QObject* parent, const QVariantList&) | 50 | CMakeDocumentation::CMakeDocumentation(QObject* parent, const QVariantList&) | ||
51 | : KDevelop::IPlugin( "kdevcmakedocumentation", parent ) | 51 | : KDevelop::IPlugin( "kdevcmakedocumentation", parent ) | ||
52 | , mCMakeCmd(CMake::findExecutable()) | 52 | , m_cmakeExecutable(CMake::findExecutable()) | ||
53 | , m_index(nullptr) | 53 | , m_index(nullptr) | ||
54 | { | 54 | { | ||
55 | if (mCMakeCmd.isEmpty()) { | 55 | if (m_cmakeExecutable.isEmpty()) { | ||
56 | setErrorDescription(i18n("Unable to find cmake executable. Is it installed on the system?") ); | 56 | setErrorDescription(i18n("Unable to find a CMake executable. Is one installed on the system?")); | ||
57 | return; | 57 | return; | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | CMakeDoc::s_provider=this; | 60 | CMakeDoc::s_provider=this; | ||
61 | m_index= new QStringListModel(this); | 61 | m_index= new QStringListModel(this); | ||
62 | initializeModel(); | 62 | initializeModel(); | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | static const char* args[] = { "--help-command", "--help-variable", "--help-module", "--help-property", nullptr, nullptr }; | 65 | static const char* args[] = { "--help-command", "--help-variable", "--help-module", "--help-property", nullptr, nullptr }; | ||
66 | 66 | | |||
67 | void CMakeDocumentation::delayedInitialization() | 67 | void CMakeDocumentation::delayedInitialization() | ||
68 | { | 68 | { | ||
69 | for(int i=0; i<=Property; i++) { | 69 | for(int i=0; i<=Property; i++) { | ||
70 | collectIds(QString(args[i])+"-list", (Type) i); | 70 | collectIds(QString(args[i])+"-list", (Type) i); | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | m_index->setStringList(m_typeForName.keys()); | 73 | m_index->setStringList(m_typeForName.keys()); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | void CMakeDocumentation::collectIds(const QString& param, Type type) | 76 | void CMakeDocumentation::collectIds(const QString& param, Type type) | ||
77 | { | 77 | { | ||
78 | QStringList ids=CMake::executeProcess(mCMakeCmd, QStringList(param)).split('\n'); | 78 | QStringList ids = CMake::executeProcess(m_cmakeExecutable, QStringList(param)).split(QLatin1Char('\n')); | ||
79 | ids.takeFirst(); | 79 | ids.takeFirst(); | ||
80 | foreach(const QString& name, ids) | 80 | foreach(const QString& name, ids) | ||
81 | { | 81 | { | ||
82 | m_typeForName[name]=type; | 82 | m_typeForName[name]=type; | ||
83 | } | 83 | } | ||
84 | } | 84 | } | ||
85 | 85 | | |||
86 | QStringList CMakeDocumentation::names(CMakeDocumentation::Type t) const | 86 | QStringList CMakeDocumentation::names(CMakeDocumentation::Type t) const | ||
87 | { | 87 | { | ||
88 | return m_typeForName.keys(t); | 88 | return m_typeForName.keys(t); | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | QString CMakeDocumentation::descriptionForIdentifier(const QString& id, Type t) const | 91 | QString CMakeDocumentation::descriptionForIdentifier(const QString& id, Type t) const | ||
92 | { | 92 | { | ||
93 | QString desc; | 93 | QString desc; | ||
94 | if(args[t]) { | 94 | if(args[t]) { | ||
95 | desc = CMake::executeProcess(mCMakeCmd, { args[t], id.simplified() }); | 95 | desc = CMake::executeProcess(m_cmakeExecutable, { args[t], id.simplified() }); | ||
96 | desc = desc.remove(":ref:"); | 96 | desc = desc.remove(":ref:"); | ||
97 | 97 | | |||
98 | const QString rst2html = QStandardPaths::findExecutable(QStringLiteral("rst2html")); | 98 | const QString rst2html = QStandardPaths::findExecutable(QStringLiteral("rst2html")); | ||
99 | if (rst2html.isEmpty()) { | 99 | if (rst2html.isEmpty()) { | ||
100 | desc = ("<html><body style='background:#fff'><pre><code>" + desc.toHtmlEscaped() + "</code></pre>" | 100 | desc = ("<html><body style='background:#fff'><pre><code>" + desc.toHtmlEscaped() + "</code></pre>" | ||
101 | + i18n("<p>For better cmake documentation rendering, install rst2html</p>") | 101 | + i18n("<p>For better cmake documentation rendering, install rst2html</p>") | ||
102 | + "</body></html>"); | 102 | + "</body></html>"); | ||
103 | } else { | 103 | } else { | ||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |