summaryrefslogtreecommitdiff
path: root/wizards/source/gimmicks/ReadDir.xba
blob: 806188cc45fb58c7c8442bfc7d496a92bdbb3768 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?xml version="1.0" encoding="UTF-8"?>

<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ReadDir" script:language="StarBasic">Option Explicit
&apos; Verzeichnis StarOne überprüfen (letzte beiden Dateien)
&apos; Ordnung nach Verzeichnis und dann die Dateien ( indem &quot;AAAA&quot; vor den Verzeichnisnamen gesetzt wird).
&apos; Nicht-Verzeichnisnamen abfangen
Const SBBASEWIDTH = 8000
Const SBBASEHEIGHT = 1000
Const SBPAGEX = 800
Const SBPAGEY = 800
Const SBBASECHARHEIGHT = 12
Const SBRELDIST = 1.1

REM Names of the second Dimension of the Array iLevelPos
Const SBBASEX = 0
Const SBBASEY = 1

Const SBOLDSTARTX = 2
Const SBOLDSTARTY = 3

Const SBOLDENDX = 4
Const SBOLDENDY = 5

Const SBNEWSTARTX = 6
Const SBNEWSTARTY = 7

Const SBNEWENDX = 8
Const SBNEWENDY = 9

Public ConnectLevel As Integer
Public iLevelPos(10,9) As Integer
Public Source as String
Public iCurLevel, nConnectLevel as Integer
Public nOldWidth, nOldHeight As Integer
Public nOldX, nOldY, nOldLevel As Integer
Public oOldLeavingLine As Object
Public oOldArrivingLine As Object


Sub Main
	LoadLibrary(&quot;tools&quot;)
	LoadLibrary(&quot;template&quot;)
	ReadDirDlg.Load
	ReadDirDlg.Show
End Sub


Sub TreeInfo()
Dim oCurTextShape As Object
Dim oDesktop As Object
Dim oDocument As Object
Dim iCurPage As Integer
Dim oPage As Object
Dim oOldPage As Object
Dim i, n, s  as Integer
Dim bStartUpRun As Boolean
Dim FileNames(600,2) as String 
Dim CurFile as String
Dim BaseLevel as Integer
Dim oController as Object
Dim FileCount as Integer
Dim oStatusline as Object
	ReadDirDlg.Unload
	bStartUpRun  = TRUE
	nOldHeight = 200
	nOldY = SBPAGEY
	nOldX = SBPAGEX
	nOldWidth = SBPAGEX
	iCurPage = 0
	
	oDesktop = createUnoService(&quot;com.sun.star.frame.Desktop&quot;)
	oDocument = StarDesktop.ActiveFrame.Controller.Model
	oPage = oDocument.DrawPages(iCurPage)
	oStatusline = oDocument.GetCurrentController.GetFrame.GetStatusIndicator
	oStatusLine.Start(&quot;Fortschritt:&quot;,100)
	oController = oDocument.GetCurrentController
	Source = ConvertToURL(ReadDirdlg.Textbox1.Text) 
	BaseLevel = CountCharsInString(Source, &quot;/&quot;, 1)

	oStatusline.SetValue(2)	
	FileNames() = ReadSourceDirectory(Source)
	oStatusline.SetValue(8)
	FileNames() = BubbleSortList(FileNames())
	oStatusline.SetValue(10)
	
	FileCount = Val(FileNames(0,0))
	For i = 1 To FileCount
		oStatusLine.SetValue(10 + i/FileCount * 90) 
		CurFile = FileNames(i,1)
		iCurLevel= CountCharsInString(FileNames(i,0), &quot;/&quot;, 1) - BaseLevel
		If iCurLevel &lt;&gt; 0 Then
			nConnectLevel = iCurLevel- 1
		Else
			nConnectLevel = iCurLevel
		End If

