Hi Ivan, Cor,
unfortunately, the suggested solution has a disadvantage that a bunch of
SaveAs UI action related features are lost, as for example the document
type dependent filter selection, error handling and etc. It could of
course be implemented as well, but then it would be just a duplication
of the sourcecode implemented in sfx2. From other side there is
currently no way to preselect the suggested file name for a document.
It is already planned for OOo3.1 to implement possibility to preselect
the path that will be used in SaveAs dialog while storing the document.
It looks to make sense to allow to preselect the file name as well, I
have just added this to the issue
http://qa.openoffice.org/issues/show_bug.cgi?id=94273
Another idea was to allow to specify it in template as well.
Thus, if it should be implemented for OOo3.0.x, an own dispatch
interceptor for SaveAs UI action should be registered. This interceptor
should implement functionality similar to the one suggested by Cor. It
could be improved to be close to the intern implementation of SaveAs
action, but it is up to you to decide how much efforts do you want to
invest into the implementation. You can take a look to the current
implementation in sfx2/souce/doc/guisaveas.cxx method
SfxStoringHelper::GuiStoreModel() for details. This implementation is
mainly UNO API based, so it could probably help.
I would recommend to wait for OOo3.1 if it is possible, since it will be
a pretty easy task there.
Hope that helps.
Best regards,
Mikhail.
On 10/17/08 10:36, Cor Nouws wrote:
Hi Ivan,
Jedlička Ivan [P4] wrote (17-10-2008 10:18)
Is there any way how to suggest a filename using API for saving
document created from a template? Such document has the filename
field in the SaveAs dialog blank. I have tried set the filename using
XModel.attachResource(URL, props), but without any effect. The method
XModel.getURL() returns then URL I had allready set though, but the
filename field of SaveAs Dialog remains still blank. From where gets
the SaveAs Dialog the value for filename field and how can I set the
value as needed? Ivan Jedlicka
In Basic, I mostly use the following:
Sub SaveThisDocument(oDoc)
Dim sDocPath$, sFileName$, sSaveURL$, s$
Dim nRslt%, l%, m%
Dim args(0) As New com.sun.star.beans.PropertyValue
On Error GoTo ErrorHandler
' Get the default name/location for the documents
sDocPath = GiveThisDocsDefaultPath() ' code of your choice
sFileName = GiveThisDocsDefaultName() ' code of your choice
sSaveURL = GetNameUsingFilePicker(sDocPath, sFileName)
If len(sSaveURL) > 0 Then
args(0).Name = "Overwrite"
args(0).Value = "False"
oDoc.storeAsUrl(sSaveURL,args())
End If
Exit Sub
ErrorHandler:
MyErrMessenger("SaveThisDocument")
End Sub
'-------------------------------------------------------------------------
Function GetNameUsingFilePicker (sDocPath$, sFileName$) as String
Dim sTitle$
Dim oFilePickerDlg
Dim sFilePickerArgs
Dim sFilesPicked () as String
On Error GoTo ErrorHandler
sTitle = "you choice"
oFilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )
sFilePickerArgs =
Array(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
)
With oFilePickerDlg
.Initialize ( sFilePickerArgs() )
.setTitle(sTitle)
If Len(sDocPath) > 0 Then .SetDisplayDirectory (ConvertToURL(sDocPath))
If Len(sFileName) > 0 Then .SetDefaultName (sFileName)
' .SetDisplayDirectory (sDocPath)
' .SetDefaultName (sFileName)
.AppendFilter( "All files (*.*)", "*.*" )
.AppendFilter( "OpenDocument Text (.odt)", "*.odt" )
.AppendFilter( "OpenDocument Text Template (.ott)", "*.ott" )
' Option !
'.AppendFilter( "Microsoft Word 97/2000/XP (.doc)", "*.doc" )
'.appendFilter( "OpenOffice.org Calc (SXC)", "sxc" )
'appendFilter( "Microsoft Excel (XLS)", "xls" )
.SetCurrentFilter( "OpenDocument Text (.odt)" )
.SetValue(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_AUTOEXTENSION,
0, true)
.SetValue(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_PASSWORD,
0, false)
'.EnableControl(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_PASSWORD,
false)
End With
If oFilePickerDlg.execute() > 0 Then
sFilesPicked() = oFilePickerDlg.getFiles()
GetNameUsingFilePicker = sFilesPicked(0)
End If
Exit Function
ErrorHandler:
MyErrMessenger("GetNameUsingFilePicker")
End Function
'-------------------------------------------------------------------------
Regards,
Cor
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]