- There are three different ways to use this class:
-
- - You may derive a new class from wxFileSystemWatcher and override the
- wxFileSystemWatcher::OnChange member to perform the required action
- when file system change occurrs. Additionally you may also want to
- override wxFileSystemWatcher::OnWarning and
- wxFileSystemWatcher::OnError to be notified when an error condition
- arises.
- - You may use a derived class and the @c EVT_FSWATCHER macro or
- wxEvtHandler::Connect to redirect events to an event handler defined in
- the derived class. If the default constructor is used, the file system
- watcher object will be its own owner object, since it is derived from
- wxEvtHandler.
- - You may redirect the notifications of file system changes as well as of
- error conditions to any wxEvtHandler derived object by using
- wxFileSystemWatcher::SetOwner.
- Then use the @c EVT_FSWATCHER macro or wxEvtHandler::Connect to send the
- events to the event handler which will receive wxFileSystemWatcherEvent.
-
- For example:
-
- @code
- class MyWatcher : public wxFileSystemWatcher
- {
- protected:
- void OnChange(int changeType, const wxFileName& path, const wxFileName& newPath)
- {
- // do whatever you like with the event
- }
- };
-
- class MyApp : public wxApp
- {
- public:
- ...
- void OnEventLoopEnter(wxEventLoopBase* WXUNUSED(loop))
- {
- // you have to construct the watcher here, because it needs an active loop
- m_watcher = new MyWatcher();
-
- // please notify me when a new log file is created
- m_watcher->Add(wxFileName::DirName("/var/log", wxFSW_EVENT_CREATE);
- }
-
- private:
- MyWatcher* m_watcher;
- };
- @endcode
+ This class notifies the application about the file system changes by
+ sending events of wxFileSystemWatcherEvent class. By default these events
+ are sent to the wxFileSystemWatcher object itself so you can derive from it
+ and use the event table @c EVT_FSWATCHER macro to handle these events in a
+ derived class method. Alternatively, you can use
+ wxFileSystemWatcher::SetOwner() to send the events to another object. Or
+ you could use wxEvtHandler::Connect() with @c wxEVT_FSWATCHER to handle
+ these events in any other object. See the fswatcher sample for an example
+ of the latter approach.