X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/84605707d116d42c3fc3dba931786bc55bbdc1d8..ad653fa23069c5d9378247084f03c9a718c3ad62:/src/generic/dirctrlg.cpp?ds=sidebyside diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp index 7eba8af2f9..d0860a624e 100644 --- a/src/generic/dirctrlg.cpp +++ b/src/generic/dirctrlg.cpp @@ -106,7 +106,8 @@ bool wxIsDriveAvailable(const wxString& dirName); // events // ---------------------------------------------------------------------------- -wxDEFINE_EVENT( wxEVT_COMMAND_DIRCTRL_CHANGED, wxTreeEvent ); +wxDEFINE_EVENT( wxEVT_DIRCTRL_SELECTIONCHANGED, wxTreeEvent ); +wxDEFINE_EVENT( wxEVT_DIRCTRL_FILEACTIVATED, wxTreeEvent ); // ---------------------------------------------------------------------------- // wxGetAvailableDrives, for WINDOWS, DOS, OS2, MAC, UNIX (returns "/") @@ -448,6 +449,7 @@ BEGIN_EVENT_TABLE(wxGenericDirCtrl, wxControl) EVT_TREE_BEGIN_LABEL_EDIT (wxID_TREECTRL, wxGenericDirCtrl::OnBeginEditItem) EVT_TREE_END_LABEL_EDIT (wxID_TREECTRL, wxGenericDirCtrl::OnEndEditItem) EVT_TREE_SEL_CHANGED (wxID_TREECTRL, wxGenericDirCtrl::OnTreeSelChange) + EVT_TREE_ITEM_ACTIVATED (wxID_TREECTRL, wxGenericDirCtrl::OnItemActivated) EVT_SIZE (wxGenericDirCtrl::OnSize) END_EVENT_TABLE() @@ -518,7 +520,7 @@ bool wxGenericDirCtrl::Create(wxWindow *parent, m_treeCtrl = CreateTreeCtrl(this, wxID_TREECTRL, wxPoint(0,0), GetClientSize(), treeStyle); - if (!filter.empty()) + if (!filter.empty() && (style & wxDIRCTRL_SHOW_FILTERS)) m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL); m_defaultPath = dir; @@ -703,13 +705,42 @@ void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event) void wxGenericDirCtrl::OnTreeSelChange(wxTreeEvent &event) { - wxTreeEvent changedEvent(wxEVT_COMMAND_DIRCTRL_CHANGED, GetId()); + wxTreeEvent changedEvent(wxEVT_DIRCTRL_SELECTIONCHANGED, GetId()); + changedEvent.SetEventObject(this); changedEvent.SetItem(event.GetItem()); changedEvent.SetClientObject(m_treeCtrl->GetItemData(event.GetItem())); - GetEventHandler()->SafelyProcessEvent(changedEvent); - event.Skip(); + if (GetEventHandler()->SafelyProcessEvent(changedEvent) && !changedEvent.IsAllowed()) + event.Veto(); + else + event.Skip(); +} + +void wxGenericDirCtrl::OnItemActivated(wxTreeEvent &event) +{ + wxTreeItemId treeid = event.GetItem(); + const wxDirItemData *data = GetItemData(treeid); + + if (data->m_isDir) + { + // is dir + event.Skip(); + } + else + { + // is file + wxTreeEvent changedEvent(wxEVT_DIRCTRL_FILEACTIVATED, GetId()); + + changedEvent.SetEventObject(this); + changedEvent.SetItem(treeid); + changedEvent.SetClientObject(m_treeCtrl->GetItemData(treeid)); + + if (GetEventHandler()->SafelyProcessEvent(changedEvent) && !changedEvent.IsAllowed()) + event.Veto(); + else + event.Skip(); + } } void wxGenericDirCtrl::OnExpandItem(wxTreeEvent &event) @@ -1244,7 +1275,7 @@ void wxGenericDirCtrl::SetFilter(const wxString& filter) { m_filter = filter; - if (!filter.empty() && !m_filterListCtrl) + if (!filter.empty() && !m_filterListCtrl && HasFlag(wxDIRCTRL_SHOW_FILTERS)) m_filterListCtrl = new wxDirFilterListCtrl(this, wxID_FILTERLISTCTRL); else if (filter.empty() && m_filterListCtrl) {