Page 1 of 1

New Plugin doen't catch events

Posted: Fri Dec 19, 2008 10:46 pm
by jfouche
Hi

I'm creating a new Plugin (surprise for christmas ;) ), and I have a problem : I can catch event from my own menu (created in

Code: Select all

void MyPlugin::CreatePluginMenu(wxMenu *pluginsMenu)
, but not from CL (those inside EVENT_TABLE) :

Code: Select all

static MyPlugin* thePlugin = NULL;

//Define the plugin entry point
extern "C" __declspec(dllexport) IPlugin *CreatePlugin(IManager *manager)
{
	if (thePlugin == 0) {
		thePlugin = new MyPlugin(manager);
	}
	return thePlugin;
}

extern "C" __declspec(dllexport) PluginInfo GetPluginInfo()
{
	PluginInfo info;
	info.SetAuthor(wxT("Jérémie Fouché"));
	info.SetName(wxT("MyPlugin"));
	info.SetDescription(wxT("MyPlugin"));
	info.SetVersion(wxT("v0.1"));
	return info;
}

extern "C" __declspec(dllexport) int GetPluginInterfaceVersion()
{
	return PLUGIN_INTERFACE_VERSION;
}

BEGIN_EVENT_TABLE(MyPlugin, IPlugin)
	EVT_COMMAND(wxID_ANY, wxEVT_SHELL_COMMAND_STARTED, MyPlugin::OnShellCommandStarted)
	EVT_COMMAND(wxID_ANY, wxEVT_SHELL_COMMAND_STARTED_NOCLEAN, MyPlugin::OnShellCommandStarted)
	EVT_COMMAND(wxID_ANY, wxEVT_SHELL_COMMAND_PROCESS_ENDED, MyPlugin::OnShellCommandEnded)
END_EVENT_TABLE()

MyPlugin::MyPlugin(IManager *manager)
: IPlugin(manager)
, m_topWindow(NULL)
{
	m_longName  = wxT("MyPlugin");
	m_shortName = wxT("MyPlugin");
	
	m_topWindow = m_mgr->GetTheApp();
}

MyPlugin::~MyPlugin()
{
}

wxToolBar *MyPlugin::CreateToolBar(wxWindow *parent)
{
	return NULL;
}

