diff options
author | Malte Timmermann [mt] <malte.timmermann@sun.com> | 2010-07-02 13:17:39 +0200 |
---|---|---|
committer | Malte Timmermann [mt] <malte.timmermann@sun.com> | 2010-07-02 13:17:39 +0200 |
commit | 996f5c6b48988025295ab6e48d3256892a84adf6 (patch) | |
tree | 720e85ca1e2f9daa542c02989066e6f5c1b6e6b7 /svtools/source/contnr | |
parent | 3ca307cc08b0039a33ccb879779d026e60957216 (diff) | |
parent | be588658ea127a6a05390435126f1d739a477b58 (diff) |
codecleanup02: merge with DEV300_m84
Diffstat (limited to 'svtools/source/contnr')
-rw-r--r-- | svtools/source/contnr/fileview.cxx | 231 |
1 files changed, 172 insertions, 59 deletions
diff --git a/svtools/source/contnr/fileview.cxx b/svtools/source/contnr/fileview.cxx index 843de83f7710..af19379d8b8f 100644 --- a/svtools/source/contnr/fileview.cxx +++ b/svtools/source/contnr/fileview.cxx @@ -54,6 +54,9 @@ #include <vcl/waitobj.hxx> #include <com/sun/star/io/XPersist.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/ucb/XCommandInfo.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> #include <algorithm> #include <memory> @@ -100,7 +103,7 @@ using ::rtl::OUString; DECLARE_LIST( StringList_Impl, OUString* ) -#define ROW_HEIGHT 17 // the height of a row has to be a little higher than the bitmap +#define ROW_HEIGHT 17 // the height of a row has to be a little higher than the bitmap #define QUICK_SEARCH_TIMEOUT 1500 // time in mSec before the quicksearch string will be reseted namespace @@ -210,6 +213,7 @@ private: sal_Bool mbResizeDisabled : 1; sal_Bool mbAutoResize : 1; sal_Bool mbEnableDelete : 1; + sal_Bool mbEnableRename : 1; void DeleteEntries(); void DoQuickSearch( const xub_Unicode& rChar ); @@ -232,6 +236,7 @@ public: void EnableAutoResize() { mbAutoResize = sal_True; } void EnableDelete( sal_Bool bEnable ) { mbEnableDelete = bEnable; } + void EnableRename( sal_Bool bEnable ) { mbEnableRename = bEnable; } sal_Bool IsDeleteOrContextMenuEnabled() { return mbEnableDelete || IsContextMenuHandlingEnabled(); } Reference< XCommandEnvironment > GetCommandEnvironment() const { return mxCmdEnv; } @@ -299,11 +304,11 @@ inline const OUString& HashedEntry::GetName() const class HashedEntryList : protected List {// provides a list of _unique_ Entries protected: - inline HashedEntry* First(); - inline HashedEntry* Next(); - inline void Append( HashedEntry* pNewEntry ); + inline HashedEntry* First(); + inline HashedEntry* Next(); + inline void Append( HashedEntry* pNewEntry ); public: - virtual ~HashedEntryList(); + virtual ~HashedEntryList(); const HashedEntry* Find( const OUString& rNameToSearchFor ); const HashedEntry* Find( const HashedEntry& rToSearchFor ); @@ -338,7 +343,7 @@ HashedEntryList::~HashedEntryList() const HashedEntry* HashedEntryList::Find( const OUString& rRefName ) { // simple linear search, which should be fast enough for this purpose - HashedEntry aRef( rRefName ); + HashedEntry aRef( rRefName ); HashedEntry* pIter = First(); while( pIter && *pIter != aRef ) pIter = Next(); @@ -419,12 +424,12 @@ class NameTranslationList : protected HashedEntryList { // contains a list of substitutes of strings for a given folder (as URL) // explanation of the circumstances see in remarks for Init(); protected: - INetURLObject maTransFile; // URL of file with translation entries - HashedEntry maHashedURL; // for future purposes when dealing with a set of cached - // NameTranslationLists + INetURLObject maTransFile; // URL of file with translation entries + HashedEntry maHashedURL; // for future purposes when dealing with a set of cached + // NameTranslationLists private: const String maTransFileName; - void Init(); // reads the translation file and fills the (internal) list + void Init(); // reads the translation file and fills the (internal) list public: NameTranslationList( const INetURLObject& rBaseURL ); @@ -436,12 +441,12 @@ public: using List::operator!=; inline sal_Bool operator !=( const HashedEntry& rRef ) const; - const OUString* Translate( const OUString& rName ) const; + const OUString* Translate( const OUString& rName ) const; // returns NULL, if rName can't be found - inline void Update(); // clears list and init + inline void Update(); // clears list and init - inline const String& GetTransTableFileName() const; + inline const String& GetTransTableFileName() const; // returns the name for the file, which contains the translation strings }; @@ -463,7 +468,7 @@ void NameTranslationList::Init() if( aTestContent.isDocument() ) {// ... also tests the existence of maTransFile by throwing an Exception - const sal_Char* pSection = "TRANSLATIONNAMES"; + const sal_Char* pSection = "TRANSLATIONNAMES"; String aFsysName( maTransFile.getFSysPath( INetURLObject::FSYS_DETECT ) ); Config aConfig( aFsysName ); @@ -475,7 +480,7 @@ void NameTranslationList::Init() Insert( new NameTranslationEntry( aConfig.GetKeyName( nCnt ), aConfig.ReadKey( nCnt ) ) ); } } - catch( Exception& ) {} + catch( Exception const & ) {} } NameTranslationList::NameTranslationList( const INetURLObject& rBaseURL ): @@ -527,7 +532,7 @@ public: // IContentTitleTranslation virtual sal_Bool GetTranslation( const OUString& rOriginalName, OUString& rTranslatedName ) const; - void UpdateTranslationTable(); // reads the translation file again + void UpdateTranslationTable(); // reads the translation file again void SetActualFolder( const INetURLObject& rActualFolder ); const String* GetTransTableFileName() const; @@ -600,7 +605,7 @@ public: void OpenFolder_Impl(); // #83004# ------- - void ReplaceTabWithString( OUString& aValue ); + void ReplaceTabWithString( OUString& aValue ); void CreateDisplayText_Impl(); void CreateVector_Impl( const Sequence < OUString > &rList ); void SortFolderContent_Impl(); @@ -661,11 +666,13 @@ inline void SvtFileView_Impl::EnableDelete( sal_Bool bEnable ) inline sal_Bool SvtFileView_Impl::EnableNameReplacing( sal_Bool bEnable ) { + mpView->EnableRename( bEnable ); + sal_Bool bRet; if( mpView->IsDeleteOrContextMenuEnabled() ) { DBG_ASSERT( !mbReplaceNames, "SvtFileView_Impl::EnableNameReplacing(): state should be not possible!" ); - bRet = !bEnable; // only for enabling this is an unsuccessful result + bRet = !bEnable; // only for enabling this is an unsuccessful result } else { @@ -744,7 +751,8 @@ ViewTabListBox_Impl::ViewTabListBox_Impl( Window* pParentWin, mnSearchIndex ( 0 ), mbResizeDisabled ( sal_False ), mbAutoResize ( sal_False ), - mbEnableDelete ( sal_True ) + mbEnableDelete ( sal_True ), + mbEnableRename ( sal_True ) { Size aBoxSize = pParentWin->GetSizePixel(); @@ -824,7 +832,7 @@ void ViewTabListBox_Impl::Resize() mbResizeDisabled = sal_True; Point aPos = GetPosPixel(); SetPosSizePixel( Point( 0, aBarSize.Height() ), - Size( aBoxSize.Width(), aBoxSize.Height() - aBarSize.Height() ) ); + Size( aBoxSize.Width(), aBoxSize.Height() - aBarSize.Height() ) ); mbResizeDisabled = sal_False; } } @@ -870,20 +878,90 @@ void ViewTabListBox_Impl::KeyInput( const KeyEvent& rKEvt ) PopupMenu* ViewTabListBox_Impl::CreateContextMenu( void ) { - PopupMenu* pRet; - sal_Int32 nSelectedEntries = GetSelectionCount(); + bool bEnableDelete = mbEnableDelete; + bool bEnableRename = mbEnableRename; + + if ( bEnableDelete || bEnableRename ) + { + sal_Int32 nSelectedEntries = GetSelectionCount(); + bEnableDelete &= nSelectedEntries > 0; + bEnableRename &= nSelectedEntries == 1; + } + + if ( bEnableDelete || bEnableRename ) + { + SvLBoxEntry* pEntry = FirstSelected(); + while ( pEntry ) + { + ::ucbhelper::Content aCnt; + try + { + OUString aURL( static_cast< SvtContentEntry * >( + pEntry->GetUserData() )->maURL ); + aCnt = ::ucbhelper::Content( aURL, mxCmdEnv ); + } + catch( Exception const & ) + { + bEnableDelete = bEnableRename = false; + } + + if ( bEnableDelete ) + { + try + { + Reference< XCommandInfo > aCommands = aCnt.getCommands(); + if ( aCommands.is() ) + bEnableDelete + = aCommands->hasCommandByName( + OUString::createFromAscii( "delete" ) ); + else + bEnableDelete = false; + } + catch( Exception const & ) + { + bEnableDelete = false; + } + } + + if ( bEnableRename ) + { + try + { + Reference< XPropertySetInfo > aProps = aCnt.getProperties(); + if ( aProps.is() ) + { + Property aProp + = aProps->getPropertyByName( + OUString::createFromAscii( "Title" ) ); + bEnableRename + = !( aProp.Attributes & PropertyAttribute::READONLY ); + } + else + bEnableRename = false; + } + catch( Exception const & ) + { + bEnableRename = false; + } + } + + pEntry = ( bEnableDelete || bEnableRename ) + ? NextSelected( pEntry ) + : 0; + } + } - if ( nSelectedEntries ) + if ( bEnableDelete || bEnableRename ) { - pRet = new PopupMenu( SvtResId( RID_FILEVIEW_CONTEXTMENU ) ); - pRet->EnableItem( MID_FILEVIEW_DELETE, 0 < nSelectedEntries ); - pRet->EnableItem( MID_FILEVIEW_RENAME, 1 == nSelectedEntries ); + PopupMenu * pRet + = new PopupMenu( SvtResId( RID_FILEVIEW_CONTEXTMENU ) ); + pRet->EnableItem( MID_FILEVIEW_DELETE, bEnableDelete ); + pRet->EnableItem( MID_FILEVIEW_RENAME, bEnableRename ); pRet->RemoveDisabledEntries( sal_True, sal_True ); + return pRet; } - else - pRet = NULL; - return pRet; + return NULL; } // ----------------------------------------------------------------------- @@ -928,12 +1006,31 @@ void ViewTabListBox_Impl::DeleteEntries() aURL = ( (SvtContentEntry*)pCurEntry->GetUserData() )->maURL; if ( !aURL.Len() ) - return; + continue; + + bool canDelete = true; + try + { + ::ucbhelper::Content aCnt( aURL, mxCmdEnv ); + Reference< XCommandInfo > aCommands = aCnt.getCommands(); + if ( aCommands.is() ) + canDelete + = aCommands->hasCommandByName( + OUString::createFromAscii( "delete" ) ); + else + canDelete = false; + } + catch( Exception const & ) + { + canDelete = false; + } - INetURLObject aObj( aURL ); + if (!canDelete) + continue; // process next entry if ( eResult != svtools::QUERYDELETE_ALL ) { + INetURLObject aObj( aURL ); svtools::QueryDeleteDlg_Impl aDlg( NULL, aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) ); if ( sDialogPosition.Len() ) aDlg.SetWindowState( sDialogPosition ); @@ -979,22 +1076,44 @@ BOOL ViewTabListBox_Impl::EditedEntry( SvLBoxEntry* pEntry, try { + OUString aPropName = OUString::createFromAscii( "Title" ); + bool canRename = true; ::ucbhelper::Content aContent( aURL, mxCmdEnv ); - OUString aPropName = OUString::createFromAscii( "Title" ); - Any aValue; - aValue <<= OUString( rNewText ); - aContent.setPropertyValue( aPropName, aValue ); - mpParent->EntryRenamed( aURL, rNewText ); + try + { + Reference< XPropertySetInfo > aProps = aContent.getProperties(); + if ( aProps.is() ) + { + Property aProp = aProps->getPropertyByName( aPropName ); + canRename = !( aProp.Attributes & PropertyAttribute::READONLY ); + } + else + { + canRename = false; + } + } + catch ( Exception const & ) + { + canRename = false; + } + + if ( canRename ) + { + Any aValue; + aValue <<= OUString( rNewText ); + aContent.setPropertyValue( aPropName, aValue ); + mpParent->EntryRenamed( aURL, rNewText ); - pData->maURL = aURL; - pEntry->SetUserData( pData ); + pData->maURL = aURL; + pEntry->SetUserData( pData ); - bRet = TRUE; + bRet = TRUE; + } + } + catch( Exception const & ) + { } - catch( ::com::sun::star::ucb::ContentCreationException ) {} - catch( ::com::sun::star::ucb::CommandAbortedException ) {} - catch( ::com::sun::star::uno::Exception ) {} return bRet; } @@ -1095,12 +1214,12 @@ sal_Bool ViewTabListBox_Impl::Kill( const OUString& rContent ) ::ucbhelper::Content aCnt( rContent, mxCmdEnv ); aCnt.executeCommand( OUString::createFromAscii( "delete" ), makeAny( sal_Bool( sal_True ) ) ); } - catch( ::com::sun::star::ucb::CommandAbortedException& ) + catch( ::com::sun::star::ucb::CommandAbortedException const & ) { DBG_WARNING( "CommandAbortedException" ); bRet = sal_False; } - catch( ::com::sun::star::uno::Exception& ) + catch( Exception const & ) { DBG_WARNING( "Any other exception" ); bRet = sal_False; @@ -1314,7 +1433,7 @@ sal_Bool SvtFileView::GetParentURL( String& rParentURL ) const } } } - catch( ::com::sun::star::uno::Exception ) + catch( Exception const & ) { // perhaps an unkown url protocol (e.g. "private:newdoc") } @@ -1366,7 +1485,7 @@ sal_Bool SvtFileView::Initialize( const ::com::sun::star::uno::Reference< ::com: mpImp->FilterFolderContent_Impl( rFilter ); - mpImp->SortFolderContent_Impl(); // possibly not necessary!!!!!!!!!! + mpImp->SortFolderContent_Impl(); // possibly not necessary!!!!!!!!!! mpImp->CreateDisplayText_Impl(); mpImp->OpenFolder_Impl(); @@ -1999,7 +2118,7 @@ void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter ) { // normalize the content title (we always match case-insensitive) // 91872 - 11.09.2001 - frank.schoenheit@sun.com - sCompareString = (*aContentLoop)->GetFileName(); // filter works on file name, not on title! + sCompareString = (*aContentLoop)->GetFileName(); // filter works on file name, not on title! sal_Bool bDelete; if( bHideTransFile && sCompareString == sHideEntry ) @@ -2643,12 +2762,12 @@ QueryDeleteDlg_Impl::QueryDeleteDlg_Impl ModalDialog( pParent, SvtResId( DLG_SVT_QUERYDELETE ) ), - _aEntryLabel ( this, SvtResId( TXT_ENTRY ) ), - _aEntry ( this, SvtResId( TXT_ENTRYNAME ) ), - _aQueryMsg ( this, SvtResId( TXT_QUERYMSG ) ), - _aYesButton ( this, SvtResId( BTN_YES ) ), - _aAllButton ( this, SvtResId( BTN_ALL ) ), - _aNoButton ( this, SvtResId( BTN_NO ) ), + _aEntryLabel ( this, SvtResId( TXT_ENTRY ) ), + _aEntry ( this, SvtResId( TXT_ENTRYNAME ) ), + _aQueryMsg ( this, SvtResId( TXT_QUERYMSG ) ), + _aYesButton ( this, SvtResId( BTN_YES ) ), + _aAllButton ( this, SvtResId( BTN_ALL ) ), + _aNoButton ( this, SvtResId( BTN_NO ) ), _aCancelButton( this, SvtResId( BTN_CANCEL ) ) { @@ -2671,12 +2790,6 @@ QueryDeleteDlg_Impl::QueryDeleteDlg_Impl // ----------------------------------------------------------------------- IMPL_STATIC_LINK( QueryDeleteDlg_Impl, ClickLink, PushButton*, pBtn ) - -/* [Beschreibung] - - Die Methode wertet das Resultat der Abfrage aus. -*/ - { if ( pBtn == &pThis->_aYesButton ) pThis->_eResult = QUERYDELETE_YES; |