diff options
author | Abhilash Singh <abhilash300singh@gmail.com> | 2017-01-22 14:42:15 +0530 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-01-28 00:08:47 +0000 |
commit | 413232229cbfd9d49ce9d1cdbb6b6e2dbe83af38 (patch) | |
tree | d53892366680bec211e7a74e2b4633b8735c06b2 /sc | |
parent | 3084e8f5b12e865d565278168c27c7af15282191 (diff) |
tdf#86214 User isn't warned entering a cell address not allowed
Refactored ScRangeData::IsNameValid
Change-Id: I74dd5830d13e48e8fe9a5180a819be4acdc9a1db
Reviewed-on: https://gerrit.libreoffice.org/33386
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/globstr.hrc | 4 | ||||
-rw-r--r-- | sc/inc/rangenam.hxx | 10 | ||||
-rw-r--r-- | sc/source/core/tool/rangenam.cxx | 12 | ||||
-rw-r--r-- | sc/source/ui/app/inputwin.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/dbgui/dbnamdlg.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/namedefdlg.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namedefdlg.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namedlg.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/src/globstr.src | 4 | ||||
-rw-r--r-- | sc/source/ui/vba/vbanames.cxx | 4 | ||||
-rw-r--r-- | sc/uiconfig/scalc/ui/definename.ui | 2 |
11 files changed, 40 insertions, 16 deletions
diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc index 68d48d9e7da5..3b3cef607032 100644 --- a/sc/inc/globstr.hrc +++ b/sc/inc/globstr.hrc @@ -712,7 +712,9 @@ #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 diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx index 19c288b8ac87..737c5e6b01af 100644 --- a/sc/inc/rangenam.hxx +++ b/sc/inc/rangenam.hxx @@ -59,6 +59,13 @@ public: AbsPos = 0x0080 }; + enum IsNameValidType + { + NAME_VALID, + NAME_INVALID_CELL_REF, + NAME_INVALID_BAD_STRING + }; + private: OUString aName; OUString aUpperName; // #i62977# for faster searching (aName is never modified after ctor) @@ -154,7 +161,8 @@ public: void ValidateTabRefs(); 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; SCCOL GetMaxCol() const; diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx index d7fba04de639..1728460f9767 100644 --- a/sc/source/core/tool/rangenam.cxx +++ b/sc/source/core/tool/rangenam.cxx @@ -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 * ScfTools::ConvertToScDefinedName needs to be changed too. */ sal_Char a('.'); if (rName.indexOf(a) != -1) - return false; + return NAME_INVALID_BAD_STRING; sal_Int32 nPos = 0; sal_Int32 nLen = rName.getLength(); if ( !nLen || !ScCompiler::IsCharFlagAllConventions( rName, nPos++, ScCharFlags::CharName ) ) - return false; + return NAME_INVALID_BAD_STRING; while ( nPos < nLen ) { if ( !ScCompiler::IsCharFlagAllConventions( rName, nPos++, ScCharFlags::Name ) ) - return false; + return NAME_INVALID_BAD_STRING; } ScAddress aAddr; ScRange aRange; @@ -500,10 +500,10 @@ bool ScRangeData::IsNameValid( const OUString& rName, ScDocument* pDoc ) if (aRange.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 diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx index 9239398829aa..9f940982a7fc 100644 --- a/sc/source/ui/app/inputwin.cxx +++ b/sc/source/ui/app/inputwin.cxx @@ -1991,7 +1991,7 @@ static ScNameInputType lcl_GetInputType( const OUString& rText ) eRet = SC_NAME_INPUT_ROW; else if ( pDoc->GetTable( rText, nNameTab ) ) 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 ) eRet = SC_NAME_INPUT_DEFINE; diff --git a/sc/source/ui/dbgui/dbnamdlg.cxx b/sc/source/ui/dbgui/dbnamdlg.cxx index 8c917580587c..45967294d460 100644 --- a/sc/source/ui/dbgui/dbnamdlg.cxx +++ b/sc/source/ui/dbgui/dbnamdlg.cxx @@ -416,7 +416,7 @@ IMPL_LINK_NOARG(ScDbNameDlg, AddBtnHdl, Button*, void) 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 ScRange aTmpRange; diff --git a/sc/source/ui/inc/namedefdlg.hxx b/sc/source/ui/inc/namedefdlg.hxx index 3a036a91a2b3..447a762af4f5 100644 --- a/sc/source/ui/inc/namedefdlg.hxx +++ b/sc/source/ui/inc/namedefdlg.hxx @@ -50,6 +50,7 @@ private: OUString maStrInfoDefault; const OUString maGlobalNameStr; const OUString maErrInvalidNameStr; + const OUString maErrInvalidNameCellRefStr; const OUString maErrNameInUse; //hack to call this dialog from Manage Names diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx index aa9642758f61..23a3c1a43db8 100644 --- a/sc/source/ui/namedlg/namedefdlg.cxx +++ b/sc/source/ui/namedlg/namedefdlg.cxx @@ -36,6 +36,7 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* p maGlobalNameStr ( ScGlobal::GetRscString(STR_GLOBAL_SCOPE) ), maErrInvalidNameStr( ScGlobal::GetRscString(STR_ERR_NAME_INVALID)), + maErrInvalidNameCellRefStr( ScGlobal::GetRscString(STR_ERR_NAME_INVALID_CELL_REF)), maErrNameInUse ( ScGlobal::GetRscString(STR_ERR_NAME_EXISTS)), maRangeMap( aRangeMap ) { @@ -150,6 +151,7 @@ bool ScNameDefDlg::IsNameValid() pRangeName = maRangeMap.find(aScope)->second; } + ScRangeData::IsNameValidType eType; m_pFtInfo->SetControlBackground(GetSettings().GetStyleSettings().GetDialogColor()); if ( aName.isEmpty() ) { @@ -157,10 +159,17 @@ bool ScNameDefDlg::IsNameValid() m_pFtInfo->SetText(maStrInfoDefault); 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->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(); return false; } diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx index 5a7a8f9df6dc..abf1f5756258 100644 --- a/sc/source/ui/namedlg/namedlg.cxx +++ b/sc/source/ui/namedlg/namedlg.cxx @@ -278,7 +278,7 @@ bool ScNameDlg::IsNameValid() 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->SetText(maErrInvalidNameStr); diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src index b11808fc0a89..dbbd3e48aebe 100644 --- a/sc/source/ui/src/globstr.src +++ b/sc/source/ui/src/globstr.src @@ -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)?"; }; + 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: */ diff --git a/sc/source/ui/vba/vbanames.cxx b/sc/source/ui/vba/vbanames.cxx index f9f1e32b0472..c366521f81e0 100644 --- a/sc/source/ui/vba/vbanames.cxx +++ b/sc/source/ui/vba/vbanames.cxx @@ -101,7 +101,7 @@ ScVbaNames::Add( const css::uno::Any& Name , NameLocal >>= sName; if ( !sName.isEmpty() ) { - if ( !ScRangeData::IsNameValid( sName , getScDocument() ) ) + if ( ScRangeData::IsNameValid( sName , getScDocument() ) != ScRangeData::NAME_VALID ) { OUString sResult ; sal_Int32 nToken = 0; @@ -112,7 +112,7 @@ ScVbaNames::Add( const css::uno::Any& Name , else sResult = sName.copy( nIndex ); sName = sResult ; - if ( !ScRangeData::IsNameValid( sName , getScDocument() ) ) + if ( ScRangeData::IsNameValid( sName , getScDocument() ) != ScRangeData::NAME_VALID ) throw uno::RuntimeException( "This Name is not valid ." ); } } diff --git a/sc/uiconfig/scalc/ui/definename.ui b/sc/uiconfig/scalc/ui/definename.ui index 25e9bf241348..01a6a69210fe 100644 --- a/sc/uiconfig/scalc/ui/definename.ui +++ b/sc/uiconfig/scalc/ui/definename.ui @@ -145,7 +145,7 @@ <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="invisible_char">•</property> - <property name="width_chars">42</property> + <property name="width_chars">50</property> </object> <packing> <property name="expand">False</property> |