Anonymous avatar Anonymous committed 3c2f0b2

CWS-TOOLING: integrate CWS filepicker02
2009-07-24 16:20:33 +0200 cd r274312 : #i95152# Use trimTrailingBlanks() correctly
2009-07-21 14:41:50 +0200 cd r274197 : #i103566# Makes fixes for MinGW port
2009-07-20 10:45:57 +0200 cd r274112 : #i95152# Return empty string when there are only blanks
2009-07-17 14:53:51 +0200 cd r274093 : #i95152# Old Windows file picker implementation now trims trailing blanks like the new Vista file picker
2009-07-17 09:45:38 +0200 cd r274080 : #i99759# Apply stability fixes from CWS filepicker01 to help QA
2009-07-17 09:00:26 +0200 cd r274078 : #i95336# Extend SfxApplication to reset last used directory
2009-07-17 08:59:10 +0200 cd r274077 : #i99759# Apply fix from filepicker01 to filepicker02 to help QA
2009-07-17 08:58:45 +0200 cd r274076 : #i99759# Apply fix from filepicker01 to filepicker02 to help QA
2009-07-16 16:08:17 +0200 cd r274059 : #103566# Use AddPlace as a fallback for directories which are not change the current folder
2009-07-16 11:54:26 +0200 cd r274038 : #i103566# Use provided folder and filename to decide to set the folder in the file dialog
2009-07-15 17:19:47 +0200 cd r274016 : #i95336# Set flag to true to force the file picker to use the default working path.
2009-07-14 14:49:48 +0200 cd r273977 : #i103346# Set work path flag to indicate file picker to use work path once
2009-07-14 14:47:49 +0200 cd r273976 : #i95336# New configuration entry for work path changes via Tools-Options
2009-07-14 14:46:19 +0200 cd r273975 : #i95336# Force file picker to use a changed work path once
2009-07-14 10:19:54 +0200 cd r273961 : #i103346# Add new advice for file picker usage. Especially for Windows Vista and higher.
2009-07-09 10:32:08 +0200 cd r273852 : #i97053# Use SetFolder()/AddPlace() for Open dialog, too.
2009-07-06 14:59:06 +0200 cd r273746 : #i103346# Destroy dialog instance within close handler to prevent problems with custom controls under Windows
2009-07-03 15:25:48 +0200 cd r273707 : #i94054# Add resource access to read localized labels for custom controls. Use SetControlLabel to set the localized label

Comments (0)

Files changed (11)

fpicker/source/win32/filepicker/VistaFilePicker.cxx

 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
 
 #include <cppuhelper/interfacecontainer.h>
