From 439ac45925039aa7a537feedab3e731e8a60a8e5 Mon Sep 17 00:00:00 2001 From: Joren De Cuyper Date: Thu, 17 Jan 2013 15:28:37 +0100 Subject: fdo#46718 Delete multiple styles at once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5f5982b2a2768d021f24693a285274544e07e40f Reviewed-on: https://gerrit.libreoffice.org/1737 Reviewed-by: Radek Doulík Tested-by: Radek Doulík --- sfx2/source/dialog/templdlg.cxx | 105 +++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx index b315453f691c..31920f202a36 100644 --- a/sfx2/source/dialog/templdlg.cxx +++ b/sfx2/source/dialog/templdlg.cxx @@ -911,6 +911,7 @@ void SfxCommonTemplateDialog_Impl::Initialize() aFilterLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FilterSelectHdl ) ); aFmtLb.SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, ApplyHdl ) ); aFmtLb.SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) ); + aFmtLb.SetSelectionMode(MULTIPLE_SELECTION); aFilterLb.Show(); aFmtLb.Show(); @@ -1046,7 +1047,7 @@ void SfxCommonTemplateDialog_Impl::SelectStyle(const String &rStr) { aFmtLb.MakeVisible( pEntry ); aFmtLb.Select( pEntry ); - bWaterDisabled = !HasSelectedStyle(); + bWaterDisabled = (aFmtLb.GetSelectionCount() <=1 ? sal_False : sal_True); FmtSelectHdl( NULL ); } } @@ -1306,7 +1307,8 @@ void SfxCommonTemplateDialog_Impl::SetWaterCanState(const SfxBoolItem *pItem) bWaterDisabled = pItem == 0; if(!bWaterDisabled) - bWaterDisabled = !HasSelectedStyle(); + //make sure the watercan is only activated when there is (only) one selection + bWaterDisabled = (aFmtLb.GetSelectionCount() <=1 ? sal_False : sal_True); if(pItem && !bWaterDisabled) { @@ -1644,6 +1646,7 @@ sal_Bool SfxCommonTemplateDialog_Impl::Execute_Impl( aUpdName.SetValue(aTemplName); pItems[ nCount++ ] = &aUpdName; } + if ( rRefStr.Len() ) pItems[ nCount++ ] = &aRefName; @@ -1660,7 +1663,7 @@ sal_Bool SfxCommonTemplateDialog_Impl::Execute_Impl( if ( !pItem || aDeleted ) return sal_False; - if ( nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId ) + if ( (nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId) && (aFmtLb.GetSelectionCount() <= 1) ) { SfxUInt16Item *pFilterItem = PTR_CAST(SfxUInt16Item, pItem); OSL_ENSURE(pFilterItem, "SfxUINT16Item expected"); @@ -1899,7 +1902,7 @@ IMPL_LINK( SfxCommonTemplateDialog_Impl, DropHdl, StyleTreeListBox_Impl *, pBox void SfxCommonTemplateDialog_Impl::NewHdl(void *) { String aEmpty; - if ( nActFamily != 0xffff ) + if ( nActFamily != 0xffff && (aFmtLb.GetSelectionCount() <= 1)) { Window* pTmp; pTmp = Application::GetDefDialogParent(); @@ -1963,39 +1966,80 @@ void SfxCommonTemplateDialog_Impl::DeleteHdl(void *) { if ( IsInitialized() && HasSelectedStyle() ) { - const String aTemplName( GetSelectedEntry() ); - SfxStyleSheetBase* pStyle = GetSelectedStyle(); - if ( pStyle ) + sal_uLong SelectionCount = 0; + sal_Bool bChecked = 0; + String aRet; + + SelectionCount = aFmtLb.GetSelectionCount(); + std::vector aList; + + SvTreeListEntry* pEntry = aFmtLb.FirstSelected(); + + while (pEntry) { - String aMsg; - if ( pStyle->IsUsed() ) - aMsg = SfxResId(STR_DELETE_STYLE_USED).toString(); - aMsg += SfxResId(STR_DELETE_STYLE).toString(); - aMsg.SearchAndReplaceAscii( "$1", aTemplName ); -#if defined UNX - QueryBox aBox( SFX_APP()->GetTopWindow(), WB_YES_NO | WB_DEF_NO, aMsg ); -#else - QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , aMsg ); -#endif - if ( RET_YES == aBox.Execute() ) + aList.push_back( pEntry ); + pEntry = aFmtLb.NextSelected( pEntry ); + SelectionCount++; + } + + std::vector::const_iterator it = aList.begin(), itEnd = aList.end(); + + for (; it != itEnd; ++it) + { + if (pTreeBox) + aRet = pTreeBox->GetEntryText( *it ); + else + aRet = aFmtLb.GetEntryText( *it ); + const String aTemplName( aRet ); + + const SfxStyleFamilyItem* pItem = GetFamilyItem_Impl(); + + SfxStyleSheetBase* pStyle = pStyleSheetPool->Find( aTemplName, pItem->GetFamily(), SFXSTYLEBIT_ALL ); + + bool bUsedStyle = pStyle->IsUsed(); + bool approve; + + if ( bChecked == 0 ) + { + String aMsg; + if ( bUsedStyle ) + aMsg = SfxResId(STR_DELETE_STYLE_USED).toString(); + aMsg += SfxResId(STR_DELETE_STYLE).toString(); + aMsg.SearchAndReplaceAscii( "$1", aTemplName ); + #if defined UNX + QueryBox aBox( SFX_APP()->GetTopWindow(), WB_YES_NO | WB_DEF_NO, aMsg ); + #else + QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , aMsg ); + #endif + if (SelectionCount > 1) //show only when there are multiple styles selected/to be deleted + aBox.SetDefaultCheckBoxText(); + approve = aBox.Execute() == RET_YES; + bChecked = aBox.GetCheckBoxState(); + if ( approve == 0 && bChecked == 1) + break; + } + else //if checkbox was selected previous time, don't ask again + approve = 1; + + if ( approve ) { PrepareDeleteAction(); - if ( pTreeBox ) // To prevent the Treelistbox to shut down while - // deleting. - { - bDontUpdate = sal_True; - } + bDontUpdate = sal_True; // To prevent the Treelistbox to shut down while deleting + Execute_Impl( SID_STYLE_DELETE, aTemplName, String(), (sal_uInt16)GetFamilyItem_Impl()->GetFamily() ); if ( pTreeBox ) { - pTreeBox->RemoveParentKeepChildren( pTreeBox->FirstSelected() ); + pTreeBox->RemoveParentKeepChildren( *it ); bDontUpdate = sal_False; } } + --SelectionCount; } + bDontUpdate = sal_False; //if everything is deleted set bDontUpdate back to false + UpdateStyles_Impl(UPDATE_FAMILY_LIST); //and force-update the list } } @@ -2045,7 +2089,7 @@ void SfxCommonTemplateDialog_Impl::EnableDelete() const SfxStyleSheetBase *pStyle = pStyleSheetPool->Find(aTemplName,eFam, pTreeBox? SFXSTYLEBIT_ALL : nFilter); - OSL_ENSURE(pStyle, "Style ot found"); + OSL_ENSURE(pStyle, "Style not found"); if(pStyle && pStyle->IsUserDefined()) { EnableDel(sal_True); @@ -2107,7 +2151,7 @@ IMPL_LINK( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox if ( IsInitialized() && IsCheckedItem(SID_STYLE_WATERCAN) && // only if that region is allowed - 0 != pFamilyState[nActFamily-1] ) + 0 != pFamilyState[nActFamily-1] && (aFmtLb.GetSelectionCount() <= 1) ) { String aEmpty; Execute_Impl(SID_STYLE_WATERCAN, @@ -2176,9 +2220,12 @@ SfxStyleFamily SfxCommonTemplateDialog_Impl::GetActualFamily() const void SfxCommonTemplateDialog_Impl::EnableExample_Impl(sal_uInt16 nId, sal_Bool bEnable) { if( nId == SID_STYLE_NEW_BY_EXAMPLE ) - bNewByExampleDisabled = !bEnable; + { + bNewByExampleDisabled = (aFmtLb.GetSelectionCount() <=1 ? !bEnable : sal_True); + } else if( nId == SID_STYLE_UPDATE_BY_EXAMPLE ) - bUpdateByExampleDisabled = !bEnable; + bUpdateByExampleDisabled = (aFmtLb.GetSelectionCount() <=1 ? !bEnable : sal_True); + EnableItem(nId, bEnable); } @@ -2603,7 +2650,7 @@ void SfxCommonTemplateDialog_Impl::UpdateFamily_Impl() } bWaterDisabled = sal_False; - bCanNew = sal_True; + bCanNew = (aFmtLb.GetSelectionCount() <=1 ? sal_True : sal_False); bTreeDrag = sal_True; bUpdateByExampleDisabled = sal_False; -- cgit v1.2.3