itaskhandler: interface cleanup

Change-Id: Ib85950a4715d6eaf4225bd8dbcc0c2a91b20dc1d
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
hjk
2012-05-04 20:10:01 +02:00
committed by hjk
parent 06dc126d7c
commit 64ade99b0c
14 changed files with 34 additions and 70 deletions

View File

@@ -197,11 +197,11 @@ public:
class DebugInfoTaskHandler : public ProjectExplorer::ITaskHandler class DebugInfoTaskHandler : public ProjectExplorer::ITaskHandler
{ {
public: public:
DebugInfoTaskHandler(GdbEngine *engine) explicit DebugInfoTaskHandler(GdbEngine *engine)
: ITaskHandler(_("Debuginfo")), m_engine(engine) : m_engine(engine)
{} {}
bool canHandle(const Task &task) bool canHandle(const Task &task) const
{ {
return m_debugInfoTasks.contains(task.taskId); return m_debugInfoTasks.contains(task.taskId);
} }
@@ -216,7 +216,7 @@ public:
m_debugInfoTasks[id] = task; m_debugInfoTasks[id] = task;
} }
QAction *createAction(QObject *parent = 0) QAction *createAction(QObject *parent) const
{ {
QAction *action = new QAction(DebuggerPlugin::tr("Install &Debug Information"), parent); QAction *action = new QAction(DebuggerPlugin::tr("Install &Debug Information"), parent);
action->setToolTip(DebuggerPlugin::tr("This tries to install missing debug information.")); action->setToolTip(DebuggerPlugin::tr("This tries to install missing debug information."));

View File

@@ -43,10 +43,6 @@
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
CopyTaskHandler::CopyTaskHandler() :
ITaskHandler(QLatin1String(Core::Constants::COPY))
{ }
void CopyTaskHandler::handle(const ProjectExplorer::Task &task) void CopyTaskHandler::handle(const ProjectExplorer::Task &task)
{ {
QString type; QString type;
@@ -68,7 +64,7 @@ void CopyTaskHandler::handle(const ProjectExplorer::Task &task)
+ type + task.description); + type + task.description);
} }
QAction *CopyTaskHandler::createAction(QObject *parent) QAction *CopyTaskHandler::createAction(QObject *parent) const
{ {
QAction *copyAction = new QAction(tr("&Copy", "Name of the action triggering the copytaskhandler"), parent); QAction *copyAction = new QAction(tr("&Copy", "Name of the action triggering the copytaskhandler"), parent);
copyAction->setToolTip(tr("Copy task to clipboard")); copyAction->setToolTip(tr("Copy task to clipboard"));

View File

@@ -43,10 +43,11 @@ class CopyTaskHandler : public ITaskHandler
Q_OBJECT Q_OBJECT
public: public:
CopyTaskHandler(); CopyTaskHandler() {}
bool canHandle(const Task &) const { return true; }
void handle(const Task &task); void handle(const Task &task);
QAction *createAction(QObject *parent = 0); QAction *createAction(QObject *parent) const;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -50,21 +50,12 @@ class PROJECTEXPLORER_EXPORT ITaskHandler : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit ITaskHandler(const QString &id) : explicit ITaskHandler() {}
m_id(id)
{ }
QString id() const virtual bool isDefaultHandler() const { return false; }
{ virtual bool canHandle(const Task &) const = 0;
return m_id;
}
virtual bool canHandle(const Task &) { return true; }
virtual void handle(const Task &) = 0; virtual void handle(const Task &) = 0;
virtual QAction *createAction(QObject *parent = 0) = 0; virtual QAction *createAction(QObject *parent) const = 0;
private:
const QString m_id;
}; };
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -84,10 +84,6 @@ const char RENAMEFILE[] = "ProjectExplorer.RenameFile";
const char SETSTARTUP[] = "ProjectExplorer.SetStartup"; const char SETSTARTUP[] = "ProjectExplorer.SetStartup";
const char PROJECTTREE_COLLAPSE_ALL[] = "ProjectExplorer.CollapseAll"; const char PROJECTTREE_COLLAPSE_ALL[] = "ProjectExplorer.CollapseAll";
const char SHOW_TASK_IN_EDITOR[] = "ProjectExplorer.ShowTaskInEditor";
const char VCS_ANNOTATE_TASK[] = "ProjectExplorer.VcsAnnotateTask";
const char SHOW_TASK_OUTPUT[] = "ProjectExplorer.ShowTaskOutput";
const char SELECTTARGET[] = "ProjectExplorer.SelectTarget"; const char SELECTTARGET[] = "ProjectExplorer.SelectTarget";
const char SELECTTARGETQUICK[] = "ProjectExplorer.SelectTargetQuick"; const char SELECTTARGETQUICK[] = "ProjectExplorer.SelectTargetQuick";

