[Libreoffice-commits] core.git: 3 commits - desktop/qa sc/sdi sc/source

Jan Holesovsky kendy at collabora.com
Wed Jan 20 23:54:04 PST 2016


 desktop/qa/data/sheets.ods                  |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx |   34 ++++++++++++
 sc/sdi/scalc.sdi                            |    4 -
 sc/source/core/data/document.cxx            |    9 +++
 sc/source/ui/view/tabvwshf.cxx              |   77 ++++++++++++++++++++--------
 5 files changed, 100 insertions(+), 24 deletions(-)

New commits:
commit 77c677a41d4bc9a2cd71ea1cc17e6c836387a6c5
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Jan 21 00:42:59 2016 +0100

    sc lok: Implement unit test for .uno:{Insert,Name,Remove} for sheets.
    
    And fix indexing when at that - the inserting is 1-based, so let's be
    consistent in the .uno:Name and .uno:Remove too.
    
    Change-Id: Ib854e81551ae0a39d3ba7c68512e81ea227e9eb1

diff --git a/desktop/qa/data/sheets.ods b/desktop/qa/data/sheets.ods
new file mode 100644
index 0000000..42226b2
Binary files /dev/null and b/desktop/qa/data/sheets.ods differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index dc870bf..abda86b 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -83,6 +83,7 @@ public:
     void testCommandResult();
     void testWriterComments();
     void testModifiedStatus();
+    void testSheetOperations();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testGetStyles);
@@ -102,6 +103,7 @@ public:
     CPPUNIT_TEST(testCommandResult);
     CPPUNIT_TEST(testWriterComments);
     CPPUNIT_TEST(testModifiedStatus);
+    CPPUNIT_TEST(testSheetOperations);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -640,6 +642,38 @@ void DesktopLOKTest::testModifiedStatus()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void DesktopLOKTest::testSheetOperations()
+{
+    comphelper::LibreOfficeKit::setActive(true);
+    LibLODocument_Impl* pDocument = loadDoc("sheets.ods");
+
+    // insert the last sheet
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:Insert",
+          "{ \"Name\": { \"type\": \"string\", \"value\": \"LastSheet\" }, \"Index\": { \"type\": \"long\", \"value\": 0 } }", false);
+
+    // insert the first sheet
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:Insert",
+          "{ \"Name\": { \"type\": \"string\", \"value\": \"FirstSheet\" }, \"Index\": { \"type\": \"long\", \"value\": 1 } }", false);
+
+    // rename the \"Sheet1\" (2nd now) to \"Renamed\"
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:Name",
+          "{ \"Name\": { \"type\": \"string\", \"value\": \"Renamed\" }, \"Index\": { \"type\": \"long\", \"value\": 2 } }", false);
+
+    // delete the \"Sheet2\" (3rd)
+    pDocument->pClass->postUnoCommand(pDocument, ".uno:Remove",
+          "{ \"Index\": { \"type\": \"long\", \"value\": 3 } }", false);
+
+    CPPUNIT_ASSERT_EQUAL(pDocument->pClass->getParts(pDocument), 6);
+
+    std::vector<OString> pExpected = { "FirstSheet", "Renamed", "Sheet3", "Sheet4", "Sheet5", "LastSheet" };
+    for (int i = 0; i < 6; ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(pExpected[i], OString(pDocument->pClass->getPartName(pDocument, i)));
+    }
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index d22ece2..8a56bfd 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -332,8 +332,14 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                     OUString      aName;
 
                     if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
+                    {
                         nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
 
+                        // inserting is 1-based, let's be consistent
+                        if (nTabNr > 0)
+                            --nTabNr;
+                    }
+
                     if( pReqArgs->HasItem( nSlot, &pItem ) )
                         aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
 
@@ -570,12 +576,18 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                 bool bHasIndex = (pReqArgs != nullptr);
 
                 // allow removing via the Index/FID_DELETE_TABLE parameter
-                SCTAB nIndexTab = nCurrentTab;
+                SCTAB nTabNr = nCurrentTab;
                 if (bHasIndex)
                 {
                     const SfxPoolItem* pItem;
                     if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem))
-                        nIndexTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+                    {
+                        nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+
+                        // inserting is 1-based, let's be consistent
+                        if (nTabNr > 0)
+                            --nTabNr;
+                    }
                 }
 
                 bool bDoIt = bHasIndex;
@@ -597,8 +609,8 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                     if (bHasIndex)
                     {
                         // sheet no. provided by the parameter
-                        TheTabs.push_back(nIndexTab);
-                        if (nNewTab > nIndexTab && nNewTab > 0)
+                        TheTabs.push_back(nTabNr);
+                        if (nNewTab > nTabNr && nNewTab > 0)
                             --nNewTab;
                     }
                     else
commit 8a79692a73dc598b7b3bf1fea744ca771aa93e3f
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Jan 21 00:02:16 2016 +0100

    sc lok: Fix .uno:Remove (removing sheets) to accept a parameter.
    
    .sdi annouces that, but it was never implemented...
    
    Change-Id: I7abfbdc88f055eeb993617a5a51371af0f825d34

diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 6c75c91..1fe4934 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -738,6 +738,9 @@ bool ScDocument::DeleteTab( SCTAB nTab )
                 // sheet names of references are not valid until sheet is deleted
                 pChartListenerCollection->UpdateScheduledSeriesRanges();
 
