added multiple selections support to wxDirCtrl (closes #10830)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60909 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -472,6 +472,7 @@ wxBEGIN_FLAGS( wxGenericDirCtrlStyle )
|
||||
wxFLAGS_MEMBER(wxDIRCTRL_DIR_ONLY)
|
||||
wxFLAGS_MEMBER(wxDIRCTRL_3D_INTERNAL)
|
||||
wxFLAGS_MEMBER(wxDIRCTRL_SELECT_FIRST)
|
||||
wxFLAGS_MEMBER(wxDIRCTRL_MULTIPLE)
|
||||
|
||||
wxEND_FLAGS( wxGenericDirCtrlStyle )
|
||||
|
||||
@@ -560,6 +561,9 @@ bool wxGenericDirCtrl::Create(wxWindow *parent,
|
||||
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;
|
||||
|
||||
@@ -629,9 +633,22 @@ void wxGenericDirCtrl::ShowHidden( bool show )
|
||||
|
||||
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
|
||||
@@ -1095,6 +1112,20 @@ wxString wxGenericDirCtrl::GetPath() const
|
||||
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();
|
||||
@@ -1110,6 +1141,21 @@ wxString wxGenericDirCtrl::GetFilePath() const
|
||||
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;
|
||||
@@ -1117,6 +1163,48 @@ void wxGenericDirCtrl::SetPath(const wxString& 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)
|
||||
|
Reference in New Issue
Block a user