[Libreoffice-commits] core.git: sc/inc sc/source

Laurent Godard lgodard.libre at laposte.net
Sat Mar 9 07:52:12 PST 2013


 sc/inc/globstr.hrc                |    5 ++
 sc/source/ui/docshell/docfunc.cxx |    8 +++-
 sc/source/ui/inc/undotab.hxx      |    7 ++-
 sc/source/ui/inc/viewfunc.hxx     |    4 +-
 sc/source/ui/src/globstr.src      |    8 ++++
 sc/source/ui/undo/undotab.cxx     |   29 +++++++++++----
 sc/source/ui/view/tabvwshf.cxx    |   54 +++++++++-------------------
 sc/source/ui/view/viewfun2.cxx    |   71 ++++++++++++++++++++++++--------------
 8 files changed, 109 insertions(+), 77 deletions(-)

New commits:
commit f1ec7dc619c84beecb05f9cd94a5c317904a7be5
Author: Laurent Godard <lgodard.libre at laposte.net>
Date:   Thu Mar 7 09:53:44 2013 +0100

    group undo action when hiding/showing 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
    Reviewed-on: https://gerrit.libreoffice.org/2579
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc
index 9d1d51e..619d8ed 100644
--- a/sc/inc/globstr.hrc
+++ b/sc/inc/globstr.hrc
@@ -654,7 +654,10 @@
 #define STR_CHG_CHILD_ORGCONTENT    524
 #define STR_CHG_EMPTY               525
 
-#define STR_COUNT                   526
+#define STR_UNDO_HIDETABS           526
+#define STR_UNDO_SHOWTABS           527
+
+#define STR_COUNT                   528
 
 #endif
 
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_Bool ScDocFunc::SetTableVisible( SCTAB nTab, bool bVisible, sal_Bool bApi )
 
         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 @@ sal_Bool ScDocFunc::SetTableVisible( SCTAB nTab, bool bVisible, sal_Bool bApi )
 
     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..25e6888 100644
--- a/sc/source/ui/inc/undotab.hxx
+++ b/sc/source/ui/inc/undotab.hxx
@@ -333,7 +333,8 @@ public:
                     TYPEINFO();
                     ScUndoShowHideTab(
                             ScDocShell* pShell,
-                            SCTAB nNewTab, sal_Bool bNewShow );
+                            const std::vector<SCTAB>& newUndoTabs,
+                            sal_Bool bNewShow );
     virtual         ~ScUndoShowHideTab();
 
     virtual void    Undo();
@@ -344,8 +345,8 @@ public:
     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..76c6734 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -273,8 +273,8 @@ public:
                                         const String& rFilter, const String& rOptions,
                                         const String& rSource, sal_uLong nRefresh );
 
-    void            ShowTable( const String& rName );
-    void            HideTable( SCTAB nTabNr );
+    void            ShowTable( const std::vector<String>& rNames );
+    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 042c9a5..9d8613e 100644
--- a/sc/source/ui/src/globstr.src
+++ b/sc/source/ui/src/globstr.src
@@ -1141,10 +1141,18 @@ Resource RID_GLOBSTR
     {
         Text [ en-US ] = "Show Sheet" ;
     };
+    String STR_UNDO_SHOWTABS
+    {
+        Text [ en-US ] = "Show Sheets" ;
+    };
     String STR_UNDO_HIDETAB
     {
         Text [ en-US ] = "Hide sheet" ;
     };
+    String STR_UNDO_HIDETABS
+    {
+        Text [ en-US ] = "Hide sheets" ;
+    };
     String STR_UNDO_TAB_RTL
     {
         Text [ en-US ] = "Flip sheet" ;
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 9732e21..a45b648 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -1117,9 +1117,9 @@ sal_Bool ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     return false;
 }
 
-ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, SCTAB nNewTab, sal_Bool bNewShow ) :
+ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, const std::vector<SCTAB>& newUndoTabs, sal_Bool bNewShow ) :
     ScSimpleUndo( pShell ),
-    nTab( nNewTab ),
+    undoTabs( newUndoTabs ),
     bShow( bNewShow )
 {
 }
@@ -1131,11 +1131,17 @@ ScUndoShowHideTab::~ScUndoShowHideTab()
 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(std::vector<SCTAB>::const_iterator itr = undoTabs.begin(), itrEnd = undoTabs.end(); itr != itrEnd; ++itr)
