sc/source/ui/inc/tabvwsh.hxx   |    2 
 sc/source/ui/view/tabvwshf.cxx |  463 +++++++++++++++++++++--------------------
 2 files changed, 242 insertions(+), 223 deletions(-)

New commits:
commit c38ebb561211e55d0a7eb5d2e3db6975f0cadbfc
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 24 12:36:03 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jan 25 07:01:15 2024 +0100

    split out set-bg-col logic from ScTabViewShell::ExecuteTable
    
    Change-Id: I528d99fbd8e369a0ceaa51184e336d24a4510706
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162510
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index 1191669f09c7..a5cafcb885d2 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -459,6 +459,7 @@ private:
     void ExecuteInsertTable( SfxRequest& rReq );
     void DoInsertTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScInsertTableDlg>& pDlg );
     void ExecuteAppendOrRenameTable( SfxRequest& rReq );
+    void ExecuteSetTableBackgroundCol( SfxRequest& rReq );
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index dd64c9e14dd1..0440fe8ac019 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -431,109 +431,8 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
 
         case FID_TAB_SET_TAB_BG_COLOR:
         case FID_TAB_MENU_SET_TAB_BG_COLOR:
-            {
-                if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
-                    nSlot = FID_TAB_SET_TAB_BG_COLOR;
-                SCTAB nTabNr = rViewData.GetTabNo();
-                ScMarkData& rMark = rViewData.GetMarkData();
-                SCTAB nTabSelCount = rMark.GetSelectCount();
-                if ( !rDoc.IsDocEditable() )
-                    break;
-
-                if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
-                    break;
-
-                if( pReqArgs != nullptr )
-                {
-                    bool                bDone = false;
-                    const SfxPoolItem*  pItem;
-                    Color               aColor;
-
-                    if( pReqArgs->HasItem( nSlot, &pItem ) )
-                        aColor = static_cast<const 
SvxColorItem*>(pItem)->GetValue();
-
-                    if ( nTabSelCount > 1 )
-                    {
-                        std::unique_ptr<ScUndoTabColorInfo::List>
-                            pTabColorList(new ScUndoTabColorInfo::List);
-                        for (const auto& rTab : rMark)
-                        {
-                            if ( !rDoc.IsTabProtected(rTab) )
-                            {
-                                ScUndoTabColorInfo aTabColorInfo(rTab);
-                                aTabColorInfo.maNewTabBgColor = aColor;
-                                pTabColorList->push_back(aTabColorInfo);
-                            }
-                        }
-                        bDone = SetTabBgColor( *pTabColorList );
-                    }
-                    else
-                    {
-                        bDone = SetTabBgColor( aColor, nCurrentTab ); 
//ScViewFunc.SetTabBgColor
-                    }
-                    if( bDone )
-                    {
-                        rReq.Done( *pReqArgs );
-                    }
-                }
-                else
-                {
-                    sal_uInt16      nRet    = RET_OK; /// temp
-                    bool        bDone   = false; /// temp
-
-                    Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
-                    ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
-                    ScopedVclPtr<AbstractScTabBgColorDlg> 
pDlg(pFact->CreateScTabBgColorDlg(
-                                                                GetFrameWeld(),
-                                                                
ScResId(SCSTR_SET_TAB_BG_COLOR),
-                                                                
ScResId(SCSTR_NO_TAB_BG_COLOR),
-                                                                aTabBgColor));
-                    while ( !bDone && nRet == RET_OK )
-                    {
-                        nRet = pDlg->Execute();
-                        if( nRet == RET_OK )
-                        {
-                            Color aSelectedColor;
-                            pDlg->GetSelectedColor(aSelectedColor);
-                            std::unique_ptr<ScUndoTabColorInfo::List>
-                                pTabColorList(new ScUndoTabColorInfo::List);
-                            if ( nTabSelCount > 1 )
-                            {
-                                for (const auto& rTab : rMark)
-                                {
-                                    if ( !rDoc.IsTabProtected(rTab) )
-                                    {
-                                        ScUndoTabColorInfo aTabColorInfo(rTab);
-                                        aTabColorInfo.maNewTabBgColor = 
aSelectedColor;
-                                        
pTabColorList->push_back(aTabColorInfo);
-                                    }
-                                }
-                                bDone = SetTabBgColor( *pTabColorList );
-                            }
-                            else
-                            {
-                                bDone = SetTabBgColor( aSelectedColor, 
nCurrentTab ); //ScViewFunc.SetTabBgColor
-                            }
-
-                            if ( bDone )
-                            {
-                                rReq.AppendItem( SvxColorItem( aTabBgColor, 
nSlot ) );
-                                rReq.Done();
-                            }
-                            else
-                            {
-                                if( rReq.IsAPI() )
-                                {
-#if HAVE_FEATURE_SCRIPTING
-                                    StarBASIC::Error( 
ERRCODE_BASIC_SETPROP_FAILED );
-#endif
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-                break;
+            ExecuteSetTableBackgroundCol(rReq);
+            break;
 
         case FID_TAB_EVENTS:
                 {
@@ -1267,4 +1166,113 @@ void 
ScTabViewShell::ExecuteAppendOrRenameTable(SfxRequest& rReq)
     }
 }
 
+void ScTabViewShell::ExecuteSetTableBackgroundCol(SfxRequest& rReq)
+{
+    ScViewData& rViewData   = GetViewData();
+    ScDocument& rDoc        = rViewData.GetDocument();
+    sal_uInt16  nSlot       = rReq.GetSlot();
+    const SfxItemSet* pReqArgs = rReq.GetArgs();
+    if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
+        nSlot = FID_TAB_SET_TAB_BG_COLOR;
+    SCTAB nTabNr = rViewData.GetTabNo();
+    ScMarkData& rMark = rViewData.GetMarkData();
+    SCTAB nTabSelCount = rMark.GetSelectCount();
+    SCTAB nCurrentTab = rViewData.GetTabNo();
+
+    if ( !rDoc.IsDocEditable() )
+        return;
+
+    if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
+        return;
+
+    if( pReqArgs != nullptr )
+    {
+        bool                bDone = false;
+        const SfxPoolItem*  pItem;
+        Color               aColor;
+
+        if( pReqArgs->HasItem( nSlot, &pItem ) )
+            aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
+
+        if ( nTabSelCount > 1 )
+        {
+            std::unique_ptr<ScUndoTabColorInfo::List>
+                pTabColorList(new ScUndoTabColorInfo::List);
+            for (const auto& rTab : rMark)
+            {
+                if ( !rDoc.IsTabProtected(rTab) )
+                {
+                    ScUndoTabColorInfo aTabColorInfo(rTab);
+                    aTabColorInfo.maNewTabBgColor = aColor;
+                    pTabColorList->push_back(aTabColorInfo);
+                }
+            }
+            bDone = SetTabBgColor( *pTabColorList );
+        }
+        else
+        {
+            bDone = SetTabBgColor( aColor, nCurrentTab ); 
//ScViewFunc.SetTabBgColor
+        }
+        if( bDone )
+        {
+            rReq.Done( *pReqArgs );
+        }
+    }
+    else
+    {
+        sal_uInt16      nRet    = RET_OK; /// temp
+        bool        bDone   = false; /// temp
+
+        Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
+        ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
+        ScopedVclPtr<AbstractScTabBgColorDlg> 
pDlg(pFact->CreateScTabBgColorDlg(
+                                                    GetFrameWeld(),
+                                                    
ScResId(SCSTR_SET_TAB_BG_COLOR),
+                                                    
ScResId(SCSTR_NO_TAB_BG_COLOR),
+                                                    aTabBgColor));
+        while ( !bDone && nRet == RET_OK )
+        {
+            nRet = pDlg->Execute();
+            if( nRet == RET_OK )
+            {
+                Color aSelectedColor;
+                pDlg->GetSelectedColor(aSelectedColor);
+                std::unique_ptr<ScUndoTabColorInfo::List>
+                    pTabColorList(new ScUndoTabColorInfo::List);
+                if ( nTabSelCount > 1 )
+                {
+                    for (const auto& rTab : rMark)
+                    {
+                        if ( !rDoc.IsTabProtected(rTab) )
+                        {
+                            ScUndoTabColorInfo aTabColorInfo(rTab);
+                            aTabColorInfo.maNewTabBgColor = aSelectedColor;
+                            pTabColorList->push_back(aTabColorInfo);
+                        }
+                    }
+                    bDone = SetTabBgColor( *pTabColorList );
+                }
+                else
+                {
+                    bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); 
//ScViewFunc.SetTabBgColor
+                }
+
+                if ( bDone )
+                {
+                    rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
+                    rReq.Done();
+                }
+                else
+                {
+                    if( rReq.IsAPI() )
+                    {
+#if HAVE_FEATURE_SCRIPTING
+                        StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED );
+#endif
+                    }
+                }
+            }
+        }
+    }
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 9aedbd5bfdb5dbad49fb448eaa34ba7db23805cb
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jan 24 12:06:44 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jan 25 07:01:02 2024 +0100

    split out append and rename table logic from ScTabViewShell::ExecuteTable
    
    Change-Id: Iab2ab8d4fcd8ed11d16701bc1319e32931c73ced
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162509
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index 1f8fe640fcd3..1191669f09c7 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -458,6 +458,7 @@ private:
     void DoMoveTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScMoveTableDlg>& pDlg );
     void ExecuteInsertTable( SfxRequest& rReq );
     void DoInsertTableFromDialog( SfxRequest& rReq, const 
VclPtr<AbstractScInsertTableDlg>& pDlg );
+    void ExecuteAppendOrRenameTable( SfxRequest& rReq );
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index a94640450a26..dd64c9e14dd1 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -198,126 +198,7 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                 //  FID_TAB_RENAME      - "name"-property for basic
                 //  equal execute, but MENU_RENAME may be disabled inside 
GetState
 
-                if ( nSlot == FID_TAB_MENU_RENAME )
-                    nSlot = FID_TAB_RENAME;             // equal execute
-
-                SCTAB nTabNr = rViewData.GetTabNo();
-                ScMarkData& rMark = rViewData.GetMarkData();
-                SCTAB nTabSelCount = rMark.GetSelectCount();
-
-                if ( !rDoc.IsDocEditable() )
-                    break; // everything locked
-
-                if ( nSlot != FID_TAB_APPEND &&
-                        ( rDoc.IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
-                    break; // no rename
-
-                if( pReqArgs != nullptr )
-                {
-                    bool        bDone   = false;
-                    const SfxPoolItem* pItem;
-                    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();
-
-                    switch ( nSlot )
-                    {
-                        case FID_TAB_APPEND:
-                            bDone = AppendTable( aName );
-                            break;
-                        case FID_TAB_RENAME:
-                            bDone = RenameTable( aName, nTabNr );
-                            break;
-                    }
-
-                    if( bDone )
-                    {
-                        rReq.Done( *pReqArgs );
-                    }
-                }
-                else
-                {
-                    sal_uInt16      nRet    = RET_OK;
-                    bool        bDone   = false;
-                    OUString      aErrMsg ( ScResId( STR_INVALIDTABNAME ) );
-                    OUString aName;
-                    OUString      aDlgTitle;
-                    OUString sHelpId;
-
-                    switch ( nSlot )
-                    {
-                        case FID_TAB_APPEND:
-                            aDlgTitle = ScResId(SCSTR_APDTABLE);
-                            rDoc.CreateValidTabName( aName );
-                            sHelpId = HID_SC_APPEND_NAME;
-                            break;
-
-                        case FID_TAB_RENAME:
-                            aDlgTitle = ScResId(SCSTR_RENAMETAB);
-                            rDoc.GetName( rViewData.GetTabNo(), aName );
-                            sHelpId = HID_SC_RENAME_NAME;
-                            break;
-                    }
-
-                    ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
-
-                    ScopedVclPtr<AbstractScStringInputDlg> 
pDlg(pFact->CreateScStringInputDlg(
-                        GetFrameWeld(), aDlgTitle, ScResId(SCSTR_NAME),
-                        aName, 
GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
-                        sHelpId));
-
-
-                    while ( !bDone && nRet == RET_OK )
-                    {
-                        nRet = pDlg->Execute();
-
-                        if ( nRet == RET_OK )
-                        {
-                            aName = pDlg->GetInputString();
-
-                            switch ( nSlot )
-                            {
-                                case FID_TAB_APPEND:
-                                    bDone = AppendTable( aName );
-                                    break;
-                                case FID_TAB_RENAME:
-                                    bDone = RenameTable( aName, nTabNr );
-                                    break;
-                            }
-
-                            if ( bDone )
-                            {
-                                rReq.AppendItem( SfxStringItem( nSlot, aName ) 
);
-                                rReq.Done();
-                            }
-                            else
-                            {
-                                if( rReq.IsAPI() )
-                                {
-#if HAVE_FEATURE_SCRIPTING
-                                    StarBASIC::Error( 
ERRCODE_BASIC_SETPROP_FAILED ); // XXX error handling???
-#endif
-                                }
-                                else
-                                {
-                                    std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(),
-                                                                              
VclMessageType::Warning, VclButtonsType::Ok, aErrMsg));
-                                    nRet = xBox->run();
-                                }
-                            }
-                        }
-                    }
-                }
+                ExecuteAppendOrRenameTable(rReq);
             }
             break;
 
@@ -1258,4 +1139,132 @@ void ScTabViewShell::DoMoveTableFromDialog( SfxRequest& 
rReq, const VclPtr<Abstr
     }
 }
 
+void ScTabViewShell::ExecuteAppendOrRenameTable(SfxRequest& rReq)
+{
+    ScViewData& rViewData   = GetViewData();
+    ScDocument& rDoc        = rViewData.GetDocument();
+    sal_uInt16  nSlot       = rReq.GetSlot();
+    const SfxItemSet* pReqArgs = rReq.GetArgs();
+
+    if ( nSlot == FID_TAB_MENU_RENAME )
+        nSlot = FID_TAB_RENAME;             // equal execute
+
+    SCTAB nTabNr = rViewData.GetTabNo();
+    ScMarkData& rMark = rViewData.GetMarkData();
+    SCTAB nTabSelCount = rMark.GetSelectCount();
+
+    if ( !rDoc.IsDocEditable() )
+        return; // everything locked
+
+    if ( nSlot != FID_TAB_APPEND &&
+            ( rDoc.IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
+        return; // no rename
+
+    if( pReqArgs != nullptr )
+    {
+        bool        bDone   = false;
+        const SfxPoolItem* pItem;
+        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();
+
+        switch ( nSlot )
+        {
+            case FID_TAB_APPEND:
+                bDone = AppendTable( aName );
+                break;
+            case FID_TAB_RENAME:
+                bDone = RenameTable( aName, nTabNr );
+                break;
+        }
+
+        if( bDone )
+        {
+            rReq.Done( *pReqArgs );
+        }
+    }
+    else
+    {
+        OUString aErrMsg ( ScResId( STR_INVALIDTABNAME ) );
+        OUString aName;
+        OUString aDlgTitle;
+        OUString sHelpId;
+
+        switch ( nSlot )
+        {
+            case FID_TAB_APPEND:
+                aDlgTitle = ScResId(SCSTR_APDTABLE);
+                rDoc.CreateValidTabName( aName );
+                sHelpId = HID_SC_APPEND_NAME;
+                break;
+
+            case FID_TAB_RENAME:
+                aDlgTitle = ScResId(SCSTR_RENAMETAB);
+                rDoc.GetName( rViewData.GetTabNo(), aName );
+                sHelpId = HID_SC_RENAME_NAME;
+                break;
+        }
+
+        ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
+
+        ScopedVclPtr<AbstractScStringInputDlg> 
pDlg(pFact->CreateScStringInputDlg(
+            GetFrameWeld(), aDlgTitle, ScResId(SCSTR_NAME),
+            aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
+            sHelpId));
+
+        sal_uInt16 nRet    = RET_OK;
+        bool     bDone   = false;
+        while ( !bDone && nRet == RET_OK )
+        {
+            nRet = pDlg->Execute();
+
+            if ( nRet == RET_OK )
+            {
+                aName = pDlg->GetInputString();
+
+                switch ( nSlot )
+                {
+                    case FID_TAB_APPEND:
+                        bDone = AppendTable( aName );
+                        break;
+                    case FID_TAB_RENAME:
+                        bDone = RenameTable( aName, nTabNr );
+                        break;
+                }
+
+                if ( bDone )
+                {
+                    rReq.AppendItem( SfxStringItem( nSlot, aName ) );
+                    rReq.Done();
+                }
+                else
+                {
+                    if( rReq.IsAPI() )
+                    {
+#if HAVE_FEATURE_SCRIPTING
+                        StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); // 
XXX error handling???
+#endif
+                    }
+                    else
+                    {
+                        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(GetFrameWeld(),
+                                                                  
VclMessageType::Warning, VclButtonsType::Ok, aErrMsg));
+                        nRet = xBox->run();
+                    }
+                }
+            }
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to