| View previous topic :: View next topic |
| Author |
Message |
azarre General User

Joined: 19 Apr 2007 Posts: 18 Location: Prague, Czech Republic
|
Posted: Thu May 03, 2007 5:35 am Post subject: [SOLVED] DDE Link - leaves behind files locked by OOo |
|
|
Struggling with file locks leftover after DDE links.... .....how to remove them?
The scene:
--------------------------------------
* OS WinXP
* OOo 2.2.0
* Create 2 new files:
C:/Doc/fred.ods
--> A1 contains string "fred"
--> Save and Close
C:/Doc/ginger.ods
--> A1 contains formula =DDE("soffice";"C:\Doc\fred.ods";"Sheet1.A1")
--> Save and Close
Now, an attempt to delete or overwrite fred.ods fails - .....file in use by another application
---------------------------------------
fred.ods is locked by OOo..... .....I tried:
* Closing all OOo applications (including Quickstarter) doesn't help
* Breaking the links in ginger.ods (Alt-e - k - Alt-b (enter)) before saving doesn't help
* Open and close fred.ods (without saving) releases the file OK.
I'd like to be able to close the "hidden" fred.ods from a Macro called by the "Close Document" event in ginger.ods
Raked the forum for any related stuff - to no avail.
Scanned through the DevelopersGuide - nothing recognizably useful in there.
So here's goes my newbie attempt:
| Code: |
Sub CleanupLinkFiles
'Called by "Close Document" event
dim oComponents as Object
dim oComponentWalker as Object
dim oComponent as Object
dim cURL as String
dim cFile as String
dim linkEnum as Object
dim oLink as Object
dim linkFName as String
oComponents = StarDesktop.getComponents()
'Walk through all DDE links
linkEnum = thisComponent.DDElinks.createEnumeration()
Do While linkEnum.hasMoreElements()
oLink = linkEnum.nextElement()
'...know nothing about non-soffice DDE links, lets not touch them
If oLink.getApplication() = "soffice" then
linkFName = oLink.getTopic()
'Check through all open files, looking for opened DDE link files
oComponentWalker = oComponents.createEnumeration()
Do While oComponentWalker.hasMoreElements()
oComponent = oComponentWalker.nextElement()
If HasUnoInterfaces( oComponent, "com.sun.star.frame.XModel" ) Then
If oComponent.hasLocation() Then
cURL = oComponent.getLocation()
cFile = ConvertFromURL( cURL )
'MsgBox( "Found an open doc - " & cFile )
If cFile = linkFName then
'Found the DDE Linked file
'--> HELP NEEDED HERE If (oComponent... ....is hidden???)
'CloseVetoException seems tricky. "true" will have to do
oComponent.close(true)
' Endif
Endif
EndIf
EndIf
Loop
Endif
Loop
End sub
|
The missing piece:
* Don't want to close DDE link source files that are explicitly open by the User,
....thus the search for any way of recognizing the "open but hidden" docs.
Still trying - but so far no luck
Shouldn't OOo already behave something like this?
What is the advantage in leaving the DDE linked files open/locked even after the document containing the links was closed?
Thank you for reading through this....
Alex
Last edited by azarre on Sat Oct 20, 2007 5:58 am; edited 1 time in total |
|
| Back to top |
|
 |
azarre General User

Joined: 19 Apr 2007 Posts: 18 Location: Prague, Czech Republic
|
Posted: Sat Oct 20, 2007 5:47 am Post subject: Solution found |
|
|
Using the following solution without any noticeable issues for a couple of months now.
Closing an .ods with approximately 500 DDE links to 3 files takes under 3 seconds on
a 1.2GHz Pentium running MS Win XP.
| Code: |
Sub On_Doc_Close
'-------------------------------------------------------------------------------
' Close all HIDEN files that were opened for DDE link updating
'
' IMHO a defect in OOo - documents that are sources of DDE-linked data, remain
' locked by OOo even ater the document containing the DDE links is closed.
'
' Triggers:
' * "Close Document" event
'-------------------------------------------------------------------------------
dim oComponents as Object
dim oComponentWalker as Object
dim oComponent as Object
dim cURL as String
dim cFile as String
dim linkEnum as Object
dim oLink as Object
dim linkFName as String
dim linkFiles(100) as String
dim noLF as Integer
dim liLoop as Integer
dim newLink as Boolean
dim oFrame as Object
dim s as Object
'Scan through all DDE links in this document, and create a list of these file-names.
noLF = -1
linkEnum = thisComponent.DDElinks.createEnumeration()
Do While linkEnum.hasMoreElements()
oLink = linkEnum.nextElement()
'Xray oLink
'We know nothing about non-soffice DDE links, lets not touch them
If oLink.getApplication() = "soffice" then
linkFName = oLink.getTopic()
newLink = true
For liLoop = 0 to noLf
'MsgBox( "OPEN doc - " )
if linkFName = linkFiles(liLoop) then
newLink = false
exit for
endif
Next liLoop
If newLink then
linkFiles(liLoop) = linkFName
noLF = noLF + 1
Endif
Endif
Loop
oComponents = StarDesktop.getComponents()
'Check through all open files, looking for opened DDE link files
oComponentWalker = oComponents.createEnumeration()
Do While oComponentWalker.hasMoreElements()
oComponent = oComponentWalker.nextElement()
'Xray oComponent
If HasUnoInterfaces( oComponent, "com.sun.star.frame.XModel" ) Then
If oComponent.hasLocation() Then
cURL = oComponent.getLocation()
cFile = ConvertFromURL( cURL )
'MsgBox( "OPEN doc - " & cFile )
'Check if the component window size is (0,0,0,0)
'...couldn't find any other way to detect the "open but hidden" files (possibly referenced by a DDE link)
oFrame = oComponent.getCurrentController().getFrame()
s = oFrame.getComponentWindow().getPosSize()
If (abs(s.X) + abs(s.Y) + s.Width + s.Height) = 0 then
'MsgBox( "HIDDEN doc - " & cFile )
'Walk through the DDE links in this document
For liLoop = 0 to noLF
If cFile = linkFiles(liLoop) then
'Yep, the HIDDEN doc is DDE Linked from this doc
'MsgBox( "LINKED and HIDDEN doc - " & cFile )
oComponent.close(true)
Endif
next liLoop
EndIf
EndIf
Endif
Loop
End sub
|
BR,
Alex |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|