+#include <comphelper/configurationhelper.hxx>
 #include <osl/diagnose.h>
 #include <osl/mutex.hxx>
 #include <osl/file.hxx>
 	throw (css::lang::IllegalArgumentException,
            css::uno::RuntimeException         )
 {
+    const ::rtl::OUString aPackage( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/"));
+    const ::rtl::OUString aRelPath( RTL_CONSTASCII_USTRINGPARAM("Path/Info"));
+    const ::rtl::OUString aKey( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged"));
+
+    css::uno::Any aValue = ::comphelper::ConfigurationHelper::readDirectKey(
+        m_xSMGR, aPackage, aRelPath, aKey, ::comphelper::ConfigurationHelper::E_READONLY);
+    
+    bool bChanged(false);
+    if (( aValue >>= bChanged ) && bChanged )
+    {
+        ::comphelper::ConfigurationHelper::writeDirectKey(
+            m_xSMGR, aPackage, aRelPath, aKey, css::uno::makeAny(false), ::comphelper::ConfigurationHelper::E_STANDARD);
+    }
+
     RequestRef rRequest(new Request());
     rRequest->setRequest (VistaFilePickerImpl::E_SET_DIRECTORY);
     rRequest->setArgument(PROP_DIRECTORY, sDirectory);
+    rRequest->setArgument(PROP_FORCE, bChanged);
 
     m_aAsyncExecute.triggerRequestThreadAware(rRequest, AsyncRequests::NON_BLOCKED);
 }

fpicker/source/win32/filepicker/VistaFilePickerImpl.cxx

 #include <comphelper/sequenceasvector.hxx>
 #include <osl/file.hxx>
 #include <osl/mutex.hxx>
+#include "..\misc\WinImplHelper.hxx"
 
  inline bool is_current_process_window(HWND hwnd)
 {
 static const ::sal_Int32 GROUP_CHECKBOXES      =   4;
 
 //-------------------------------------------------------------------------------
+static void setLabelToControl(CResourceProvider& rResourceProvider, TFileDialogCustomize iCustom, sal_uInt16 nControlId)
+{
+    ::rtl::OUString aLabel = rResourceProvider.getResString(nControlId);
+    aLabel = SOfficeToWindowsLabel(aLabel);
+    iCustom->SetControlLabel(nControlId, reinterpret_cast<LPCWSTR>(aLabel.getStr()) );
+}
+
+//-------------------------------------------------------------------------------
 void VistaFilePickerImpl::impl_sta_enableFeatures(::sal_Int32 nFeatures, ::sal_Int32 nTemplate)
 {
 	GUID aGUID = {};
 
 	iCustom->StartVisualGroup (GROUP_CHECKBOXES, L"");
 
+    sal_uInt16 nControlId(0);
     if ((nFeatures & FEATURE_AUTOEXTENSION) == FEATURE_AUTOEXTENSION)
-        iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, L"Auto Extension", true);
+    {
+        nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION;
+        iCustom->AddCheckButton (nControlId, L"Auto Extension", true);
+        setLabelToControl(m_ResProvider, iCustom, nControlId);
+    }
     
     if ((nFeatures & FEATURE_PASSWORD) == FEATURE_PASSWORD)
-        iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, L"Password", false);
+    {
+        nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_PASSWORD;
+        iCustom->AddCheckButton (nControlId, L"Password", false);
+        setLabelToControl(m_ResProvider, iCustom, nControlId);
+    }
     
     if ((nFeatures & FEATURE_READONLY) == FEATURE_READONLY)
-        iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY, L"Readonly", false);
+    {
+        nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_READONLY;
+        iCustom->AddCheckButton (nControlId, L"Readonly", false);
+        setLabelToControl(m_ResProvider, iCustom, nControlId);
+    }
     
     if ((nFeatures & FEATURE_FILTEROPTIONS) == FEATURE_FILTEROPTIONS)
-        iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS, L"Filter Options", false);
+    {
+        nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS;
+        iCustom->AddCheckButton (nControlId, L"Filter Options", false);
+        setLabelToControl(m_ResProvider, iCustom, nControlId);
+    }
     
     if ((nFeatures & FEATURE_LINK) == FEATURE_LINK)
-        iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK, L"Link", false);
+    {
+        nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_LINK;
+        iCustom->AddCheckButton (nControlId, L"Link", false);
+        setLabelToControl(m_ResProvider, iCustom, nControlId);
+    }
     
     if ((nFeatures & FEATURE_SELECTION) == FEATURE_SELECTION)
