diff options
author | Caolán McNamara <caolanm@redhat.com> | 2010-10-07 12:59:11 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2010-10-07 12:59:11 +0100 |
commit | 704e8f6e5210cfe382e809332828f0cbda94f3b2 (patch) | |
tree | 244a0e7b9bc9cb8210c19fe4711d1972d174ea8f /fpicker/source/unx | |
parent | 311325ee3f1e519ff09e819718719edc7d4a110e (diff) |
#i113141# show all appropiate formats by default on save as
Diffstat (limited to 'fpicker/source/unx')
-rw-r--r-- | fpicker/source/unx/gnome/SalGtkFilePicker.cxx | 94 | ||||
-rw-r--r-- | fpicker/source/unx/gnome/SalGtkFilePicker.hxx | 6 | ||||
-rw-r--r-- | fpicker/source/unx/gnome/resourceprovider.cxx | 3 | ||||
-rw-r--r-- | fpicker/source/unx/gnome/resourceprovider.hxx | 1 |
4 files changed, 75 insertions, 29 deletions
diff --git a/fpicker/source/unx/gnome/SalGtkFilePicker.cxx b/fpicker/source/unx/gnome/SalGtkFilePicker.cxx index 7983a932e290..0604bee8aec5 100644 --- a/fpicker/source/unx/gnome/SalGtkFilePicker.cxx +++ b/fpicker/source/unx/gnome/SalGtkFilePicker.cxx @@ -52,6 +52,7 @@ #include <iostream> #include <algorithm> +#include <set> #include "resourceprovider.hxx" #include <tools/rc.hxx> @@ -179,6 +180,7 @@ SalGtkFilePicker::SalGtkFilePicker( const uno::Reference<lang::XMultiServiceFact mbPreviewState( sal_False ), mHID_Preview( 0 ), m_pPreview( NULL ), + m_pPseudoFilter( NULL ), m_PreviewImageWidth( 256 ), m_PreviewImageHeight( 256 ) { @@ -690,7 +692,7 @@ void SalGtkFilePicker::ensureFilterList( const ::rtl::OUString& _rInitialCurrent m_pFilterList = new FilterList; // set the first filter to the current filter - if( ( !m_aCurrentFilter ) || ( !m_aCurrentFilter.getLength() ) ) + if ( !m_aCurrentFilter.getLength() ) m_aCurrentFilter = _rInitialCurrentFilter; } } @@ -713,7 +715,6 @@ void SAL_CALL SalGtkFilePicker::appendFilter( const rtl::OUString& aTitle, const // append the filter m_pFilterList->insert( m_pFilterList->end(), FilterEntry( aTitle, aFilter ) ); - // implAddFilter( aTitle, aFilter ); } //----------------------------------------------------------------------------------------- @@ -780,7 +781,10 @@ void SalGtkFilePicker::UpdateFilterfromUI() } else if( GtkFileFilter *filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(m_pDialog))) { - updateCurrentFilterFromName(gtk_file_filter_get_name( filter )); + if (m_pPseudoFilter != filter) + updateCurrentFilterFromName(gtk_file_filter_get_name( filter )); + else + updateCurrentFilterFromName(OUStringToOString( m_aInitialFilter, RTL_TEXTENCODING_UTF8 ).getStr()); } } @@ -948,9 +952,14 @@ uno::Sequence<rtl::OUString> SAL_CALL SalGtkFilePicker::getSelectedFiles() throw } } - const gchar* filtername = - gtk_file_filter_get_name( gtk_file_chooser_get_filter( GTK_FILE_CHOOSER( m_pDialog ) ) ); - sFilterName = OUString( filtername, strlen( filtername ), RTL_TEXTENCODING_UTF8 ); + GtkFileFilter *filter = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(m_pDialog)); + if (m_pPseudoFilter != filter) + { + const gchar* filtername = gtk_file_filter_get_name( filter ); + sFilterName = OUString( filtername, strlen( filtername ), RTL_TEXTENCODING_UTF8 ); + } + else + sFilterName = m_aInitialFilter; } OSL_TRACE( "2: current filter is %s\n", @@ -1915,7 +1924,7 @@ case_insensitive_filter (const GtkFileFilterInfo *filter_info, gpointer data) } } -int SalGtkFilePicker::implAddFilter( const OUString& rFilter, const OUString& rType ) +GtkFileFilter* SalGtkFilePicker::implAddFilter( const OUString& rFilter, const OUString& rType ) { GdkThreadLock aLock; @@ -1966,7 +1975,6 @@ int SalGtkFilePicker::implAddFilter( const OUString& rFilter, const OUString& rT gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( m_pDialog ), filter ); - int nAdded = 0; if (!bAllGlob) { GtkTreeIter iter; @@ -1977,30 +1985,67 @@ int SalGtkFilePicker::implAddFilter( const OUString& rFilter, const OUString& rT 2, aFilterName.getStr(), 3, OUStringToOString(rType, RTL_TEXTENCODING_UTF8).getStr(), -1); - nAdded = 1; } - return nAdded; + return filter; } -int SalGtkFilePicker::implAddFilterGroup( const OUString& /*_rFilter*/, const Sequence< StringPair >& _rFilters ) +void SalGtkFilePicker::implAddFilterGroup( const OUString& /*_rFilter*/, const Sequence< StringPair >& _rFilters ) { // Gtk+ has no filter group concept I think so ... // implAddFilter( _rFilter, String() ); - int nAdded = 0; const StringPair* pSubFilters = _rFilters.getConstArray(); const StringPair* pSubFiltersEnd = pSubFilters + _rFilters.getLength(); for( ; pSubFilters != pSubFiltersEnd; ++pSubFilters ) - nAdded += implAddFilter( pSubFilters->First, pSubFilters->Second ); - return nAdded; + implAddFilter( pSubFilters->First, pSubFilters->Second ); } void SalGtkFilePicker::SetFilters() { - OSL_TRACE( "start setting filters\n"); - GdkThreadLock aLock; - int nAdded = 0; + if (!m_aInitialFilter.getLength()) + m_aInitialFilter = m_aCurrentFilter; + + rtl::OUString sPseudoFilter; + if( GTK_FILE_CHOOSER_ACTION_SAVE == gtk_file_chooser_get_action( GTK_FILE_CHOOSER( m_pDialog ) ) ) + { + std::set<OUString> aAllFormats; + if( m_pFilterList && !m_pFilterList->empty() ) + { + for ( FilterList::iterator aListIter = m_pFilterList->begin(); + aListIter != m_pFilterList->end(); + ++aListIter + ) + { + if( aListIter->hasSubFilters() ) + { // it's a filter group + UnoFilterList aSubFilters; + aListIter->getSubFilters( aSubFilters ); + const StringPair* pSubFilters = aSubFilters.getConstArray(); + const StringPair* pSubFiltersEnd = pSubFilters + aSubFilters.getLength(); + for( ; pSubFilters != pSubFiltersEnd; ++pSubFilters ) + aAllFormats.insert(pSubFilters->Second); + } + else + aAllFormats.insert(aListIter->getFilter()); + } + } + if (aAllFormats.size() > 1) + { + rtl::OUString sAllFilter; + std::set<OUString>::const_iterator aEnd = aAllFormats.end(); + for (std::set<OUString>::const_iterator aIter = aAllFormats.begin(); aIter != aEnd; ++aIter) + { + if (sAllFilter.getLength()) + sAllFilter += OUString(sal_Unicode(';')); + sAllFilter += *aIter; + } + CResourceProvider aResProvider; + sPseudoFilter = aResProvider.getResString(FILE_PICKER_ALLFORMATS); + m_pPseudoFilter = implAddFilter( sPseudoFilter, sAllFilter ); + } + } + if( m_pFilterList && !m_pFilterList->empty() ) { for ( FilterList::iterator aListIter = m_pFilterList->begin(); @@ -2014,30 +2059,27 @@ void SalGtkFilePicker::SetFilters() UnoFilterList aSubFilters; aListIter->getSubFilters( aSubFilters ); - nAdded += implAddFilterGroup( aListIter->getTitle(), aSubFilters ); + implAddFilterGroup( aListIter->getTitle(), aSubFilters ); } else { // it's a single filter - nAdded += implAddFilter( aListIter->getTitle(), aListIter->getFilter() ); + implAddFilter( aListIter->getTitle(), aListIter->getFilter() ); } } } - if (nAdded) + if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_pFilterStore), NULL)) //If m_pFilterStore is not empty gtk_widget_show( m_pFilterExpander ); else gtk_widget_hide( m_pFilterExpander ); // set the default filter - if( m_aCurrentFilter && (m_aCurrentFilter.getLength() > 0) ) - { - OSL_TRACE( "Setting current filter to %s\n", - OUStringToOString( m_aCurrentFilter, RTL_TEXTENCODING_UTF8 ).getStr() ); - + if (sPseudoFilter.getLength()) + SetCurFilter( sPseudoFilter ); + else if(m_aCurrentFilter.getLength()) SetCurFilter( m_aCurrentFilter ); - } OSL_TRACE( "end setting filters\n"); } diff --git a/fpicker/source/unx/gnome/SalGtkFilePicker.hxx b/fpicker/source/unx/gnome/SalGtkFilePicker.hxx index 61c321cd6702..bc4ef9130f9e 100644 --- a/fpicker/source/unx/gnome/SalGtkFilePicker.hxx +++ b/fpicker/source/unx/gnome/SalGtkFilePicker.hxx @@ -310,11 +310,13 @@ class SalGtkFilePicker : gulong mnHID_SelectionChange; ::rtl::OUString m_aCurrentFilter; + ::rtl::OUString m_aInitialFilter; bool bVersionWidthUnset; sal_Bool mbPreviewState; gulong mHID_Preview; GtkWidget* m_pPreview; + GtkFileFilter* m_pPseudoFilter; sal_Int32 m_PreviewImageWidth; sal_Int32 m_PreviewImageHeight; @@ -325,8 +327,8 @@ class SalGtkFilePicker : void UpdateFilterfromUI(); void implChangeType( GtkTreeSelection *selection ); - int implAddFilter( const OUString& rFilter, const OUString& rType); - int implAddFilterGroup( const OUString& rFilter, + GtkFileFilter * implAddFilter( const OUString& rFilter, const OUString& rType ); + void implAddFilterGroup( const OUString& rFilter, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair>& _rFilters ); void updateCurrentFilterFromName(const gchar* filtername); void unselect_type(); diff --git a/fpicker/source/unx/gnome/resourceprovider.cxx b/fpicker/source/unx/gnome/resourceprovider.cxx index 8df810060ee5..22ef7a4fdc58 100644 --- a/fpicker/source/unx/gnome/resourceprovider.cxx +++ b/fpicker/source/unx/gnome/resourceprovider.cxx @@ -82,7 +82,8 @@ _Entry CtrlIdToResIdTable[] = { { CHECKBOX_SELECTION, STR_SVT_FILEPICKER_SELECTION }, { FOLDERPICKER_TITLE, STR_SVT_FOLDERPICKER_DEFAULT_TITLE }, { FOLDER_PICKER_DEF_DESCRIPTION, STR_SVT_FOLDERPICKER_DEFAULT_DESCRIPTION }, - { FILE_PICKER_OVERWRITE, STR_SVT_ALREADYEXISTOVERWRITE } + { FILE_PICKER_OVERWRITE, STR_SVT_ALREADYEXISTOVERWRITE }, + { FILE_PICKER_ALLFORMATS, STR_SVT_ALLFORMATS } }; _Entry OtherCtrlIdToResIdTable[] = { diff --git a/fpicker/source/unx/gnome/resourceprovider.hxx b/fpicker/source/unx/gnome/resourceprovider.hxx index f3ae0a495718..af9ac63b5a38 100644 --- a/fpicker/source/unx/gnome/resourceprovider.hxx +++ b/fpicker/source/unx/gnome/resourceprovider.hxx @@ -43,6 +43,7 @@ #define FILE_PICKER_TITLE_SAVE 503 #define FILE_PICKER_FILE_TYPE 504 #define FILE_PICKER_OVERWRITE 505 +#define FILE_PICKER_ALLFORMATS 506 //------------------------------------------------------------------------ // deklarations |