+                if (comphelper::LibreOfficeKit::isActive() && GetDrawLayer())
+                    GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, "");
+
                 bValid = true;
             }
         }
@@ -825,6 +828,9 @@ bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets )
                 // sheet names of references are not valid until sheet is deleted
                 pChartListenerCollection->UpdateScheduledSeriesRanges();
 
+                if (comphelper::LibreOfficeKit::isActive() && GetDrawLayer())
+                    GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, "");
+
                 bValid = true;
             }
         }
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index 8ed4937..d22ece2 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -567,37 +567,60 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
 
         case FID_DELETE_TABLE:
             {
-                //  unnecessary parameter ->  method depends on table
+                bool bHasIndex = (pReqArgs != nullptr);
 
-                bool bDoIt = rReq.IsAPI();
-                if( !bDoIt )
+                // allow removing via the Index/FID_DELETE_TABLE parameter
+                SCTAB nIndexTab = nCurrentTab;
+                if (bHasIndex)
                 {
-                    //  source isn't basic -> ask again
+                    const SfxPoolItem* pItem;
+                    if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem))
+                        nIndexTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
+                }
 
-                        bDoIt = ( RET_YES ==
-                                  ScopedVclPtr<QueryBox>::Create( GetDialogParent(),
-                                            WinBits( WB_YES_NO | WB_DEF_YES ),
-                                            ScGlobal::GetRscString(STR_QUERY_DELTAB)
-                                      )->Execute() );
+                bool bDoIt = bHasIndex;
+                if (!bDoIt)
+                {
+                    // no parameter given, ask for confirmation
+                    bDoIt = ( RET_YES ==
+                              ScopedVclPtr<QueryBox>::Create( GetDialogParent(),
+                                        WinBits( WB_YES_NO | WB_DEF_YES ),
+                                        ScGlobal::GetRscString(STR_QUERY_DELTAB)
+                                  )->Execute() );
                 }
-                if( bDoIt )
+
+                if (bDoIt)
                 {
-                    SCTAB nNewTab   = nCurrentTab;
-                    SCTAB nFirstTab=0;
-                    bool   bTabFlag=false;
-                    ScMarkData& rMark = rViewData.GetMarkData();
+                    SCTAB nNewTab = nCurrentTab;
                     std::vector<SCTAB> TheTabs;
-                    for(SCTAB i=0;i<nTabCount;i++)
+
+                    if (bHasIndex)
                     {
-                        if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i))
+                        // sheet no. provided by the parameter
+                        TheTabs.push_back(nIndexTab);
+                        if (nNewTab > nIndexTab && nNewTab > 0)
+                            --nNewTab;
+                    }
+                    else
+                    {
+                        SCTAB nFirstTab = 0;
+                        bool bTabFlag = false;
+                        ScMarkData& rMark = rViewData.GetMarkData();
+                        for (SCTAB i = 0; i < nTabCount; i++)
                         {
-                            TheTabs.push_back(i);
-                            bTabFlag=true;
-                            if(nNewTab==i) nNewTab++;
+                            if (rMark.GetTableSelect(i) && !pDoc->IsTabProtected(i))
+                            {
+                                TheTabs.push_back(i);
+                                bTabFlag = true;
+                                if (nNewTab == i)
+                                    nNewTab++;
+                            }
+                            if (!bTabFlag)
+                                nFirstTab = i;
                         }
-                        if(!bTabFlag) nFirstTab=i;
+                        if (nNewTab >= nTabCount)
+                            nNewTab = nFirstTab;
                     }
-                    if(nNewTab>=nTabCount) nNewTab=nFirstTab;
 
                     rViewData.SetTabNo(nNewTab);
                     DeleteTables(TheTabs);
commit 4d2034803646bf88b76ed8a3b897edd7209ce30a
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jan 20 22:12:33 2016 +0100

    sc lok: Fix .uno:Name (renaming sheets) to really accept parameters.
    
    The code handles them, but they were unusable, because .sdi did not announce
    them.
    
    Change-Id: I35bd3009d092eb48a36aee2ffed3964dc61946e2

diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index dd91da2..75f0233 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -4912,7 +4912,7 @@ SfxVoidItem Move FID_TAB_MOVE
 
 
 SfxStringItem Name FID_TAB_RENAME
-
+(SfxStringItem Name FID_TAB_RENAME,SfxUInt16Item Index FN_PARAM_1)
 [
     /* flags: */
     AutoUpdate = FALSE,
@@ -4927,8 +4927,6 @@ SfxStringItem Name FID_TAB_RENAME
     RecordPerSet;
     Synchron;
 
-    Readonly = FALSE,
-
     /* config: */
     AccelConfig = TRUE,
     MenuConfig = TRUE,
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 7abd034..6c75c91 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -866,6 +866,9 @@ bool ScDocument::RenameTab( SCTAB nTab, const OUString& rName, bool /* bUpdateRe
                 for (; it != maTabs.end(); ++it)
                     if ( *it && (*it)->IsStreamValid())
                         (*it)->SetStreamValid( false );
+
+                if (comphelper::LibreOfficeKit::isActive() && GetDrawLayer())
+                    GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_DOCUMENT_SIZE_CHANGED, "");
             }
         }
     }


More information about the Libreoffice-commits mailing list