// Use 3D borders on internal controls
wxDIRCTRL_3D_INTERNAL = 0x0080,
// Editable labels
- wxDIRCTRL_EDIT_LABELS = 0x0100
+ wxDIRCTRL_EDIT_LABELS = 0x0100,
+ // Allow multiple selection
+ wxDIRCTRL_MULTIPLE = 0x0200
};
//-----------------------------------------------------------------------------
// Get dir or filename
virtual wxString GetPath() const;
+ virtual void GetPaths(wxArrayString& paths) const;
// Get selected filename path only (else empty string).
// I.e. don't count a directory as a selection
virtual wxString GetFilePath() const;
+ virtual void GetFilePaths(wxArrayString& paths) const;
virtual void SetPath(const wxString& path);
+ virtual void SelectPath(const wxString& path, bool select = true);
+ virtual void SelectPaths(const wxArrayString& paths);
+
virtual void ShowHidden( bool show );
virtual bool GetShowHidden() { return m_showHidden; }
virtual wxTreeCtrl* GetTreeCtrl() const { return m_treeCtrl; }
virtual wxDirFilterListCtrl* GetFilterListCtrl() const { return m_filterListCtrl; }
+ virtual void UnselectAll();
+
// Helper
virtual void SetupSections();
// Collapse the entire tree
virtual void CollapseTree();
-
// overridden base class methods
virtual void SetFocus();
directory.
@style{wxDIRCTRL_EDIT_LABELS}
Allow the folder and file labels to be editable.
+ @style{wxDIRCTRL_MULTIPLE}
+ Allows multiple files and folders to be selected.
@endStyleTable
@library{wxbase}
*/
virtual wxString GetFilePath() const;
+ /**
+ Fills the array @a paths with the currently selected filepaths.
+
+ This function doesn't count a directory as a selection.
+ */
+ virtual void GetFilePaths(wxArrayString& paths) const;
+
/**
Returns the filter string.
*/
*/
virtual wxString GetPath() const;
+ /**
+ Fills the array @a paths with the selected directories and filenames.
+ */
+ virtual void GetPaths(wxArrayString& paths) const;
+
/**
Returns the root id for the tree control.
*/
control. If @false, they will not be displayed.
*/
virtual void ShowHidden(bool show);
+
+ /**
+ Selects the given item.
+
+ In multiple selection controls, can be also used to deselect a
+ currently selected item if the value of @a select is false.
+ Existing selections are not changed. Only visible items can be
+ (de)selected, otherwise use ExpandPath().
+ */
+ virtual void SelectPath(const wxString& path, bool select = true);
+
+ /**
+ Selects only the specified paths, clearing any previous selection.
+
+ Only supported when wxDIRCTRL_MULTIPLE is set.
+ */
+ virtual void SelectPaths(const wxArrayString& paths);
+
+ /**
+ Removes the selection from all currently selected items.
+ */
+ virtual void UnselectAll();
};
wxCheckBox *m_chkDirOnly,
*m_chk3D,
*m_chkFirst,
- *m_chkLabels;
+ *m_chkLabels,
+ *m_chkMulti;
+
// filters
wxCheckBox *m_fltr[3];
m_chk3D = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_3D_INTERNAL"));
m_chkFirst = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_SELECT_FIRST"));
m_chkLabels = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_EDIT_LABELS"));
+ m_chkMulti = CreateCheckBoxAndAddToSizer(sizerUseFlags, _T("wxDIRCTRL_MULTIPLE"));
sizerLeft->Add(sizerUseFlags, wxSizerFlags().Expand().Border());
wxSizer *sizerFilters =
( m_chkDirOnly->IsChecked() ? wxDIRCTRL_DIR_ONLY : 0 ) |
( m_chk3D->IsChecked() ? wxDIRCTRL_3D_INTERNAL : 0 ) |
( m_chkFirst->IsChecked() ? wxDIRCTRL_SELECT_FIRST : 0 ) |
- ( m_chkLabels->IsChecked() ? wxDIRCTRL_EDIT_LABELS : 0 )
+ ( m_chkLabels->IsChecked() ? wxDIRCTRL_EDIT_LABELS : 0 ) |
+ ( m_chkMulti->IsChecked() ? wxDIRCTRL_MULTIPLE : 0)
);
wxString filter;
- for (int i = 0; i < 3; ++i)
+ for (int i = 0; i < 3; ++i)
{
- if (m_fltr[i]->IsChecked())
+ if (m_fltr[i]->IsChecked())
{
if (!filter.IsEmpty())
filter += wxT("|");
wxFLAGS_MEMBER(wxDIRCTRL_DIR_ONLY)
wxFLAGS_MEMBER(wxDIRCTRL_3D_INTERNAL)
wxFLAGS_MEMBER(wxDIRCTRL_SELECT_FIRST)
+ wxFLAGS_MEMBER(wxDIRCTRL_MULTIPLE)
wxEND_FLAGS( wxGenericDirCtrlStyle )
if (style & wxDIRCTRL_EDIT_LABELS)
treeStyle |= wxTR_EDIT_LABELS;
+ if (style & wxDIRCTRL_MULTIPLE)
+ treeStyle |= wxTR_MULTIPLE;
+
if ((style & wxDIRCTRL_3D_INTERNAL) == 0)
treeStyle |= wxNO_BORDER;
m_showHidden = show;
- wxString path = GetPath();
- ReCreateTree();
- SetPath(path);
+ if ( HasFlag(wxDIRCTRL_MULTIPLE) )
+ {
+ wxArrayString paths;
+ GetPaths(paths);
+ ReCreateTree();
+ for ( unsigned n = 0; n < paths.size(); n++ )
+ {
+ ExpandPath(paths[n]);
+ }
+ }
+ else
+ {
+ wxString path = GetPath();
+ ReCreateTree();
+ SetPath(path);
+ }
}
const wxTreeItemId
return wxEmptyString;
}
+void wxGenericDirCtrl::GetPaths(wxArrayString& paths) const
+{
+ paths.clear();
+
+ wxArrayTreeItemIds items;
+ m_treeCtrl->GetSelections(items);
+ for ( unsigned n = 0; n < items.size(); n++ )
+ {
+ wxTreeItemId id = items[n];
+ wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(id);
+ paths.Add(data->m_path);
+ }
+}
+
wxString wxGenericDirCtrl::GetFilePath() const
{
wxTreeItemId id = m_treeCtrl->GetSelection();
return wxEmptyString;
}
+void wxGenericDirCtrl::GetFilePaths(wxArrayString& paths) const
+{
+ paths.clear();
+
+ wxArrayTreeItemIds items;
+ m_treeCtrl->GetSelections(items);
+ for ( unsigned n = 0; n < items.size(); n++ )
+ {
+ wxTreeItemId id = items[n];
+ wxDirItemData* data = (wxDirItemData*) m_treeCtrl->GetItemData(id);
+ if ( !data->m_isDir )
+ paths.Add(data->m_path);
+ }
+}
+
void wxGenericDirCtrl::SetPath(const wxString& path)
{
m_defaultPath = path;
ExpandPath(path);
}
+void wxGenericDirCtrl::SelectPath(const wxString& path, bool select)
+{
+ bool done = false;
+ wxTreeItemId id = FindChild(m_rootId, path, done);
+ wxTreeItemId lastId = id; // The last non-zero id
+ while ( id.IsOk() && !done )
+ {
+ id = FindChild(id, path, done);
+ if ( id.IsOk() )
+ lastId = id;
+ }
+ if ( !lastId.IsOk() )
+ return;
+
+ if ( done )
+ {
+ if(select && m_treeCtrl->IsSelected(id))
+ return;
+ else
+ {
+ m_treeCtrl->SelectItem(id, select);
+ }
+ }
+}
+
+void wxGenericDirCtrl::SelectPaths(const wxArrayString& paths)
+{
+ if ( HasFlag(wxDIRCTRL_MULTIPLE) )
+ {
+ UnselectAll();
+ for ( unsigned n = 0; n < paths.size(); n++ )
+ {
+ SelectPath(paths[n]);
+ }
+ }
+}
+
+void wxGenericDirCtrl::UnselectAll()
+{
+ m_treeCtrl->UnselectAll();
+}
+
// Not used
#if 0
void wxGenericDirCtrl::FindChildFiles(wxTreeItemId id, int dirFlags, wxArrayString& filenames)
XRC_ADD_STYLE(wxDIRCTRL_3D_INTERNAL);
XRC_ADD_STYLE(wxDIRCTRL_SELECT_FIRST);
XRC_ADD_STYLE(wxDIRCTRL_EDIT_LABELS);
+ XRC_ADD_STYLE(wxDIRCTRL_MULTIPLE);
AddWindowStyles();
}