-        iCustom->AddCheckButton (css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION, L"Selection", false);
+    {
+        nControlId = css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_SELECTION;
+        iCustom->AddCheckButton (nControlId, L"Selection", false);
+        setLabelToControl(m_ResProvider, iCustom, nControlId);
+    }
 
     /* can be ignored ... new COM dialog supports preview native now  !
     if ((nFeatures & FEATURE_PREVIEW) == FEATURE_PREVIEW)
 void VistaFilePickerImpl::impl_sta_SetDirectory(const RequestRef& rRequest)
 {
     ::rtl::OUString sDirectory = rRequest->getArgumentOrDefault(PROP_DIRECTORY, ::rtl::OUString());
+    bool            bForce     = rRequest->getArgumentOrDefault(PROP_FORCE, false);
 	
-	if( !m_bInExecute )
+	if( !m_bInExecute)
 	{
 		// Vista stores last used folders for file dialogs
 		// so we don't want the application to change the folder
 		// Store the requested folder in the mean time and decide later
 		// what to do
 		m_sDirectory = sDirectory;
-		return;
 	}
 
     // SYNCHRONIZED->
     if ( FAILED(hResult) )
         return;
     
-    iDialog->SetFolder(pFolder);
+    if ( m_bInExecute || bForce )
+        iDialog->SetFolder(pFolder);
+    else
+    {
+        // Use set default folder as Microsoft recommends in the IFileDialog documentation.
+        iDialog->SetDefaultFolder(pFolder);
+    }
 }
 
 void VistaFilePickerImpl::impl_sta_GetDirectory(const RequestRef& rRequest)
     aLock.clear();    
     // <- SYNCHRONIZED
 
+	// we set the directory only if we have a save dialog and a filename
+	// for the other cases, the file dialog remembers its last location
+	// according to its client guid.
 	if( m_sDirectory.getLength()) 
 	{
-		// we set the directory only if we have a save dialog and a filename
-		// for the other cases, the file dialog remembers its last location
-		// according to its client guid.
-		if (iSave.is() && m_sFilename.getLength())
-		{
-			ComPtr< IShellItem > pFolder;
-			#ifdef __MINGW32__
-				HRESULT hResult = SHCreateItemFromParsingName ( reinterpret_cast<LPCTSTR>(m_sDirectory.getStr()), NULL, IID_IShellItem, (void**)(&pFolder) );
-			#else
-				HRESULT hResult = SHCreateItemFromParsingName ( m_sDirectory, NULL, IID_PPV_ARGS(&pFolder) );
-			#endif
-			if ( SUCCEEDED(hResult) )
-				iDialog->SetFolder(pFolder);
+		ComPtr< IShellItem > pFolder;
+		#ifdef __MINGW32__
+			HRESULT hResult = SHCreateItemFromParsingName ( reinterpret_cast<LPCTSTR>(m_sDirectory.getStr()), NULL, IID_IShellItem, (void**)(&pFolder) );
+		#else
+			HRESULT hResult = SHCreateItemFromParsingName ( m_sDirectory, NULL, IID_PPV_ARGS(&pFolder) );
+		#endif
+		if ( SUCCEEDED(hResult) )
+        {
+		    if (m_sFilename.getLength())
+            {
+                ::rtl::OUString aFileURL(m_sDirectory);
+                sal_Int32 nIndex = aFileURL.lastIndexOf('/');
+                if (nIndex != aFileURL.getLength()-1)
+                    aFileURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/"));
+                aFileURL += m_sFilename;
+                
+                TFileDialogCustomize iCustom = impl_getCustomizeInterface();
+                
+                BOOL bValue = FALSE;
+                HRESULT hResult = iCustom->GetCheckButtonState( css::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, &bValue);
+                if ( bValue )
+                {
+                    ::rtl::OUString aExt;
+                    UINT nFileType;
+                    hResult = iDialog->GetFileTypeIndex(&nFileType);
+		            if ( SUCCEEDED(hResult) )
+                    {
+                        ::std::vector< COMDLG_FILTERSPEC > lFilters = lcl_buildFilterList(m_lFilters);
+		                LPCWSTR lpFilterExt = lFilters[nFileType].pszSpec;
+
+		                lpFilterExt = wcsrchr( lpFilterExt, '.' );
+		                if ( lpFilterExt )
+                            aFileURL += reinterpret_cast<const sal_Unicode*>(lpFilterExt);
+                    }
+                }
+
+                // Check existence of file. Set folder only for this special case
+                ::rtl::OUString aSystemPath;
+                osl_getSystemPathFromFileURL( aFileURL.pData, &aSystemPath.pData );
+
+			    WIN32_FIND_DATA	aFindFileData;
+                HANDLE	hFind = FindFirstFile( reinterpret_cast<LPCWSTR>(aSystemPath.getStr()), &aFindFileData );
+                if (hFind != INVALID_HANDLE_VALUE)
+                    iDialog->SetFolder(pFolder);
+                else
+                    hResult = iDialog->AddPlace(pFolder, FDAP_TOP);
+
+                FindClose( hFind );
+            }
+			else
+				hResult = iDialog->AddPlace(pFolder, FDAP_TOP);
 		}
 	}
 	
 }
 
 //-------------------------------------------------------------------------------
-void VistaFilePickerImpl::impl_sta_GetControlLabel(const RequestRef& rRequest)
+void VistaFilePickerImpl::impl_sta_GetControlLabel(const RequestRef& /*rRequest*/)
 {
 }
 