void MyPlugin::CreatePluginMenu(wxMenu *pluginsMenu)
{
 	wxMenu *menu = new wxMenu();
	wxMenuItem *item(NULL);
	item = new wxMenuItem(menu, XRCID("MyPlugin_settings"), _("Settings..."), _("MyPlugin settings"), wxITEM_NORMAL);
	menu->Append(item);
	pluginsMenu->Append(wxID_ANY, _("AutoVersion"), menu);
	
	m_topWindow->Connect(XRCID("MyPlugin_settings"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(AutoVersion::OnSettings), NULL, this);
}

void MyPlugin::HookPopupMenu(wxMenu *menu, MenuType type)
{
	if (type == MenuTypeEditor) {
		//TODO::Append items for the editor context menu
	} else if (type == MenuTypeFileExplorer) {
		//TODO::Append items for the file explorer context menu
	} else if (type == MenuTypeFileView_Workspace) {
		//TODO::Append items for the file view / workspace context menu
	} else if (type == MenuTypeFileView_Project) {
		//TODO::Append items for the file view/Project context menu
	} else if (type == MenuTypeFileView_Folder) {
		//TODO::Append items for the file view/Virtual folder context menu
	} else if (type == MenuTypeFileView_File) {
		//TODO::Append items for the file view/file context menu
	}
}

void MyPlugin::UnHookPopupMenu(wxMenu *menu, MenuType type)
{
	if (type == MenuTypeEditor) {
		//TODO::Unhook items for the editor context menu
	} else if (type == MenuTypeFileExplorer) {
		//TODO::Unhook  items for the file explorer context menu
	} else if (type == MenuTypeFileView_Workspace) {
		//TODO::Unhook  items for the file view / workspace context menu
	} else if (type == MenuTypeFileView_Project) {
		//TODO::Unhook  items for the file view/Project context menu
	} else if (type == MenuTypeFileView_Folder) {
		//TODO::Unhook  items for the file view/Virtual folder context menu
	} else if (type == MenuTypeFileView_File) {
		//TODO::Unhook  items for the file view/file context menu
	}
}

void MyPlugin::UnPlug()
{
	//TODO:: perform the unplug action for this plugin
}


void MyPlugin::OnSettings(wxCommandEvent& event)
{
	wxMessageBox(wxT("MyPlugin::OnSettings")); // OK
}

void MyPlugin::OnShellCommandStarted(wxCommandEvent& event)
{
	wxMessageBox(wxT("MyPlugin::OnShellCommandStarted"));  // KO : never appears
}

void MyPlugin::OnShellCommandEnded(wxCommandEvent& event)
{
	wxMessageBox(wxT("MyPlugin::OnShellCommandEnded"));  // KO : never appears
}
Do I make a big mistake ?
FYI, I'm using CL 2527, build from sources with wxWidgets 2.8.9.
--
Jérémie

Re: New Plugin doen't catch events

Posted: Fri Dec 19, 2008 10:52 pm
by eranif
In general:
Since the plugin is a DLL, you cant use the static event table to handle the events (BEGIN_EVENT_TABLE()/END_EVENT_TABLE() macros) - the reason is that DLLs have another application so events fired from the application will not be handled in the plugin.

You must use the Connect() method for this.


In your case:
I see that you want to handle the shell events - currently, these events are not passed to the plugins.

You can handle only the following set of events:

Code: Select all

enum {
	//clientData is NULL
	wxEVT_INIT_DONE = 3450,
    
    //clientData is editor config node name (wxString*)
    wxEVT_EDITOR_CONFIG_CHANGED,
    
	//clientData is NULL
	wxEVT_WORKSPACE_LOADED,
    //clientData is NULL
	wxEVT_WORKSPACE_CONFIG_CHANGED,
	//clientData is NULL
    wxEVT_WORKSPACE_CLOSED,
    
    //clientData is NULL
	wxEVT_FILE_VIEW_INIT_DONE,
	//clientData is NULL
	wxEVT_FILE_VIEW_REFRESHED,
    //clientData is NULL
	wxEVT_FILE_EXP_INIT_DONE,
	//clientData is NULL
	wxEVT_FILE_EXP_REFRESHED,
    
	//clientData is list of files added to project (wxArrayString*)
	wxEVT_PROJ_FILE_ADDED,
	//clientData is list of files which have been removed (wxArrayString*)
	wxEVT_PROJ_FILE_REMOVED,
	//clientData is the project name (wxString*)
	wxEVT_PROJ_REMOVED,
	//clientData is the project name (wxString*)
	wxEVT_PROJ_ADDED,
    
	//clientData is the selected word (wxString*)
	wxEVT_CCBOX_SELECTION_MADE,
    
	//clientData is fileName (wxString*)
	wxEVT_FILE_SAVED,
    //clientData is list of files which have been retagged (std::vector<wxFileName>*)
    wxEVT_FILE_RETAGGED,
	//clientData is ParseThreadEventData*
	wxEVT_SYNBOL_TREE_UPDATE_ITEM,
	//clientData is ParseThreadEventData*
	wxEVT_SYNBOL_TREE_DELETE_ITEM,
	//clientData is ParseThreadEventData*
	wxEVT_SYNBOL_TREE_ADD_ITEM,
    
    //clientData is active editor (IEditor*)
    wxEVT_ACTIVE_EDITOR_CHANGED,
    //clientData is closing editor (IEditor*)
    wxEVT_EDITOR_CLOSING,
    //clientData is NULL
    wxEVT_ALL_EDITORS_CLOSED,
};
The list is inside Interface/plugin.h file.

What are you trying to achieve?

Eran

Re: New Plugin doen't catch events

Posted: Fri Dec 19, 2008 11:23 pm
by jfouche
Hi Eran

I just want my plugin to execute some task before compiling a project. I allready had a look to the available event, but none of them seem to be ok for my use. Do you have an idea ?
Thanks
--
Jérémie

Re: New Plugin doen't catch events

Posted: Fri Dec 19, 2008 11:26 pm
by eranif
Are u using SVN build? If the answer is yes, I can add an event and commit it

Also:
Which OS?

Eran

Re: New Plugin doen't catch events

Posted: Fri Dec 19, 2008 11:32 pm
by jfouche
Eran

I can use the SVN head version, and I will be very happy if you can add an event for this action.
I'm under Windows XP actually.
Thanks again
--
Jérémie

Re: New Plugin doen't catch events

Posted: Sat Dec 20, 2008 12:45 am
by eranif
Events added to SVN trunk:

To handle them:

In your plugin connect them like this:

Code: Select all

m_mgr->GetTheApp()->Connect(wxEVT_BUILD_STARTED, wxCommandEventHandler(MyPlugin::OnBuildStarted), NULL, this);
m_mgr->GetTheApp()->Connect(wxEVT_BUILD_ENDED, wxCommandEventHandler(MyPlugin::OnBuildEnded), NULL, this);
Some rules when coding plugins:

- Never use any of the available singletons:
DONT DO:

Code: Select all

WorkspaceST::Get()->...
DO

Code: Select all

m_mgr->GetWorkspace()->...
- DONT use the wxTheApp macro, instead use

Code: Select all

m_mgr->GetTheApp()->...
- You are allowed to include files from the following projects:
1) Interface
2) Plugin
3) CodeLite

If you need something from LIteEditor project -> let me know and I will add it to the interfaces.

Eran

Re: New Plugin doen't catch events

Posted: Sat Dec 20, 2008 2:27 am
by jfouche
Let's have a try, see you probably tomorow for questions...
Thanks
--
Jérémie