]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxEVT_DIRCTRL_FILEACTIVATED wxDirCtrl event.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 May 2013 14:33:07 +0000 (14:33 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 16 May 2013 14:33:07 +0000 (14:33 +0000)
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

docs/changes.txt
include/wx/generic/dirctrlg.h
interface/wx/dirctrl.h
samples/widgets/dirctrl.cpp
src/generic/dirctrlg.cpp

index c7c93b4643f65e9e936b09b9b10aba7e71d852c6..20015c11a3fb04315f627e740cc0d4bd4b2f4c51 100644 (file)
@@ -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).
index 6d625ba67add665fa9b09d75fbc50789f4adc0c4..73bf95d51c4fa772ee27b5256e55b6758aefe0a3 100644 (file)
@@ -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_
index 65f0592c18721581c455af9d1e937b72be2103a5..d2cdad556f7023837bf0a85bb0aaca36a34100e9 100644 (file)
@@ -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;
index 27bcb2cd563b706c30c44a624a0c00689b002a71..485c247c34d1fd5b6514ce9ec9f211218200fdcd 100644 (file)
@@ -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
index 824c8369427ea37fbbfcc13124c7dcb71376ac54..d0860a624ec173185b121d5bdf493bb2fd887abc 100644 (file)
@@ -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)