Difference between revisions of "Currently open documents"
From Apache OpenOffice Wiki
m |
|||
| Line 1: | Line 1: | ||
'''The following function returns an array of the currently open documents. It calls fnWhichComponent which is available from [[Currently active document]].''' | '''The following function returns an array of the currently open documents. It calls fnWhichComponent which is available from [[Currently active document]].''' | ||
| − | < | + | <syntaxhighlight lang="oobas"> |
function fnCurrentDocuments(optional sType as string) | function fnCurrentDocuments(optional sType as string) | ||
dim oEnum as object, oPosDoc as object, i as integer | dim oEnum as object, oPosDoc as object, i as integer | ||
| Line 46: | Line 46: | ||
fnCurrentDocuments = mDocs() | fnCurrentDocuments = mDocs() | ||
end function | end function | ||
| − | </ | + | </syntaxhighlight> |
An example of calling the above function. This function returns an array of the titles for the currently open documents. | An example of calling the above function. This function returns an array of the titles for the currently open documents. | ||
| − | < | + | <syntaxhighlight lang="oobas"> |
function fnCurrentDocTitles(optional sType as string) | function fnCurrentDocTitles(optional sType as string) | ||
if isMissing(sType) then | if isMissing(sType) then | ||
| Line 70: | Line 70: | ||
fnCurrentDocTitles = mTitles() | fnCurrentDocTitles = mTitles() | ||
End function | End function | ||
| − | </ | + | </syntaxhighlight> |
An example of displaying the titles of the currently open documents: | An example of displaying the titles of the currently open documents: | ||
| − | < | + | <syntaxhighlight lang="oobas"> |
sText = "Text" | sText = "Text" | ||
mCurTitles = fnCurrentDocTitles(sText) | mCurTitles = fnCurrentDocTitles(sText) | ||
| Line 81: | Line 81: | ||
msgbox "No Text documents currently open." | msgbox "No Text documents currently open." | ||
end if | end if | ||
| − | </ | + | </syntaxhighlight> |
[[Category:Basic:Tutorials]] | [[Category:Basic:Tutorials]] | ||
Latest revision as of 14:40, 24 August 2022
The following function returns an array of the currently open documents. It calls fnWhichComponent which is available from Currently active document.
function fnCurrentDocuments(optional sType as string)
dim oEnum as object, oPosDoc as object, i as integer
dim oListboxDocs as object
oEnum = StarDesktop.getComponents.createEnumeration
'Count windows
i = -1
while oEnum.hasMoreElements
oPosDoc = oEnum.nextElement
' The check for interface XserviceInfo necessary as some windows, e.g. Help
' don't have the interface and need to be excluded anyway.
If HasUnoInterfaces(oPosDoc, "com.sun.star.lang.XServiceInfo") Then
if isMissing(sType) then
i = i + 1
elseif fnWhichComponent(oPosDoc) = Stype then
i = i + 1
end if
end if
wend
if i = -1 then
'no documents of specified type currently open
exit function
end if
dim mDocs(i)
i = -1
oEnum = StarDesktop.getComponents.createEnumeration
while oEnum.hasMoreElements
oPosDoc = oEnum.nextElement
If HasUnoInterfaces( oPosDoc, "com.sun.star.lang.XServiceInfo") Then
If isMissing(sType) then
i = i + 1
mDocs(i) = oPosDoc
elseif fnWhichComponent(oPosDoc) = Stype then
i = i + 1
mDocs(i) = oPosDoc
end if
end if
wend
fnCurrentDocuments = mDocs()
end function
An example of calling the above function. This function returns an array of the titles for the currently open documents.
function fnCurrentDocTitles(optional sType as string)
if isMissing(sType) then
mDocs = fnCurrentDocuments()
else
mDocs = fnCurrentDocuments(SType)
end if
if isEmpty(mDocs) then
exit function
end if
nDocs = uBound(mDocs)
dim mTitles(nDocs)
for i = 0 to nDocs
mTitles(i) = mDocs(i).getCurrentController.getFrame.getPropertyValue("Title")
next
fnCurrentDocTitles = mTitles()
End function
An example of displaying the titles of the currently open documents:
sText = "Text"
mCurTitles = fnCurrentDocTitles(sText)
if not isEmpty(mCurTitles) then
msgbox join(mCurTitles, chr(10)), 0, "Currently open " & sText & "documents."
else
msgbox "No Text documents currently open."
end if