#include "wx/wx.h"
#endif
-#ifndef __WXMSW__
+#ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm"
#endif
MyFrame(const wxString& title);
virtual ~MyFrame();
- void AddDirectory(const wxString& dir);
+ // Add an entry of the specified type asking the user for the filename if
+ // the one passed to this function is empty.
+ void AddEntry(wxFSWPathType type, wxString filename = wxString());
bool CreateWatcherIfNecessary();
void OnAbout(wxCommandEvent& event);
void OnAdd(wxCommandEvent& event);
+ void OnAddTree(wxCommandEvent& event);
void OnRemove(wxCommandEvent& event);
void OnFileSystemEvent(wxFileSystemWatcherEvent& event);
if ( m_frame->CreateWatcherIfNecessary() )
{
if ( !m_dirToWatch.empty() )
- m_frame->AddDirectory(m_dirToWatch);
+ m_frame->AddEntry(wxFSWPath_Dir, m_dirToWatch);
}
}
MENU_ID_WATCH = 101,
BTN_ID_ADD = 200,
- BTN_ID_REMOVE = 201,
+ BTN_ID_ADD_TREE,
+ BTN_ID_REMOVE
};
// ================================================================
// the "About" item should be in the help menu
wxMenu *menuHelp = new wxMenu;
- menuHelp->Append(wxID_ABOUT, "&About...\tF1", "Show about dialog");
+ menuHelp->Append(wxID_ABOUT, "&About\tF1", "Show about dialog");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar();
// buttons
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");
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));
// and put it all together
// buttons
Connect(BTN_ID_ADD, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(MyFrame::OnAdd));
+ Connect(BTN_ID_ADD_TREE, wxEVT_COMMAND_BUTTON_CLICKED,
+ wxCommandEventHandler(MyFrame::OnAddTree));
Connect(BTN_ID_REMOVE, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(MyFrame::OnRemove));
void MyFrame::OnAdd(wxCommandEvent& WXUNUSED(event))
{
- wxCHECK_RET(m_watcher, "Watcher not initialized");
-
- // TODO account for adding the files as well
- const wxString& dir = wxDirSelector("Choose a folder to watch", "",
- wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
- if ( dir.empty() )
- return;
+ AddEntry(wxFSWPath_Dir);
+}
- AddDirectory(dir);
+void MyFrame::OnAddTree(wxCommandEvent& WXUNUSED(event))
+{
+ AddEntry(wxFSWPath_Tree);
}
-void MyFrame::AddDirectory(const wxString& dir)
+void MyFrame::AddEntry(wxFSWPathType type, wxString filename)
{
- wxLogDebug("Adding directory: '%s'", dir);
+ if ( filename.empty() )
+ {
+ // TODO account for adding the files as well
+ filename = wxDirSelector("Choose a folder to watch", "",
+ wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
+ if ( filename.empty() )
+ return;
+ }
+
+ wxCHECK_RET(m_watcher, "Watcher not initialized");
+
+ wxLogDebug("Adding %s: '%s'",
+ filename,
+ type == wxFSWPath_Dir ? "directory" : "directory tree");
- if (!m_watcher->Add(wxFileName::DirName(dir), wxFSW_EVENT_ALL))
+ bool ok = false;
+ switch ( type )
{
- wxLogError("Error adding '%s' to watched paths", dir);
+ case wxFSWPath_Dir:
+ ok = m_watcher->Add(wxFileName::DirName(filename));
+ break;
+
+ case wxFSWPath_Tree:
+ ok = m_watcher->AddTree(wxFileName::DirName(filename));
+ break;
+
+ case wxFSWPath_File:
+ case wxFSWPath_None:
+ wxFAIL_MSG( "Unexpected path type." );
}
- else
+
+ if (!ok)
{
- m_filesList->InsertItem(m_filesList->GetItemCount(), dir);
+ wxLogError("Error adding '%s' to watched paths", filename);
+ return;
}
+
+ m_filesList->InsertItem(m_filesList->GetItemCount(), filename);
}
void MyFrame::OnRemove(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnFileSystemEvent(wxFileSystemWatcherEvent& event)
{
// TODO remove when code is rock-solid
- wxLogDebug(wxTRACE_FSWATCHER, "*** %s ***", event.ToString());
+ wxLogTrace(wxTRACE_FSWATCHER, "*** %s ***", event.ToString());
LogEvent(event);
}