#include <kdevcore.h>

Public Types | |
enum | Type { EditorContext, DocumentationContext, FileContext, ProjectModelItemContext, CodeModelItemContext } |
Public Member Functions | |
virtual int | type () const =0 |
virtual bool | hasType (int type) const |
Protected Member Functions | |
Context () | |
virtual | ~Context () |
Detailed Description
Base class for every context.
Think of a Context-based class as "useful info associated to a context menu". Several context menu can be defined, each defining different information: because of these context menus being used in many modules, they are defined here.
When context menu with a certain "context" associated appears, KDevelop core sends a notification signal and all plugins which receive this signal have the ability to add own items into the menu. For example, VCS plugin could add "commit" and "update" menu items to the context menu of a file.
How to use context from a plugin:
- Create a popup menu in context menu event handler:TDEPopupMenu menu(this);
- Create a context:MyContext context(param).
- Fill a context menu:core()->fillContextMenu(&menu, &context);
- Show the popup menu:menu.exec(event->globalPos());
In this example event is an object of TQContextMenuEvent class which you have access to if you reimplement TQWidget::contextMenuEvent method.
How to fill context menu from a plugin:
- Create aslot in your plugin class.contextMenu(TQPopupMenu *, const Context *)
- Connect KDevCore::contextMenu(TQPopupMenu *, const Context *) signal to that slot in the constructor of your plugin:
- Fill the menu in the slot you created, for example:
if (context->hasType(Context::EditorContext)){int id = popup->insertItem(i18n("My Menu Item 1"), this, TQT_SLOT(myMenuAction1()));popup->setWhatsThis(id, i18n("What's this for my menu item 1"));}{int id = popup->insertItem(......}...
Definition at line 100 of file kdevcore.h.
Member Enumeration Documentation
◆ Type
enum Context::Type |
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 tdevelop official context types.
Definition at line 106 of file kdevcore.h.
Constructor & Destructor Documentation
◆ Context()
|
protected |
Constructor.
Definition at line 33 of file kdevcore.cpp.
◆ ~Context()
|
protectedvirtual |
Destructor.
Definition at line 37 of file kdevcore.cpp.
Member Function Documentation
◆ hasType()
|
virtual |
- Returns
- The type of this Context, so clients can discriminate between different file contexts.
Definition at line 41 of file kdevcore.cpp.
◆ type()
|
pure virtual |
Implement this in the context so we can provide rtti.
Implemented in ProjectModelItemContext, CodeModelItemContext, FileContext, DocumentationContext, and EditorContext.
The documentation for this class was generated from the following files: