forked from qt-creator/qt-creator
CMake: Add locator filter to open CMake target definitions
Add a "cmo" filter to the locator that will open the CMake target definition in the editor. Note that this is based on the target data extracted from cmake. For tealeaf-reader and server-mode this information is guessed based on the targets source directory (plus CMakeLists.txt). These modes will just open that file. For fileapi the information is accurate and based on the backtrace that comes with the target information. "cmo" will open the exact file/line from the backtrace here. Task-number: QTCREATORBUG-18553 Change-Id: I4ee0eb25d1d763bd0d8033e506bf85cb2bc1f2dc Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
@@ -28,12 +28,13 @@
|
||||
#include "cmakebuildstep.h"
|
||||
#include "cmakeproject.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/buildsteplist.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
@@ -160,3 +161,34 @@ void BuildCMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
||||
ProjectExplorerPlugin::buildProject(cmakeProject);
|
||||
buildStep->setBuildTarget(oldTarget);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// OpenCMakeTargetLocatorFilter:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
OpenCMakeTargetLocatorFilter::OpenCMakeTargetLocatorFilter()
|
||||
{
|
||||
setId("Open CMake target definition");
|
||||
setDisplayName(tr("Open CMake target"));
|
||||
setShortcutString("cmo");
|
||||
setPriority(Medium);
|
||||
}
|
||||
|
||||
void OpenCMakeTargetLocatorFilter::accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText,
|
||||
int *selectionStart,
|
||||
int *selectionLength) const
|
||||
{
|
||||
Q_UNUSED(newText)
|
||||
Q_UNUSED(selectionStart)
|
||||
Q_UNUSED(selectionLength)
|
||||
|
||||
const QVariantMap extraData = selection.internalData.toMap();
|
||||
const int line = extraData.value("line").toInt();
|
||||
const QString file = extraData.value("file").toString();
|
||||
|
||||
if (line >= 0)
|
||||
Core::EditorManager::openEditorAt(file, line);
|
||||
else
|
||||
Core::EditorManager::openEditor(file);
|
||||
}
|
||||
|
@@ -61,5 +61,18 @@ public:
|
||||
int *selectionLength) const final;
|
||||
};
|
||||
|
||||
class OpenCMakeTargetLocatorFilter : CMakeTargetLocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OpenCMakeTargetLocatorFilter();
|
||||
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText,
|
||||
int *selectionStart,
|
||||
int *selectionLength) const final;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace CMakeProjectManager
|
||||
|
@@ -75,7 +75,8 @@ public:
|
||||
SimpleRunWorkerFactory<SimpleTargetRunner, CMakeRunConfiguration> runWorkerFactory;
|
||||
CMakeBuildConfigurationFactory buildConfigFactory;
|
||||
CMakeEditorFactory editorFactor;
|
||||
BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFiler;
|
||||
BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFilter;
|
||||
OpenCMakeTargetLocatorFilter openCMakeTargetLocationFilter;
|
||||
|
||||
CMakeKitAspect cmakeKitAspect;
|
||||
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;
|
||||
|
Reference in New Issue
Block a user