fpicker/source/win32/filepicker/VistaFilePickerImpl.hxx

 #include "FilterContainer.hxx"
 #include "VistaFilePickerEventHandler.hxx"
 #include "IVistaFilePickerInternalNotify.hxx"
+#include "..\misc\resourceprovider.hxx"
 
 #include <com/sun/star/uno/Sequence.hxx>
 
 static const ::rtl::OUString PROP_TEMPLATE_DESCR	  = ::rtl::OUString::createFromAscii("templatedescription"); // [sal_Int32]
 static const ::rtl::OUString PROP_FILTER_TITLE        = ::rtl::OUString::createFromAscii("filter_title"       ); // [OUString]
 static const ::rtl::OUString PROP_FILTER_VALUE        = ::rtl::OUString::createFromAscii("filter_value"       ); // [OUString]
+static const ::rtl::OUString PROP_FORCE               = ::rtl::OUString::createFromAscii("force"              ); // [sal_Bool]
 
 static const ::rtl::OUString PROP_CONTROL_ID          = ::rtl::OUString::createFromAscii("control_id"         ); // [sal_Int16]
 static const ::rtl::OUString PROP_CONTROL_ACTION      = ::rtl::OUString::createFromAscii("control_action"     ); // [sal_Int16]
 
 		//
 		::rtl::OUString m_sFilename;
+
+        // Resource provider
+        CResourceProvider m_ResProvider;      
 };
 
 } // namespace vista

fpicker/source/win32/filepicker/filepickerstate.cxx

     return path;   
 }
 
+//-----------------------------------------------------------------------------------------
+// 
+//-----------------------------------------------------------------------------------------
+static ::rtl::OUString trimTrailingSpaces(const ::rtl::OUString& rString)
+{
+    rtl::OUString aResult(rString);
+    
+    sal_Int32 nIndex = rString.lastIndexOf(' ');
+    if (nIndex == rString.getLength()-1)
+    {
+        while (nIndex >= 0 && rString[nIndex] == ' ')
+            nIndex--;
+        if (nIndex >= 0)
+            aResult = rString.copy(0,nIndex+1);
+        else
+            aResult = ::rtl::OUString();
+    }
+    return aResult;
+}
+        
 Sequence< OUString > SAL_CALL CNonExecuteFilePickerState::getFiles( CFileOpenDialog* aFileOpenDialog )
 {
     OSL_PRECOND( aFileOpenDialog, "invalid parameter" );
 
         for ( sal_Int32 i = 0; i < lenFileList; i++ )
         {	        
-            rc = ::osl::FileBase::getFileURLFromSystemPath( 
-                aFilePathList[i], aFilePathURL );
+			aFilePath = trimTrailingSpaces(aFilePathList[i]);
+			rc = ::osl::FileBase::getFileURLFromSystemPath( 
+                aFilePath, aFilePathURL );
                 
             // we do return all or nothing, that means
             // in case of failures we destroy the sequence

offapi/com/sun/star/ui/dialogs/FilePicker.idl

 //=============================================================================
 /** A FilePicker. 
 
+    It is <strong>NOT</strong> recommended to cache a reference to a file 
+    picker instance. Due to restrictions by the underlying system there can 
+    be specific limitations possible. To overcome these problems it'
+    s recommended to create a new instance on demand.
+
 	@see XFilePicker
 */
 

officecfg/registry/schema/org/openoffice/Office/Common.xcs

 				<author>MBA</author>
 				<desc>Contains the current and default path settings used by the Office.</desc>
 			</info>
+      <group oor:name="Info">
+        <info>
+          <author>CD</author>
+          <desc>Contains various properties information purpose only.</desc>
+        </info>
+        <prop oor:name="WorkPathChanged" oor:type="xs:boolean">
+          <info>
+            <desc>A flag which is set by the tools options dialog whenever a user changed the work path.</desc>
+          </info>
+          <value>true</value>
+        </prop>
+      </group>
 			<group oor:name="Current">
 				<info>
 					<author>MBA</author>

sfx2/inc/sfx2/app.hxx

                                                   BOOL bActivate,
                                                   BOOL bForbidVisible = FALSE,
                                                   const String* pPostStr = 0);
+    void                        ResetLastDir();
 
 //#if 0 // _SOLAR__PRIVATE
 	SAL_DLLPRIVATE static SfxApplication* Is_Impl() { return pApp;}

sfx2/inc/sfx2/filedlghelper.hxx

     
     /** Provides the selected files with full path information */
     ::com::sun::star::uno::Sequence< ::rtl::OUString > GetSelectedFiles() const;
+    
+    /** Provides the selected files with full path information */
+    ::com::sun::star::uno::Sequence< ::rtl::OUString > GetSelectedFiles() const;
 
     void                     AddFilter( const String& rFilterName, const String& rExtension );
     void                     SetCurrentFilter( const String& rFilter );

sfx2/source/appl/app.cxx

 
 //--------------------------------------------------------------------
 
+void SfxApplication::ResetLastDir()
+{
+    String aEmpty;
+    pAppData_Impl->aLastDir = aEmpty;
+}
+
+//--------------------------------------------------------------------
+
 SfxDispatcher* SfxApplication::GetDispatcher_Impl()
 {
     return pAppData_Impl->pViewFrame? pAppData_Impl->pViewFrame->GetDispatcher(): pAppData_Impl->pAppDispat;

sfx2/source/appl/shutdownicon.cxx

         }
     }
 
