From fad6e10eff6ef9f3ad1167534e1d1b0cf7f1c557 Mon Sep 17 00:00:00 2001 From: Laurent Balland-Poirier Date: Sat, 4 Aug 2012 22:07:20 +0200 Subject: [PATCH] fdo#47674 Save settings for Paste unformatted text First step for this issue. Next step will be to treat also Text to Column. Change-Id: Ia52dc9ddcfe809b66d5d245659e1f38175aaa9d1 --- .../registry/schema/org/openoffice/Office/Calc.xcs | 86 ++++++++++++++++++++ sc/source/ui/dbgui/scuiasciiopt.cxx | 70 ++++++++++++---- sc/source/ui/inc/scuiasciiopt.hxx | 2 + sc/source/ui/view/viewfun5.cxx | 1 + 4 files changed, 143 insertions(+), 16 deletions(-) diff --git a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs index 0f5898e..b1e3c14 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Calc.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Calc.xcs @@ -1141,6 +1141,92 @@ + + + Contains setting for Text CSV Import + + + + muthusuba + Merge Delimiter check box status + + + false + + + + kyoshida + If true, quoted field is always imported as text + with no exception. + + + false + + + + kyoshida + If true, Calc tries to detect special number format, such as date and scientific notation. + + + false + + + + kyoshida + Language to use for CSV import. This determines how the numbers are parsed. + + + 0 + + + + muthusuba + List of Separators - as a String + + + ,; + + + + muthusuba + Text Separators + + + " + + + + muthusuba + Fixed width + + + false + + + + muthusuba + From Row + + + 1 + + + + muthusuba + Char Set + + + -1 + + + + muthusuba + Fixed Width List of separators + + + + + diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx index 11b2bb3..a0c1a10 100644 --- a/sc/source/ui/dbgui/scuiasciiopt.cxx +++ b/sc/source/ui/dbgui/scuiasciiopt.cxx @@ -63,6 +63,7 @@ using ::rtl::OUString; #define DETECT_SPECIAL_NUM "DetectSpecialNumbers" #define LANGUAGE "Language" #define SEP_PATH "Office.Calc/Dialogs/CSVImport" +#define SEP_PATH_CLPBRD "Office.Calc/Dialogs/ClipboardTextImport" // ============================================================================ @@ -114,13 +115,16 @@ sal_Unicode lcl_CharFromCombo( ComboBox& rCombo, const String& rList ) static void load_Separators( OUString &sFieldSeparators, OUString &sTextSeparators, bool &bMergeDelimiters, bool& bQuotedAsText, bool& bDetectSpecialNum, bool &bFixedWidth, sal_Int32 &nFromRow, sal_Int32 &nCharSet, - sal_Int32& nLanguage ) + sal_Int32& nLanguage, bool bFileImport ) { SequenceaValues; const Any *pProperties; Sequence aNames(9); OUString* pNames = aNames.getArray(); - ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) ); +// ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) ); + OUString aSepPathFile= OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH)); + OUString aSepPathClipboard= OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH_CLPBRD)); + ScLinkConfigItem aItem( bFileImport?aSepPathFile:aSepPathClipboard ); pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( MERGE_DELIMITERS )); pNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM( SEPARATORS )); @@ -163,7 +167,7 @@ static void load_Separators( OUString &sFieldSeparators, OUString &sTextSeparato static void save_Separators( String maSeparators, String maTxtSep, bool bMergeDelimiters, bool bQuotedAsText, - bool bDetectSpecialNum, bool bFixedWidth, sal_Int32 nFromRow, sal_Int32 nCharSet, sal_Int32 nLanguage ) + bool bDetectSpecialNum, bool bFixedWidth, sal_Int32 nFromRow, sal_Int32 nCharSet, sal_Int32 nLanguage, bool bFileImport ) { OUString sFieldSeparators = OUString( maSeparators ); OUString sTextSeparators = OUString( maTxtSep ); @@ -171,7 +175,10 @@ static void save_Separators( Any *pProperties; Sequence aNames(9); OUString* pNames = aNames.getArray(); - ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) ); +// ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) ); + OUString aSepPathFile= OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH)); + OUString aSepPathClipboard= OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH_CLPBRD)); + ScLinkConfigItem aItem( bFileImport?aSepPathFile:aSepPathClipboard ); pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( MERGE_DELIMITERS )); pNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM( SEPARATORS )); @@ -276,16 +283,16 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName, sal_Int32 nFromRow = 1; sal_Int32 nCharSet = -1; sal_Int32 nLanguage = 0; - if (mbFileImport) +// if (mbFileImport) // load separators only when importing csv files. load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters, - bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage); - else - { + bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage,mbFileImport); +// else +// { // #i115474# otherwise use sensible defaults - sFieldSeparators = OUString( cSep ); - sTextSeparators = OUString( ScAsciiOptions::cDefaultTextSep ); - } +// sFieldSeparators = OUString( cSep ); +// sTextSeparators = OUString( ScAsciiOptions::cDefaultTextSep ); +// } maFieldSeparators = String(sFieldSeparators); if( bMergeDelimiters ) @@ -299,7 +306,9 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName, if( nFromRow != 1 ) aNfRow.SetValue( nFromRow ); - rtl::OString sString(rtl::OUStringToOString(maFieldSeparators, + // Set Separators in the dialog from maFiledSeparators + SetSeparators(); +/* rtl::OString sString(rtl::OUStringToOString(maFieldSeparators, RTL_TEXTENCODING_MS_1252)); const sal_Char *aSep = sString.getStr(); int len = maFieldSeparators.Len(); @@ -315,7 +324,7 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName, aCkbOther.Check(); aEdOther.SetText( aEdOther.GetText() + OUString( aSep[i] ) ); } - } + }*/ // Get Separators from the dialog maFieldSeparators = GetSeparators(); @@ -537,6 +546,8 @@ void ScImportAsciiDlg::SetTextToColumnsMode() aLbCustomLang.Disable(); aFtRow.Disable(); aNfRow.Disable(); + maFieldSeparators = OUString('\t' ); // should also be saved in settings? + SetSeparators(); // Quoted field as text option is not used for text-to-columns mode. aCkbQuotedAsText.Check(false); @@ -549,16 +560,43 @@ void ScImportAsciiDlg::SetTextToColumnsMode() void ScImportAsciiDlg::SaveParameters() { - if (!mbFileImport) +// if (!mbFileImport) // We save parameters only for file import. - return; +// return; save_Separators( maFieldSeparators, aCbTextSep.GetText(), aCkbAsOnce.IsChecked(), aCkbQuotedAsText.IsChecked(), aCkbDetectNumber.IsChecked(), aRbFixed.IsChecked(), static_cast(aNfRow.GetValue()), static_cast(aLbCharSet.GetSelectEntryPos()), - static_cast(aLbCustomLang.GetSelectLanguage()) ); + static_cast(aLbCustomLang.GetSelectLanguage()),mbFileImport ); +} + +void ScImportAsciiDlg::SetSeparators() +{ + aCkbTab.Check(false); + aCkbSemicolon.Check(false); + aCkbComma.Check(false); + aCkbSpace.Check(false); +// aEdOther.SetText('\0'); + aCkbOther.Check(false); + rtl::OString sString(rtl::OUStringToOString(maFieldSeparators, + RTL_TEXTENCODING_MS_1252)); + const sal_Char *aSep = sString.getStr(); + int len = maFieldSeparators.Len(); + for (int i = 0; i < len; ++i) + { + switch( aSep[i] ) + { + case '\t': aCkbTab.Check(); break; + case ';': aCkbSemicolon.Check(); break; + case ',': aCkbComma.Check(); break; + case ' ': aCkbSpace.Check(); break; + default: + aCkbOther.Check(); + aEdOther.SetText( aEdOther.GetText() + OUString( aSep[i] ) ); + } + } } void ScImportAsciiDlg::SetSelectedCharSet() diff --git a/sc/source/ui/inc/scuiasciiopt.hxx b/sc/source/ui/inc/scuiasciiopt.hxx index c45b9ac..39d32c2 100644 --- a/sc/source/ui/inc/scuiasciiopt.hxx +++ b/sc/source/ui/inc/scuiasciiopt.hxx @@ -109,6 +109,8 @@ public: private: /** Sets the selected char set data to meCharSet and mbCharSetSystem. */ void SetSelectedCharSet(); + /** Set separators in ui from maFieldSeprators */ + void SetSeparators(); /** Returns all separator characters in a string. */ String GetSeparators() const; diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx index 6f7e890..7faeedd 100644 --- a/sc/source/ui/view/viewfun5.cxx +++ b/sc/source/ui/view/viewfun5.cxx @@ -346,6 +346,7 @@ sal_Bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, { ScAsciiOptions aOptions; pDlg->GetOptions( aOptions ); + pDlg->SaveParameters(); aObj.SetExtOptions( aOptions ); bRet = aObj.ImportString( aStr, nFormatId ); -- 1.7.7