officecfg/registry/schema/org/openoffice/Office/Calc.xcs | 18 +++++- sc/source/ui/dbgui/scuiasciiopt.cxx | 41 +++++++-------- 2 files changed, 37 insertions(+), 22 deletions(-)
New commits: commit 9556677d1aa726fafa79c4b0f34a68213dfd7fe0 Author: Mike Kaganski <[email protected]> AuthorDate: Wed Jun 4 19:23:30 2025 +0500 Commit: Christian Lohmaier <[email protected]> CommitDate: Fri Jun 27 13:10:13 2025 +0200 [API CHANGE] tdf#166208: New "Encoding" property for text import / clipboard paste The problem appeared, because the existing CharSet property was storing the index of the selection in the encoding list box; and that meant, that any change in the list box content (different sorting; added elements) could suddenly make the selection wrong the next time. With introduction of the autodetection entry into the top of the list box in tdf#152336 (in commit 565b619d57a3b98b0826c4b49dee6606f9ae70e0), many people who had UTF-8 selected in the dialog previously, got UTF-7 instead; and many had not noticed the difference, thus seeing unexpected results after import. The said commit intended to force-select autodetection for the users who had not used the updated dialog yet; but the detection of that scenario was flawed, and didn't work (that was discussed, and respective code was dropped in commit ...). This change implements that idea. I decided to ignore the stored CharSet value; after the change, autodetection entry will be pre-selected at the first start of the dialog. This will be a minor annoyance for users who have already re-selected wanted encoding after previous upgrade; but it allows to resolve the bug for people upgrading from versions prior to 25.2. Also, since new versions will not write to CharSet, it's possible to use a shared profile between old and new versions without breaking the encoding selection in either. Change-Id: I59640b16f703077b6fda44a34eadf2edbe8e6bf5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186240 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> (cherry picked from commit d16535788721238a423408ba59805f4bcacc4e12) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186246 Reviewed-by: Xisco Fauli <[email protected]> Reviewed-by: Christian Lohmaier <[email protected]> diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs index 22e14c4421fe..44def6f19193 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs @@ -1084,11 +1084,18 @@ </prop> <prop oor:name="CharSet" oor:type="xs:int" oor:nillable="false"> <info> - <desc>Char Set</desc> + <desc>Char Set (index of selected item in the dialog's list box; obsoleted by Encoding)</desc> <label>CharSet</label> </info> <value>-1</value> </prop> + <prop oor:name="Encoding" oor:type="xs:short" oor:nillable="false"> + <info> + <desc>Encoding (an rtl_TextEncoding value; default is "don't know")</desc> + <label>Encoding</label> + </info> + <value>0</value> + </prop> <prop oor:name="FixedWidthList" oor:type="xs:string" oor:nillable="false"> <info> <desc>Fixed Width List of separators</desc> @@ -1187,11 +1194,18 @@ </prop> <prop oor:name="CharSet" oor:type="xs:int" oor:nillable="false"> <info> - <desc>Char Set</desc> + <desc>Char Set (index of selected item in the dialog's list box; obsoleted by Encoding)</desc> <label>CharSet</label> </info> <value>-1</value> </prop> + <prop oor:name="Encoding" oor:type="xs:short" oor:nillable="false"> + <info> + <desc>Encoding (an rtl_TextEncoding value; default is "don't know")</desc> + <label>Encoding</label> + </info> + <value>0</value> + </prop> <prop oor:name="FixedWidthList" oor:type="xs:string" oor:nillable="false"> <info> <desc>Fixed Width List of separators</desc> diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx index 01ed46b0d90b..8d05bc4fd8bb 100644 --- a/sc/source/ui/dbgui/scuiasciiopt.cxx +++ b/sc/source/ui/dbgui/scuiasciiopt.cxx @@ -79,7 +79,7 @@ constexpr OUString CSVIO_RemoveSpace = u"RemoveSpace"_ustr; constexpr OUString CSVIO_EvaluateFormulas = u"EvaluateFormulas"_ustr; constexpr OUString CSVIO_SeparatorType = u"SeparatorType"_ustr; constexpr OUString CSVIO_FromRow = u"FromRow"_ustr; -constexpr OUString CSVIO_CharSet = u"CharSet"_ustr; +constexpr OUString CSVIO_Encoding = u"Encoding"_ustr; constexpr OUString CSVIO_QuotedAsText = u"QuotedFieldAsText"_ustr; constexpr OUString CSVIO_DetectSpecialNum = u"DetectSpecialNumbers"_ustr; constexpr OUString CSVIO_DetectScientificNum = u"DetectScientificNumbers"_ustr; @@ -158,7 +158,7 @@ static OUString lcl_GetConfigPath(ScImportAsciiCall eCall) static void lcl_LoadSeparators(ScImportAsciiCall eCall, OUString& rFieldSeparators, OUString& rTextSeparators, bool& rMergeDelimiters, bool& rQuotedAsText, bool& rDetectSpecialNum, bool& rDetectScientificNum, - SeparatorType& rSepType, sal_Int32& rFromRow, sal_Int32& rCharSet, + SeparatorType& rSepType, sal_Int32& rFromRow, rtl_TextEncoding& rEncoding, sal_Int32& rLanguage, bool& rSkipEmptyCells, bool& rRemoveSpace, bool& rEvaluateFormulas) { @@ -166,6 +166,8 @@ static void lcl_LoadSeparators(ScImportAsciiCall eCall, OUString& rFieldSeparato const Sequence<OUString> aNames = aItem.GetNodeNames({}); const Sequence<Any> aValues = aItem.GetProperties(aNames); + rEncoding = RTL_TEXTENCODING_DONTKNOW; + for (sal_Int32 i = 0; i < aNames.getLength(); ++i) { const OUString& name = aNames[i]; @@ -186,8 +188,8 @@ static void lcl_LoadSeparators(ScImportAsciiCall eCall, OUString& rFieldSeparato rEvaluateFormulas = ScUnoHelpFunctions::GetBoolFromAny(value); else if (name == CSVIO_FromRow) value >>= rFromRow; - else if (name == CSVIO_CharSet) - value >>= rCharSet; + else if (name == CSVIO_Encoding) + value >>= rEncoding; else if (name == CSVIO_QuotedAsText) value >>= rQuotedAsText; else if (name == CSVIO_DetectSpecialNum) @@ -204,7 +206,7 @@ static void lcl_LoadSeparators(ScImportAsciiCall eCall, OUString& rFieldSeparato static void lcl_SaveSeparators(ScImportAsciiCall eCall, const OUString& sFieldSeparators, const OUString& sTextSeparators, bool bMergeDelimiters, bool bQuotedAsText, bool bDetectSpecialNum, bool bDetectScientificNum, SeparatorType rSepType, sal_Int32 nFromRow, - sal_Int32 nCharSet, sal_Int32 nLanguage, bool bSkipEmptyCells, bool bRemoveSpace, bool bEvaluateFormulas) + rtl_TextEncoding eEncoding, sal_Int32 nLanguage, bool bSkipEmptyCells, bool bRemoveSpace, bool bEvaluateFormulas) { ScLinkConfigItem aItem(lcl_GetConfigPath(eCall)); std::unordered_map<OUString, Any> properties; @@ -225,8 +227,8 @@ static void lcl_SaveSeparators(ScImportAsciiCall eCall, properties[name] <<= static_cast<sal_Int16>(rSepType); else if (name == CSVIO_FromRow) properties[name] <<= nFromRow; - else if (name == CSVIO_CharSet) - properties[name] <<= nCharSet; + else if (name == CSVIO_Encoding) + properties[name] <<= eEncoding; else if (name == CSVIO_QuotedAsText) properties[name] <<= bQuotedAsText; else if (name == CSVIO_DetectSpecialNum) @@ -315,12 +317,12 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD bool bSkipEmptyCells = true; bool bRemoveSpace = false; sal_Int32 nFromRow = 1; - sal_Int32 nCharSet = -1; + rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW; sal_Int32 nLanguage = 0; lcl_LoadSeparators ( meCall, sFieldSeparators, sTextSeparators, bMergeDelimiters, bQuotedFieldAsText, bDetectSpecialNum, bDetectScientificNum, eSepType, nFromRow, - nCharSet, nLanguage, bSkipEmptyCells, bRemoveSpace, bEvaluateFormulas); + eEncoding, nLanguage, bSkipEmptyCells, bRemoveSpace, bEvaluateFormulas); maFieldSeparators = sFieldSeparators; @@ -359,10 +361,6 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD if (nFromRow != 1) mxNfRow->set_value(nFromRow); - // Clipboard is always Unicode, else rely on default/config. - rtl_TextEncoding ePreselectUnicode = (meCall == SC_IMPORTFILE ? - RTL_TEXTENCODING_DONTKNOW : RTL_TEXTENCODING_UNICODE); - // Detect character set only once and then use it for "Detect" option. SvStreamEndian eEndian; SfxObjectShell::DetectCharSet(*mpDatStream, meDetectedCharSet, eEndian); @@ -419,12 +417,13 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD // Insert one for detecting charset. mxLbCharSet->InsertTextEncoding( RTL_TEXTENCODING_USER_DETECTED, "- " + ScResId( SCSTR_AUTOMATIC ) + " -" ); - if (ePreselectUnicode != RTL_TEXTENCODING_DONTKNOW) - mxLbCharSet->SelectTextEncoding( ePreselectUnicode ); - else if (nCharSet >= 0) - mxLbCharSet->set_active(nCharSet); - else - mxLbCharSet->SelectTextEncoding(RTL_TEXTENCODING_USER_DETECTED); + // Clipboard is always Unicode, and TextToColumns doesn't use encoding. + if (meCall != SC_IMPORTFILE) + eEncoding = RTL_TEXTENCODING_UNICODE; + else if (eEncoding == RTL_TEXTENCODING_DONTKNOW) + eEncoding = RTL_TEXTENCODING_USER_DETECTED; + + mxLbCharSet->SelectTextEncoding(eEncoding); SetSelectedCharSet(); mxLbCharSet->connect_changed( LINK( this, ScImportAsciiDlg, CharSetHdl ) ); @@ -462,6 +461,8 @@ ScImportAsciiDlg::ScImportAsciiDlg(weld::Window* pParent, std::u16string_view aD if (meCall == SC_TEXTTOCOLUMNS) { + m_xBuilder->weld_frame(u"frame1"_ustr)->hide(); // the whole "Import" section + mxFtCharSet->set_sensitive(false); mxLbCharSet->set_sensitive(false); mxFtCustomLang->set_sensitive(false); @@ -594,7 +595,7 @@ void ScImportAsciiDlg::SaveParameters() mxCkbQuotedAsText->get_active(), mxCkbDetectNumber->get_active(), mxCkbDetectScientificNumber->get_active(), mxRbFixed->get_active() ? FIXED : (mxRbDetectSep->get_active() ? DETECT_SEPARATOR : SEPARATOR), mxNfRow->get_value(), - mxLbCharSet->get_active(), + mxLbCharSet->GetSelectTextEncoding(), static_cast<sal_uInt16>(mxLbCustomLang->get_active_id()), mxCkbSkipEmptyCells->get_active(), mxCkbRemoveSpace->get_active(), mxCkbEvaluateFormulas->get_active());