View File

@@ -42,11 +42,7 @@
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
ShowInEditorTaskHandler::ShowInEditorTaskHandler() : bool ShowInEditorTaskHandler::canHandle(const ProjectExplorer::Task &task) const
ITaskHandler(QLatin1String(Constants::SHOW_TASK_IN_EDITOR))
{ }
bool ShowInEditorTaskHandler::canHandle(const ProjectExplorer::Task &task)
{ {
if (task.file.isEmpty()) if (task.file.isEmpty())
return false; return false;
@@ -60,7 +56,7 @@ void ShowInEditorTaskHandler::handle(const ProjectExplorer::Task &task)
TextEditor::BaseTextEditorWidget::openEditorAt(fi.canonicalFilePath(), task.movedLine); TextEditor::BaseTextEditorWidget::openEditorAt(fi.canonicalFilePath(), task.movedLine);
} }
QAction *ShowInEditorTaskHandler::createAction(QObject *parent) QAction *ShowInEditorTaskHandler::createAction(QObject *parent) const
{ {
QAction *showAction = new QAction(tr("&Show in Editor"), parent); QAction *showAction = new QAction(tr("&Show in Editor"), parent);
showAction->setToolTip(tr("Show task location in an editor.")); showAction->setToolTip(tr("Show task location in an editor."));

View File

@@ -43,11 +43,12 @@ class ShowInEditorTaskHandler : public ITaskHandler
Q_OBJECT Q_OBJECT
public: public:
ShowInEditorTaskHandler(); ShowInEditorTaskHandler() {}
bool canHandle(const Task &); bool isDefaultHandler() const { return true; }
bool canHandle(const Task &) const;
void handle(const Task &task); void handle(const Task &task);
QAction *createAction(QObject *parent = 0); QAction *createAction(QObject *parent ) const;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -42,13 +42,12 @@
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
ShowOutputTaskHandler::ShowOutputTaskHandler(CompileOutputWindow *window) : ShowOutputTaskHandler::ShowOutputTaskHandler(CompileOutputWindow *window) :
ITaskHandler(QLatin1String(Constants::SHOW_TASK_OUTPUT)),
m_window(window) m_window(window)
{ {
Q_ASSERT(m_window); Q_ASSERT(m_window);
} }
bool ShowOutputTaskHandler::canHandle(const ProjectExplorer::Task &task) bool ShowOutputTaskHandler::canHandle(const ProjectExplorer::Task &task) const
{ {
return m_window->knowsPositionOf(task); return m_window->knowsPositionOf(task);
} }
@@ -60,7 +59,7 @@ void ShowOutputTaskHandler::handle(const ProjectExplorer::Task &task)
m_window->showPositionOf(task); m_window->showPositionOf(task);
} }
QAction *ShowOutputTaskHandler::createAction(QObject *parent) QAction *ShowOutputTaskHandler::createAction(QObject *parent) const
{ {
QAction *outputAction = new QAction(tr("Show &Output"), parent); QAction *outputAction = new QAction(tr("Show &Output"), parent);
outputAction->setToolTip(tr("Show output generating this issue.")); outputAction->setToolTip(tr("Show output generating this issue."));

View File

@@ -45,11 +45,11 @@ class ShowOutputTaskHandler : public ITaskHandler
Q_OBJECT Q_OBJECT
public: public:
ShowOutputTaskHandler(CompileOutputWindow *); explicit ShowOutputTaskHandler(CompileOutputWindow *window);
bool canHandle(const Task &); bool canHandle(const Task &) const;
void handle(const Task &task); void handle(const Task &task);
QAction *createAction(QObject *parent = 0); QAction *createAction(QObject *parent) const;
private: private:
CompileOutputWindow * m_window; CompileOutputWindow * m_window;

View File

@@ -427,7 +427,7 @@ void TaskWindow::triggerDefaultHandler(const QModelIndex &index)
if (!d->m_defaultHandler) { if (!d->m_defaultHandler) {
QList<ITaskHandler *> handlers = ExtensionSystem::PluginManager::instance()->getObjects<ITaskHandler>(); QList<ITaskHandler *> handlers = ExtensionSystem::PluginManager::instance()->getObjects<ITaskHandler>();
foreach(ITaskHandler *handler, handlers) { foreach(ITaskHandler *handler, handlers) {
if (handler->id() == QLatin1String(Constants::SHOW_TASK_IN_EDITOR)) { if (handler->isDefaultHandler()) {
d->m_defaultHandler = handler; d->m_defaultHandler = handler;
break; break;
} }

View File

@@ -45,11 +45,7 @@
using namespace ProjectExplorer::Internal; using namespace ProjectExplorer::Internal;
VcsAnnotateTaskHandler::VcsAnnotateTaskHandler() : bool VcsAnnotateTaskHandler::canHandle(const ProjectExplorer::Task &task) const
ITaskHandler(QLatin1String(Constants::VCS_ANNOTATE_TASK))
{ }
bool VcsAnnotateTaskHandler::canHandle(const ProjectExplorer::Task &task)
{ {
QFileInfo fi(task.file.toFileInfo()); QFileInfo fi(task.file.toFileInfo());
if (!fi.exists() || !fi.isFile() || !fi.isReadable()) if (!fi.exists() || !fi.isFile() || !fi.isReadable())
@@ -69,7 +65,7 @@ void VcsAnnotateTaskHandler::handle(const ProjectExplorer::Task &task)
vc->vcsAnnotate(fi.absoluteFilePath(), task.movedLine); vc->vcsAnnotate(fi.absoluteFilePath(), task.movedLine);
} }
QAction *VcsAnnotateTaskHandler::createAction(QObject *parent) QAction *VcsAnnotateTaskHandler::createAction(QObject *parent) const
{ {
QAction *vcsannotateAction = new QAction(tr("&Annotate"), parent); QAction *vcsannotateAction = new QAction(tr("&Annotate"), parent);
vcsannotateAction->setToolTip(tr("Annotate using version control system")); vcsannotateAction->setToolTip(tr("Annotate using version control system"));

View File

@@ -35,10 +35,6 @@
#include "itaskhandler.h" #include "itaskhandler.h"
namespace Core {
class IVersionControl;
}
namespace ProjectExplorer { namespace ProjectExplorer {
namespace Internal { namespace Internal {
@@ -47,11 +43,11 @@ class VcsAnnotateTaskHandler : public ITaskHandler
Q_OBJECT Q_OBJECT
public: public:
VcsAnnotateTaskHandler(); VcsAnnotateTaskHandler() {}
bool canHandle(const Task &); bool canHandle(const Task &) const;
void handle(const Task &task); void handle(const Task &task);
QAction *createAction(QObject *parent = 0); QAction *createAction(QObject *parent) const;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -48,14 +48,7 @@ using namespace TaskList::Internal;
// StopMonitoringHandler // StopMonitoringHandler
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
StopMonitoringHandler::StopMonitoringHandler() : bool StopMonitoringHandler::canHandle(const ProjectExplorer::Task &task) const
ProjectExplorer::ITaskHandler(QLatin1String("TaskList.StopMonitoringHandler"))
{ }
StopMonitoringHandler::~StopMonitoringHandler()
{ }
bool StopMonitoringHandler::canHandle(const ProjectExplorer::Task &task)
{ {
return task.category == Core::Id(Constants::TASKLISTTASK_ID); return task.category == Core::Id(Constants::TASKLISTTASK_ID);
} }
@@ -67,7 +60,7 @@ void StopMonitoringHandler::handle(const ProjectExplorer::Task &task)
TaskList::TaskListPlugin::instance()->stopMonitoring(); TaskList::TaskListPlugin::instance()->stopMonitoring();
} }
QAction *StopMonitoringHandler::createAction(QObject *parent) QAction *StopMonitoringHandler::createAction(QObject *parent) const
{ {
const QString text = const QString text =
QCoreApplication::translate("TaskList::Internal::StopMonitoringHandler", QCoreApplication::translate("TaskList::Internal::StopMonitoringHandler",

View File

@@ -41,12 +41,11 @@ namespace Internal {
class StopMonitoringHandler : public ProjectExplorer::ITaskHandler class StopMonitoringHandler : public ProjectExplorer::ITaskHandler
{ {
public: public:
StopMonitoringHandler(); StopMonitoringHandler() {}
~StopMonitoringHandler();
bool canHandle(const ProjectExplorer::Task &); bool canHandle(const ProjectExplorer::Task &) const;
void handle(const ProjectExplorer::Task &); void handle(const ProjectExplorer::Task &);
QAction *createAction(QObject *parent = 0); QAction *createAction(QObject *parent) const;
}; };
} // namespace Internal } // namespace Internal