forked from qt-creator/qt-creator
C++: Add tool button in editor for "Analyze File"
Adds a button for analyze file to all text editors that have a C++ source file open. Task-number: QTCREATORBUG-23348 Change-Id: If08f2969304ee0817f00c9ee5ff8c0d4f96f7f72 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -36,18 +36,23 @@
|
||||
#include "clangtoolsunittests.h"
|
||||
#endif
|
||||
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/mimetypes/mimetype.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <cppeditor/cppeditorconstants.h>
|
||||
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
@@ -57,8 +62,9 @@
|
||||
#include <QAction>
|
||||
#include <QDebug>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QToolBar>
|
||||
|
||||
using namespace Core;
|
||||
using namespace ProjectExplorer;
|
||||
@@ -96,6 +102,20 @@ bool ClangToolsPlugin::initialize(const QStringList &arguments, QString *errorSt
|
||||
|
||||
d = new ClangToolsPluginPrivate;
|
||||
|
||||
registerAnalyzeActions();
|
||||
|
||||
auto panelFactory = m_projectPanelFactoryInstance = new ProjectPanelFactory;
|
||||
panelFactory->setPriority(100);
|
||||
panelFactory->setId(Constants::PROJECT_PANEL_ID);
|
||||
panelFactory->setDisplayName(tr("Clang Tools"));
|
||||
panelFactory->setCreateWidgetFunction([](Project *project) { return new ProjectSettingsWidget(project); });
|
||||
ProjectPanelFactory::registerFactory(panelFactory);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClangToolsPlugin::registerAnalyzeActions()
|
||||
{
|
||||
ActionManager::registerAction(d->clangTool.startAction(), Constants::RUN_ON_PROJECT);
|
||||
Command *cmd = ActionManager::registerAction(d->clangTool.startOnCurrentFileAction(),
|
||||
Constants::RUN_ON_CURRENT_FILE);
|
||||
@@ -106,16 +126,27 @@ bool ClangToolsPlugin::initialize(const QStringList &arguments, QString *errorSt
|
||||
Core::ActionContainer *mcontext = Core::ActionManager::actionContainer(
|
||||
CppEditor::Constants::M_CONTEXT);
|
||||
if (mcontext)
|
||||
mcontext->addAction(cmd, CppEditor::Constants::G_CONTEXT_FIRST); // TODO
|
||||
mcontext->addAction(cmd, CppEditor::Constants::G_CONTEXT_FIRST);
|
||||
|
||||
auto panelFactory = m_projectPanelFactoryInstance = new ProjectPanelFactory;
|
||||
panelFactory->setPriority(100);
|
||||
panelFactory->setId(Constants::PROJECT_PANEL_ID);
|
||||
panelFactory->setDisplayName(tr("Clang Tools"));
|
||||
panelFactory->setCreateWidgetFunction([](Project *project) { return new ProjectSettingsWidget(project); });
|
||||
ProjectPanelFactory::registerFactory(panelFactory);
|
||||
|
||||
return true;
|
||||
// add button to tool bar of C++ source files
|
||||
connect(EditorManager::instance(), &EditorManager::editorOpened, this, [this, cmd](IEditor *editor) {
|
||||
if (editor->document()->filePath().isEmpty()
|
||||
|| !Utils::mimeTypeForName(editor->document()->mimeType()).inherits("text/x-c++src"))
|
||||
return;
|
||||
auto *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
|
||||
if (!textEditor)
|
||||
return;
|
||||
TextEditor::TextEditorWidget *widget = textEditor->editorWidget();
|
||||
if (!widget)
|
||||
return;
|
||||
const QIcon icon = Utils::Icon({{":/debugger/images/debugger_singleinstructionmode.png",
|
||||
Utils::Theme::IconsBaseColor}})
|
||||
.icon();
|
||||
QAction *action = widget->toolBar()->addAction(icon, tr("Analyze File"), [this, editor]() {
|
||||
d->clangTool.startTool(editor->document()->filePath());
|
||||
});
|
||||
cmd->augmentActionWithShortcutToolTip(action);
|
||||
});
|
||||
}
|
||||
|
||||
QVector<QObject *> ClangToolsPlugin::createTestObjects() const
|
||||
|
||||
Reference in New Issue
Block a user