+#ifdef WNT
+    // #103346 Destroy dialog to prevent problems with custom controls
+    delete pThis->m_pFileDlg;
+    pThis->m_pFileDlg = NULL;
+#endif
+
     LeaveModalMode();
     return 0;
 }

svx/source/cui/optpath.cxx

 #include <tools/shl.hxx>
 #include <vcl/msgbox.hxx>
 #include <sfx2/filedlghelper.hxx>
+#include <sfx2/app.hxx>
 #include <svtools/pickerhelper.hxx>
 #include <svtools/aeitem.hxx>
 #include <svtools/svtabbx.hxx>
 #include <unotools/localfilehelper.hxx>
 #include <svtools/pathoptions.hxx>
 #include <svtools/moduleoptions.hxx>
+#include <svtools/viewoptions.hxx>
 
 #define _SVX_OPTPATH_CXX
 
 #include <svx/dialogs.hrc>
 #include "helpid.hrc"
 #include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
 #include <com/sun/star/uno/Exception.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #define POSTFIX_WRITABLE    String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_writable" ) )
 #define POSTFIX_READONLY    String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_readonly" ) )
 #define VAR_ONE             String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "%1" ) )
+#define IODLG_CONFIGNAME	String(DEFINE_CONST_UNICODE("FilePicker_Save"))
 
 // struct OptPath_Impl ---------------------------------------------------
 
         pPathImpl = (PathUserData_Impl*)pPathBox->GetEntry(nPos)->GetUserData();
         pPathImpl->eState = SFX_ITEM_SET;
         pPathImpl->sWritablePath = sNewPathStr;
+        if ( SvtPathOptions::PATH_WORK == pPathImpl->nRealId )
+        {
+            // Remove view options entry so the new work path
+            // will be used for the next open dialog.
+            SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
+            aDlgOpt.Delete();
+		    // Reset also last used dir in the sfx application instance
+            SfxApplication *pSfxApp = SFX_APP();
+		    pSfxApp->ResetLastDir();
+            
+    		// Set configuration flag to notify file picker that it's necessary
+            // to take over the path provided.
+            Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
+            ::comphelper::ConfigurationHelper::writeDirectKey(xFactory,
+                ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Common/")),
+                ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Path/Info")),
+                ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WorkPathChanged")),
+                ::com::sun::star::uno::makeAny(true),
+                ::comphelper::ConfigurationHelper::E_STANDARD);
+        }
     }
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.