Properly use RemoveTree() in fswatcher sample.
We need to use RemoveTree() to remove watches for the paths added with AddTree(). See #14480. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72067 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -351,15 +351,18 @@ void MyFrame::AddEntry(wxFSWPathType type, wxString filename)
|
|||||||
filename,
|
filename,
|
||||||
type == wxFSWPath_Dir ? "directory" : "directory tree");
|
type == wxFSWPath_Dir ? "directory" : "directory tree");
|
||||||
|
|
||||||
|
wxString prefix;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
switch ( type )
|
switch ( type )
|
||||||
{
|
{
|
||||||
case wxFSWPath_Dir:
|
case wxFSWPath_Dir:
|
||||||
ok = m_watcher->Add(wxFileName::DirName(filename));
|
ok = m_watcher->Add(wxFileName::DirName(filename));
|
||||||
|
prefix = "Dir: ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFSWPath_Tree:
|
case wxFSWPath_Tree:
|
||||||
ok = m_watcher->AddTree(wxFileName::DirName(filename));
|
ok = m_watcher->AddTree(wxFileName::DirName(filename));
|
||||||
|
prefix = "Tree: ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFSWPath_File:
|
case wxFSWPath_File:
|
||||||
@@ -373,7 +376,10 @@ void MyFrame::AddEntry(wxFSWPathType type, wxString filename)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_filesList->InsertItem(m_filesList->GetItemCount(), filename);
|
// Prepend 'prefix' to the filepath, partly for display
|
||||||
|
// but mostly so that OnRemove() can work out the correct way to remove it
|
||||||
|
m_filesList->InsertItem(m_filesList->GetItemCount(),
|
||||||
|
prefix + wxFileName::DirName(filename).GetFullPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnRemove(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnRemove(wxCommandEvent& WXUNUSED(event))
|
||||||
@@ -383,10 +389,23 @@ void MyFrame::OnRemove(wxCommandEvent& WXUNUSED(event))
|
|||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxString path = m_filesList->GetItemText(idx);
|
bool ret;
|
||||||
|
wxString path;
|
||||||
// TODO we know it is a dir, but it doesn't have to be
|
// TODO we know it is a dir, but it doesn't have to be
|
||||||
if (!m_watcher->Remove(wxFileName::DirName(path)))
|
if (m_filesList->GetItemText(idx).StartsWith("Dir: ", &path))
|
||||||
|
{
|
||||||
|
ret = m_watcher->Remove(wxFileName::DirName(path));
|
||||||
|
}
|
||||||
|
else if (m_filesList->GetItemText(idx).StartsWith("Tree: ", &path))
|
||||||
|
{
|
||||||
|
ret = m_watcher->RemoveTree(wxFileName::DirName(path));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxFAIL_MSG("Unexpected item in wxListView.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
{
|
{
|
||||||
wxLogError("Error removing '%s' from watched paths", path);
|
wxLogError("Error removing '%s' from watched paths", path);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user