Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

[SOLVED]request for a new CodeblocksEvent type : end of a 'multiple files add'

<< < (3/4) > >>

Biplab:
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.

Edit 1: Or addition of one extra SDK function would do the job (something like ProjectManager::IsLoadingProjectFiles()).

orel:

--- Quote from: Biplab on November 30, 2007, 05:33:53 pm ---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.
--- End quote ---
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!



--- Quote from: Biplab on November 30, 2007, 05:33:53 pm ---Edit 1: Or addition of one extra SDK function would do the job (something like ProjectManager::IsLoadingProjectFiles()).

--- End quote ---
A function just for that purpose? I am not sure, this would prevent the addition of another rarely used function :)


Biplab:

--- Quote from: orel on November 30, 2007, 06:09:31 pm ---
--- Quote from: Biplab on November 30, 2007, 05:33:53 pm ---Edit 1: Or addition of one extra SDK function would do the job (something like ProjectManager::IsLoadingProjectFiles()).

--- End quote ---
A function just for that purpose? I am not sure, this would prevent the addition of another rarely used function :)

--- End quote ---

There's a difference. An event will always be fired irrespective of anyone needs it or not. On the other hand the *extra* function would not be used unless someone calls it.

thomas:
There is no way the IDE can know reliably that several files will be added.

Martin's proposal about sending an event in AddMultipleFilesToProject() is a possibility to reduce some workload, but that one is problematic too. For correct operation, the IDE would have to skip the files on cbEVT_PROJECT_FILE_ADDED if an event has already sent, else you cannot listen to single files being added.
Or, you would have to keep a list yourself, or... some other thing.

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.

Still, it does not solve the problem either, it can only reduce some of the workload. To solve your problem, the IDE must know when the user starts adding files and when the user no longer does so. This really could only be implemented if the user was required to press a "finish" button when he is done (no thank you!) or with a timer hack, which is... well... a hack.

On the other hand, running svn status asynchronously is quite acceptable, and if that's rate-limited, no excessive overhead occurs.

orel:

--- Quote from: thomas on November 30, 2007, 07:04:32 pm ---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.

--- End quote ---

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!!


--- Code: ---    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);
    }

--- End code ---

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/)


--- Code: ---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();

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version