TutorialOpen.xba 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--***********************************************************
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. ***********************************************************-->
  23. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="TutorialOpen" script:language="StarBasic">REM ***** BASIC *****
  24. Dim myOpenDialog As Object
  25. Dim oListBox As Object
  26. Dim files As Object
  27. Dim oUcb As Object
  28. Dim oListener As Object
  29. Sub TutorialOpenMain
  30. GlobalScope.BasicLibraries.LoadLibrary(&quot;Tools&quot;)
  31. myOpenDialog = LoadDialog(&quot;Tutorials&quot;,&quot;TutorialOpenDialog&quot;)
  32. init()
  33. myOpenDialog.Execute()
  34. End Sub
  35. Sub Init
  36. On Local Error Goto NOFILE
  37. myOpenDialog.Title = &quot;Tutorials&quot;
  38. oListBox = myOpenDialog.GetControl(&quot;ListBox&quot;)
  39. templatePath = GetPathSettings(&quot;Template&quot;,false, 0)
  40. Dim tutorialPath As String
  41. iPos = InStr(templatePath,&quot;/&quot;)
  42. if(iPos &gt; 0) Then
  43. tutorialPath = templatePath &amp; &quot;/tutorials&quot;
  44. Else
  45. tutorialPath = templatePath &amp; &quot;\tutorials&quot;
  46. End If
  47. oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
  48. files = oUcb.getFolderContents(tutorialPath,true)
  49. size = Ubound( files() )
  50. Dim tempFiles(size) As String
  51. tempCount = 0
  52. For iCount = 0 To size
  53. completPath = files(iCount)
  54. oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
  55. oDocInfo.Read(completPath)
  56. sDocTitle = oDocInfo.Title
  57. if(not isNull(sDocTitle) And len(sDocTitle) &gt; 0) Then
  58. oListbox.additem(sDocTitle,0)
  59. tempFiles(tempCount) = completPath
  60. tempCount = tempCount + 1
  61. End If
  62. Next iCount
  63. &apos;printdbgInfo oListbox
  64. size = oListbox.ItemCount - 1
  65. Dim tempFiles2(size) As String
  66. For iCount = 0 To size
  67. tempFiles2(iCount) = tempFiles(iCount)
  68. Next iCount
  69. files() = tempFiles2()
  70. Exit Sub
  71. NOFILE:
  72. If Err &lt;&gt; 0 Then
  73. Msgbox &quot;No file found error!&quot; &amp; CHR(13) &amp; &quot;Path: ...\share\template\...\tutorials\&quot;
  74. myOpenDialog.model.Open.enabled = False
  75. End If
  76. End Sub
  77. Sub ItemSelected(oEvent)
  78. On Local Error Goto NOFILE
  79. completPath = files(Ubound(files()) - oEvent.Selected)
  80. oTextField = myOpenDialog.GetControl(&quot;Label&quot;) &apos;TextField
  81. oTextField.setText(&quot;&quot;)
  82. Dim NoArgs() as new com.sun.star.beans.PropertyValue
  83. oDocInfo = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
  84. oDocInfo.Read(completPath)
  85. sDocDescription = oDocInfo.Description
  86. if(not isNull(sDocTitle) And len(sDocDescription) &gt; 0) Then
  87. oTextField.setText(sDocDescription)
  88. Else
  89. oTextField.setText(&quot;Not Description!!!.&quot;)
  90. End If
  91. Exit Sub
  92. NOFILE:
  93. If Err &lt;&gt; 0 Then
  94. Msgbox &quot;Open file error!&quot;
  95. End If
  96. End Sub
  97. Sub OpenTutorial(aEvent)
  98. completPath = files(Ubound(files()) - oListBox.getSelectedItemPos())
  99. Dim Args(2) as new com.sun.star.beans.PropertyValue
  100. Args(1).Name = &quot;MacroExecutionMode&quot;
  101. Args(1).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE
  102. Args(2).Name = &quot;AsTemplate&quot;
  103. Args(2).Value = true
  104. StarDesktop.LoadComponentFromURL(completPath,&quot;_default&quot;,0, Args())
  105. myOpenDialog.endExecute()
  106. End Sub
  107. Sub Cancel(aEvent)
  108. myOpenDialog.endExecute()
  109. End Sub
  110. </script:module>