1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Harm van der Heijden and Robert Roebling
7 // Copyright: (c) Harm van der Heijden and Robert Roebling
8 // Licence: wxWindows licence
10 // Notes: wxDirDialog class written by Harm van der Heijden,
11 // uses wxDirCtrl class written by Robert Roebling for the
12 // wxFile application, modified by Harm van der Heijden
14 // Description: This generic dirdialog implementation defines three classes:
15 // 1) wxDirItemData(public wxTreeItemData) stores pathname and
16 // displayed name for each item in the directory tree
17 // 2) wxDirCtrl(public wxTreeCtrl) is a tree widget that
18 // displays a directory tree. It is possible to define sections
19 // for fast access to parts of the file system (such as the
20 // user's homedir, /usr/local, /tmp ...etc), similar to
21 // Win95 Explorer's shortcuts to 'My Computer', 'Desktop', etc.
22 // 3) wxDirDialog is the dialog box itself. The user can choose
23 // a directory by navigating the tree, or by typing a dir
24 // in an inputbox. The inputbox displays paths selected in the
25 // tree. It is possible to create new directories. The user
26 // will automatically be prompted for dir creation if he
27 // enters a non-existing dir.
29 // TODO/BUGS: - standard sections only have reasonable defaults for Unix
30 // (but others are easily added in wxDirCtrl::SetupSections)
31 // - No direct support for "show hidden" toggle. Partly due
32 // to laziness on my part and partly because
33 // wxFindFirst/NextFile never seems to find hidden dirs
35 // - No automatic update of the tree (branch) after directory
37 // - I call wxBeginBusyCursor while expanding items (creating
38 // a new branch might take a few seconds, especially if a
39 // CDROM drive or something is involved) but that doesn't
40 // seem to do anything. Need to look into that.
41 // - Am still looking for an efficient way to delete wxTreeCtrl
42 // branches. DeleteChildren has disappeared and
43 // CollapseAndReset( parent ) deletes the parent as well.
44 // - The dialog window layout is done using wxConstraints. It
45 // works, but it's not as simple as I'd like it to be (see
46 // comments in wxDirDialog::doSize)
48 /////////////////////////////////////////////////////////////////////////////
50 #ifndef _WX_DIRDLGG_H_
51 #define _WX_DIRDLGG_H_
54 #pragma interface "dirdlgg.h"
61 #include "wx/dialog.h"
62 #include "wx/checkbox.h"
63 #include "wx/treectrl.h"
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 WXDLLEXPORT_DATA(extern const wxChar
*) wxFileSelectorPromptStr
;
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
83 class WXDLLEXPORT wxDirItemData
: public wxTreeItemData
86 wxDirItemData(wxString
& path
, wxString
& name
);
89 void SetNewDirName( wxString path
);
90 wxString m_path
, m_name
;
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 class WXDLLEXPORT wxDirCtrl
: public wxTreeCtrl
103 wxTreeItemId m_rootId
;
106 wxDirCtrl(wxWindow
*parent
, const wxWindowID id
= -1,
107 const wxString
&dir
= "/",
108 const wxPoint
& pos
= wxDefaultPosition
,
109 const wxSize
& size
= wxDefaultSize
,
110 const long style
= wxTR_HAS_BUTTONS
,
111 const wxString
& name
= "wxTreeCtrl" );
112 void ShowHidden( const bool yesno
);
113 void OnExpandItem(wxTreeEvent
&event
);
114 void OnCollapseItem(wxTreeEvent
&event
);
115 void OnBeginEditItem(wxTreeEvent
&event
);
116 void OnEndEditItem(wxTreeEvent
&event
);
119 void CreateItems(const wxTreeItemId
&parent
);
120 void SetupSections();
121 wxArrayString m_paths
, m_names
;
124 DECLARE_EVENT_TABLE()
125 DECLARE_DYNAMIC_CLASS(wxDirCtrl
)
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
132 class WXDLLEXPORT wxDirDialog
: public wxDialog
135 wxDirDialog(wxWindow
*parent
,
136 const wxString
& message
= wxFileSelectorPromptStr
,
137 const wxString
& defaultPath
= wxEmptyString
,
138 long style
= 0, const wxPoint
& pos
= wxDefaultPosition
);
139 inline void SetMessage(const wxString
& message
) { m_message
= message
; }
140 inline void SetPath(const wxString
& path
) { m_path
= path
; }
141 inline void SetStyle(long style
) { m_dialogStyle
= style
; }
143 inline wxString
GetMessage() const { return m_message
; }
144 inline wxString
GetPath() const { return m_path
; }
145 inline long GetStyle() const { return m_dialogStyle
; }
149 void OnTreeSelected( wxTreeEvent
&event
);
150 void OnTreeKeyDown( wxTreeEvent
&event
);
151 void OnOK(wxCommandEvent
& event
);
152 void OnCancel(wxCommandEvent
& event
);
153 void OnNew(wxCommandEvent
& event
);
154 // void OnCheck(wxCommandEvent& event);
163 wxCheckBox
*m_check
; // not yet used
164 wxButton
*m_ok
, *m_cancel
, *m_new
;
167 DECLARE_EVENT_TABLE()
168 DECLARE_DYNAMIC_CLASS(wxDirDialog
)