From 18178718e2d417bbc8ede98ccebf66a3ff74f4f7 Mon Sep 17 00:00:00 2001 From: Tobias Hunger <tobias.hunger@nokia.com> Date: Fri, 18 Jun 2010 11:18:13 +0200 Subject: [PATCH] Add task handler used to show VCS blame output * Add task handler to show VCS blame output. * This taskhandler is not yet used! --- .../projectexplorer/projectexplorer.cpp | 2 + .../projectexplorer/projectexplorer.pro | 2 + .../projectexplorerconstants.h | 1 + .../vcsannotatetaskhandler.cpp | 74 +++++++++++++++++++ .../projectexplorer/vcsannotatetaskhandler.h | 60 +++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 src/plugins/projectexplorer/vcsannotatetaskhandler.cpp create mode 100644 src/plugins/projectexplorer/vcsannotatetaskhandler.h diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index c6a888af6ad..26ef517c938 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -35,6 +35,7 @@ #include "targetsettingspanel.h" #include "copytaskhandler.h" #include "showineditortaskhandler.h" +#include "vcsannotatetaskhandler.h" #include "applicationrunconfiguration.h" #include "allprojectsfilter.h" #include "allprojectsfind.h" @@ -283,6 +284,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er addAutoReleasedObject(new CopyTaskHandler); addAutoReleasedObject(new ShowInEditorTaskHandler); + addAutoReleasedObject(new VcsAnnotateTaskHandler); d->m_buildManager = new BuildManager(this); connect(d->m_buildManager, SIGNAL(buildStateChanged(ProjectExplorer::Project *)), diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 5ccab95084c..7d5f198a9e6 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -20,6 +20,7 @@ HEADERS += projectexplorer.h \ itaskhandler.h \ copytaskhandler.h \ showineditortaskhandler.h \ + vcsannotatetaskhandler.h \ taskwindow.h \ outputwindow.h \ persistentsettings.h \ @@ -100,6 +101,7 @@ SOURCES += projectexplorer.cpp \ task.cpp \ copytaskhandler.cpp \ showineditortaskhandler.cpp \ + vcsannotatetaskhandler.cpp \ taskwindow.cpp \ outputwindow.cpp \ persistentsettings.cpp \ diff --git a/src/plugins/projectexplorer/projectexplorerconstants.h b/src/plugins/projectexplorer/projectexplorerconstants.h index ac4eeedda72..7a4509972f1 100644 --- a/src/plugins/projectexplorer/projectexplorerconstants.h +++ b/src/plugins/projectexplorer/projectexplorerconstants.h @@ -77,6 +77,7 @@ const char * const REMOVEFILE = "ProjectExplorer.RemoveFile"; const char * const RENAMEFILE = "ProjectExplorer.RenameFile"; const char * const SHOW_TASK_IN_EDITOR = "ProjectExplorer.ShowTaskInEditor"; +const char * const VCS_ANNOTATE_TASK = "ProjectExplorer.VcsAnnotateTask"; // Run modes const char * const RUNMODE = "ProjectExplorer.RunMode"; diff --git a/src/plugins/projectexplorer/vcsannotatetaskhandler.cpp b/src/plugins/projectexplorer/vcsannotatetaskhandler.cpp new file mode 100644 index 00000000000..435b02db51c --- /dev/null +++ b/src/plugins/projectexplorer/vcsannotatetaskhandler.cpp @@ -0,0 +1,74 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "vcsannotatetaskhandler.h" + +#include "task.h" +#include "projectexplorerconstants.h" + +#include <coreplugin/icore.h> +#include <coreplugin/iversioncontrol.h> +#include <coreplugin/vcsmanager.h> + +#include <QtCore/QFileInfo> + +#include <QtGui/QAction> + +using namespace ProjectExplorer::Internal; + +VcsAnnotateTaskHandler::VcsAnnotateTaskHandler() : + ITaskHandler(QLatin1String(Constants::VCS_ANNOTATE_TASK)) +{ } + +bool VcsAnnotateTaskHandler::canHandle(const ProjectExplorer::Task &task) +{ + QFileInfo fi(task.file); + if (!fi.exists() || !fi.isFile() || !fi.isReadable()) + return false; + Core::IVersionControl *vc = Core::ICore::instance()->vcsManager()->findVersionControlForDirectory(fi.absolutePath()); + if (!vc) + return false; + return vc->supportsOperation(Core::IVersionControl::AnnotateOperation); +} + +void VcsAnnotateTaskHandler::handle(const ProjectExplorer::Task &task) +{ + QFileInfo fi(task.file); + Core::IVersionControl *vc = Core::ICore::instance()->vcsManager()->findVersionControlForDirectory(fi.absolutePath()); + Q_ASSERT(vc); + Q_ASSERT(vc->supportsOperation(Core::IVersionControl::AnnotateOperation)); + vc->vcsAnnotate(fi.absoluteFilePath(), task.line); +} + +QAction *VcsAnnotateTaskHandler::createAction(QObject *parent) +{ + QAction *vcsannotateAction = new QAction(tr("&Annotate"), parent); + vcsannotateAction->setToolTip("Annotate using version control system"); + return vcsannotateAction; +} diff --git a/src/plugins/projectexplorer/vcsannotatetaskhandler.h b/src/plugins/projectexplorer/vcsannotatetaskhandler.h new file mode 100644 index 00000000000..1c34199b4a6 --- /dev/null +++ b/src/plugins/projectexplorer/vcsannotatetaskhandler.h @@ -0,0 +1,60 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef PROJECTEXPLORER_VCSANNOTATETASKHANDLER_H +#define PROJECTEXPLORER_VCSANNOTATETASKHANDLER_H + +#include "projectexplorer_export.h" + +#include "itaskhandler.h" + +#include <QtCore/QHash> +#include <QtCore/QString> + +namespace Core { +class IVersionControl; +} + +namespace ProjectExplorer { +namespace Internal { + +class PROJECTEXPLORER_EXPORT VcsAnnotateTaskHandler : public ITaskHandler +{ +public: + VcsAnnotateTaskHandler(); + + bool canHandle(const Task &); + void handle(const Task &task); + QAction *createAction(QObject *parent = 0); +}; + +} // namespace Internal +} // namespace ProjectExplorer + +#endif // PROJECTEXPLORER_VCSANNOTATETASKHANDLER_H -- GitLab