summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@qt.io>2019-07-24 14:49:27 +0200
committerTobias Hunger <tobias.hunger@qt.io>2019-07-25 12:22:05 +0000
commitd9cf17bbda5eda66bf0de0fa1ad0cfc587e2d95c (patch)
tree2d96802f7bc2adebd4a2bb90c269342b4f2ac5c6
parentf240a9a9478643491a0181c006f099c0d01985fe (diff)
downloadqt-creator-d9cf17bbda5eda66bf0de0fa1ad0cfc587e2d95c.tar.gz
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>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp36
-rw-r--r--src/plugins/cmakeprojectmanager/cmakelocatorfilter.h13
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp3
3 files changed, 49 insertions, 3 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp
index fccf745fc3..cfaaefe178 100644
--- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp
@@ -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);
+}
diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h
index d68db1a496..7bf295dd28 100644
--- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h
+++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.h
@@ -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
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
index facbcaa9f6..d8d2164395 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectplugin.cpp
@@ -75,7 +75,8 @@ public:
SimpleRunWorkerFactory<SimpleTargetRunner, CMakeRunConfiguration> runWorkerFactory;
CMakeBuildConfigurationFactory buildConfigFactory;
CMakeEditorFactory editorFactor;
- BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFiler;
+ BuildCMakeTargetLocatorFilter buildCMakeTargetLocatorFilter;
+ OpenCMakeTargetLocatorFilter openCMakeTargetLocationFilter;
CMakeKitAspect cmakeKitAspect;
CMakeGeneratorKitAspect cmakeGeneratorKitAspect;