From: Vadim Zeitlin Date: Thu, 16 May 2013 14:33:07 +0000 (+0000) Subject: Add wxEVT_DIRCTRL_FILEACTIVATED wxDirCtrl event. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4d623b67ee74794fbeba5805a269433d030c67d5 Add wxEVT_DIRCTRL_FILEACTIVATED wxDirCtrl event. Allow processing double clicks on the files in the directory control. Closes #15208. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74003 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index c7c93b4643..20015c11a3 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -635,6 +635,7 @@ All (GUI): - Implement clipping for wxSVGFileDC (Steve Benbow). - Add wxDirCtrl::GetPath() (troelsk). - Add wxEVT_DIRCTRL_SELECTIONCHANGED event (troelsk). +- Add wxEVT_DIRCTRL_FILEACTIVATED event (troelsk). - Add wxControl::GetSizeFromTextSize() (Manuel Martin). - Optionally allow showing tooltips for disabled ribbon buttons (wxBen). - Add wxTL_NO_HEADER style to wxTreeListCtrl (robboto). diff --git a/include/wx/generic/dirctrlg.h b/include/wx/generic/dirctrlg.h index 6d625ba67a..73bf95d51c 100644 --- a/include/wx/generic/dirctrlg.h +++ b/include/wx/generic/dirctrlg.h @@ -110,6 +110,7 @@ public: void OnBeginEditItem(wxTreeEvent &event ); void OnEndEditItem(wxTreeEvent &event ); void OnTreeSelChange(wxTreeEvent &event); + void OnItemActivated(wxTreeEvent &event); void OnSize(wxSizeEvent &event ); // Try to expand as much of the given path as possible. @@ -210,11 +211,13 @@ private: }; wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRCTRL_SELECTIONCHANGED, wxTreeEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRCTRL_FILEACTIVATED, wxTreeEvent ); #define wx__DECLARE_DIRCTRL_EVT(evt, id, fn) \ wx__DECLARE_EVT1(wxEVT_DIRCTRL_ ## evt, id, wxTreeEventHandler(fn)) #define EVT_DIRCTRL_SELECTIONCHANGED(id, fn) wx__DECLARE_DIRCTRL_EVT(SELECTIONCHANGED, id, fn) +#define EVT_DIRCTRL_FILEACTIVATED(id, fn) wx__DECLARE_DIRCTRL_EVT(FILEACTIVATED, id, fn) //----------------------------------------------------------------------------- // wxDirFilterListCtrl @@ -310,6 +313,7 @@ extern WXDLLIMPEXP_DATA_CORE(wxFileIconsTable *) wxTheFileIconsTable; // old wxEVT_COMMAND_* constants #define wxEVT_COMMAND_DIRCTRL_SELECTIONCHANGED wxEVT_DIRCTRL_SELECTIONCHANGED +#define wxEVT_COMMAND_DIRCTRL_FILEACTIVATED wxEVT_DIRCTRL_FILEACTIVATED #endif // _WX_DIRCTRLG_H_ diff --git a/interface/wx/dirctrl.h b/interface/wx/dirctrl.h index 65f0592c18..d2cdad556f 100644 --- a/interface/wx/dirctrl.h +++ b/interface/wx/dirctrl.h @@ -57,6 +57,9 @@ enum Notice that this event is generated even for the changes done by the program itself and not only those done by the user. @since 2.9.5 + @event{EVT_DIRCTRL_FILEACTIVATED(id, func)} + The user activated a file by double-clicking or pressing Enter. + @since 2.9.5 */ class wxGenericDirCtrl : public wxControl { @@ -279,3 +282,4 @@ public: }; wxEventType wxEVT_DIRCTRL_SELECTIONCHANGED; +wxEventType wxEVT_DIRCTRL_FILEACTIVATED; diff --git a/samples/widgets/dirctrl.cpp b/samples/widgets/dirctrl.cpp index 27bcb2cd56..485c247c34 100644 --- a/samples/widgets/dirctrl.cpp +++ b/samples/widgets/dirctrl.cpp @@ -113,6 +113,7 @@ protected: void OnCheckBox(wxCommandEvent& event); void OnRadioBox(wxCommandEvent& event); void OnSelChanged(wxTreeEvent& event); + void OnFileActivated(wxTreeEvent& event); // reset the control parameters void Reset(); @@ -157,6 +158,7 @@ BEGIN_EVENT_TABLE(DirCtrlWidgetsPage, WidgetsPage) EVT_CHECKBOX(wxID_ANY, DirCtrlWidgetsPage::OnCheckBox) EVT_RADIOBOX(wxID_ANY, DirCtrlWidgetsPage::OnRadioBox) EVT_DIRCTRL_SELECTIONCHANGED(DirCtrlPage_Ctrl, DirCtrlWidgetsPage::OnSelChanged) + EVT_DIRCTRL_FILEACTIVATED(DirCtrlPage_Ctrl, DirCtrlWidgetsPage::OnFileActivated) END_EVENT_TABLE() // ============================================================================ @@ -377,4 +379,15 @@ void DirCtrlWidgetsPage::OnSelChanged(wxTreeEvent& event) event.Skip(); } +void DirCtrlWidgetsPage::OnFileActivated(wxTreeEvent& event) +{ + if ( m_dirCtrl ) + { + wxLogMessage("File activated \"%s\"", + m_dirCtrl->GetPath(event.GetItem())); + } + + event.Skip(); +} + #endif // wxUSE_DIRDLG diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp index 824c836942..d0860a624e 100644 --- a/src/generic/dirctrlg.cpp +++ b/src/generic/dirctrlg.cpp @@ -107,6 +107,7 @@ bool wxIsDriveAvailable(const wxString& dirName); // ---------------------------------------------------------------------------- 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() @@ -710,13 +712,35 @@ void wxGenericDirCtrl::OnTreeSelChange(wxTreeEvent &event) changedEvent.SetClientObject(m_treeCtrl->GetItemData(event.GetItem())); 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)