diff --git a/docs/changes.txt b/docs/changes.txt index 9cd86bbe5f..a6942dcc88 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -583,6 +583,7 @@ All: - Fix wxSocket::WaitForAccept() in non-main thread (Hajo Kirchhoff). - Fix memory overallocation in wxVector::reserve() (Nigel Paton). - Fix `wx-config --libs` in monolithic build. +- Fix wxFileSystemWatcher::RemoveAll() (Melroy Tellis). - Fix the build under HP-UX (tested under 11.31). - Add Aragonese translation. diff --git a/include/wx/private/fswatcher.h b/include/wx/private/fswatcher.h index cfffba4a89..e2bf55a89d 100644 --- a/include/wx/private/fswatcher.h +++ b/include/wx/private/fswatcher.h @@ -84,8 +84,16 @@ public: virtual bool RemoveAll() { + bool ret = true; + for ( wxFSWatchEntries::iterator it = m_watches.begin(); + it != m_watches.end(); + ++it ) + { + if ( !DoRemove(it->second) ) + ret = false; + } m_watches.clear(); - return true; + return ret; } // Check whether any filespec matches the file's ext (if present) diff --git a/samples/fswatcher/fswatcher.cpp b/samples/fswatcher/fswatcher.cpp index d8279a9057..727ce088e1 100644 --- a/samples/fswatcher/fswatcher.cpp +++ b/samples/fswatcher/fswatcher.cpp @@ -51,7 +51,9 @@ private: void OnAdd(wxCommandEvent& event); void OnAddTree(wxCommandEvent& event); void OnRemove(wxCommandEvent& event); + void OnRemoveAll(wxCommandEvent& WXUNUSED(event)); void OnRemoveUpdateUI(wxUpdateUIEvent& event); + void OnRemoveAllUpdateUI(wxUpdateUIEvent& event); void OnFileSystemEvent(wxFileSystemWatcherEvent& event); void LogEvent(const wxFileSystemWatcherEvent& event); @@ -151,7 +153,8 @@ MyFrame::MyFrame(const wxString& title) BTN_ID_ADD = 200, BTN_ID_ADD_TREE, - BTN_ID_REMOVE + BTN_ID_REMOVE, + BTN_ID_REMOVE_ALL }; // ================================================================ @@ -215,10 +218,12 @@ MyFrame::MyFrame(const wxString& title) wxButton* buttonAdd = new wxButton(panel, BTN_ID_ADD, "&Add"); wxButton* buttonAddTree = new wxButton(panel, BTN_ID_ADD_TREE, "Add &tree"); wxButton* buttonRemove = new wxButton(panel, BTN_ID_REMOVE, "&Remove"); + wxButton* buttonRemoveAll = new wxButton(panel, BTN_ID_REMOVE_ALL, "Remove a&ll"); wxSizer *btnSizer = new wxGridSizer(2); btnSizer->Add(buttonAdd, wxSizerFlags().Center().Border(wxALL)); btnSizer->Add(buttonAddTree, wxSizerFlags().Center().Border(wxALL)); btnSizer->Add(buttonRemove, wxSizerFlags().Center().Border(wxALL)); + btnSizer->Add(buttonRemoveAll, wxSizerFlags().Center().Border(wxALL)); // and put it all together leftSizer->Add(btnSizer, wxSizerFlags(0).Expand()); @@ -280,6 +285,10 @@ MyFrame::MyFrame(const wxString& title) wxCommandEventHandler(MyFrame::OnRemove)); Connect(BTN_ID_REMOVE, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(MyFrame::OnRemoveUpdateUI)); + Connect(BTN_ID_REMOVE_ALL, wxEVT_BUTTON, + wxCommandEventHandler(MyFrame::OnRemoveAll)); + Connect(BTN_ID_REMOVE_ALL, wxEVT_UPDATE_UI, + wxUpdateUIEventHandler(MyFrame::OnRemoveAllUpdateUI)); // and show itself (the frames, unlike simple controls, are not shown when // created initially) @@ -453,11 +462,26 @@ void MyFrame::OnRemove(wxCommandEvent& WXUNUSED(event)) } } +void MyFrame::OnRemoveAll(wxCommandEvent& WXUNUSED(event)) +{ + if ( !m_watcher->RemoveAll() ) + { + wxLogError("Error removing all paths from watched paths"); + } + + m_filesList->DeleteAllItems(); +} + void MyFrame::OnRemoveUpdateUI(wxUpdateUIEvent& event) { event.Enable(m_filesList->GetFirstSelected() != wxNOT_FOUND); } +void MyFrame::OnRemoveAllUpdateUI(wxUpdateUIEvent& event) +{ + event.Enable( m_filesList->GetItemCount() != 0 ); +} + void MyFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event) { // TODO remove when code is rock-solid diff --git a/src/common/fswatchercmn.cpp b/src/common/fswatchercmn.cpp index 66fb869e9c..cb32a14100 100644 --- a/src/common/fswatchercmn.cpp +++ b/src/common/fswatchercmn.cpp @@ -305,9 +305,9 @@ bool wxFileSystemWatcherBase::RemoveTree(const wxFileName& path) bool wxFileSystemWatcherBase::RemoveAll() { - m_service->RemoveAll(); + const bool ret = m_service->RemoveAll(); m_watches.clear(); - return true; + return ret; } int wxFileSystemWatcherBase::GetWatchedPathsCount() const