+    {
+        nTab = *itr;
+        pDoc->SetVisible( nTab, bShowP );
+        if (pViewShell)
+            pViewShell->SetTabNo(nTab,sal_True);
+    }
 
     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
     pDocShell->SetDocumentModified();
@@ -1166,7 +1172,16 @@ sal_Bool ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
 
 rtl::OUString ScUndoShowHideTab::GetComment() const
 {
-    sal_uInt16 nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
+    sal_uInt16 nId;
+    if (undoTabs.size() > 1)
+    {
+        nId = bShow ? STR_UNDO_SHOWTABS : STR_UNDO_HIDETABS;
+    }
+    else
+    {
+        nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
+    }
+
     return ScGlobal::GetRscString( nId );
 }
 
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index f3b629d..d26c22a 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -84,49 +84,27 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
 
                 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
                 {
-                    ShowTable( aName );
+                    std::vector<String> rNames;
+                    rNames.push_back(aName);
+                    ShowTable( rNames );
                 }
             }
             break;
 
         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;
@@ -134,14 +112,15 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
         case FID_TABLE_SHOW:
             {
                 String aName;
+                std::vector<String> rNames;
                 if ( pReqArgs )
                 {
                     const SfxPoolItem* pItem;
                     if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) )
                     {
                         aName = ((const SfxStringItem*)pItem)->GetValue();
-
-                        ShowTable( aName );
+                        rNames.push_back(aName);
+                        ShowTable( rNames );
 
                         if( ! rReq.IsAPI() )
                             rReq.Done();
@@ -173,9 +152,10 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                         for (sal_uInt16 nPos=0; nPos<nCount; nPos++)
                         {
                             aName = pDlg->GetSelectEntry(nPos);
-                            ShowTable( aName );
+                            rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
+                            rNames.push_back(aName);
                         }
-                        rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) );
+                        ShowTable( rNames );
                         rReq.Done();
                     }
                     delete pDlg;
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index b7d5221..bd71699 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2794,34 +2794,38 @@ void ScViewFunc::MoveTable(
 
 //----------------------------------------------------------------------------
 
-void ScViewFunc::ShowTable( const String& rName )
+void ScViewFunc::ShowTable( const std::vector<String>& rNames )
 {
     ScDocShell* pDocSh = GetViewData()->GetDocShell();
     ScDocument* pDoc = pDocSh->GetDocument();
     sal_Bool bUndo(pDoc->IsUndoEnabled());
-    sal_Bool bFound = false;
+
+    std::vector<SCTAB> undoTabs;
+    rtl::OUString aName;
     SCTAB nPos = 0;
-    rtl::OUString aTabName;
-    SCTAB nCount = pDoc->GetTableCount();
-    for (SCTAB i=0; i<nCount; i++)
+
+    bool bFound(false);
+
+    for (std::vector<String>::const_iterator itr=rNames.begin(), itrEnd = rNames.end(); itr!=itrEnd; ++itr)
     {
-        pDoc->GetName( i, aTabName );
-        if ( aTabName.equals(rName) )
+        aName = *itr;
+        if (pDoc->GetTable(aName, nPos))
         {
-            nPos = i;
-            bFound = sal_True;
+            pDoc->SetVisible( nPos, sal_True );
+            SetTabNo( nPos, sal_True );
+            SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
+            if (!bFound)
+                bFound = true;
+            if (bUndo)
+                undoTabs.push_back(nPos);
         }
     }
-
     if (bFound)
     {
-        pDoc->SetVisible( nPos, sal_True );
         if (bUndo)
         {
-            pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, nPos, sal_True ) );
+            pDocSh->GetUndoManager()->AddUndoAction( new ScUndoShowHideTab( pDocSh, undoTabs, true ) );
         }
-        SetTabNo( nPos, sal_True );
-        SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
         pDocSh->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_EXTRAS);
         pDocSh->SetDocumentModified();
     }
@@ -2830,31 +2834,48 @@ void ScViewFunc::ShowTable( const String& rName )
 
 //----------------------------------------------------------------------------
 
-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 ; 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();


More information about the Libreoffice-commits mailing list