1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <svtools/foldertree.hxx>
#include "contentenumeration.hxx"
FolderTree::FolderTree( vcl::Window* pParent, WinBits nBits )
: SvTreeListBox( pParent, nBits | WB_SORT | WB_TABSTOP )
, m_aFolderImage( SvtResId( IMG_SVT_FOLDER ) )
{
Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
Reference< XInteractionHandler > xInteractionHandler(
InteractionHandler::createWithParent( xContext, 0 ), UNO_QUERY_THROW );
m_xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
SetDefaultCollapsedEntryBmp( m_aFolderImage );
SetDefaultExpandedEntryBmp( m_aFolderImage );
}
void FolderTree::RequestingChildren( SvTreeListEntry* pEntry )
{
FillTreeEntry( pEntry );
}
void FolderTree::FillTreeEntry( SvTreeListEntry* pEntry )
{
// fill only empty entries
if( pEntry && GetChildCount( pEntry ) == 0 )
{
::std::vector< SortingData_Impl* > aContent;
FileViewContentEnumerator* pContentEnumerator = new FileViewContentEnumerator(
m_xEnv, aContent, m_aMutex, NULL );
OUString* pURL = static_cast< OUString* >( pEntry->GetUserData() );
if( pURL )
{
FolderDescriptor aFolder( *pURL );
EnumerationResult eResult =
pContentEnumerator->enumerateFolderContentSync( aFolder, m_aBlackList );
if ( SUCCESS == eResult )
{
for( unsigned int i = 0; i < aContent.size(); i++ )
{
if( aContent[i]->mbIsFolder )
{
SvTreeListEntry* pNewEntry = InsertEntry( aContent[i]->GetTitle(), pEntry, true );
OUString* sData = new OUString( aContent[i]->maTargetURL );
pNewEntry->SetUserData( static_cast< void* >( sData ) );
}
}
}
}
}
}
void FolderTree::SetTreePath( OUString sUrl )
{
INetURLObject aUrl( sUrl );
aUrl.setFinalSlash();
OUString sPath = aUrl.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
SvTreeListEntry* pEntry = First();
bool end = false;
while( pEntry && !end )
{
if( pEntry->GetUserData() )
{
OUString sNodeUrl = *static_cast< OUString* >( pEntry->GetUserData() );
INetURLObject aUrlObj( sNodeUrl );
aUrlObj.setFinalSlash();
sNodeUrl = aUrlObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
if( sPath == sNodeUrl )
{
Select( pEntry );
end = true;
}
else if( sPath.startsWith( sNodeUrl ) )
{
if( !IsExpanded( pEntry ) )
Expand( pEntry );
pEntry = FirstChild( pEntry );
}
else
{
pEntry = NextSibling( pEntry );
}
}
else
break;
}
}
void FolderTree::SetBlackList( const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
{
m_aBlackList = rBlackList;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|