calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / wizards / source / importwizard / FilesModul.xba
blobcfac77dfe6cd29b9ff96e23c35601d216b1d9e9c
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.
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/.
10 * This file incorporates work covered by the following license notice:
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="FilesModul" script:language="StarBasic">Option Explicit
22 Public AbsTemplateFound as Integer
23 Public AbsDocuFound as Integer
24 Public oLogDocument as Object
25 Public oLogTable as Object
26 Public bLogExists as Boolean
27 Public sComment as String
28 Public MaxCollectIndex as Integer
29 Public bInsertRow as Boolean
30 Public sLogUrl as String
31 Public sCurPassWord as String
32 Public FileCount as Integer
33 Public XMLTemplateCount as Integer
34 Public PathCollection(7,3) as String
35 Public bIsFirstLogTable as Boolean
38 Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
39 Dim FilterIndex as Integer
40 Dim bRecursive as Boolean
41 Dim SearchDir as String
42 Dim i as Integer
43 Dim n as Integer
44 Dim a as Integer
45 Dim s as Integer
46 Dim t as Integer
47 Dim sFileContent() as String
48 Dim NewList(0,1) as String
49 Dim Index as Integer
50 Dim CurFileName as String
51 Dim CurExtension as String
52 Dim CurFileContent as String
53 Dim XMLTemplateContentList() as String
54 Dim bIsTemplatePath as Boolean
55 Dim MaxIndex as Integer
56 Dim NewContentList() as String
57 Dim XMLTemplateContentString as String
58 Dim ApplIndex as Integer
59 Dim bAssignFileName as Boolean
60 Dim bInterruptSearch as Boolean
61 bInterruptSearch = False
62 For i = 0 To MaxCollectIndex
63 SearchDir = PathCollection(i,0)
64 bRecursive = PathCollection(i,1)
65 sFileContent() = ArrayoutofString(PathCollection(i,2), &quot;|&quot;)
66 NewList() = ReadDirectories(SearchDir, bRecursive, False, False, sFileContent(), &quot;&quot;)
67 If InterruptProcess Then
68 ReadCollectionPaths() = False
69 Exit Function
70 End If
71 If Ubound(NewList()) &gt; -1 Then
72 bIsTemplatePath = FieldInList(&quot;vor&quot;, sFileContent)
73 If bIsTemplatePath Then
74 XMLTemplateContentString = PathCollection(i,3)
75 XMLTemplateContentList() = ArrayoutofString(XMLTemplateContentString, &quot;|&quot;)
76 If Ubound(XMLTemplateContentList()) &gt; -1 Then
77 MaxIndex = Ubound(NewList())
78 ReDim Preserve NewList(MaxIndex, 1) as String
79 ReDim Preserve NewContentList(MaxIndex) as String
80 a = -1
81 For n = 0 To MaxIndex
82 bAssignFileName = True
83 If InterruptProcess() Then
84 ReadCollectionPaths() = False
85 Exit Function
86 End If
87 CurFileContent = &quot;&quot;
88 CurFileName = NewList(n,0)
89 If (FieldInList(NewList(n,1), XMLTemplateList())) Then
90 CurFileContent = GetRealFileContent(CurFileName)
91 t = SearchArrayforPartString(CurFileContent, XMLTemplateContentList())
92 bAssignFileName = (t &gt; -1)
93 If bAssignFileName Then
94 CurFileContent = XMLTemplateContentList(t)
95 End If
96 NewList(n,1) = CurFileContent
97 End If
98 CurExtension = NewList(n,1)
99 If bAssignFileName Then
100 If a &lt; n Then
101 a = a + 1
102 NewList(a,0) = CurFileName
103 NewList(a,1) = CurExtension
104 If CurFileContent = &quot;&quot; Then
105 CurFileContent = CurExtension
106 End If
107 ApplIndex = GetApplicationIndex(CurFileContent, sFiltername())
108 NewContentList(a) = ApplIndex
109 End If
110 End If
111 Next n
112 If a &lt; MaxIndex And a &gt; -1 Then
113 ReDim Preserve NewList(a, 1) as String
114 End If
115 If a &gt; -1 Then
116 AddListtoFilesList(FilesList(), NewList(), NewContentList())
117 End If
118 End If
119 Else
120 MaxIndex = Ubound(NewList())
121 ReDim Preserve NewContentList(MaxIndex) as String
122 For s = 0 To MaxIndex
123 CurExtension = NewList(s,1)
124 NewContentList(s) = GetApplicationIndex(CurExtension, sFiltername())
125 Next s
126 AddListtoFilesList(FilesList(), NewList(), NewContentList())
127 End If
128 End If
129 Next i
130 ReadCollectionPaths() = Ubound(FilesList()) &gt; -1
131 End Function
134 Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
135 Dim Index as Integer
136 Dim i as Integer
137 Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
138 If Index &gt;= MaxApplCount Then
139 Index = Index - MaxApplCount
140 End If
141 For i = 0 To MaxApplCount - 1
142 If Applications(i, SBAPPLKEY) = Index Then
143 GetApplicationIndex() = i
144 Exit Function
145 End If
146 Next i
147 GetApplicationIndex() = - 1
148 End Function
151 Function InterruptProcess() as Boolean
152 If bCancelTask Or RetValue = 0 Then
153 bConversionIsRunning = False
154 InterruptProcess() = True
155 Exit Function
156 End if
157 InterruptProcess() = False
158 End Function
161 Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
162 MaxCollectIndex = MaxCollectIndex + 1
163 PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
164 PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
165 AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
166 End Sub
169 Function SetExtension(LocExtension) as String
170 if (Instr(LocExtension, &quot;vnd.sun.xml.impress&quot;)) &gt; 0 then
171 SetExtension() = &quot;vor|sti|std&quot;
172 elseif (Instr(LocExtension, &quot;vnd.sun.xml.writer&quot;)) &gt; 0 then
173 SetExtension() = &quot;vor|stw&quot;
174 elseif (Instr(LocExtension, &quot;vnd.sun.xml.calc&quot;)) &gt; 0 then
175 SetExtension() = &quot;vor|stc&quot;
176 elseif (Instr(LocExtension, &quot;vnd.sun.xml.draw&quot;)) &gt; 0 then
177 SetExtension() = &quot;vor|std|sti&quot;
178 endif
179 End Function
181 Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
182 Dim iKey as Integer
183 Dim CurListString as String
184 Dim LocExtension as String
185 Dim LocContentString as String
186 Dim LocXMLTemplateContent as String
187 iKey = Applications(ApplIndex, SBAPPLKEY)
188 CurListString = PathCollection(CollectIndex, 2)
189 LocExtension = sFilterName(iKey +DistIndex, 0)
190 If Instr(LocExtension, &quot;vnd.sun.xml.&quot;) = 1 Then
191 LocExtension = SetExtension(LocExtension)
192 LocContentString = sFilterName(iKey +DistIndex, 0)
193 LocContentString = ReplaceString(LocContentString, &quot;|&quot;, &quot;;&quot;)
194 LocXMLTemplateContent = PathCollection(CollectIndex, 3)
195 If LocXMLTemplateContent = &quot;&quot; Then
196 LocXMLTemplateContent = LocContentString
197 Else
198 LocXMLTemplateContent = LocXMLTemplateContent &amp; &quot;|&quot; &amp; LocContentString
199 End If
200 PathCollection(CollectIndex, 3) = LocXMLTemplateContent
201 End If
202 If CurListString = &quot;&quot; Then
203 PathCollection(CollectIndex, 2) = LocExtension
204 Else
205 If Instr(CurListString, LocExtension) = 0 Then
206 PathCollection(CollectIndex, 2) = CurListString &amp; &quot;|&quot; &amp; LocExtension
207 End If
208 End If
209 End Sub
212 Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
213 Dim CollectIndex as Integer
214 Dim bCheckDocuType as Boolean
215 bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
216 If bCheckDocuType Then
217 CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
218 If (CollectIndex &gt;-1) Then
219 If Applications(ApplIndex, RecursiveIndex) &lt;&gt; PathCollection(CollectIndex, 1) Then
220 AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
221 Else
222 AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
223 End If
224 Else
225 AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
226 End If
227 End If
228 End Sub
231 Sub CollectPaths(sFiltername() as String)
232 Dim i as Integer
233 Dim XMLTemplateContentString as String
234 MaxCollectIndex = -1
235 For i = 0 To ApplCount-1
236 CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
237 Next i
238 XMLTemplateCount = 0
239 XMLTemplateContentString = &quot;&quot;
240 For i = 0 To ApplCount-1
241 CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
242 Next i
243 End Sub
246 Sub ConvertAllDocuments(sFilterName() as String)
247 Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
248 Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
249 Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
250 Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
251 Dim oInteractionHandler as Object
252 Dim InteractionTypes(0) as Long
253 Dim FilesList(0,2) as String
254 Dim sViewPath as String
255 Dim i as Integer
256 Dim FilterIndex as Integer
257 Dim sSourceUrl as String
258 Dim CurFilename as String
259 Dim oDocument as Object
260 Dim sExtension as String
261 Dim OldExtension as String
262 Dim CurFound as Integer
263 Dim TotFound as Integer
264 Dim TargetStemDir as String
265 Dim SourceStemDir as String
266 Dim TargetDir as String
267 Dim sTargetUrl as String
268 Dim CurFilterName as String
269 Dim ApplIndex as Integer
270 Dim Index as Integer
271 Dim bIsDocument as Boolean
272 Dim bDoSave as Boolean
273 Dim sCurFileExists as String
274 Dim MaxFileIndex as Integer
275 Dim bContainsBasicMacro as Boolean
276 Dim bIsPassWordProtected as Boolean
277 Dim iOverwrite as Integer
278 Dim sMimeTypeorExtension as String
279 Dim sPrevMimeTypeorExtension as String
280 bConversionisrunning = True
281 InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
282 oInteractionHandler = createUnoService(&quot;com.sun.star.task.InteractionHandler&quot;)
283 oInteractionHandler.initialize(InteractionTypes())
284 iGeneralOverwrite = SBOVERWRITEUNDEFINED
285 bConversionIsRunning = True
286 bLogExists = false
287 AbsTemplateFound = 0
288 AbsDocuFound = 0
289 CollectPaths(sFiltername())
290 If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
291 TotFound = 0
292 SetProgressDisplay(0)
293 bConversionisrunning = false
294 FinalizeDialogButtons()
295 Exit Sub
296 End If
297 TotFound = Ubound(FilesList()) + 1
298 If FilesList(0,0) = &quot;&quot; Then &apos; Querying the number of fields in a multidimensional Array is unsecure
299 TotFound = 0 &apos; because it will return the value 0 (and not -1) even when the Array is empty
300 SetProgressDisplay(0)
301 End If
302 BubbleSortList(FilesList(), true)
303 If TotFound &gt; 0 Then
304 CreateLogDocument(OpenProperties())
305 InitializeProgressPage(ImportDialog)
306 OpenProperties(0).Name = &quot;Hidden&quot;
307 OpenProperties(0).Value = True
308 OpenProperties(1).Name = &quot;AsTemplate&quot;
309 OpenProperties(1).Value = False
310 OpenProperties(2).Name = &quot;MacroExecutionMode&quot;
311 OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE
312 OpenProperties(3).Name = &quot;UpdateDocMode&quot;
313 OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
314 OpenProperties(4).Name = &quot;InteractionHandler&quot;
315 OpenProperties(4).Value = oInteractionHandler
316 MaxFileIndex = Ubound(FilesList(),1)
317 FileCount = 0
318 For i = 0 To MaxFileIndex
319 sComment = &quot;&quot;
320 If InterruptProcess() Then
321 Exit For
322 End If
323 bDoSave = True
324 sSourceUrl = FilesList(i,0)
325 sPrevMimeTypeorExtension = sMimeTypeorExtension
326 sMimeTypeorExtension = FilesList(i,1)
327 CurFiltername = GetFilterName(sMimeTypeorExtension, sFilterName(), sExtension, FilterIndex)
328 ApplIndex = FilesList(i,2)
329 If sMimeTypeorExtension &lt;&gt; sPrevMimeTypeorExtension Then
330 CreateLogTable(ApplIndex, sMimeTypeOrExtension, sFiltername())
331 End If
332 If ApplIndex &gt; Ubound(Applications) or (ApplIndex &lt; 0) Then
333 Msgbox &quot;Applicationindex out of bounds:&quot; &amp; sSourcUrl
334 End If
335 sViewPath = ConvertFromUrl(sSourceUrl) &apos; CutPathView(sSourceUrl, 70)
336 ImportDialog.LabelCurDocument.Label = Str(i+1) &amp; &quot;/&quot; &amp; MaxFileIndex + 1 &amp; &quot; (&quot; &amp; sViewPath &amp; &quot;)&quot;
337 Select Case lcase(sExtension)
338 Case &quot;odt&quot;, &quot;ods&quot;, &quot;odp&quot;, &quot;odg&quot;, &quot;odm&quot;, &quot;odf&quot;
339 SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), &quot;/&quot;)
340 TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), &quot;/&quot;)
341 Case Else &apos; Templates and Helper-Applications remain
342 SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), &quot;/&quot;)
343 TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), &quot;/&quot;)
344 End Select
345 sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
346 CurFilename = GetFileNameWithoutExtension(sTargetUrl, &quot;/&quot;)
347 OldExtension = GetFileNameExtension(sTargetUrl)
348 sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
349 sTargetUrl = sTargetUrl &amp; sExtension
350 TargetDir = RTrimStr(sTargetUrl, CurFilename &amp; &quot;.&quot; &amp; sExtension)
351 If (oUcb.Exists(sTargetUrl)) Then
352 If (iGeneralOverwrite &lt;&gt; SBOVERWRITEALWAYS) Then
353 If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
354 ShowOverwriteAllDialog(sTargetUrl, sTitle)
355 bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
356 Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
357 bDoSave = False
358 ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
359 &apos; Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog.
360 &apos; In this case my own UI becomes obsolete
361 sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), &quot;&lt;1&gt;&quot;)
362 sCurFileExists = ReplaceString(sCurFileExists, chr(13), &quot;&lt;CR&gt;&quot;)
363 iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
364 Select Case iOverWrite
365 Case 1 &apos; OK
366 &apos; In the FileProperty-Bean this is already default
367 bDoSave = True
368 Case 2 &apos; Abort
369 CancelTask(False)
370 bDoSave = False
371 Case 7 &apos; No
372 bDoSave = False
373 End Select
374 End If
375 End If
376 End If
377 If bDoSave Then
378 If Not oUcb.Exists(TargetDir) Then
379 bDoSave = CreateFolder(TargetDir)
380 End If
381 If bDoSave Then
382 oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, &quot;_default&quot;, 0, OpenProperties())
383 If Not IsNull(oDocument) Then
384 InsertSourceUrlToLogDocument(sSourceUrl, &quot;&quot;)
385 bIsPassWordProtected = CheckPassWordProtection(oDocument)
386 CheckIfMacroExists(oDocument.BasicLibraries, sComment)
387 On Local Error Goto NOSAVING
388 If bIsPassWordProtected Then
389 PWFileProperties(0).Name = &quot;FilterName&quot;
390 PWFileProperties(0).Value = CurFilterName
391 PWFileProperties(1).Name = &quot;Overwrite&quot;
392 PWFileProperties(1).Value = True
393 PWFileProperties(2).Name = &quot;Password&quot;
394 PWFileProperties(2).Value = sCurPassWord
395 oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
396 Else
397 FileProperties(0).Name = &quot;FilterName&quot;
398 FileProperties(0).Value = CurFilterName
399 FileProperties(1).Name = &quot;Overwrite&quot;
400 FileProperties(1).Value = True
401 oDocument.StoreAsUrl(sTargetUrl,FileProperties())
402 End If
403 &apos; Todo: Make sure that an errorbox pops up when saving fails
404 NOSAVING:
405 If Err &lt;&gt; 0 Then
406 sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), &quot;&lt;1&gt;&quot;)
407 sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
408 Resume LETSGO
409 LETSGO:
410 Else
411 FileCount = FileCount + 1
412 End If
413 oDocument.Dispose()
414 InsertTargetUrlToLogDocument(sTargetUrl, sComment)
415 Else
416 sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), &quot;&lt;1&gt;&quot;)
417 sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
418 InsertSourceUrlToLogDocument(sSourceUrl, sComment)
419 End If
420 End If
421 End If
422 Next i
423 End If
424 AddLogStatistics()
425 FinalizeDialogButtons()
426 bConversionIsRunning = False
427 Exit Sub
428 RTError:
429 Msgbox sRTErrorDesc, 16, sRTErrorHeader
430 End Sub
434 Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
435 Dim sLocExtension as String
436 Dim FirstStart as Integer
437 Dim FirstEnd as Integer
438 Dim i as Integer
439 Dim s as Integer
440 If FirstList(0,0) = &quot;&quot; Then
441 FirstStart = Ubound(FirstList(),1)
442 Else
443 FirstStart = Ubound(FirstList(),1) + 1
444 End If
445 FirstEnd = FirstStart + Ubound(SecList(),1)
446 ReDim Preserve FirstList(FirstEnd,2)
447 s = 0
448 For i = FirstStart To FirstEnd
449 FirstList(i,0) = SecList(s,0)
450 FirstList(i,1) = SecList(s,1)
451 sLocExtension = lcase(FirstList(i,1))
452 Select Case sLocExtension
453 Case &quot;sdw&quot;, &quot;sdc&quot;, &quot;sda&quot;, &quot;sdd&quot;, &quot;smf&quot;, &quot;sgl&quot;, &quot;doc&quot;, &quot;docx&quot;, &quot;docm&quot;, &quot;xls&quot;, &quot;xlsx&quot;, &quot;xlsm&quot;, &quot;ppt&quot;, &quot;pps&quot;, &quot;pptx&quot;, &quot;pptm&quot;, &quot;ppsx&quot;, &quot;ppsm&quot;, &quot;pub&quot;, &quot;sxi&quot;, &quot;sxw&quot;, &quot;sxd&quot;, &quot;sxg&quot;, &quot;sxm&quot;, &quot;sxc&quot;
454 AbsDocuFound = AbsDocuFound + 1
455 Case else
456 AbsTemplateFound = AbsTemplateFound + 1
457 End Select
458 FirstList(i,2) = CStr(NewContentList(s))
459 s = s + 1
460 Next i
461 SetProgressDisplay(Ubound(FirstList()) + 1)
462 End Sub
466 Function GetTargetTemplatePath(Index as Integer)
467 Select Case WizardMode
468 Case SBMICROSOFTMODE
469 GetTargetTemplatePath() = SOTemplatePath &amp; &quot;/&quot; &amp; sTemplateGroupName
470 End Select
471 End Function
474 &apos; Retrieves the second value for a next to &apos;SearchString&apos; in
475 &apos; a two-dimensional string-Array
476 Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
477 Dim i as Integer
478 Dim MaxIndex as Integer
479 Dim sLocFilterlist() as String
480 For i = 0 To Ubound(sFiltername(),1)
481 If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) &lt;&gt; 0 Then
482 sLocFilterList() = ArrayoutofString(sFiltername(i,0),&quot;|&quot;, MaxIndex)
483 If MaxIndex = 0 Then
484 sExtension = sFiltername(i,2)
485 GetFilterName = sFilterName(i,1)
486 Else
487 Dim b as Integer
488 Dim sLocExtensionList() as String
489 b = SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
490 sLocFilterList() = ArrayoutofString(sFiltername(i,1),&quot;|&quot;, MaxIndex)
491 GetFilterName = sLocFilterList(b)
492 sLocExtensionList() = ArrayoutofString(sFilterName(i,2), &quot;|&quot;, MaxIndex)
493 sExtension = sLocExtensionList(b)
494 End If
495 Exit For
496 End If
497 Next
498 FilterIndex = i
499 End Function
502 Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
503 Dim i as Integer
504 Dim a as Integer
505 Dim StringList() as String
506 For i = Lbound(LocList(),1) to Ubound(LocList(),1)
507 StringList() = ArrayoutofString(LocList(i), &quot;|&quot;)
508 For a = 0 To Ubound(StringList())
509 If (Instr(1, SearchString, StringList(a)) &lt;&gt; 0) Then
510 SearchArrayForPartString() = i
511 Exit Function
512 End If
513 Next a
514 Next i
515 SearchArrayForPartString() = -1
516 End Function
519 Sub CreateLogTable(ApplIndex as Integer, CurFileContent as String, sFilterName() as String)
520 Dim oLogCursor as Object
521 Dim oLogRows as Object
522 Dim FilterIndex as Integer
523 Dim sDocumentType as String
524 Dim oTextCursor
525 Dim oCell
526 If Not bLogExists Then
527 Exit Sub
528 End If
529 FilterIndex = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
530 sDocumentType = sFiltername(FilterIndex,3)
531 oLogCursor = oLogDocument.Text.createTextCursor()
532 oLogCursor.GotoEnd(False)
533 If Not bIsFirstLogTable Then
534 oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
535 Else
536 bisFirstLogTable = False
537 End If
538 oLogCursor.HyperLinkURL = &quot;&quot;
539 oLogCursor.HyperLinkName = &quot;&quot;
540 oLogCursor.HyperLinkTarget = &quot;&quot;
541 oLogCursor.ParaStyleName = &quot;Heading 1&quot;
542 oLogCursor.setString(sDocumentType)
543 oLogCursor.CollapsetoEnd()
544 oLogDocument.Text.insertControlCharacter(oLogCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
545 oLogTable = oLogDocument.CreateInstance(&quot;com.sun.star.text.TextTable&quot;)
546 oLogTable.RepeatHeadline = true
547 oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
548 oTextCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
549 oTextCursor.SetString(sSourceDocuments)
550 oTextCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
551 oTextCursor.SetString(sTargetDocuments)
552 bInsertRow = False
553 End Sub
556 Function GetSize(iWidth, iHeight) As New com.sun.star.awt.Size
557 Dim aSize As New com.sun.star.awt.Size
558 aSize.Width = iWidth
559 aSize.Height = iHeight
560 GetSize() = aSize
561 End Function
564 Sub InsertCommandButtonatViewCursor(oLocDocument, oLocCursor, TargetUrl as String, Optional aSize)
565 Dim oDocument
566 Dim oController
567 Dim oCommandButton
568 Dim oShape
569 Dim oDrawPage
570 Dim oCommandControl
571 Dim oEvent
572 Dim oCell
573 oCommandButton = oLocDocument.createInstance(&quot;com.sun.star.form.component.CommandButton&quot;)
574 oShape = oLocDocument.CreateInstance (&quot;com.sun.star.drawing.ControlShape&quot;)
575 If IsMissing(aSize) Then
576 oShape.Size = GetSize(4000, 600)
577 End If
578 oCommandButton.Label = FileNameoutofPath(Targeturl)
579 oCommandButton.TargetFrame = &quot;_default&quot;
580 oCommandButton.ButtonType = com.sun.star.form.FormButtonType.URL
581 oCommandbutton.DispatchUrlInternal = True
582 oCommandButton.TargetURL = ConverttoUrl(TargetUrl)
583 oShape.Control = oCommandbutton
584 oLocCursor.Text.InsertTextContent(oLocCursor, oShape, True)
585 End Sub
589 Sub CreateLogDocument(HiddenProperties())
590 Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
591 Dim NoArgs()
592 Dim i as Integer
593 Dim bLogIsThere as Boolean
594 If ImportDialog.chkLogfile.State = 1 Then
595 i = 2
596 OpenProperties(0).Name = &quot;Hidden&quot;
597 OpenProperties(0).Value = True
598 oLogDocument = StarDesktop.LoadComponentFromURL(&quot;private:factory/swriter&quot;, &quot;_default&quot;, 4, OpenProperties())
599 SOWorkPath = RTrimStr(SOWorkPath,&quot;/&quot;)
600 sLogUrl = SOWorkPath &amp; &quot;/Logfile.odt&quot;
602 bLogIsThere = oUcb.Exists(sLogUrl)
603 If bLogIsThere Then
604 If i = 2 Then
605 sLogUrl = ReplaceString(sLogUrl, &quot;/Logfile_2.odt&quot;, &quot;/Logfile.odt&quot;)
606 Else
607 sLogUrl = ReplaceString(sLogUrl, &quot;/Logfile_&quot; &amp; cStr(i) &amp; &quot;.odt&quot;, &quot;/Logfile_&quot; &amp; cStr(i-1) &amp; &quot;.odt&quot;)
608 End If
609 i = i + 1
610 End If
611 Loop Until Not bLogIsThere
612 bLogExists = True
613 oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
614 End If
615 End Sub
618 Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String)
619 Dim oCell
620 Dim oTextCursor
621 Dim CurFilterTracingpath as String
622 If (bLogExists) And (sTargetUrl &lt;&gt; &quot;&quot;) Then
623 If sTargetUrl &lt;&gt; &quot;&quot; Then
624 oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
625 InsertCommentToLogCell(sComment, oCell)
626 InsertHyperLinkToLogCell(sTargetUrl, oCell)
627 oLogDocument.Store()
628 End If
629 End If
630 End Sub
633 Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment) &apos;
634 Dim oCell as Object
635 If bLogExists Then
636 If bInsertRow Then
637 oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
638 Else
639 bInsertRow = True
640 End If
641 oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
642 InsertCommentToLogCell(sComment, oCell)
643 InsertHyperLinkToLogCell(SourceUrl, oCell)
644 oLogDocument.Store()
645 End If
646 End Sub
649 Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
650 Dim oLogCursor as Object
651 Dim LocFileName as String
652 oLogCursor = oCell.createTextCursor()
653 oLogCursor.CollapseToStart()
654 oLogCursor.HyperLinkURL = sUrl
655 oLogCursor.HyperLinkName = sUrl
656 oLogCursor.HyperLinkTarget = sUrl
657 LocFileName = FileNameOutOfPath(sUrl)
658 oCell.InsertString(oLogCursor, LocFileName,False)
659 End Sub
662 Sub InsertCommentToLogCell(sComment as string, oCell as Object)
663 Dim oCommentCursor as Object
664 If sComment &lt;&gt; &quot;&quot; Then
665 oCommentCursor = oCell.createTextCursor()
666 oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
667 oCell.insertString(oCommentCursor, sComment, false)
668 End If
669 End Sub
672 Sub AddLogStatistics()
673 Dim oCell as Object
674 Dim oLogCursor as Object
675 Dim MaxRowIndex as Integer
676 If bLogExists Then
677 MaxRowIndex = oLogTable.Rows.Count
678 sLogSummary = ReplaceString(sLogSummary, FileCount, &quot;&lt;COUNT&gt;&quot;)
679 &apos; oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
680 &apos; oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
681 &apos; oLogCursor = oCell.createTextCursor()
682 &apos; oCell.InsertString(oLogCursor, sLogSummary,False)
683 &apos; MergeRange(oLogTable, oCell, 1)
685 oLogCursor = oLogDocument.Text.CreateTextCursor
686 oLogCursor.gotoEnd(False)
687 oLogCursor.HyperLinkURL = &quot;&quot;
688 oLogCursor.HyperLinkName = &quot;&quot;
689 oLogCursor.HyperLinkTarget = &quot;&quot;
690 oLogCursor.SetString(sLogSummary)
691 oLogDocument.Store()
692 oLogDocument.Dispose()
693 bLogExists = False
694 End If
695 End Sub
699 Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
700 Dim ModuleNames() as String
701 Dim ModuleName as String
702 Dim MaxLibIndex as Integer
703 Dim MaxModuleIndex as Integer
704 Dim bMacroExists as Boolean
705 Dim n as Integer
706 Dim m as Integer
707 Dim LibName as String
708 Dim sBasicCode as String
709 Dim oLibrary as Object
710 bMacroExists = False
711 bMacroExists = oBasicLibraries.hasElements
712 If bMacroExists Then
713 MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
714 For n = 0 To MaxLibIndex
715 LibName = oBasicLibraries.ElementNames(n)
716 If oBasicLibraries.isLibraryLoaded(LibName) Then
717 oLibrary = oBasicLibraries.getbyName(LibName)
718 If oLibrary.hasElements() Then
719 MaxModuleIndex = Ubound(oLibrary.ElementNames())
720 For m = 0 To MaxModuleIndex
721 ModuleName = oLibrary.ElementNames(m)
722 sBasicCode = oLibrary.getbyName(ModuleName)
723 If sBasicCode &lt;&gt; &quot;&quot; Then
724 ConcatComment(sComment, sReeditMacro)
725 CheckIfMacroExists() = True
726 Exit Function
727 End If
728 Next m
729 End If
730 End If
731 Next n
732 End If
733 CheckIfMacroExists() = False
734 End Function
738 Function CheckPassWordProtection(oDocument as Object)
739 Dim bIsPassWordProtected as Boolean
740 Dim i as Integer
741 Dim oArgs()
742 Dim MaxIndex as Integer
743 Dim sblabla as String
744 bIsPassWordProtected = false
745 oArgs() = oDocument.getArgs()
746 MaxIndex = Ubound(oArgs())
747 For i = 0 To MaxIndex
748 sblabla = oArgs(i).Name
749 If oArgs(i).Name = &quot;Password&quot; Then
750 bIsPassWordProtected = True
751 sCurPassWord = oArgs(i).Value
752 Exit For
753 End If
754 Next i
755 CheckPassWordProtection() = bIsPassWordProtected
756 End Function
759 Sub OpenLogDocument()
761 bShowLogFile = True
762 ImportDialogArea.endexecute()
764 End Sub
767 Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)
768 Dim oTableCursor as Object
769 oTableCursor = oTable.createCursorByCellName(oCell.CellName)
770 oTableCursor.goRight(MergeCount, True)
771 oTableCursor.mergeRange()
772 End Sub
775 Function ConcatComment(sComment as String, AdditionalComment as String)
776 If sComment = &quot;&quot; Then
777 sComment = AdditionalComment
778 Else
779 sComment = sComment &amp; chr(13) + AdditionalComment
780 End If
781 ConcatComment = sComment
782 End Function
783 </script:module>