REM	 Add New page If necessary
REM	ck	IF nOldY + nOldHeight * 1/SBRELDIST &gt; oPage.Height - SBPAGEY Then
		IF nOldY + (nOldHeight + SBBASECHARHEIGHT) * 1.5 &gt; oPage.Height - SBPAGEY Then
			iCurPage = iCurPage + 1
			oDocument.getDrawPages.InsertNewbyIndex(iCurPage)

			oPage = oDocument.DrawPages(iCurPage)
			oController.SetCurrentPage (oPage)

			For n = 0 To nConnectLevel
				iLevelPos(n,SBNEWENDY) = nOldY + nOldHeight REM oOldPage.Height
				oOldLeavingLine = DrawLine(n, SBNEWSTARTX, SBNEWSTARTY, SBNEWSTARTX, SBNEWENDY, oOldPage)
REM	ck			                           SBNEWENDX, SBNEWENDY)
			Next
			For n = 0 To nConnectLevel
				iLevelPos(n,SBNEWSTARTY) = SBPAGEY
			Next
			nOldY = SBPAGEY
		End If
		oCurTextShape = CreateTextShape(oPage, CurFile)

REM	 The Current TextShape has To be connected with a TextShape
REM  one Level higher
REM	 - except For a TextShape In Level 0 

REM	 Line Coordinates
		If Not bStartUpRun Then		
		
REM	 A leaving Line Is only drawn when level is not 0
			If iCurLevel&lt;&gt; 0 Then
