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

Joined: 17 Jan 2005 Posts: 7
|
Posted: Mon Jan 17, 2005 8:18 am Post subject: Close document fails (basic, writer, latest 2.0 preview) |
|
|
Hi
Usual disclaimers: I'm a newbie to Oo macros and have searched the forum and found no answer that helped.
I'm using the latest 2.0 preview, 1.9.69, running on XP Pro, using Basic.
I have a problem closing a writer document, in that I get the "Controller disagree" exception from com.sun.star.util.CloseVetoException.
In my code, I open a simple custom dialog, then when the user selects a 'Save & Close' button I run the following:
| Code: | Sub
oDialogSaveClose.EndExecute()
ThisComponent.store()
ThisComponent.Close(true)
end sub
|
If I comment out the dialog EndExecute line and call the Sub from a custom menu, it works fine, as soon as a dialog button is the trigger - exception.
Can anyone tell me what I'm doing wrong?
Many thanks
Paul. |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Mon Jan 17, 2005 8:45 am Post subject: |
|
|
Interesting,
what happens if you use thisComponent.close(False), does that produce the same exception?
And secondly I would put a wait statement under the line thisComponent.save() to give the saving process some time before I close the document.
However that shouldn't really be the problem here, if the problem still occurs, please give response and I will try this with OOo 1.1.x .
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
paulhh General User

Joined: 17 Jan 2005 Posts: 7
|
Posted: Mon Jan 17, 2005 9:01 am Post subject: |
|
|
I get the same exception if I use ThisComponent.close(false).
If I comment out the ThisComponent.save() , I still get the exception.
Cheers
Paul. |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Mon Jan 17, 2005 9:54 am Post subject: |
|
|
Hi,
I think it is not a problem related to 1.9
Apparently you trigger your sub from an event "button pushed", and then you call endExecute. In fact the dialog will only close after the event subroutine is finished. So you are trying to close a document before the dialog is closed.
A much simpler method is to define your Set&Close button as an OK button. You do this in the EDI with the properties panel, property Button type.
Then your dialog will close when the button is pushed. No need for an event routine.
In your main program you should have something like
| Code: |
if oDialogSaveClose.execute = 1 then
ThisComponent.store()
ThisComponent.Close(true)
' end of your program ...
else
' user has cancelled dialog
' do something else ...
end if |
If you still want to close your dialog by endExecute it is still necessary to close the document after the return from execute, like in the code above.
________
Bernard |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Mon Jan 17, 2005 10:29 am Post subject: |
|
|
That's a good point B Marcelly, I have not tested this but afterall it seems to be logical in a way. However this is not a good behavior, endExecute should kill the dialog whatsoever, even if there is still an event being processed.
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
paulhh General User

Joined: 17 Jan 2005 Posts: 7
|
Posted: Tue Jan 18, 2005 1:11 am Post subject: |
|
|
Yes, the approach of using the OK & Cancel button types on the dialog and calling it in the way suggested works. So, many thanks!
It does seem a bit limiting, though, since I'm sure there are situations when you'd like to be able to keep the dialog open until the action has completed - for example, to show any errors that may have occurred in the "ok" action and allow them to try again or do something different, without having the dialog disappear & reappear (very bad usability).
I also have to say that Oo is going to have its work cut out trying to make macros more accessible to casual developers (I know it's a community thing, so I should make an effort), but I'm thinking from the point of getting wider acceptance. We've done some pretty cool stuff with Office 2003 and I was hoping we'd be able to transfer it to Oo, but it'll be hard work for us.
Cheers
Paul |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Tue Jan 18, 2005 2:42 am Post subject: |
|
|
| Quote: | | It does seem a bit limiting, though, since I'm sure there are situations when you'd like to be able to keep the dialog open until the action has completed |
In such a case you will use an event routine with your button : set it as normal button, and if OK call endExecute, else show a message.
| Code: | | I also have to say that Oo is going to have its work cut out trying to make macros more accessible to casual developers |
Do you look for documentation ?
- see the External Resources page
- see also http://development.openoffice.org/index.html
- search through this section, and look also at the Code Snippets section
________
Bernard |
|
| Back to top |
|
 |
paulhh General User

Joined: 17 Jan 2005 Posts: 7
|
Posted: Tue Jan 18, 2005 4:27 am Post subject: |
|
|
Thanks for the solution, I had looked through the documentation, but it wasn't easy to get into - I guess that's what my comment is, there's a learning curve that's going to stop some people from even trying.
Cheers
Paul. |
|
| Back to top |
|
 |
|