How to prevent save or edit operation until an option in dropdown is selected by the user? I am trying to create such extension

I want to design a libreoffice extension in Python that creates a dropdown. How should I prevent the save or edit operation in the file (text or sheet) until the user must select one option from this dropdown? Please help.

@ishwar66,

you may find some help at: https://wiki.documentfoundation.org/Development/Extension_Development.

One step seems to be this: How do you cancel an event? If you trap the Save Document event then how do you tell LO not to save (should that be the case)? In VBA I seem to recall setting the Event.Cancel to True or False, or something like that. But the passed object in LO is a very thin wrapper around the Source, which is the document itself. It would be easy to save just using e.Source.storeToUrl(…), but it seems like LO will go on to save in any case. How do you cancel?

Yeah, this is what I am thinking. I checked available methods, but was not able to find one that can do something like this.

I forgot details, but there are veto-able events. Iff saving would be such an event then throwing a (derived) VetoException would be the way to go. But on a quick glance I only found listeners on closables with CloseVetoException and terminate listeners with TerminationVetoException.

Turn your dropdown into a modal dialog box, then the user can’t do other things. Only automatic saving (and that doesn’t overwrite the real file, just saves data for crash recovery) can’t be disabled that way, but is that really important?

LibreOffice comes with a database component. Any relational database stores complete records only. Incomplete records can not be stored. You define what a complete record is. Entering field values by means of listboxes is just a matter of course when using a dtabase form. No matter how much silly Basic code you throw at a spreadsheet, you will never get close to the functionality of a mature database application.

Thanks @Villeroy , but I just want to prevent the save operation somehow. I am not saving anything.

@anon87010807 Is it not possible with a dropdown?

I don’t know.

This is not my area, but I tried some approaches I could think of. I can mimic the desire as a mock-up very easily…say, throw a dialog that requires “Consent” vs “No consent”, etc. But if I get to the dialog through a save event (Save Document) LO will always go ahead and save. In some ways it is comforting :slightly_smiling_face:. Yet it seems odd that LO/UNO provide no general way to cancel within trapped events chains/bubbles.

As for using a database, I’m envisioning the motive is to keep honest people honest about what they save and that they know the consequences of saving. @ishwar66, perhaps a better description of the actual goal (workflow) would lead to new ideas about how to get the same end result.

Hello,
.
This may be of some help for save (code in Basic) > Prevent user from saving calc doc
.
As for stopping Edit, that seems to then be unable to make a selection.
.
Edit:
.
This question seems very much like:

and

1 Like

I suppose that that first stackoverflow question is a cross-post of Preventing the save operation from within the libreoffice plugin.

Take a look at com::sun::star::frame::XModel2::setArgs, appeared in 6.3.