Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/2579
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/79/2579/1
group undo action when hiding sheets
- the test if there are enough tabs before hiding is now in HideTabs
- a vector is passed to Undo
- modification of the displayed text
- minor optimization on looping over sheets (exit when condition is fullfilled)
Change-Id: I86196c6bb0f5fd6ba5b44c69efadc16b119a7f11
---
M sc/inc/globstr.hrc
M sc/source/ui/docshell/docfunc.cxx
M sc/source/ui/inc/undotab.hxx
M sc/source/ui/inc/viewfunc.hxx
M sc/source/ui/src/globstr.src
M sc/source/ui/undo/undotab.cxx
M sc/source/ui/view/tabvwshf.cxx
M sc/source/ui/view/viewfun2.cxx
8 files changed, 68 insertions(+), 62 deletions(-)
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 66da261..772b56a 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -381,7 +381,7 @@
#define STR_MATRIXFRAGMENTERR 310
#define STR_UNDO_SHOWTAB 311
-#define STR_UNDO_HIDETAB 312
+#define STR_UNDO_HIDETABS 312
#define STR_UNDO_INSERTAREALINK 313
#define STR_REIMPORT_AFTER_LOAD 314
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 7173a89..28c7af4 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -3079,7 +3079,7 @@
sal_uInt16 nVisCount = 0;
SCTAB nCount = pDoc->GetTableCount();
- for (SCTAB i=0; i<nCount; i++)
+ for (SCTAB i=0; i<nCount && nVisCount<2; i++)
if (pDoc->IsVisible(i))
++nVisCount;
@@ -3093,7 +3093,11 @@
pDoc->SetVisible( nTab, bVisible );
if (bUndo)
- rDocShell.GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( &rDocShell, nTab,
bVisible ) );
+ {
+ std::vector<SCTAB> undoTabs;
+ undoTabs.push_back(nTab);
+ rDocShell.GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( &rDocShell, undoTabs,
bVisible ) );
+ }
// Views updaten:
if (!bVisible)
diff --git a/sc/source/ui/inc/undotab.hxx b/sc/source/ui/inc/undotab.hxx
index 5b7d8e6..764a320 100644
--- a/sc/source/ui/inc/undotab.hxx
+++ b/sc/source/ui/inc/undotab.hxx
@@ -333,7 +333,8 @@
TYPEINFO();
ScUndoShowHideTab(
ScDocShell* pShell,
- SCTAB nNewTab, sal_Bool bNewShow );
+ std::vector<SCTAB> newUndoTabs,
+ sal_Bool bNewShow );
virtual ~ScUndoShowHideTab();
virtual void Undo();
@@ -344,8 +345,8 @@
virtual rtl::OUString GetComment() const;
private:
- SCTAB nTab;
- sal_Bool bShow;
+ std::vector<SCTAB> undoTabs;
+ sal_Bool bShow;
void DoChange( sal_Bool bShow ) const;
};
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 748a386..dce6830 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -274,7 +274,7 @@
const String& rSource, sal_uLong nRefresh );
void ShowTable( const String& rName );
- void HideTable( SCTAB nTabNr );
+ void HideTable( const ScMarkData& rMark );
void MakeScenario( const String& rName, const String& rComment,
const Color& rColor, sal_uInt16 nFlags );
diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src
index 7305950..c0019d3 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -1140,9 +1140,9 @@
{
Text [ en-US ] = "Show Sheet" ;
};
- String STR_UNDO_HIDETAB
+ String STR_UNDO_HIDETABS
{
- Text [ en-US ] = "Hide sheet" ;
+ Text [ en-US ] = "Hide sheets" ;
};
String STR_UNDO_TAB_RTL
{
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 9732e21..9ac8070 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -1117,9 +1117,9 @@
return false;
}
-ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, SCTAB nNewTab, sal_Bool bNewShow ) :
+ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, std::vector<SCTAB> newUndoTabs, sal_Bool
bNewShow ) :
ScSimpleUndo( pShell ),
- nTab( nNewTab ),
+ undoTabs( newUndoTabs ),
bShow( bNewShow )
{
}
@@ -1131,11 +1131,17 @@
void ScUndoShowHideTab::DoChange( sal_Bool bShowP ) const
{
ScDocument* pDoc = pDocShell->GetDocument();
- pDoc->SetVisible( nTab, bShowP );
-
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
- if (pViewShell)
- pViewShell->SetTabNo(nTab,sal_True);
+
+ SCTAB nTab;
+
+ for (size_t i = 0; i < undoTabs.size(); ++i)
+ {
+ nTab = undoTabs[i];
+ pDoc->SetVisible( nTab, bShowP );
+ if (pViewShell)
+ pViewShell->SetTabNo(nTab,sal_True);
+ }
SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
pDocShell->SetDocumentModified();
@@ -1166,7 +1172,7 @@
rtl::OUString ScUndoShowHideTab::GetComment() const
{
- sal_uInt16 nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
+ sal_uInt16 nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETABS;
return ScGlobal::GetRscString( nId );
}
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index f3b629d..9131538 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -84,18 +84,11 @@
if( ! bVisible ) // ausblenden
{
- ScMarkData& rMark = pViewData->GetMarkData();
- SCTAB nTabSelCount = rMark.GetSelectCount();
- sal_uInt16 nVis = 0;
- for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
- if (pDoc->IsVisible(i))
- ++nVis;
- if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 )
- break;
-
- SCTAB nHideTab;
- if (pDoc->GetTable( aName, nHideTab ))
- HideTable( nHideTab );
+ if ( pDoc->IsDocEditable() )
+ {
+ ScMarkData& rMark = pViewData->GetMarkData();
+ HideTable( rMark );
+ }
}
else // einblenden
{
@@ -106,27 +99,10 @@
case FID_TABLE_HIDE:
{
- ScMarkData& rMark = pViewData->GetMarkData();
- SCTAB nTabSelCount = rMark.GetSelectCount();
- sal_uInt16 nVis = 0;
-
- // check to make sure we won't hide all sheets. we need at least one visible at
all times.
- for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
- if (pDoc->IsVisible(i))
- ++nVis;
- if ( nVis<=nTabSelCount || !pDoc->IsDocEditable() )
- break;
-
- SCTAB nHideTab;
- ScMarkData::MarkedTabsType::const_iterator it;
-
- ScMarkData::MarkedTabsType selectedTabs = rMark.GetSelectedTabs();
-
- for (it=selectedTabs.begin(); it!=selectedTabs.end(); ++it)
+ if ( pDoc->IsDocEditable() )
{
- nHideTab = *it;
- if (pDoc->IsVisible( nHideTab ))
- HideTable( nHideTab );
+ ScMarkData& rMark = pViewData->GetMarkData();
+ HideTable( rMark );
}
}
break;
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index b7d5221..bc11eaa 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2803,13 +2803,13 @@
SCTAB nPos = 0;
rtl::OUString aTabName;
SCTAB nCount = pDoc->GetTableCount();
- for (SCTAB i=0; i<nCount; i++)
+ for (SCTAB i=0; i<nCount && !bFound; i++)
{
pDoc->GetName( i, aTabName );
if ( aTabName.equals(rName) )
{
nPos = i;
- bFound = sal_True;
+ bFound = true;
}
}
@@ -2818,7 +2818,9 @@
pDoc->SetVisible( nPos, sal_True );
if (bUndo)
{
- pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, nPos, sal_True
) );
+ std::vector<SCTAB> undoTabs;
+ undoTabs.push_back(nPos);
+ pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, undoTabs, true
) );
}
SetTabNo( nPos, sal_True );
SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
@@ -2830,31 +2832,48 @@
//----------------------------------------------------------------------------
-void ScViewFunc::HideTable( SCTAB nTab )
+void ScViewFunc::HideTable( const ScMarkData& rMark )
{
ScDocShell* pDocSh = GetViewData()->GetDocShell();
ScDocument* pDoc = pDocSh->GetDocument();
sal_Bool bUndo(pDoc->IsUndoEnabled());
SCTAB nVisible = 0;
- SCTAB nCount = pDoc->GetTableCount();
- for (SCTAB i=0; i<nCount; i++)
- {
+ SCTAB nTabCount = pDoc->GetTableCount();
+
+ SCTAB nTabSelCount = rMark.GetSelectCount();
+
+ // check to make sure we won't hide all sheets. we need at least one visible at all times.
+ for ( SCTAB i=0; i < nTabCount && nVisible<nTabSelCount + 1; i++ )
if (pDoc->IsVisible(i))
++nVisible;
- }
- if (nVisible > 1)
+ if (nVisible > nTabSelCount)
{
- pDoc->SetVisible( nTab, false );
+ SCTAB nTab;
+ ScMarkData::MarkedTabsType::const_iterator it;
+ std::vector<SCTAB> undoTabs;
+
+ ScMarkData::MarkedTabsType selectedTabs = rMark.GetSelectedTabs();
+ for (it=selectedTabs.begin(); it!=selectedTabs.end(); ++it)
+ {
+ nTab = *it;
+ if (pDoc->IsVisible( nTab ))
+ {
+ pDoc->SetVisible( nTab, false );
+ // Update views
+ pDocSh->Broadcast( ScTablesHint( SC_TAB_HIDDEN, nTab ) );
+ SetTabNo( nTab, true );
+ // Store for undo
+ if (bUndo)
+ undoTabs.push_back(nTab);
+ }
+ }
if (bUndo)
{
- pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, nTab, false )
);
+ pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, undoTabs,
false ) );
}
// Update views
- pDocSh->Broadcast( ScTablesHint( SC_TAB_HIDDEN, nTab ) );
-
- SetTabNo( nTab, sal_True );
SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
pDocSh->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_EXTRAS);
pDocSh->SetDocumentModified();
--
To view, visit https://gerrit.libreoffice.org/2579
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I86196c6bb0f5fd6ba5b44c69efadc16b119a7f11
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Laurent Godard <lgodard.libre@laposte.net>
Context
- [PATCH] group undo action when hiding sheets · Laurent Godard (via Code Review)
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.