Kaydet (Commit) 41323222 authored tarafından Abhilash Singh's avatar Abhilash Singh Kaydeden (comit) Eike Rathke

tdf#86214 User isn't warned entering a cell address not allowed

Refactored ScRangeData::IsNameValid

Change-Id: I74dd5830d13e48e8fe9a5180a819be4acdc9a1db
Reviewed-on: https://gerrit.libreoffice.org/33386Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 3084e8f5
...@@ -712,7 +712,9 @@ ...@@ -712,7 +712,9 @@
#define STR_QUERY_PIVOTTABLE_DELTAB 545 #define STR_QUERY_PIVOTTABLE_DELTAB 545
#define SC_GLOBSTR_STR_COUNT 546 /**< the count of permanently resident strings */ #define STR_ERR_NAME_INVALID_CELL_REF 546
#define SC_GLOBSTR_STR_COUNT 547 /**< the count of permanently resident strings */
#endif #endif
......
...@@ -59,6 +59,13 @@ public: ...@@ -59,6 +59,13 @@ public:
AbsPos = 0x0080 AbsPos = 0x0080
}; };
enum IsNameValidType
{
NAME_VALID,
NAME_INVALID_CELL_REF,
NAME_INVALID_BAD_STRING
};
private: private:
OUString aName; OUString aName;
OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor) OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor)
...@@ -154,7 +161,8 @@ public: ...@@ -154,7 +161,8 @@ public:
void ValidateTabRefs(); void ValidateTabRefs();
static void MakeValidName( OUString& rName ); static void MakeValidName( OUString& rName );
SC_DLLPUBLIC static bool IsNameValid( const OUString& rName, ScDocument* pDoc );
SC_DLLPUBLIC static IsNameValidType IsNameValid( const OUString& rName, ScDocument* pDoc );
SCROW GetMaxRow() const; SCROW GetMaxRow() const;
SCCOL GetMaxCol() const; SCCOL GetMaxCol() const;
......
...@@ -474,21 +474,21 @@ void ScRangeData::MakeValidName( OUString& rName ) ...@@ -474,21 +474,21 @@ void ScRangeData::MakeValidName( OUString& rName )
} }
} }
bool ScRangeData::IsNameValid( const OUString& rName, ScDocument* pDoc ) ScRangeData::IsNameValidType ScRangeData::IsNameValid( const OUString& rName, ScDocument* pDoc )
{ {
/* XXX If changed, sc/source/filter/ftools/ftools.cxx /* XXX If changed, sc/source/filter/ftools/ftools.cxx
* ScfTools::ConvertToScDefinedName needs to be changed too. */ * ScfTools::ConvertToScDefinedName needs to be changed too. */
sal_Char a('.'); sal_Char a('.');
if (rName.indexOf(a) != -1) if (rName.indexOf(a) != -1)
return false; return NAME_INVALID_BAD_STRING;
sal_Int32 nPos = 0; sal_Int32 nPos = 0;
sal_Int32 nLen = rName.getLength(); sal_Int32 nLen = rName.getLength();
if ( !nLen || !ScCompiler::IsCharFlagAllConventions( rName, nPos++, ScCharFlags::CharName ) ) if ( !nLen || !ScCompiler::IsCharFlagAllConventions( rName, nPos++, ScCharFlags::CharName ) )
return false; return NAME_INVALID_BAD_STRING;
while ( nPos < nLen ) while ( nPos < nLen )
{ {
if ( !ScCompiler::IsCharFlagAllConventions( rName, nPos++, ScCharFlags::Name ) ) if ( !ScCompiler::IsCharFlagAllConventions( rName, nPos++, ScCharFlags::Name ) )
return false; return NAME_INVALID_BAD_STRING;
} }
ScAddress aAddr; ScAddress aAddr;
ScRange aRange; ScRange aRange;
...@@ -500,10 +500,10 @@ bool ScRangeData::IsNameValid( const OUString& rName, ScDocument* pDoc ) ...@@ -500,10 +500,10 @@ bool ScRangeData::IsNameValid( const OUString& rName, ScDocument* pDoc )
if (aRange.Parse(rName, pDoc, details) != ScRefFlags::ZERO || if (aRange.Parse(rName, pDoc, details) != ScRefFlags::ZERO ||
aAddr.Parse(rName, pDoc, details) != ScRefFlags::ZERO ) aAddr.Parse(rName, pDoc, details) != ScRefFlags::ZERO )
{ {
return false; return NAME_INVALID_CELL_REF;
} }
} }
return true; return NAME_VALID;
} }
SCROW ScRangeData::GetMaxRow() const SCROW ScRangeData::GetMaxRow() const
......
...@@ -1991,7 +1991,7 @@ static ScNameInputType lcl_GetInputType( const OUString& rText ) ...@@ -1991,7 +1991,7 @@ static ScNameInputType lcl_GetInputType( const OUString& rText )
eRet = SC_NAME_INPUT_ROW; eRet = SC_NAME_INPUT_ROW;
else if ( pDoc->GetTable( rText, nNameTab ) ) else if ( pDoc->GetTable( rText, nNameTab ) )
eRet = SC_NAME_INPUT_SHEET; eRet = SC_NAME_INPUT_SHEET;
else if ( ScRangeData::IsNameValid( rText, pDoc ) ) // nothing found, create new range? else if ( ScRangeData::IsNameValid( rText, pDoc ) == ScRangeData::NAME_VALID ) // nothing found, create new range?
{ {
if ( rViewData.GetSimpleArea( aRange ) == SC_MARK_SIMPLE ) if ( rViewData.GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
eRet = SC_NAME_INPUT_DEFINE; eRet = SC_NAME_INPUT_DEFINE;
......
...@@ -416,7 +416,7 @@ IMPL_LINK_NOARG(ScDbNameDlg, AddBtnHdl, Button*, void) ...@@ -416,7 +416,7 @@ IMPL_LINK_NOARG(ScDbNameDlg, AddBtnHdl, Button*, void)
if ( !aNewName.isEmpty() && !aNewArea.isEmpty() ) if ( !aNewName.isEmpty() && !aNewArea.isEmpty() )
{ {
if ( ScRangeData::IsNameValid( aNewName, pDoc ) && aNewName != STR_DB_LOCAL_NONAME ) if ( ScRangeData::IsNameValid( aNewName, pDoc ) == ScRangeData::NAME_VALID && aNewName != STR_DB_LOCAL_NONAME )
{ {
// weil jetzt editiert werden kann, muss erst geparst werden // weil jetzt editiert werden kann, muss erst geparst werden
ScRange aTmpRange; ScRange aTmpRange;
......
...@@ -50,6 +50,7 @@ private: ...@@ -50,6 +50,7 @@ private:
OUString maStrInfoDefault; OUString maStrInfoDefault;
const OUString maGlobalNameStr; const OUString maGlobalNameStr;
const OUString maErrInvalidNameStr; const OUString maErrInvalidNameStr;
const OUString maErrInvalidNameCellRefStr;
const OUString maErrNameInUse; const OUString maErrNameInUse;
//hack to call this dialog from Manage Names //hack to call this dialog from Manage Names
......
...@@ -36,6 +36,7 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* p ...@@ -36,6 +36,7 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* p
maGlobalNameStr ( ScGlobal::GetRscString(STR_GLOBAL_SCOPE) ), maGlobalNameStr ( ScGlobal::GetRscString(STR_GLOBAL_SCOPE) ),
maErrInvalidNameStr( ScGlobal::GetRscString(STR_ERR_NAME_INVALID)), maErrInvalidNameStr( ScGlobal::GetRscString(STR_ERR_NAME_INVALID)),
maErrInvalidNameCellRefStr( ScGlobal::GetRscString(STR_ERR_NAME_INVALID_CELL_REF)),
maErrNameInUse ( ScGlobal::GetRscString(STR_ERR_NAME_EXISTS)), maErrNameInUse ( ScGlobal::GetRscString(STR_ERR_NAME_EXISTS)),
maRangeMap( aRangeMap ) maRangeMap( aRangeMap )
{ {
...@@ -150,6 +151,7 @@ bool ScNameDefDlg::IsNameValid() ...@@ -150,6 +151,7 @@ bool ScNameDefDlg::IsNameValid()
pRangeName = maRangeMap.find(aScope)->second; pRangeName = maRangeMap.find(aScope)->second;
} }
ScRangeData::IsNameValidType eType;
m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor()); m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor());
if ( aName.isEmpty() ) if ( aName.isEmpty() )
{ {
...@@ -157,10 +159,17 @@ bool ScNameDefDlg::IsNameValid() ...@@ -157,10 +159,17 @@ bool ScNameDefDlg::IsNameValid()
m_pFtInfo->SetText(maStrInfoDefault); m_pFtInfo->SetText(maStrInfoDefault);
return false; return false;
} }
else if (!ScRangeData::IsNameValid( aName, mpDoc )) else if ((eType = ScRangeData::IsNameValid( aName, mpDoc )) != ScRangeData::NAME_VALID)
{ {
m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor()); m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor());
m_pFtInfo->SetText(maErrInvalidNameStr); if (eType == ScRangeData::NAME_INVALID_BAD_STRING)
{
m_pFtInfo->SetText(maErrInvalidNameStr);
}
else if (eType == ScRangeData::NAME_INVALID_CELL_REF)
{
m_pFtInfo->SetText(maErrInvalidNameCellRefStr);
}
m_pBtnAdd->Disable(); m_pBtnAdd->Disable();
return false; return false;
} }
......
...@@ -278,7 +278,7 @@ bool ScNameDlg::IsNameValid() ...@@ -278,7 +278,7 @@ bool ScNameDlg::IsNameValid()
ScRangeName* pRangeName = GetRangeName( aScope ); ScRangeName* pRangeName = GetRangeName( aScope );
if (!ScRangeData::IsNameValid( aName, mpDoc )) if (ScRangeData::IsNameValid( aName, mpDoc ) != ScRangeData::NAME_VALID)
{ {
m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor()); m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetHighlightColor());
m_pFtInfo->SetText(maErrInvalidNameStr); m_pFtInfo->SetText(maErrInvalidNameStr);
......
...@@ -2113,6 +2113,10 @@ Resource RID_GLOBSTR ...@@ -2113,6 +2113,10 @@ Resource RID_GLOBSTR
{ {
Text [ en-US ] = "The selected sheet(s) contain source data of related pivot tables that will be lost. Are you sure you want to delete the selected sheet(s)?"; Text [ en-US ] = "The selected sheet(s) contain source data of related pivot tables that will be lost. Are you sure you want to delete the selected sheet(s)?";
}; };
String STR_ERR_NAME_INVALID_CELL_REF
{
Text [ en-US ] = "Invalid name. Reference to a cell, or a range of cells not allowed.";
};
}; };
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -101,7 +101,7 @@ ScVbaNames::Add( const css::uno::Any& Name , ...@@ -101,7 +101,7 @@ ScVbaNames::Add( const css::uno::Any& Name ,
NameLocal >>= sName; NameLocal >>= sName;
if ( !sName.isEmpty() ) if ( !sName.isEmpty() )
{ {
if ( !ScRangeData::IsNameValid( sName , getScDocument() ) ) if ( ScRangeData::IsNameValid( sName , getScDocument() ) != ScRangeData::NAME_VALID )
{ {
OUString sResult ; OUString sResult ;
sal_Int32 nToken = 0; sal_Int32 nToken = 0;
...@@ -112,7 +112,7 @@ ScVbaNames::Add( const css::uno::Any& Name , ...@@ -112,7 +112,7 @@ ScVbaNames::Add( const css::uno::Any& Name ,
else else
sResult = sName.copy( nIndex ); sResult = sName.copy( nIndex );
sName = sResult ; sName = sResult ;
if ( !ScRangeData::IsNameValid( sName , getScDocument() ) ) if ( ScRangeData::IsNameValid( sName , getScDocument() ) != ScRangeData::NAME_VALID )
throw uno::RuntimeException( "This Name is not valid ." ); throw uno::RuntimeException( "This Name is not valid ." );
} }
} }
......
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="invisible_char"></property> <property name="invisible_char"></property>
<property name="width_chars">42</property> <property name="width_chars">50</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment