diff -urNp sfx2orig/source/dialog/filedlghelper.cxx sfx2/source/dialog/filedlghelper.cxx --- sfx2orig/source/dialog/filedlghelper.cxx 2006-05-04 22:33:20.000000000 +0800 +++ sfx2/source/dialog/filedlghelper.cxx 2006-07-29 20:11:50.000000000 +0800 @@ -103,6 +103,30 @@ #include #endif +#ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_ +#include +#endif + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include +#endif + +#ifndef _COM_SUN_STAR_TEXT_XTEXTDOCUMENT_HPP_ +#include +#endif + +#ifndef _COM_SUN_STAR_DOCUMENT_XDOCUMENTINFOSUPPLIER_HPP_ +#include +#endif + +#ifndef _COM_SUN_STAR_DOCUMENT_XDOCUMENTINFO_HPP_ +#include +#endif + +#ifndef _COM_SUN_STAR_TEXT_XPARAGRAPHCURSOR_HPP_ +#include +#endif + #ifndef _COMPHELPER_PROCESSFACTORY_HXX_ #include #endif @@ -235,6 +259,8 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::rtl; using namespace ::cppu; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::text; //----------------------------------------------------------------------------- @@ -1675,10 +1701,80 @@ void FileDialogHelper_Impl::displayFolde } } +using namespace ::com::sun::star::document; +//whether a unicode char is premitted in filename +BOOL isPermitChar(sal_Unicode uChar) +{ + if ( (uChar > 0x0020 && uChar <= 0x002F) + || (uChar >= 0x003A && uChar <= 0x0040) + || (uChar >= 0x005B && uChar <= 0x0060) + || (uChar >= 0x007B && uChar <= 0x00FF) + || (uChar >= 0xFF01 && uChar <= 0xFF0F) + || (uChar >= 0xFF1A && uChar <= 0xFF20) + || (uChar >= 0xFF3B && uChar <= 0xFF40) + || (uChar >= 0xFF5B && uChar <= 0xFFE5) + || (uChar == 0x000D) + || (uChar == 0x000A) + ) + return FALSE; + else + return TRUE; +} + // ------------------------------------------------------------------------ void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile ) { maFileName = _rFile; + //if there is no default filename, then we set one + if( _rFile.getLength() ) + maFileName = _rFile; + else + { + //first set default filename to Untitle as defined in STR_NONAME + maFileName = String( SfxResId( STR_NONAME ) ); + + Reference < XDesktop > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY ); + Reference< XComponent > xComponent = xDesktop->getCurrentComponent(); + Reference< XTextDocument > xTextDocument( xComponent, UNO_QUERY ); + + ::rtl::OUString defaultName; + //if it is in writer module, then set default filename + if( xTextDocument.is() ) + { + //select the first 50 characters + Reference< XText > xText = xTextDocument->getText(); + Reference< XTextCursor > xTextCursor = xText->createTextCursor(); + xTextCursor->gotoStart( FALSE ); + xTextCursor->goRight( 50, TRUE ); + + defaultName = xTextCursor->getString(); + + //remove some special characters which are not permited to be in filename + UniString uTemp=UniString(defaultName.getStr()); + int i=0, j=0; + int uTempLen = uTemp.Len(); + //find the first permit char, omit forbidden char such as return + while ( i < uTempLen ) + { + if ( isPermitChar( uTemp.GetChar( i )) ) + break; + i++; + } + //if we encount a forbidden char, just stop + j = i; + while ( j < uTempLen ) + { + if ( !isPermitChar( uTemp.GetChar( j )) ) + break; + j++; + } + + defaultName=defaultName.copy(i, j-i); + + if( defaultName.getLength() ) + maFileName = defaultName; + } + } if ( mxFileDlg.is() ) { try @@ -2439,6 +2535,7 @@ void FileDialogHelper::SetDisplayDirecto NAMESPACE_VOS( OSecurity ) aSecurity; aSecurity.getHomeDir( sFolder ); } + mpImp->setFileName( ::rtl::OUString() ); mpImp->displayFolder( sFolder ); } }