TutorialOpen.xba 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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="TutorialOpen" script:language="StarBasic">REM ***** BASIC *****
  21. Dim myOpenDialog As Object
  22. Dim oListBox As Object
  23. Dim files As Object
  24. Dim oUcb As Object
  25. Dim oListener As Object
  26. Sub TutorialOpenMain
  27. GlobalScope.BasicLibraries.LoadLibrary(&quot;Tools&quot;)
  28. myOpenDialog = LoadDialog(&quot;Tutorials&quot;,&quot;TutorialOpenDialog&quot;)
  29. init()
  30. myOpenDialog.Execute()
  31. End Sub
  32. Sub Init
  33. On Local Error Goto NOFILE
  34. myOpenDialog.Title = &quot;Tutorials&quot;
  35. oListBox = myOpenDialog.GetControl(&quot;ListBox&quot;)
  36. templatePath = GetPathSettings(&quot;Template&quot;,false, 0)
  37. Dim tutorialPath As String
  38. iPos = InStr(templatePath,&quot;/&quot;)
  39. if(iPos &gt; 0) Then
  40. tutorialPath = templatePath &amp; &quot;/tutorials&quot;
  41. Else
  42. tutorialPath = templatePath &amp; &quot;\tutorials&quot;
  43. End If
  44. oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
  45. files = oUcb.getFolderContents(tutorialPath,true)
  46. size = Ubound( files() )
  47. Dim tempFiles(size) As String
  48. tempCount = 0
  49. For iCount = 0 To size
  50. completPath = files(iCount)
  51. oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
  52. oDocInfo.Read(completPath)
  53. sDocTitle = oDocInfo.Title
  54. if(not isNull(sDocTitle) And len(sDocTitle) &gt; 0) Then
  55. oListbox.addItem(sDocTitle,0)
  56. tempFiles(tempCount) = completPath
  57. tempCount = tempCount + 1
  58. End If
  59. Next iCount
  60. &apos;printdbgInfo oListbox
  61. size = oListbox.ItemCount - 1
  62. Dim tempFiles2(size) As String
  63. For iCount = 0 To size
  64. tempFiles2(iCount) = tempFiles(iCount)
  65. Next iCount
  66. files() = tempFiles2()
  67. Exit Sub
  68. NOFILE:
  69. If Err &lt;&gt; 0 Then
  70. Msgbox &quot;No file found error!&quot; &amp; CHR(13) &amp; &quot;Path: ...\share\template\...\tutorials\&quot;
  71. myOpenDialog.model.Open.enabled = False
  72. End If
  73. End Sub
  74. Sub ItemSelected(oEvent)
  75. On Local Error Goto NOFILE
  76. completPath = files(Ubound(files()) - oEvent.Selected)
  77. oTextField = myOpenDialog.GetControl(&quot;Label&quot;) &apos;TextField
  78. oTextField.setText(&quot;&quot;)
  79. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  80. oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
  81. oDocInfo.Read(completPath)
  82. sDocDescription = oDocInfo.Description
  83. if(not isNull(sDocTitle) And len(sDocDescription) &gt; 0) Then
  84. oTextField.setText(sDocDescription)
  85. Else
  86. oTextField.setText(&quot;Not Description!!!.&quot;)
  87. End If
  88. Exit Sub
  89. NOFILE:
  90. If Err &lt;&gt; 0 Then
  91. Msgbox &quot;Open file error!&quot;
  92. End If
  93. End Sub
  94. Sub OpenTutorial(aEvent)
  95. completPath = files(Ubound(files()) - oListBox.getSelectedItemPos())
  96. Dim Args(2) as new com.sun.star.beans.PropertyValue
  97. Args(1).Name = &quot;MacroExecutionMode&quot;
  98. Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
  99. Args(2).Name = &quot;AsTemplate&quot;
  100. Args(2).Value = true
  101. StarDesktop.LoadComponentFromURL(completPath,&quot;_default&quot;,0, Args())
  102. myOpenDialog.endExecute()
  103. End Sub
  104. Sub Cancel(aEvent)
  105. myOpenDialog.endExecute()
  106. End Sub
  107. </script:module>