I've found these hooks to be helpful:
// -- Project events
// EVT_PROJECT_OPEN( BrowseTracker::OnProjectOpened)
////Manager::Get()->RegisterEventSink(cbEVT_PROJECT_OPEN, new cbEventFunctor<BrowseTracker, CodeBlocksEvent>(this, &BrowseTracker::OnProjectOpened));
// EVT_PROJECT_ACTIVATE( BrowseTracker::OnProjectActivated)
Manager::Get()->RegisterEventSink(cbEVT_PROJECT_ACTIVATE, new cbEventFunctor<BrowseTracker, CodeBlocksEvent>(this, &BrowseTracker::OnProjectActivated));
your solution with the timer is exactly the same than my second one :D. That's not that bad but i don't like those sort of hack because my svn command won't be executed before the timer ends. It is really a loss of time, even in an asynchronous process. Maybe you will find i am little bit dandy with that !Well, no. I don't "get the time between each cbEVT_PROJECT_FILE_ADDED event", i hardcode it (which is easier and safe, why should a file take 5 seconds to be added?)
That's not that bad but i don't like those sort of hack because my svn command won't be executed before the timer ends. Maybe you will find i am little bit dandy with that !:)
Well, no. I don't "get the time between each cbEVT_PROJECT_FILE_ADDED event", i hardcode it (which is easier and safe, )
why should a file take 5 seconds to be added?
Nasty hack, I think.Which hack are you talking about? the one with the timer or the one with the new message.
I'm against such a message, not only because I think it's not necessary, but there is no good way to implement it either.
You only have to send this event once, when all files has been added, as I said at the end of the for loop in ProjectManager::AddMultipleFilesToProject ()If that's all, please provide a patch accordingly. But I see a drawback: One could think it's good to listen to both: cbEVT_PROJECT_FILE_ADDED and cbEVT_PROJECT_MULTIPLE_FILES_ADDED. In both cases when the last file is added an operation listening on both would be executed two times.
You only have to send this event once, when all files has been added, as I said at the end of the for loop in ProjectManager::AddMultipleFilesToProject ()If that's all, please provide a patch accordingly. But I see a drawback: One could think it's good to listen to both: cbEVT_PROJECT_FILE_ADDED and cbEVT_PROJECT_MULTIPLE_FILES_ADDED. In both cases when the last file is added an operation listening on both would be executed two times.
Mine was a justification for the "5 seconds" span. What i meant is: there's no file that will take 5 seconds to load, so waiting 5 seconds is safe.why should a file take 5 seconds to be added?
Because as you see in the diagram, you have to wait at least 5 seconds to execute the command. Those 5 seconds represents the timer expiration needed to understand that no more file will be added.
There is another alternative. Extend the function ProjectManager::IsBusy() to incorporate this. This function would return true while loading multiple files. You should then add the file specified by cbEVT_PROJECT_FILE_ADDED to a list that will be processed once the ProjectManager::IsBusy() returns false. This would prevent the addition of another rarely used event.Why not? I will let the developers find the best way to do that, i will provide a patch for the new event tonight and let them choose!
Edit 1: Or addition of one extra SDK function would do the job (something like ProjectManager::IsLoadingProjectFiles()).A function just for that purpose? I am not sure, this would prevent the addition of another rarely used function :)
Edit 1: Or addition of one extra SDK function would do the job (something like ProjectManager::IsLoadingProjectFiles()).A function just for that purpose? I am not sure, this would prevent the addition of another rarely used function :)
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.
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);
}
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();
What all of you miss is that adding multiple files can also be done by successively calling AddFile(). In case you wonder, this is already done by the project loader, while opening the project...You are right. But maybe i missed something because when a project is opened, addition of files to it doesn't send cbEVT_PROJECT_FILE_ADDED event, so IMHO it wouldn't be a problem.
@orel: thanks for the patch but it can't be used. We 'll have to come up with something better (yes, I have something in mind).You are welcome and so is your better solution :D :D
What all of you miss is that adding multiple files can also be done by successively calling AddFile(). In case you wonder, this is already done by the project loader, while opening the project...This is why I say that the IDE has no way of knowing when adding files is done. The user would have to press a "finish" button or something...
But still, the proposal made by kkez and implemented by orel does not break any existing functionality, and it allows to save a little work, since at least he doesn't call svn 200 times if 200 files are added with "Add recursively...". Thus, while it is no solution, it's maybe still better than nothing.Effectively, this solution would make easy the development of SVNInside functionnality i was talking about : instantly and rapidly refreshing the status of the newly added files. This would be a convenience and it's not stopping me developing the plugin, i could also set the newly added files as 'not-yet-statued' and the user would have to call 'refresh status' on the whole project or on each file to remediate this.