Fix wxFileSystemWatcher::RemoveAll() to actually work.
We need to call DoRemove() on all watcher objects to really remove them, just removing our record of them was not enough and e.g. resulted in errors if we tried to re-add a previously watched path again. Closes #15531. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
5b43c1858d
commit
de22d0def4
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user