The solution proposed by kkez (sending a BEGIN and END event at the beginning/end of AddMultipleFilesToProject()) would likely work in the most reliable way, and if anything really must be implemented, this is what I'd go for, since it involves the least hacks and tampering, and it will be compatible with the old path.
I really find this solution the best without changing too many things in the current CB code. So i am finally coming with a little patch to implement both new events.
I named them cbEVT_PROJECT_FILES_ADDED_BEGIN and cbEVT_PROJECT_FILES_ADDED_END, i couldn't find best names that are shorter!!
if (addedFiles.GetCount() != 0)
{
// send the event indicating files are going to be added
CodeBlocksEvent begin_event(cbEVT_PROJECT_FILES_ADDED_BEGIN);
begin_event.SetProject(project);
begin_event.SetInt(addedFiles.GetCount());
Manager::Get()->GetPluginManager()->NotifyPlugins(begin_event);
for (unsigned int i = 0; i < addedFiles.GetCount(); ++i)
{
CodeBlocksEvent event(cbEVT_PROJECT_FILE_ADDED);
event.SetProject(project);
event.SetString(addedFiles[i]);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
// send the event indicating the end of files addition
CodeBlocksEvent end_event(cbEVT_PROJECT_FILES_ADDED_END);
end_event.SetProject(project);
end_event.SetInt(addedFiles.GetCount());
Manager::Get()->GetPluginManager()->NotifyPlugins(end_event);
}
So this event is fired before the for loop adding the files and sending cbEVT_PROJECT_FILE_ADDED for each. The only data inside those events are
- the number of files to be added (sent via event.SetInt()
- the project to which files are added (sent via event.SetProject())
So, in client code, to make the difference between a single or multiple files add you just have to set a flag when receiving cbEVT_PROJECT_FILES_ADDED_BEGIN. Thus in your cbEVT_PROJECT_FILE_ADDED handler, if this flag is set you skip the event and treat the addition of files when cbEVT_PROJECT_FILES_ADDED_END is here.
This way this will be very simple to call svn status, only once, whan all is done !! i would really be glad if this patch is added
So here it is (patch against .../CBMAINDIR/src/)
Index: include/sdk_events.h
===================================================================
--- include/sdk_events.h (revision 4693)
+++ include/sdk_events.h (working copy)
@@ -59,7 +59,7 @@
// for some editor events
int m_X;
int m_Y;
-
+
wxString m_TargetName;
wxString m_OldTargetName;
private:
@@ -237,6 +237,10 @@
#define EVT_PROJECT_ACTIVATE(fn) DECLARE_EVENT_TABLE_ENTRY( cbEVT_PROJECT_ACTIVATE, -1, -1, (wxObjectEventFunction)(wxEventFunction)(CodeBlocksEventFunction)&fn, (wxObject *) NULL ),
extern EVTIMPORT const wxEventType cbEVT_PROJECT_FILE_ADDED;
#define EVT_PROJECT_FILE_ADDED(fn) DECLARE_EVENT_TABLE_ENTRY( cbEVT_PROJECT_FILE_ADDED, -1, -1, (wxObjectEventFunction)(wxEventFunction)(CodeBlocksEventFunction)&fn, (wxObject *) NULL ),
+extern EVTIMPORT const wxEventType cbEVT_PROJECT_FILES_ADDED_BEGIN;
+#define cbEVT_PROJECT_FILES_ADDED_BEGIN(fn) DECLARE_EVENT_TABLE_ENTRY( cbEVT_PROJECT_FILES_ADDED_BEGIN, -1, -1, (wxObjectEventFunction)(wxEventFunction)(CodeBlocksEventFunction)&fn, (wxObject *) NULL ),
+extern EVTIMPORT const wxEventType cbEVT_PROJECT_FILES_ADDED_END;
+#define cbEVT_PROJECT_FILES_ADDED_END(fn) DECLARE_EVENT_TABLE_ENTRY( cbEVT_PROJECT_FILES_ADDED_END, -1, -1, (wxObjectEventFunction)(wxEventFunction)(CodeBlocksEventFunction)&fn, (wxObject *) NULL ),
extern EVTIMPORT const wxEventType cbEVT_PROJECT_FILE_REMOVED;
#define EVT_PROJECT_FILE_REMOVED(fn) DECLARE_EVENT_TABLE_ENTRY( cbEVT_PROJECT_FILE_REMOVED, -1, -1, (wxObjectEventFunction)(wxEventFunction)(CodeBlocksEventFunction)&fn, (wxObject *) NULL ),
extern EVTIMPORT const wxEventType cbEVT_PROJECT_POPUP_MENU;
Index: sdk/projectmanager.cpp
===================================================================
--- sdk/projectmanager.cpp (revision 4693)
+++ sdk/projectmanager.cpp (working copy)
@@ -1380,6 +1380,12 @@
if (addedFiles.GetCount() != 0)
{
+ // send the event indicating files are going to be added
+ CodeBlocksEvent begin_event(cbEVT_PROJECT_FILES_ADDED_BEGIN);
+ begin_event.SetProject(project);
+ begin_event.SetInt(addedFiles.GetCount());
+ Manager::Get()->GetPluginManager()->NotifyPlugins(begin_event);
+
for (unsigned int i = 0; i < addedFiles.GetCount(); ++i)
{
CodeBlocksEvent event(cbEVT_PROJECT_FILE_ADDED);
@@ -1387,6 +1393,12 @@
event.SetString(addedFiles[i]);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
+
+ // send the event indicating the end of files addition
+ CodeBlocksEvent end_event(cbEVT_PROJECT_FILES_ADDED_END);
+ end_event.SetProject(project);
+ end_event.SetInt(addedFiles.GetCount());
+ Manager::Get()->GetPluginManager()->NotifyPlugins(end_event);
}
return targets.GetCount();
}
Index: sdk/sdk_events.cpp
===================================================================
--- sdk/sdk_events.cpp (revision 4693)
+++ sdk/sdk_events.cpp (working copy)
@@ -109,6 +109,8 @@
const wxEventType cbEVT_PROJECT_SAVE = wxNewEventType();
const wxEventType cbEVT_PROJECT_ACTIVATE = wxNewEventType();
const wxEventType cbEVT_PROJECT_FILE_ADDED = wxNewEventType();
+const wxEventType cbEVT_PROJECT_FILES_ADDED_BEGIN = wxNewEventType();
+const wxEventType cbEVT_PROJECT_FILES_ADDED_END = wxNewEventType();
const wxEventType cbEVT_PROJECT_FILE_REMOVED = wxNewEventType();
const wxEventType cbEVT_PROJECT_POPUP_MENU = wxNewEventType();
const wxEventType cbEVT_PROJECT_TARGETS_MODIFIED = wxNewEventType();