From b5b1a8e45a0bfeeb3a9f57946060c638ae110485 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jul 2012 11:22:06 +0000 Subject: [PATCH] Add the root and all the files in wxFileSystemWatcherBase::AddTree(). When watching a tree recursively, add the files and not only the directories. Also, add -- and remove in RemoveTree() -- the root directory itself and not only its children. Closes #14480. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72066 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/fswatchercmn.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/fswatchercmn.cpp b/src/common/fswatchercmn.cpp index 73a608c450..9983369c41 100644 --- a/src/common/fswatchercmn.cpp +++ b/src/common/fswatchercmn.cpp @@ -159,17 +159,22 @@ bool wxFileSystemWatcherBase::AddTree(const wxFileName& path, int events, // all of them to Add() and let it choose? this is useful when adding a // file to a dir that is already watched, then not only should we know // about that, but Add() should also behave well then - virtual wxDirTraverseResult OnFile(const wxString& WXUNUSED(filename)) + virtual wxDirTraverseResult OnFile(const wxString& filename) { + wxLogTrace(wxTRACE_FSWATCHER, + "--- AddTree adding file '%s' ---", filename); + m_watcher->DoAdd(wxFileName::FileName(filename), + m_events, wxFSWPath_File); return wxDIR_CONTINUE; } virtual wxDirTraverseResult OnDir(const wxString& dirname) { - wxLogTrace(wxTRACE_FSWATCHER, "--- AddTree adding '%s' ---", - dirname); + wxLogTrace(wxTRACE_FSWATCHER, + "--- AddTree adding directory '%s' ---", dirname); // we add as much as possible and ignore errors - m_watcher->Add(wxFileName(dirname), m_events); + m_watcher->DoAdd(wxFileName::DirName(dirname), + m_events, wxFSWPath_Dir); return wxDIR_CONTINUE; } @@ -183,6 +188,9 @@ bool wxFileSystemWatcherBase::AddTree(const wxFileName& path, int events, AddTraverser traverser(this, events); dir.Traverse(traverser, filter); + // Add the path itself explicitly as Traverse() doesn't return it. + Add(path.GetPathWithSep(), events); + return true; } @@ -209,7 +217,7 @@ bool wxFileSystemWatcherBase::RemoveTree(const wxFileName& path) virtual wxDirTraverseResult OnDir(const wxString& dirname) { - m_watcher->RemoveTree(wxFileName(dirname)); + m_watcher->Remove(wxFileName::DirName(dirname)); return wxDIR_CONTINUE; } @@ -221,6 +229,9 @@ bool wxFileSystemWatcherBase::RemoveTree(const wxFileName& path) RemoveTraverser traverser(this); dir.Traverse(traverser); + // As in AddTree() above, handle the path itself explicitly. + Remove(path); + return true; } -- 2.47.2