"Save As" file type information

Hi!

When user does “Save As” and chooses the file type, I want the file type to be known through some EventListener or any other mechanism. I need it because my XPackageEncryption implementation depends on filetype user have chosen.

I’d appreciate any help!

I don’t know where I found next macro, but it was for Save As plain text. I add the ODT to filter to show the possibilities. If you change the args(0).Name according to selected filter then you can have own Save As.

private oStoreDialog as object
private bFirst as boolean 'don't show listener during initialization of dialog
Sub SaveAsPlainText()
	dim ListAny(0) as long
	dim args(0) as new com.sun.star.beans.PropertyValue
	dim sFileName as string
	dim oListener
	GlobalScope.BasicLibraries.loadLibrary("Tools")
	ListAny(0)=com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
	oStoreDialog=CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	oStoreDialog.Initialize(ListAny)
	oStoreDialog.AppendFilter("Plain text (*.plain)",  ".plain")
	oStoreDialog.AppendFilter("ODT (*.odt)",  ".odt")
	sFileName=ThisComponent.getURL()
	if sFileName <> "" then oStoreDialog.SetDefaultName(GetFileNameWithoutExtension(ThisComponent.getURL(), "/"))
	oStoreDialog.setValue(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_AUTOEXTENSION, 0,  true)
	
	oListener=CreateUnoListener("L_", "com.sun.star.ui.dialogs.XFilePickerListener")
	oStoreDialog.addFilePickerListener(oListener)
	
	if oStoreDialog.Execute()<>1 then exit sub
	oStoreDialog.dispose()
	args(0).Name="FilterName"
	args(0).Value="Text"
	ThisComponent.storeAsURL(oStoreDialog.Files(0), args)
End Sub

Sub L_fileSelectionChanged(oEvt as object)
End Sub

Sub L_directoryChanged(oEvt as object)
End Sub

Sub L_helpRequested(oEvt as object)
End Sub

Sub L_controlStateChanged(oEvt as object)
	if bFirst then msgbox oStoreDialog.CurrentFilter
	bFirst=true
End Sub

Sub L_dialogSizeChanged(oEvt as object)
End Sub

Thank you so much! I’ll try implement it in my c++ code. As I can see, you just creating your own dialog and a listener, then executing the dialog. But how it could replace LibreOffice FilePicker invoke?

I don’t know but I suppose it will be complicated and I think it need changes in source code :-(.