ReadDir.xba 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--
  4. * This file is part of the LibreOffice project.
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. *
  10. * This file incorporates work covered by the following license notice:
  11. *
  12. * Licensed to the Apache Software Foundation (ASF) under one or more
  13. * contributor license agreements. See the NOTICE file distributed
  14. * with this work for additional information regarding copyright
  15. * ownership. The ASF licenses this file to you under the Apache
  16. * License, Version 2.0 (the "License"); you may not use this file
  17. * except in compliance with the License. You may obtain a copy of
  18. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  19. -->
  20. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="ReadDir" script:language="StarBasic">Option Explicit
  21. Public Const SBPAGEX = 800
  22. Public Const SBPAGEY = 800
  23. Public Const SBRELDIST = 1.3
  24. &apos; Names of the second Dimension of the Array iLevelPos
  25. Public Const SBBASEX = 0
  26. Public Const SBBASEY = 1
  27. Public Const SBOLDSTARTX = 2
  28. Public Const SBOLDSTARTY = 3
  29. Public Const SBOLDENDX = 4
  30. Public Const SBOLDENDY = 5
  31. Public Const SBNEWSTARTX = 6
  32. Public Const SBNEWSTARTY = 7
  33. Public Const SBNEWENDX = 8
  34. Public Const SBNEWENDY = 9
  35. Public ConnectLevel As Integer
  36. Public iLevelPos(1,9) As Long
  37. Public Source as String
  38. Public iCurLevel as Integer
  39. Public nConnectLevel as Integer
  40. Public nOldWidth, nOldHeight As Long
  41. Public nOldX, nOldY, nOldLevel As Integer
  42. Public oOldLeavingLine As Object
  43. Public oOldArrivingLine As Object
  44. Public DlgReadDir as Object
  45. Dim oProgressBar as Object
  46. Dim oDocument As Object
  47. Dim oPage As Object
  48. Sub Main()
  49. Dim oStandardTemplate as Object
  50. BasicLibraries.LoadLibrary(&quot;Tools&quot;)
  51. oDocument = CreateNewDocument(&quot;sdraw&quot;)
  52. If Not IsNull(oDocument) Then
  53. oPage = oDocument.DrawPages(0)
  54. oStandardTemplate = oDocument.StyleFamilies.GetByName(&quot;graphics&quot;).GetByName(&quot;standard&quot;)
  55. oStandardTemplate.CharHeight = 10
  56. oStandardTemplate.TextLeftDistance = 100
  57. oStandardTemplate.TextRightDistance = 100
  58. oStandardTemplate.TextUpperDistance = 50
  59. oStandardTemplate.TextLowerDistance = 50
  60. DlgReadDir = LoadDialog(&quot;Gimmicks&quot;,&quot;ReadFolderDlg&quot;)
  61. oProgressBar = DlgReadDir.Model.ProgressBar1
  62. DlgReadDir.Model.TextField1.Text = ConvertFromUrl(GetPathSettings(&quot;Work&quot;))
  63. DlgReadDir.Model.cmdGoOn.DefaultButton = True
  64. DlgReadDir.GetControl(&quot;TextField1&quot;).SetFocus()
  65. DlgReadDir.Execute
  66. End If
  67. End Sub
  68. Sub TreeInfo()
  69. Dim oCurTextShape As Object
  70. Dim i as Integer
  71. Dim bStartUpRun As Boolean
  72. Dim CurFilename as String
  73. Dim BaseLevel as Integer
  74. Dim oController as Object
  75. Dim MaxFileIndex as Integer
  76. Dim FileNames() as String
  77. ToggleDialogControls(False)
  78. oProgressBar.ProgressValueMin = 0
  79. oProgressBar.ProgressValueMax = 100
  80. bStartUpRun = True
  81. nOldHeight = 200
  82. nOldY = SBPAGEY
  83. nOldX = SBPAGEX
  84. nOldWidth = SBPAGEX
  85. oController = oDocument.GetCurrentController
  86. Source = ConvertToURL(DlgReadDir.Model.TextField1.Text)
  87. BaseLevel = CountCharsInString(Source, &quot;/&quot;, 1)
  88. oProgressBar.ProgressValue = 5
  89. DlgReadDir.Model.Label3.Enabled = True
  90. FileNames() = ReadSourceDirectory(Source)
  91. DlgReadDir.Model.Label4.Enabled = True
  92. DlgReadDir.Model.Label3.Enabled = False
  93. oProgressBar.ProgressValue = 12
  94. FileNames() = BubbleSortList(FileNames())
  95. DlgReadDir.Model.Label5.Enabled = True
  96. DlgReadDir.Model.Label4.Enabled = False
  97. oProgressBar.ProgressValue = 20
  98. MaxFileIndex = Ubound(FileNames(),1)
  99. For i = 0 To MaxFileIndex
  100. oProgressBar.ProgressValue = 20 + (i/MaxFileIndex * 80)
  101. CurFilename = FileNames(i,1)
  102. SetNewLevels(FileNames(i,0), BaseLevel)
  103. oCurTextShape = CreateTextShape(oPage, CurFilename)
  104. CheckPageWidth(oCurTextShape.Size.Width)
  105. iLevelPos(iCurLevel,SBBASEY) = oCurTextShape.Position.Y
  106. If i = 0 Then
  107. AdjustPageHeight(oCurTextShape.Size.Height, MaxFileIndex + 1)
  108. End If
  109. &apos; The Current TextShape has To be connected with a TextShape one Level higher
  110. &apos; except for a TextShape In Level 0:
  111. If Not bStartUpRun Then
  112. &apos; A leaving Line Is only drawn when level is not 0
  113. If iCurLevel&lt;&gt; 0 Then
  114. &apos; Determine the Coordinates of the arriving Line
  115. iLevelPos(iCurLevel,SBOLDSTARTX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
  116. iLevelPos(iCurLevel,SBOLDSTARTY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
  117. iLevelPos(iCurLevel,SBOLDENDX) = iLevelPos(iCurLevel,SBBASEX)
  118. iLevelPos(iCurLevel,SBOLDENDY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
  119. oOldArrivingLine = DrawLine(iCurLevel, SBOLDSTARTX, SBOLDSTARTY, SBOLDENDX, SBOLDENDY, oPage)
  120. &apos; Determine the End-Coordinates of the last leaving Line
  121. iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
  122. iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
  123. Else
  124. &apos; On Level 0 the last Leaving Line&apos;s Endpoint is the upper edge of the TextShape
  125. iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y
  126. iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
  127. End If
  128. &apos; Draw the Connectors To the previous TextShapes
  129. oOldLeavingLine = DrawLine(nConnectLevel, SBNEWSTARTX, SBNEWSTARTY, SBNEWENDX, SBNEWENDY, oPage)
  130. Else
  131. &apos; StartingPoint of the leaving Edge
  132. bStartUpRun = FALSE
  133. End If
  134. &apos; Determine the beginning Coordinates of the leaving Line
  135. iLevelPos(iCurLevel,SBNEWSTARTX) = iLevelPos(iCurLevel,SBBASEX) + 0.5 * oCurTextShape.Size.Width
  136. iLevelPos(iCurLevel,SBNEWSTARTY) = iLevelPos(iCurLevel,SBBASEY) + oCurTextShape.Size.Height
  137. &apos; Save the values For the Next run
  138. nOldHeight = oCurTextShape.Size.Height
  139. nOldX = oCurTextShape.Position.X
  140. nOldWidth = oCurTextShape.Size.Width
  141. nOldLevel = iCurLevel
  142. Next i
  143. ToggleDialogControls(True)
  144. DlgReadDir.Model.cmdGoOn.Enabled = False
  145. End Sub
  146. Function CreateTextShape(oPage as Object, Filename as String)
  147. Dim oTextShape As Object
  148. Dim aPoint As New com.sun.star.awt.Point
  149. aPoint.X = CalculateXPoint()
  150. aPoint.Y = nOldY + SBRELDIST * nOldHeight
  151. nOldY = aPoint.Y
  152. oTextShape = oDocument.createInstance(&quot;com.sun.star.drawing.TextShape&quot;)
  153. oTextShape.LineStyle = 1
  154. oTextShape.Position = aPoint
  155. oPage.add(oTextShape)
  156. oTextShape.TextAutoGrowWidth = TRUE
  157. oTextShape.TextAutoGrowHeight = TRUE
  158. oTextShape.String = FileName
  159. &apos; Configure Size And Position of the TextShape according to its Scripting
  160. aPoint.X = iLevelPos(iCurLevel,SBBASEX)
  161. oTextShape.Position = aPoint
  162. CreateTextShape() = oTextShape
  163. End Function
  164. Function CalculateXPoint()
  165. &apos; The current level Is lower than the Old one
  166. If (iCurLevel&lt; nOldLevel) And (iCurLevel&lt;&gt; 0) Then
  167. &apos; ClearArray(iLevelPos(),iCurLevel+1)
  168. Elseif iCurLevel= 0 Then
  169. iLevelPos(iCurLevel,SBBASEX) = SBPAGEX
  170. &apos; The current level Is higher than the old one
  171. Elseif iCurLevel&gt; nOldLevel Then
  172. iLevelPos(iCurLevel,SBBASEX) = iLevelPos(iCurLevel-1,SBBASEX) + nOldWidth + 100
  173. End If
  174. CalculateXPoint = iLevelPos(iCurLevel,SBBASEX)
  175. End Function
  176. Function DrawLine(nLevel, nStartX, nStartY, nEndX, nEndY As Integer, oPage as Object)
  177. Dim oConnect As Object
  178. Dim aPoint As New com.sun.star.awt.Point
  179. Dim aSize As New com.sun.star.awt.Size
  180. aPoint.X = iLevelPos(nLevel,nStartX)
  181. aPoint.Y = iLevelPos(nLevel,nStartY)
  182. aSize.Width = iLevelPos(nLevel,nEndX) - iLevelPos(nLevel,nStartX)
  183. aSize.Height = iLevelPos(nLevel,nEndY) - iLevelPos(nLevel,nStartY)
  184. oConnect = oDocument.createInstance(&quot;com.sun.star.drawing.LineShape&quot;)
  185. oConnect.Position = aPoint
  186. oConnect.Size = aSize
  187. oPage.Add(oConnect)
  188. DrawLine() = oConnect
  189. End Function
  190. Sub GetSourceDirectory()
  191. GetFolderName(DlgReadDir.Model.TextField1)
  192. End Sub
  193. Function ReadSourceDirectory(ByVal Source As String)
  194. Dim i as Integer
  195. Dim m as Integer
  196. Dim n as Integer
  197. Dim s as integer
  198. Dim FileName as string
  199. Dim FileNameList(100,1) as String
  200. Dim DirList(0) as String
  201. Dim oUCBobject as Object
  202. Dim DirContent() as String
  203. Dim SystemPath as String
  204. Dim PathSeparator as String
  205. Dim MaxFileIndex as Integer
  206. PathSeparator = GetPathSeparator()
  207. oUcbobject = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
  208. m = 0
  209. s = 0
  210. DirList(0) = Source
  211. FileNameList(n,0) = Source
  212. SystemPath = ConvertFromUrl(Source)
  213. FileNameList(n,1) = FileNameoutofPath(SystemPath, PathSeparator)
  214. n = 1
  215. Do
  216. Source = DirList(m)
  217. m = m + 1
  218. DirContent() = oUcbObject.GetFolderContents(Source,True)
  219. If Ubound(DirContent()) &lt;&gt; -1 Then
  220. MaxFileIndex = Ubound(DirContent())
  221. For i = 0 to MaxFileIndex
  222. FileName = DirContent(i)
  223. FileNameList(n,0) = FileName
  224. SystemPath = ConvertFromUrl(FileName)
  225. FileNameList(n,1) = FileNameOutofPath(SystemPath, PathSeparator)
  226. n = n + 1
  227. If n &gt; Ubound(FileNameList(),1) Then
  228. ReDim Preserve FileNameList(n + 10,1) as String
  229. End If
  230. If oUcbObject.IsFolder(FileName) Then
  231. s = s + 1
  232. ReDim Preserve DirList(s) as String
  233. DirList(s) = FileName
  234. End If
  235. Next i
  236. End If
  237. Loop Until m &gt; Ubound(DirList())
  238. ReDim Preserve FileNameList(n-1,1) as String
  239. ReadSourceDirectory() = FileNameList()
  240. End Function
  241. Sub CloseDialog
  242. DlgReadDir.EndExecute
  243. End Sub
  244. Sub AdjustPageHeight(lShapeHeight, FileCount)
  245. Dim lNecHeight as Long
  246. Dim lBorders as Long
  247. oDocument.LockControllers
  248. lBorders = oPage.BorderTop + oPage.BorderBottom
  249. lNecHeight = SBPAGEY + (FileCount * SBRELDIST * lShapeHeight)
  250. If lNecHeight &gt; (oPage.Height - lBorders) Then
  251. oPage.Height = lNecHeight + lBorders + 500
  252. End If
  253. oDocument.UnlockControllers
  254. End Sub
  255. Sub SetNewLevels(FileName as String, BaseLevel as Integer)
  256. iCurLevel= CountCharsInString(FileName, &quot;/&quot;, 1) - BaseLevel
  257. If iCurLevel &lt;&gt; 0 Then
  258. nConnectLevel = iCurLevel- 1
  259. Else
  260. nConnectLevel = iCurLevel
  261. End If
  262. If iCurLevel &gt; Ubound(iLevelPos(),1) Then
  263. ReDim Preserve iLevelPos(iCurLevel,9) as Long
  264. End If
  265. End Sub
  266. Sub CheckPageWidth(TextWidth as Long)
  267. Dim PageWidth as Long
  268. Dim BaseX as Long
  269. PageWidth = oPage.Width
  270. BaseX = iLevelPos(iCurLevel,SBBASEX)
  271. If BaseX + TextWidth &gt; PageWidth - 1000 Then
  272. oPage.Width = 1000 + BaseX + TextWidth
  273. End If
  274. End Sub
  275. Sub ToggleDialogControls(bDoEnable as Boolean)
  276. With DlgReadDir.Model
  277. .cmdGoOn.Enabled = bDoEnable
  278. .cmdGetDir.Enabled = bDoEnable
  279. .Label1.Enabled = bDoEnable
  280. .Label2.Enabled = bDoEnable
  281. .TextField1.Enabled = bDoEnable
  282. End With
  283. End Sub</script:module>