sc/inc/document.hxx                          |    3 ++-
 sc/qa/uitest/range_name/create_range_name.py |    3 ++-
 sc/source/core/data/documen3.cxx             |   13 ++++++++++---
 sc/source/ui/app/inputhdl.cxx                |    9 ++++++++-
 sc/source/ui/app/inputwin.cxx                |    7 ++-----
 sc/source/ui/inc/inputwin.hxx                |    2 ++
 6 files changed, 26 insertions(+), 11 deletions(-)

New commits:
commit 65cba409936d133aa05f9934db28bd2555a38676
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Tue Mar 30 01:50:38 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Mar 30 14:02:12 2021 +0200

    Related: tdf#137577 Display (sheetname) with sheet-local names in Name Box
    
    ... if current cell selection matches a sheet-local name, so it
    can be differentiated from an identically named global name. Which
    is already the case when listing and picking a name from the list.
    
    Made it necessary to adapt an UI test checking for Name Box
    content.
    
    Change-Id: Ia90b8961c3ae213cf7bb53f3b610a65805bba6b9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113330
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 72f84cd9ba9b..0d3078327390 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -820,7 +820,8 @@ public:
     void                         RefreshDirtyTableColumnNames();
     SC_DLLPUBLIC sc::ExternalDataMapper& GetExternalDataMapper();
 
-    SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, 
OUString* pName ) const;
+    SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, 
OUString* pName,
+                                                     bool* pSheetLocal = 
nullptr ) const;
 
     SC_DLLPUBLIC bool                  HasPivotTable() const;
     SC_DLLPUBLIC ScDPCollection*       GetDPCollection();
diff --git a/sc/qa/uitest/range_name/create_range_name.py 
b/sc/qa/uitest/range_name/create_range_name.py
index e4fab4e4329d..989532bf5643 100644
--- a/sc/qa/uitest/range_name/create_range_name.py
+++ b/sc/qa/uitest/range_name/create_range_name.py
@@ -114,7 +114,8 @@ class CreateRangeNameTest(UITestCase):
 
         # tdf#67007: Without the fix in place, this test would have failed with
         # AssertionError: 'localRangeName' != 'A1'
-        self.assertEqual('localRangeName', 
get_state_as_dict(xPosWindow)['Text'])
+        # Additionally, newly check a sheet-local scoped name has " 
(sheetname)" appended.
+        self.assertEqual('localRangeName (Sheet1)', 
get_state_as_dict(xPosWindow)['Text'])
 
         gridwin = calcDoc.getChild("grid_window")
         enter_text_to_cell(gridwin, "A1", "1")
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 798fa467948b..6f6a9a6f27d6 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -234,7 +234,7 @@ bool ScDocument::InsertNewRangeName( SCTAB nTab, const 
OUString& rName, const Sc
     return pLocalNames->insert(pName);
 }
 
-const ScRangeData* ScDocument::GetRangeAtBlock( const ScRange& rBlock, 
OUString* pName ) const
+const ScRangeData* ScDocument::GetRangeAtBlock( const ScRange& rBlock, 
OUString* pName, bool* pSheetLocal ) const
 {
     const ScRangeData* pData = nullptr;
     if (rBlock.aStart.Tab() == rBlock.aEnd.Tab())
@@ -247,6 +247,8 @@ const ScRangeData* ScDocument::GetRangeAtBlock( const 
ScRange& rBlock, OUString*
             {
                 if (pName)
                     *pName = pData->GetName();
+                if (pSheetLocal)
+                    *pSheetLocal = true;
                 return pData;
             }
         }
@@ -254,8 +256,13 @@ const ScRangeData* ScDocument::GetRangeAtBlock( const 
ScRange& rBlock, OUString*
     if ( pRangeName )
     {
         pData = pRangeName->findByRange( rBlock );
-        if (pData && pName)
-            *pName = pData->GetName();
+        if (pData)
+        {
+            if (pName)
+                *pName = pData->GetName();
+            if (pSheetLocal)
+                *pSheetLocal = false;
+        }
     }
     return pData;
 }
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 540d342728ac..109035c62a82 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -4103,13 +4103,14 @@ void ScInputHandler::NotifyChange( const 
ScInputHdlState* pState,
                 if ( pInputWin || comphelper::LibreOfficeKit::isActive())      
                  // Named range input
                 {
                     OUString aPosStr;
+                    bool bSheetLocal = false;
                     const ScAddress::Details aAddrDetails( rDoc, aCursorPos );
 
                     // Is the range a name?
                     //! Find by Timer?
                     if ( pActiveViewSh )
                         pActiveViewSh->GetViewData().GetDocument().
-                            GetRangeAtBlock( ScRange( rSPos, rEPos ), &aPosStr 
);
+                            GetRangeAtBlock( ScRange( rSPos, rEPos ), 
&aPosStr, &bSheetLocal);
 
                     if ( aPosStr.isEmpty() )           // Not a name -> format
                     {
@@ -4125,6 +4126,12 @@ void ScInputHandler::NotifyChange( const 
ScInputHdlState* pState,
                         else
                             aPosStr = aCursorPos.Format(ScRefFlags::VALID | 
nFlags, &rDoc, aAddrDetails);
                     }
+                    else if (bSheetLocal)
+                    {
+                        OUString aName;
+                        if (rDoc.GetName( rSPos.Tab(), aName))
+                            aPosStr = ScPosWnd::createLocalRangeName( aPosStr, 
aName);
+                    }
 
                     if (pInputWin)
                     {
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index c7beb52ed9e6..3473ffc48109 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -2185,15 +2185,12 @@ void ScPosWnd::SetPos( const OUString& rPosStr )
     }
 }
 
-namespace {
-
-OUString createLocalRangeName(std::u16string_view rName, std::u16string_view 
rTableName)
+// static
+OUString ScPosWnd::createLocalRangeName(std::u16string_view rName, 
std::u16string_view rTableName)
 {
     return OUString::Concat(rName) + " (" + rTableName + ")";
 }
 
-}
-
 void ScPosWnd::FillRangeNames()
 {
     m_xWidget->clear();
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index aadad8bbf71f..4767d09e9db3 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -177,6 +177,8 @@ public:
     void            SetPos( const OUString& rPosStr );        // Displayed Text
     void            SetFormulaMode( bool bSet );
 
+    static OUString createLocalRangeName(std::u16string_view rName, 
std::u16string_view rTableName);
+
 private:
     DECL_LINK(OnAsyncGetFocus, void*, void);
     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to