diff --git a/interfaces/context.h b/interfaces/context.h index 527d3feb07..39faeaead8 100644 --- a/interfaces/context.h +++ b/interfaces/context.h @@ -1,211 +1,212 @@ /* This file is part of KDevelop Copyright 2001-2002 Matthias Hoelzer-Kluepfel Copyright 2001-2002 Bernd Gehrmann Copyright 2001 Sandy Meier Copyright 2002 Daniel Engelschalt Copyright 2002 Simon Hausmann Copyright 2002-2003 Roberto Raggi Copyright 2003 Mario Scalas Copyright 2003 Harald Fernengel Copyright 2003,2006 Hamish Rodda Copyright 2004 Alexander Dymo Copyright 2006 Adam Treat Copyright 2007 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_CONTEXT_H #define KDEVPLATFORM_CONTEXT_H #include "interfacesexport.h" #include #include #include template class QList; namespace KDevelop { class ProjectBaseItem; /** Base class for every context. Think of a Context-based class as "useful information associated with a context menu". When a context menu with a certain "context" associated appears, the platform's PluginController requests all plugins to return a list of QActions* they want to add to the context menu and a QString that should be used as the submenu entry. For example, a SVN plugin could add "commit" and "update" actions to the context menu of a document in a submenu called "Subversion". The plugin that originally gets the contextmenu event shouldn't add its own actions directly to the menu but instead use the same mechanism. How to show a context menu from a plugin: -# Create a QMenu in context menu event handler: @code QMenu menu(this); @endcode -# Create a context: @code FileContext context(list). @endcode -# Query for plugins: @code @code QList extensions = ICore::self()->pluginController()->queryPluginsForContextMenuExtensions( context ); @endcode -# Populate the menu: @code ContextMenuExtension::populateMenu(menu, extensions); @endcode -# Show the popup menu: @code menu.exec(mapToGlobal(pos)); @endcode How to fill a context menu from a plugin: -# Implement the @code contextMenuExtension(Context*) @endcode function in your plugin class. -# Depending on the context fill the returned ContextMenuExtension with actions:\n @code ContextMenuExtension ext; if (context->hasType(Context::EditorContext)) { ext.addAction(ContextMenuExtension::EditorGroup, new QAction(...)); } else if context->hasType(Context::FileContext)) { ext.addAction(ContextMenuExtension::FileGroup, new QAction(...)); ... } return ext; @endcode */ class KDEVPLATFORMINTERFACES_EXPORT Context { public: + /**Destructor.*/ + virtual ~Context(); + /**Pre-defined context types. More may be added so it is possible to add custom contexts. We reserve enum values until 1000 (yeah, it is one thousand ) for kdevplatform official context types.*/ enum Type { FileContext, /** urls() const = 0; /**@return The type of this Context, so clients can discriminate between different file contexts.*/ bool hasType( int type ) const; protected: /**Constructor.*/ Context(); - /**Destructor.*/ - virtual ~Context(); private: class ContextPrivate* const d; Q_DISABLE_COPY(Context) }; /** A context for the a list of selected urls. */ class KDEVPLATFORMINTERFACES_EXPORT FileContext : public Context { public: /**Builds the file context using a @ref QList @param urls The list of selected url.*/ explicit FileContext( const QList &urls ); /**Destructor.*/ virtual ~FileContext(); virtual int type() const override; /**@return A reference to the selected URLs.*/ virtual QList urls() const override; private: class FileContextPrivate* const d; Q_DISABLE_COPY(FileContext) }; /** A context for ProjectItem's. */ class KDEVPLATFORMINTERFACES_EXPORT ProjectItemContext : public Context { public: /**Builds the context. @param items The items to build the context from.*/ explicit ProjectItemContext( const QList &items ); /**Destructor.*/ virtual ~ProjectItemContext(); virtual int type() const override; /** * @return The project model items for the selected items. */ QList items() const; private: class ProjectItemContextPrivate* const d; Q_DISABLE_COPY(ProjectItemContext) }; /** * Context menu to open files with custom applications. */ class KDEVPLATFORMINTERFACES_EXPORT OpenWithContext : public Context { public: /** * @p url The files to open. * @p mimeType The mime type of said file. */ OpenWithContext(const QList& urls, const QMimeType& mimeType); virtual ~OpenWithContext(); /** * @return Context::OpenWithContext */ virtual int type() const override; /** * @return The files to open. */ virtual QList urls() const override; /** * @return The mimetype of the url to open. */ QMimeType mimeType() const; private: class OpenWithContextPrivate* const d; Q_DISABLE_COPY(OpenWithContext) }; } #endif diff --git a/shell/selectioncontroller.cpp b/shell/selectioncontroller.cpp index a6aa58a0b9..91047706a2 100644 --- a/shell/selectioncontroller.cpp +++ b/shell/selectioncontroller.cpp @@ -1,64 +1,62 @@ /* This file is part of KDevelop Copyright 2009 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "selectioncontroller.h" #include namespace KDevelop { class SelectionControllerPrivate { public: - Context* currentSelection; + QScopedPointer currentSelection; }; SelectionController::SelectionController( QObject* o ) : ISelectionController( o ), d(new SelectionControllerPrivate) { - d->currentSelection = 0; } SelectionController::~SelectionController() { delete d; } Context* SelectionController::currentSelection() { - return d->currentSelection; + return d->currentSelection.data(); } void SelectionController::updateSelection( Context* ctx ) { - d->currentSelection = ctx; - emit selectionChanged( d->currentSelection ); + d->currentSelection.reset(ctx); + emit selectionChanged(d->currentSelection.data()); } void SelectionController::initialize() { } void SelectionController::cleanup() { } } -