ClangTools: Add "go to project settings" toolbar button

With the introduction of the "Analyze Current File" action the widget to
configure the diagnostic config was moved to the project panel (Project
mode > Project Settings > Clang Tools).

As not too many users are aware of the project settings there and
navigating there involves more user interation now (mode switch, looking
for the "Clang Tools" item), add a toolbar button as a shortcut.

Change-Id: I4c864045ef41ff501d925d3175ce604def213f29
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Nikolai Kosjar
2019-11-25 10:09:21 +01:00
parent 2ca150c097
commit b2f5ed78e1
11 changed files with 77 additions and 1 deletions

View File

@@ -33,6 +33,7 @@
#include "clangtoolsdiagnosticmodel.h"
#include "clangtoolsdiagnosticview.h"
#include "clangtoolslogfilereader.h"
#include "clangtoolsplugin.h"
#include "clangtoolsprojectsettings.h"
#include "clangtoolssettings.h"
#include "clangtoolsutils.h"
@@ -399,6 +400,15 @@ ClangTool::ClangTool()
ApplyFixIts(diagnosticItems).apply(m_diagnosticModel);
});
// Open Project Settings
action = new QAction(this);
action->setIcon(Utils::Icons::SETTINGS_TOOLBAR.icon());
//action->setToolTip(tr("Open Project Settings")); // TODO: Uncomment in master.
connect(action, &QAction::triggered, []() {
ProjectExplorerPlugin::activateProjectPanel(Constants::PROJECT_PANEL_ID);
});
m_openProjectSettings = action;
ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER);
const QString toolTip = tr("Clang-Tidy and Clazy use a customized Clang executable from the "
"Clang project to search for diagnostics.");
@@ -424,6 +434,7 @@ ClangTool::ClangTool()
m_perspective.addToolBarAction(m_startAction);
m_perspective.addToolBarAction(m_startOnCurrentFileAction);
m_perspective.addToolBarAction(m_stopAction);
m_perspective.addToolBarAction(m_openProjectSettings);
m_perspective.addToolBarAction(m_loadExported);
m_perspective.addToolBarAction(m_clear);
m_perspective.addToolBarAction(m_goBack);

View File

@@ -129,6 +129,7 @@ private:
Utils::FancyLineEdit *m_filterLineEdit = nullptr;
QToolButton *m_applyFixitsButton = nullptr;
QAction *m_openProjectSettings = nullptr;
QAction *m_goBack = nullptr;
QAction *m_goNext = nullptr;
QAction *m_loadExported = nullptr;

View File

@@ -28,6 +28,8 @@
namespace ClangTools {
namespace Constants {
const char PROJECT_PANEL_ID[] = "ClangTools";
const char RUN_ON_PROJECT[] = "ClangTools.RunOnProject";
const char RUN_ON_CURRENT_FILE[] = "ClangTools.RunOnCurrentFile";

View File

@@ -67,6 +67,13 @@ using namespace ProjectExplorer;
namespace ClangTools {
namespace Internal {
static ProjectPanelFactory *m_projectPanelFactoryInstance = nullptr;
ProjectPanelFactory *projectPanelFactory()
{
return m_projectPanelFactoryInstance;
}
class ClangToolsOptionsPage : public IOptionsPage
{
public:
@@ -123,8 +130,9 @@ bool ClangToolsPlugin::initialize(const QStringList &arguments, QString *errorSt
ActionManager::registerAction(d->clangTool.startOnCurrentFileAction(),
Constants::RUN_ON_CURRENT_FILE);
auto panelFactory = new ProjectPanelFactory();
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);

View File

@@ -27,9 +27,13 @@
#include <extensionsystem/iplugin.h>
namespace ProjectExplorer { class ProjectPanelFactory; }
namespace ClangTools {
namespace Internal {
ProjectExplorer::ProjectPanelFactory *projectPanelFactory();
class ClangToolsPlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT

View File

@@ -3903,6 +3903,12 @@ void ProjectExplorerPlugin::updateActions()
dd->updateActions();
}
void ProjectExplorerPlugin::activateProjectPanel(Core::Id panelId)
{
Core::ModeManager::activateMode(Constants::MODE_SESSION);
dd->m_proWindow->activateProjectPanel(panelId);
}
QList<QPair<QString, QString> > ProjectExplorerPlugin::recentProjects()
{
return dd->recentProjects();

View File

@@ -172,6 +172,8 @@ public:
static void updateActions();
static void activateProjectPanel(Core::Id panelId);
signals:
void finishedInitialization();

View File

@@ -80,6 +80,16 @@ void ProjectPanelFactory::destroyFactories()
s_factories.clear();
}
Core::Id ProjectPanelFactory::id() const
{
return m_id;
}
void ProjectPanelFactory::setId(Core::Id id)
{
m_id = id;
}
QString ProjectPanelFactory::icon() const
{
return m_icon;

View File

@@ -30,6 +30,8 @@
#include "panelswidget.h"
#include "projectwindow.h"
#include <coreplugin/id.h>
#include <utils/treemodel.h>
#include <functional>
@@ -44,6 +46,9 @@ class PROJECTEXPLORER_EXPORT ProjectPanelFactory
public:
ProjectPanelFactory();
Core::Id id() const;
void setId(Core::Id id);
// simple properties
QString displayName() const;
void setDisplayName(const QString &name);
@@ -78,6 +83,7 @@ private:
friend class ProjectExplorerPlugin;
static void destroyFactories();
Core::Id m_id;
int m_priority = 0;
QString m_displayName;
SupportsFunction m_supportsFunction;

View File

@@ -84,6 +84,8 @@ public:
Qt::ItemFlags flags(int column) const override;
bool setData(int column, const QVariant &, int role) override;
ProjectPanelFactory *factory() const { return m_factory; }
protected:
ProjectPanelFactory *m_factory = nullptr;
QPointer<Project> m_project;
@@ -281,6 +283,13 @@ public:
return activeItem ? activeItem->index() : QModelIndex();
}
TreeItem *itemForProjectPanel(Core::Id panelId)
{
return m_miscItem->findChildAtLevel(1, [panelId](const TreeItem *item){
return static_cast<const MiscSettingsPanelItem *>(item)->factory()->id() == panelId;
});
}
private:
int m_currentChildIndex = 0; // Start with Build & Run.
Project *m_project = nullptr;
@@ -497,6 +506,14 @@ public:
item->setData(0, QVariant(), ItemActivatedDirectlyRole);
}
void activateProjectPanel(Core::Id panelId)
{
if (ProjectItem *projectItem = m_projectsModel.rootItem()->childAt(0)) {
if (TreeItem *item = projectItem->itemForProjectPanel(panelId))
itemActivated(item->index());
}
}
void openContextMenu(const QPoint &pos)
{
QMenu menu;
@@ -606,6 +623,11 @@ ProjectWindow::ProjectWindow()
setContextMenuPolicy(Qt::CustomContextMenu);
}
void ProjectWindow::activateProjectPanel(Core::Id panelId)
{
d->activateProjectPanel(panelId);
}
ProjectWindow::~ProjectWindow() = default;
QSize SelectorDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const

View File

@@ -31,6 +31,8 @@
#include <memory>
namespace Core { class Id; }
namespace ProjectExplorer {
namespace Internal {
@@ -60,6 +62,8 @@ public:
ProjectWindow();
~ProjectWindow() override;
void activateProjectPanel(Core::Id panelId);
private:
const std::unique_ptr<ProjectWindowPrivate> d;
};