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