]> git.saurik.com Git - wxWidgets.git/blame - include/wx/private/fswatcher.h
Optionally allow showing tooltips for disabled ribbon buttons.
[wxWidgets.git] / include / wx / private / fswatcher.h
CommitLineData
6b8ef0b3
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/private/fswatcher.h
3// Purpose: File system watcher impl classes
4// Author: Bartosz Bekier
5// Created: 2009-05-26
6// RCS-ID: $Id$
7// Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef WX_PRIVATE_FSWATCHER_H_
12#define WX_PRIVATE_FSWATCHER_H_
13
14#include "wx/sharedptr.h"
15
16#ifdef wxHAS_INOTIFY
17 class wxFSWatchEntryUnix;
18 #define wxFSWatchEntry wxFSWatchEntryUnix
19 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
20 #include "wx/unix/private/fswatcher_inotify.h"
21#elif defined(wxHAS_KQUEUE)
22 class wxFSWatchEntryKq;
23 #define wxFSWatchEntry wxFSWatchEntryKq
24 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
25 #include "wx/unix/private/fswatcher_kqueue.h"
d98a58c5 26#elif defined(__WINDOWS__)
6b8ef0b3
VZ
27 class wxFSWatchEntryMSW;
28 #define wxFSWatchEntry wxFSWatchEntryMSW
29 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
30 #include "wx/msw/private/fswatcher.h"
31#else
32 #define wxFSWatchEntry wxFSWatchEntryPolling
33#endif
34
35class wxFSWatcherImpl
36{
37public:
38 wxFSWatcherImpl(wxFileSystemWatcherBase* watcher) :
39 m_watcher(watcher)
40 {
41 }
42
43 virtual ~wxFSWatcherImpl()
44 {
45 (void) RemoveAll();
46 }
47
48 virtual bool Init() = 0;
49
50 virtual bool Add(const wxFSWatchInfo& winfo)
51 {
76cfd1bf
VZ
52 if ( m_watches.find(winfo.GetPath()) != m_watches.end() )
53 {
54 wxLogTrace(wxTRACE_FSWATCHER,
55 "Path '%s' is already watched", winfo.GetPath());
56 // This can happen if a dir is watched, then a parent tree added
57 return true;
58 }
6b8ef0b3 59
5cd99866 60 // construct watch entry
6b8ef0b3
VZ
61 wxSharedPtr<wxFSWatchEntry> watch(new wxFSWatchEntry(winfo));
62
63 if (!DoAdd(watch))
64 return false;
65
66 // add watch to our map (always succeedes, checked above)
67 wxFSWatchEntries::value_type val(watch->GetPath(), watch);
68 return m_watches.insert(val).second;
69 }
70
71 virtual bool Remove(const wxFSWatchInfo& winfo)
72 {
73 wxFSWatchEntries::iterator it = m_watches.find(winfo.GetPath());
76cfd1bf
VZ
74 if ( it == m_watches.end() )
75 {
76 wxLogTrace(wxTRACE_FSWATCHER,
77 "Path '%s' is not watched", winfo.GetPath());
78 // This can happen if a dir is watched, then a parent tree added
79 return true;
80 }
6b8ef0b3
VZ
81 wxSharedPtr<wxFSWatchEntry> watch = it->second;
82 m_watches.erase(it);
83 return DoRemove(watch);
84 }
85
86 virtual bool RemoveAll()
87 {
88 m_watches.clear();
89 return true;
90 }
91
6eef5763
VZ
92 // Check whether any filespec matches the file's ext (if present)
93 bool MatchesFilespec(const wxFileName& fn, const wxString& filespec) const
94 {
95 return filespec.empty() || wxMatchWild(filespec, fn.GetFullName());
96 }
97
6b8ef0b3
VZ
98protected:
99 virtual bool DoAdd(wxSharedPtr<wxFSWatchEntry> watch) = 0;
100
101 virtual bool DoRemove(wxSharedPtr<wxFSWatchEntry> watch) = 0;
102
103 wxFSWatchEntries m_watches;
104 wxFileSystemWatcherBase* m_watcher;
105};
106
107
108#endif /* WX_PRIVATE_FSWATCHER_H_ */