Changeset View
Changeset View
Standalone View
Standalone View
analyzers/cppcheck/plugin.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 51 | Plugin::Plugin(QObject* parent, const QVariantList&) | |||
---|---|---|---|---|---|
52 | : IPlugin(QStringLiteral("kdevcppcheck"), parent) | 52 | : IPlugin(QStringLiteral("kdevcppcheck"), parent) | ||
53 | , m_job(nullptr) | 53 | , m_job(nullptr) | ||
54 | , m_currentProject(nullptr) | 54 | , m_currentProject(nullptr) | ||
55 | , m_model(new ProblemModel(this)) | 55 | , m_model(new ProblemModel(this)) | ||
56 | { | 56 | { | ||
57 | qCDebug(KDEV_CPPCHECK) << "setting cppcheck rc file"; | 57 | qCDebug(KDEV_CPPCHECK) << "setting cppcheck rc file"; | ||
58 | setXMLFile(QStringLiteral("kdevcppcheck.rc")); | 58 | setXMLFile(QStringLiteral("kdevcppcheck.rc")); | ||
59 | 59 | | |||
60 | m_actionFile = new QAction(QIcon::fromTheme(QStringLiteral("cppcheck")), i18n("Cppcheck (Current File)"), this); | 60 | QIcon cppcheckIcon = QIcon::fromTheme(QStringLiteral("cppcheck")); | ||
61 | connect(m_actionFile, &QAction::triggered, [this](){ | 61 | | ||
62 | m_menuActionFile = new QAction(cppcheckIcon, i18n("Analyze Current File with Cppcheck"), this); | ||||
63 | connect(m_menuActionFile, &QAction::triggered, this, [this](){ | ||||
64 | runCppcheck(false); | ||||
65 | }); | ||||
66 | actionCollection()->addAction(QStringLiteral("cppcheck_file"), m_menuActionFile); | ||||
67 | | ||||
68 | m_contextActionFile = new QAction(cppcheckIcon, i18n("Cppcheck"), this); | ||||
69 | connect(m_contextActionFile, &QAction::triggered, this, [this]() { | ||||
kossebau: Could this action text (and similar for the other checks) be reduced to just "Cppcheck", like… | |||||
Name reduction will be great at menu but then we will have two actions with same name but with different mean (file/project analysis) in shortcuts editor :( Do you have an ideas how to fix this with "right way"? antonanikin: > Could this action text (and similar for the other checks) be reduced to just "Cppcheck", like… | |||||
62 | runCppcheck(false); | 70 | runCppcheck(false); | ||
63 | }); | 71 | }); | ||
64 | actionCollection()->addAction(QStringLiteral("cppcheck_file"), m_actionFile); | | |||
65 | 72 | | |||
66 | m_actionProject = new QAction(QIcon::fromTheme(QStringLiteral("cppcheck")), i18n("Cppcheck (Current Project)"), this); | 73 | m_menuActionProject = new QAction(cppcheckIcon, i18n("Analyze Current Project with Cppcheck"), this); | ||
67 | connect(m_actionProject, &QAction::triggered, [this](){ | 74 | connect(m_menuActionProject, &QAction::triggered, this, [this](){ | ||
75 | runCppcheck(true); | ||||
76 | }); | ||||
77 | actionCollection()->addAction(QStringLiteral("cppcheck_project"), m_menuActionProject); | ||||
78 | | ||||
kossebau: See first comment. | |||||
79 | m_contextActionProject = new QAction(cppcheckIcon, i18n("Cppcheck"), this); | ||||
mwolff: missing third argument "this" | |||||
80 | connect(m_contextActionProject, &QAction::triggered, this, [this]() { | ||||
68 | runCppcheck(true); | 81 | runCppcheck(true); | ||
69 | }); | 82 | }); | ||
70 | actionCollection()->addAction(QStringLiteral("cppcheck_project"), m_actionProject); | | |||
71 | 83 | | |||
72 | m_actionProjectItem = new QAction(QIcon::fromTheme(QStringLiteral("cppcheck")), i18n("Cppcheck"), this); | 84 | m_contextActionProjectItem = new QAction(cppcheckIcon, i18n("Cppcheck"), this); | ||
73 | 85 | | |||
mwolff: missing third argument "this" | |||||
74 | connect(core()->documentController(), &KDevelop::IDocumentController::documentClosed, | 86 | connect(core()->documentController(), &KDevelop::IDocumentController::documentClosed, | ||
75 | this, &Plugin::updateActions); | 87 | this, &Plugin::updateActions); | ||
76 | connect(core()->documentController(), &KDevelop::IDocumentController::documentActivated, | 88 | connect(core()->documentController(), &KDevelop::IDocumentController::documentActivated, | ||
77 | this, &Plugin::updateActions); | 89 | this, &Plugin::updateActions); | ||
78 | 90 | | |||
79 | connect(core()->projectController(), &KDevelop::IProjectController::projectOpened, | 91 | connect(core()->projectController(), &KDevelop::IProjectController::projectOpened, | ||
80 | this, &Plugin::updateActions); | 92 | this, &Plugin::updateActions); | ||
81 | connect(core()->projectController(), &KDevelop::IProjectController::projectClosed, | 93 | connect(core()->projectController(), &KDevelop::IProjectController::projectClosed, | ||
Show All 31 Lines | 123 | core()->uiController()->findToolView( | |||
113 | nullptr, | 125 | nullptr, | ||
114 | KDevelop::IUiController::FindFlags::Raise); | 126 | KDevelop::IUiController::FindFlags::Raise); | ||
115 | } | 127 | } | ||
116 | 128 | | |||
117 | void Plugin::updateActions() | 129 | void Plugin::updateActions() | ||
118 | { | 130 | { | ||
119 | m_currentProject = nullptr; | 131 | m_currentProject = nullptr; | ||
120 | 132 | | |||
121 | m_actionFile->setEnabled(false); | 133 | m_menuActionFile->setEnabled(false); | ||
122 | m_actionProject->setEnabled(false); | 134 | m_menuActionProject->setEnabled(false); | ||
123 | 135 | | |||
124 | if (isRunning()) { | 136 | if (isRunning()) { | ||
125 | return; | 137 | return; | ||
126 | } | 138 | } | ||
127 | 139 | | |||
128 | KDevelop::IDocument* activeDocument = core()->documentController()->activeDocument(); | 140 | KDevelop::IDocument* activeDocument = core()->documentController()->activeDocument(); | ||
129 | if (!activeDocument) { | 141 | if (!activeDocument) { | ||
130 | return; | 142 | return; | ||
131 | } | 143 | } | ||
132 | 144 | | |||
133 | QUrl url = activeDocument->url(); | 145 | QUrl url = activeDocument->url(); | ||
134 | 146 | | |||
135 | m_currentProject = core()->projectController()->findProjectForUrl(url); | 147 | m_currentProject = core()->projectController()->findProjectForUrl(url); | ||
136 | if (!m_currentProject) { | 148 | if (!m_currentProject) { | ||
137 | return; | 149 | return; | ||
138 | } | 150 | } | ||
139 | 151 | | |||
140 | m_actionFile->setEnabled(true); | 152 | m_menuActionFile->setEnabled(true); | ||
141 | m_actionProject->setEnabled(true); | 153 | m_menuActionProject->setEnabled(true); | ||
142 | } | 154 | } | ||
143 | 155 | | |||
144 | void Plugin::projectClosed(KDevelop::IProject* project) | 156 | void Plugin::projectClosed(KDevelop::IProject* project) | ||
145 | { | 157 | { | ||
146 | if (project != m_model->project()) { | 158 | if (project != m_model->project()) { | ||
147 | return; | 159 | return; | ||
148 | } | 160 | } | ||
149 | 161 | | |||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
209 | 221 | | |||
210 | KDevelop::ContextMenuExtension Plugin::contextMenuExtension(KDevelop::Context* context) | 222 | KDevelop::ContextMenuExtension Plugin::contextMenuExtension(KDevelop::Context* context) | ||
211 | { | 223 | { | ||
212 | KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context); | 224 | KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context); | ||
213 | 225 | | |||
214 | if (context->hasType(KDevelop::Context::EditorContext) && | 226 | if (context->hasType(KDevelop::Context::EditorContext) && | ||
215 | m_currentProject && !isRunning()) { | 227 | m_currentProject && !isRunning()) { | ||
216 | 228 | | |||
217 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeGroup, m_actionFile); | 229 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeFileGroup, m_contextActionFile); | ||
218 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeGroup, m_actionProject); | 230 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeProjectGroup, m_contextActionProject); | ||
219 | } | 231 | } | ||
220 | 232 | | |||
221 | if (context->hasType(KDevelop::Context::ProjectItemContext) && !isRunning()) { | 233 | if (context->hasType(KDevelop::Context::ProjectItemContext) && !isRunning()) { | ||
222 | auto pContext = dynamic_cast<KDevelop::ProjectItemContext*>(context); | 234 | auto pContext = dynamic_cast<KDevelop::ProjectItemContext*>(context); | ||
223 | if (pContext->items().size() != 1) { | 235 | if (pContext->items().size() != 1) { | ||
224 | return extension; | 236 | return extension; | ||
225 | } | 237 | } | ||
226 | 238 | | |||
227 | auto item = pContext->items().first(); | 239 | auto item = pContext->items().first(); | ||
228 | 240 | | |||
229 | switch (item->type()) { | 241 | switch (item->type()) { | ||
230 | case KDevelop::ProjectBaseItem::File: | 242 | case KDevelop::ProjectBaseItem::File: | ||
231 | case KDevelop::ProjectBaseItem::Folder: | 243 | case KDevelop::ProjectBaseItem::Folder: | ||
232 | case KDevelop::ProjectBaseItem::BuildFolder: | 244 | case KDevelop::ProjectBaseItem::BuildFolder: | ||
233 | break; | 245 | break; | ||
234 | 246 | | |||
235 | default: | 247 | default: | ||
236 | return extension; | 248 | return extension; | ||
237 | } | 249 | } | ||
238 | 250 | | |||
239 | m_actionProjectItem->disconnect(); | 251 | m_contextActionProjectItem->disconnect(); | ||
240 | connect(m_actionProjectItem, &QAction::triggered, [this, item](){ | 252 | connect(m_contextActionProjectItem, &QAction::triggered, this, [this, item](){ | ||
mwolff: missing third argument "this" | |||||
241 | runCppcheck(item->project(), item->path().toLocalFile()); | 253 | runCppcheck(item->project(), item->path().toLocalFile()); | ||
242 | }); | 254 | }); | ||
243 | 255 | | |||
244 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeGroup, m_actionProjectItem); | 256 | extension.addAction(KDevelop::ContextMenuExtension::AnalyzeProjectGroup, m_contextActionProjectItem); | ||
245 | } | 257 | } | ||
246 | 258 | | |||
247 | return extension; | 259 | return extension; | ||
248 | } | 260 | } | ||
249 | 261 | | |||
250 | KDevelop::ConfigPage* Plugin::perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent) | 262 | KDevelop::ConfigPage* Plugin::perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent) | ||
251 | { | 263 | { | ||
252 | return number ? nullptr : new ProjectConfigPage(this, options.project, parent); | 264 | return number ? nullptr : new ProjectConfigPage(this, options.project, parent); | ||
Show All 10 Lines |
Could this action text (and similar for the other checks) be reduced to just "Cppcheck", like done with the context actions?
That would remove all the duplicated "Analyze Current File With" which makes the menu more complex (more stuff to read).
And the same action could be reused again for both toplevel menu and context menu.
What was the motivation to have different menu texts and thus QAction objects?