REM	 Determine the Coordinates of the arriving Line
				iLevelPos(iCurLevel,SBOLDSTARTX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
				iLevelPos(iCurLevel,SBOLDSTARTY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height

				iLevelPos(iCurLevel,SBOLDENDX) = iLevelPos(iCurLevel,SBBASEX)
				iLevelPos(iCurLevel,SBOLDENDY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height

				oOldArrivingLine = DrawLine(iCurLevel, SBOLDSTARTX, SBOLDSTARTY, SBOLDENDX, SBOLDENDY, oPage)

REM	 Determine the End-Coordinates of the last leaving Line
				iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
				iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
			Else
REM	On Level 0 the last Leaving Line&apos;s endpoint 
REM is the upper edge of the textShape
				iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y
				iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
			End If
REM	 Draw the Connectors To the previous TextShapes
			oOldLeavingLine = DrawLine(nConnectLevel, SBNEWSTARTX, SBNEWSTARTY, SBNEWENDX, SBNEWENDY, oPage)
		Else
REM	 StartingPoint of the leaving edge
			bStartUpRun = FALSE
		End If

REM	 Determine the beginning Coordinates of the leaving Line
		iLevelPos(iCurLevel,SBNEWSTARTX) = iLevelPos(iCurLevel,SBBASEX) + 0.5 * oCurTextShape.Size.Width
		iLevelPos(iCurLevel,SBNEWSTARTY) = iLevelPos(iCurLevel,SBBASEY) + oCurTextShape.Size.Height
		
REM	Save the values For the Next run
		nOldHeight = oCurTextShape.Size.Height
		nOldX = oCurTextShape.Position.X
		nOldWidth = oCurTextShape.Size.Width
		nOldLevel = iCurLevel
		Set oOldPage = oPage
	Next i
	oStatusLine.End
	Exit Sub
ErrorHandler:
	MsgBox error, 0,&quot;Error in Line&quot; &amp; erl
End Sub



Function CreateTextShape(oPage as Object, Filename as String)
Dim oTextShape As Object
Dim PageWidth, BaseX, TextWidth
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size

	aSize.Width = SBBASEWIDTH  
	aSize.Height = SBBASEHEIGHT 

	aPoint.x = CalculateXPoint()
	aPoint.y = nOldY + SBRELDIST * nOldHeight  
	nOldY  = aPoint.y

	oTextShape = oDocument.createInstance(&quot;com.sun.star.drawing.TextShape&quot;)
	oTextShape.Size = aSize
	oTextShape.Position = aPoint

	oPage.add(oTextShape)
	oTextShape.LineStyle = 1
	oTextShape.Charheight = SBBASECHARHEIGHT 
	oTextShape.TextAutoGrowWidth = TRUE
	oTextShape.TextAutoGrowHeight = TRUE
	oTextShape.String = FileName

REM	 Configure Size And Position of the TextShape  according to its Scripting
	aPoint.x = iLevelPos(iCurLevel,SBBASEX)
	oTextShape.Position = aPoint
	aSize.Height = SBRELDIST * oTextShape.CharHeight
	aSize.Width = SBRELDIST * oTextShape.Size.Width

	PageWidth = oPage.Width
	TextWidth = aSize.Width
	BaseX = aPoint.x
	If BaseX + TextWidth &gt; PageWidth - 1000 Then
		oPage.Width = 1000 + BaseX + TextWidth
	End If
	oTextShape.Size = aSize
	iLevelPos(iCurLevel,SBBASEY) = oTextShape.Position.Y
	CreateTextShape = oTextShape	
End Function



Function CalculateXPoint()

REM	 The current level Is lower than the Old one
	If (iCurLevel&lt; nOldLevel) And (iCurLevel&lt;&gt; 0) Then
REM		ClearArray(iLevelPos(),iCurLevel+1)
	Elseif iCurLevel= 0 Then
		iLevelPos(iCurLevel,SBBASEX) = SBPAGEX
REM	 The current level Is higher than the old one
	Elseif iCurLevel&gt; nOldLevel Then
		iLevelPos(iCurLevel,SBBASEX) = iLevelPos(iCurLevel-1,SBBASEX) + nOldWidth + 100
	End If
	CalculateXPoint = iLevelPos(iCurLevel,SBBASEX)
End Function



Function DrawLine(nLevel, nStartX, nStartY, nEndX, nEndY As Integer, oPage as Object) 
Dim oConnect As Object

	aPoint.X = iLevelPos(nLevel,nStartX)
	aPoint.Y = iLevelPos(nLevel,nStartY)
	aSize.Width = iLevelPos(nLevel,nEndX) - iLevelPos(nLevel,nStartX)
	aSize.Height = iLevelPos(nLevel,nEndY) - iLevelPos(nLevel,nStartY)

	oConnect = oDocument.createInstance(&quot;com.sun.star.drawing.LineShape&quot;)

	oConnect.Position = aPoint
	oConnect.Size = aSize
	oPage.Add(oConnect)

	DrawLine = oConnect
End Function


Sub SourceSearchDialog()
	Source = Application.FileDialog( &quot;P&quot;, &quot;Wählen Sie ein Verzeichnis&quot;, &quot;D:\Arbeitsverzeichnis&quot; )  &apos; &quot;Wählen Sie ein Verzeichnis&quot;
	If Len( Source ) &gt; 0 Then
		ReadDirDlg.Textbox1.Text = Source
	End If
End Sub



Function ReadSourceDirectory(ByVal Source As String)
Dim i, m, n, s as integer
Dim FileCount As Integer
Dim FileCountinDir as Integer
Dim FileName as string
Dim FileNameList(2000,1) as String
Dim DirList(200) as String
Dim oUCBobject as Object
	
	oUcbobject = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	&apos;isfolder
	m = 0
	s = 1
	DirList(0) = Source
	FileNameList(1,0) = Source 
	FileNameList(1,1) = GetFileNameoutofPath(Source) 
	n = 2
	Do
		Source = DirList(m)
		m = m + 1

		DirContent = oUcbObject.GetFolderContents(Source,True)

		If Ubound(DirContent()) &lt;&gt; -1 Then
			FileCountinDir = Ubound(DirContent()) + 1
			For i = 0 to FilecountinDir -1
				FileName = DirContent(i)
				FilenameList(n,0) = FileName
				FileNameList(n,1) = GetFileNameOutofPath(FileName)				
				n = n + 1
				If oUcbObject.IsFolder(FileName) Then
					DirList(s) = FileName
					DirList(0) = CStr(s)
					s = s + 1
				End If
			Next i
		End If
	Loop Until m  = cInt(DirList(0))+ 1
	FileNameList(0,0) = n - 1
	ReadSourceDirectory = FileNameList()
End Function
</script:module>