diff options
author | Kai Sommerfeld <kso@openoffice.org> | 2010-06-07 10:56:29 +0200 |
---|---|---|
committer | Kai Sommerfeld <kso@openoffice.org> | 2010-06-07 10:56:29 +0200 |
commit | ac433a52867211e4c8c8a1a306ed38ba575645e1 (patch) | |
tree | ac50a1c74b358b99727f1384c53a92acdccb0f96 /svtools/source/contnr | |
parent | 996674302efa782dc956e173b222f810aa3a4c00 (diff) |
#i112173# - context menu items reflect actual file properties.
Diffstat (limited to 'svtools/source/contnr')
-rw-r--r-- | svtools/source/contnr/fileview.cxx | 102 |
1 files changed, 90 insertions, 12 deletions
diff --git a/svtools/source/contnr/fileview.cxx b/svtools/source/contnr/fileview.cxx index 1d80461b060f..73a0aac06f3f 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> @@ -204,12 +207,13 @@ private: Timer maResetQuickSearch; OUString maQuickSearchText; String msAccessibleDescText; - Strin msFolder; + String msFolder; String msFile; sal_uInt32 mnSearchIndex; 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; } @@ -613,7 +618,7 @@ public: ULONG GetEntryPos( const OUString& rURL ); - inline voi EnableContextMenu( sal_Bool bEnable ); + inline void EnableContextMenu( sal_Bool bEnable ); inline void EnableDelete( sal_Bool bEnable ); void Resort_Impl( sal_Int16 nColumn, sal_Bool bAscending ); @@ -661,6 +666,8 @@ 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() ) { @@ -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(); @@ -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 ( 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 ); + 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 ( bEnableDelete || bEnableRename ) + { + 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; } // ----------------------------------------------------------------------- |