diff options
author | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2023-11-09 16:18:35 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2023-11-16 08:03:32 +0100 |
commit | 1f874d384228867ee450d3e1d53c821519b51722 (patch) | |
tree | 5888576735cea126c251b9b2822cb193ffa7cc4c /cui/source | |
parent | 7f79b0caf194ff9d7dfa2f85379a5c752c905476 (diff) |
expert config: Proper editing support for numbers
Change-Id: Ib97e027cedfdf2c5bb3c956aeee75af25198e498
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159355
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
Diffstat (limited to 'cui/source')
-rw-r--r-- | cui/source/dialogs/dlgname.cxx | 22 | ||||
-rw-r--r-- | cui/source/options/optaboutconfig.cxx | 144 |
2 files changed, 115 insertions, 51 deletions
diff --git a/cui/source/dialogs/dlgname.cxx b/cui/source/dialogs/dlgname.cxx index a1f6283d92b5..a96b59290bbd 100644 --- a/cui/source/dialogs/dlgname.cxx +++ b/cui/source/dialogs/dlgname.cxx @@ -60,6 +60,28 @@ IMPL_LINK_NOARG(SvxNameDialog, ModifyHdl, weld::Entry&, void) m_xEdtName->set_tooltip_text(rTip); } +SvxNumberDialog::SvxNumberDialog(weld::Window* pParent, const OUString& rDesc, sal_Int64 nValue, + sal_Int64 nMin, sal_Int64 nMax) + : GenericDialogController(pParent, "cui/ui/numberdialog.ui", "NumberDialog") + , m_xEdtNumber(m_xBuilder->weld_spin_button("number_spinbtn")) + , m_xFtDescription(m_xBuilder->weld_label("description_label")) +{ + m_xFtDescription->set_label(rDesc); + m_xEdtNumber->set_min(nMin); + m_xEdtNumber->set_max(nMax); + m_xEdtNumber->set_value(nValue); +} + +SvxDecimalNumberDialog::SvxDecimalNumberDialog(weld::Window* pParent, const OUString& rDesc, + double fValue) + : GenericDialogController(pParent, "cui/ui/numberdialog.ui", "NumberDialog") + , m_xEdtNumber(m_xBuilder->weld_formatted_spin_button("number_spinbtn")) + , m_xFtDescription(m_xBuilder->weld_label("description_label")) +{ + m_xFtDescription->set_label(rDesc); + m_xEdtNumber->GetFormatter().SetValue(fValue); +} + // #i68101# // Dialog for editing Object Name // plus uniqueness-callback-linkHandler diff --git a/cui/source/options/optaboutconfig.cxx b/cui/source/options/optaboutconfig.cxx index bdc51afdea51..11806faa8477 100644 --- a/cui/source/options/optaboutconfig.cxx +++ b/cui/source/options/optaboutconfig.cxx @@ -654,96 +654,138 @@ IMPL_LINK_NOARG( CuiAboutConfigTabPage, StandardHdl_Impl, weld::Button&, void ) { if( bOpenDialog ) { - SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); - aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); - if (aNameDialog.run() == RET_OK ) + if (sPropertyType == "short" || sPropertyType == "int" || sPropertyType == "long") { - OUString sNewValue = aNameDialog.GetName(); - bSaveChanges = true; - if ( sPropertyType == "short") + sal_Int64 nMin = sPropertyType == "short" + ? SAL_MIN_INT16 + : sPropertyType == "int" ? SAL_MIN_INT32 : SAL_MIN_INT64; + sal_Int64 nMax = sPropertyType == "short" + ? SAL_MAX_INT16 + : sPropertyType == "int" ? SAL_MAX_INT32 : SAL_MAX_INT64; + SvxNumberDialog aNumberDialog(m_pParent, sPropertyName, sDialogValue.toInt64(), + nMin, nMax); + if (aNumberDialog.run() == RET_OK) { - sal_Int16 nShort; - sal_Int32 nNumb = sNewValue.toInt32(); - - //if the value is 0 and length is not 1, there is something wrong - if( ( nNumb==0 && sNewValue.getLength()!=1 ) || nNumb > SAL_MAX_INT16 || nNumb < SAL_MIN_INT16) - throw uno::Exception("out of range short", nullptr); - nShort = static_cast<sal_Int16>(nNumb); - pProperty->Value <<= nShort; - } - else if( sPropertyType == "int" ) - { - sal_Int32 nLong = sNewValue.toInt32(); - if( nLong==0 && sNewValue.getLength()!=1) - throw uno::Exception("out of range int", nullptr); - pProperty->Value <<= nLong; - } - else if( sPropertyType == "long") - { - sal_Int64 nHyper = sNewValue.toInt64(); - if( nHyper==0 && sNewValue.getLength()!=1) - throw uno::Exception("out of range long", nullptr); - pProperty->Value <<= nHyper; + sal_Int64 nNewValue = aNumberDialog.GetNumber(); + if (sPropertyType == "short") + { + pProperty->Value <<= static_cast<sal_Int16>(nNewValue); + } + else if (sPropertyType == "int") + { + pProperty->Value <<= static_cast<sal_Int32>(nNewValue); + } + else if (sPropertyType == "long") + { + pProperty->Value <<= nNewValue; + } + bSaveChanges = true; + sDialogValue = OUString::number(nNewValue); } - else if( sPropertyType == "double") + } + else if( sPropertyType == "double") + { + SvxDecimalNumberDialog aNumberDialog(m_pParent, sPropertyName, sDialogValue.toDouble()); + if (aNumberDialog.run() == RET_OK) { - double nDoub = sNewValue.toDouble(); - if( nDoub ==0 && sNewValue.getLength()!=1) - throw uno::Exception("out of range double", nullptr); - pProperty->Value <<= nDoub; + double fNewValue = aNumberDialog.GetNumber(); + pProperty->Value <<= fNewValue; + bSaveChanges = true; + sDialogValue = OUString::number(fNewValue); } - else if( sPropertyType == "string" ) + } + else if( sPropertyType == "string" ) + { + SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); + aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); + if (aNameDialog.run() == RET_OK ) { - pProperty->Value <<= sNewValue; + sDialogValue = aNameDialog.GetName(); + pProperty->Value <<= sDialogValue; + bSaveChanges = true; } - else if( sPropertyType == "short-list" ) + } + else if( sPropertyType == "short-list" ) + { + SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); + aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); + if (aNameDialog.run() == RET_OK ) { + sDialogValue = aNameDialog.GetName(); //create string sequence from comma separated string //uno::Sequence< OUString > seqStr; - std::vector< OUString > seqStr = commaStringToSequence( sNewValue ); + std::vector< OUString > seqStr = commaStringToSequence( sDialogValue ); //create appropriate sequence with same size as string sequence uno::Sequence< sal_Int16 > seqShort( seqStr.size() ); //convert all strings to appropriate type std::transform(seqStr.begin(), seqStr.end(), seqShort.getArray(), - [](const auto& str) - { return static_cast<sal_Int16>(str.toInt32()); }); + [](const auto& str) + { return static_cast<sal_Int16>(str.toInt32()); }); pProperty->Value <<= seqShort; + bSaveChanges = true; } - else if( sPropertyType == "int-list" ) + + } + else if( sPropertyType == "int-list" ) + { + SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); + aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); + if (aNameDialog.run() == RET_OK ) { - std::vector< OUString > seqStrLong = commaStringToSequence( sNewValue ); + sDialogValue = aNameDialog.GetName(); + std::vector< OUString > seqStrLong = commaStringToSequence( sDialogValue ); uno::Sequence< sal_Int32 > seqLong( seqStrLong.size() ); std::transform(seqStrLong.begin(), seqStrLong.end(), seqLong.getArray(), [](const auto& str) { return str.toInt32(); }); pProperty->Value <<= seqLong; + bSaveChanges = true; } - else if( sPropertyType == "long-list" ) + } + else if( sPropertyType == "long-list" ) + { + SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); + aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); + if (aNameDialog.run() == RET_OK ) { - std::vector< OUString > seqStrHyper = commaStringToSequence( sNewValue ); + sDialogValue = aNameDialog.GetName(); + std::vector< OUString > seqStrHyper = commaStringToSequence( sDialogValue ); uno::Sequence< sal_Int64 > seqHyper( seqStrHyper.size() ); std::transform(seqStrHyper.begin(), seqStrHyper.end(), seqHyper.getArray(), [](const auto& str) { return str.toInt64(); }); pProperty->Value <<= seqHyper; + bSaveChanges = true; } - else if( sPropertyType == "double-list" ) + } + else if( sPropertyType == "double-list" ) + { + SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); + aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); + if (aNameDialog.run() == RET_OK ) { - std::vector< OUString > seqStrDoub = commaStringToSequence( sNewValue ); + sDialogValue = aNameDialog.GetName(); + std::vector< OUString > seqStrDoub = commaStringToSequence( sDialogValue ); uno::Sequence< double > seqDoub( seqStrDoub.size() ); std::transform(seqStrDoub.begin(), seqStrDoub.end(), seqDoub.getArray(), [](const auto& str) { return str.toDouble(); }); pProperty->Value <<= seqDoub; + bSaveChanges = true; } - else if( sPropertyType == "string-list" ) + } + else if( sPropertyType == "string-list" ) + { + SvxNameDialog aNameDialog(m_pParent, sDialogValue, sPropertyName); + aNameDialog.SetCheckNameHdl( LINK( this, CuiAboutConfigTabPage, ValidNameHdl ) ); + if (aNameDialog.run() == RET_OK ) { - pProperty->Value <<= comphelper::containerToSequence( commaStringToSequence( sNewValue )); + sDialogValue = aNameDialog.GetName(); + pProperty->Value <<= comphelper::containerToSequence( commaStringToSequence( sDialogValue )); + bSaveChanges = true; } - else //unknown - throw uno::Exception("unknown property type " + sPropertyType, nullptr); - - sDialogValue = sNewValue; } + else //unknown + throw uno::Exception("unknown property type " + sPropertyType, nullptr); } if(bSaveChanges) |