summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorLaurent Balland-Poirier <laurent.balland-poirier@laposte.net>2012-08-04 22:07:20 +0200
committerEike Rathke <erack@redhat.com>2012-08-14 15:41:42 +0200
commit597bdd89d108fb8325d81f5b30ffdd0d3ea68072 (patch)
treeadd095f51488339b3a93f196f5af83a83a891634 /sc
parentea7b1af01511d147ba7bfea925d407e72723a7db (diff)
fdo#47674 Save settings for Import Ascii Text Dlg
Add save of settings for Paste Unformatted Text and Text to Columns. Remove useless cSep parameter because default are set in Calc.xcs Change-Id: Iff4b976f434a63d2d1f56e497852c7c1e763151c
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/scabstdlg.hxx4
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.cxx9
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.hxx3
-rw-r--r--sc/source/ui/dbgui/scuiasciiopt.cxx156
-rw-r--r--sc/source/ui/inc/asciiopt.hxx6
-rw-r--r--sc/source/ui/inc/scuiasciiopt.hxx7
-rw-r--r--sc/source/ui/unoobj/filtuno.cxx9
-rw-r--r--sc/source/ui/view/cellsh2.cxx4
-rw-r--r--sc/source/ui/view/viewfun5.cxx3
9 files changed, 110 insertions, 91 deletions
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index 58e46596e989..2dca713940ce 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -38,6 +38,7 @@
#include "global.hxx"
#include "pivot.hxx"
#include "i18npool/lang.h"
+#include "asciiopt.hxx"
#include <tabvwsh.hxx>
@@ -65,7 +66,6 @@ class AbstractScImportAsciiDlg : public VclAbstractDialog //add for ScImportAsc
{
public:
virtual void GetOptions( ScAsciiOptions& rOpt ) = 0;
- virtual void SetTextToColumnsMode() = 0;
virtual void SaveParameters() = 0;
};
@@ -342,7 +342,7 @@ public:
virtual AbstractScImportAsciiDlg * CreateScImportAsciiDlg( Window* pParent, String aDatName, //add for ScImportAsciiDlg
SvStream* pInStream, int nId,
- sal_Unicode cSep = '\t') = 0;
+ ScImportAsciiCall eCall) = 0;
virtual AbstractScTextImportOptionsDlg * CreateScTextImportOptionsDlg( Window* pParent, int nId ) = 0;
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index 4dd5292133dd..eb341068d6a8 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -161,11 +161,6 @@ void AbstractScImportAsciiDlg_Impl::GetOptions( ScAsciiOptions& rOpt )
pDlg->GetOptions( rOpt );
}
-void AbstractScImportAsciiDlg_Impl::SetTextToColumnsMode()
-{
- pDlg->SetTextToColumnsMode();
-}
-
void AbstractScImportAsciiDlg_Impl::SaveParameters()
{
pDlg->SaveParameters();
@@ -657,13 +652,13 @@ bool AbstractScTextImportOptionsDlg_Impl::IsDateConversionSet() const
AbstractScImportAsciiDlg * ScAbstractDialogFactory_Impl::CreateScImportAsciiDlg ( Window* pParent, String aDatName,
- SvStream* pInStream, int nId, sal_Unicode cSep )
+ SvStream* pInStream, int nId, ScImportAsciiCall eCall )
{
ScImportAsciiDlg* pDlg=NULL;
switch ( nId )
{
case RID_SCDLG_ASCII :
- pDlg = new ScImportAsciiDlg( pParent, aDatName,pInStream, cSep );
+ pDlg = new ScImportAsciiDlg( pParent, aDatName,pInStream, eCall );
break;
default:
break;
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index f5b2e91b6a0c..a6a8ad5df709 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -119,7 +119,6 @@ class AbstractScImportAsciiDlg_Impl : public AbstractScImportAsciiDlg //add for
{
DECL_ABSTDLG_BASE(AbstractScImportAsciiDlg_Impl, ScImportAsciiDlg)
virtual void GetOptions( ScAsciiOptions& rOpt );
- virtual void SetTextToColumnsMode();
virtual void SaveParameters();
};
@@ -412,7 +411,7 @@ public:
virtual AbstractScImportAsciiDlg * CreateScImportAsciiDlg( Window* pParent, String aDatName, //add for ScImportAsciiDlg
SvStream* pInStream, int nId,
- sal_Unicode cSep = '\t');
+ ScImportAsciiCall eCall);
virtual AbstractScTextImportOptionsDlg * CreateScTextImportOptionsDlg( Window* pParent, int nId );
diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx
index 11b2bb3533d8..753bda608b4a 100644
--- a/sc/source/ui/dbgui/scuiasciiopt.cxx
+++ b/sc/source/ui/dbgui/scuiasciiopt.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include "miscuno.hxx"
+#include <tools/urlobj.hxx>
//! TODO make dynamic
const SCSIZE ASCIIDLG_MAXROWS = MAXROWCOUNT;
@@ -63,6 +64,8 @@ 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"
+#define SEP_PATH_TEXT2COL "Office.Calc/Dialogs/TextToColumnsImport"
// ============================================================================
@@ -114,13 +117,24 @@ 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, ScImportAsciiCall eCall )
{
Sequence<Any>aValues;
const Any *pProperties;
Sequence<OUString> aNames(9);
OUString* pNames = aNames.getArray();
- ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) );
+ OUString aSepPath;
+ switch(eCall)
+ {
+ case SC_IMPORTFILE : aSepPath=OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH));
+ break;
+ case SC_PASTETEXT : aSepPath=OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH_CLPBRD));
+ break;
+ case SC_TEXTTOCOLUMNS :
+ default : aSepPath=OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH_TEXT2COL));
+ break;
+ }
+ ScLinkConfigItem aItem( aSepPath );
pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( MERGE_DELIMITERS ));
pNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM( SEPARATORS ));
@@ -163,7 +177,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, ScImportAsciiCall eCall )
{
OUString sFieldSeparators = OUString( maSeparators );
OUString sTextSeparators = OUString( maTxtSep );
@@ -171,7 +185,18 @@ static void save_Separators(
Any *pProperties;
Sequence<OUString> aNames(9);
OUString* pNames = aNames.getArray();
- ScLinkConfigItem aItem( OUString(RTL_CONSTASCII_USTRINGPARAM( SEP_PATH )) );
+ OUString aSepPath;
+ switch(eCall)
+ {
+ case SC_IMPORTFILE : aSepPath=OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH));
+ break;
+ case SC_PASTETEXT : aSepPath=OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH_CLPBRD));
+ break;
+ case SC_TEXTTOCOLUMNS :
+ default : aSepPath=OUString(RTL_CONSTASCII_USTRINGPARAM(SEP_PATH_TEXT2COL));
+ break;
+ }
+ ScLinkConfigItem aItem( aSepPath );
pNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( MERGE_DELIMITERS ));
pNames[1] = OUString(RTL_CONSTASCII_USTRINGPARAM( SEPARATORS ));
@@ -200,7 +225,7 @@ static void save_Separators(
// ----------------------------------------------------------------------------
ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
- SvStream* pInStream, sal_Unicode cSep ) :
+ SvStream* pInStream, ScImportAsciiCall eCall ) :
ModalDialog ( pParent, ScResId( RID_SCDLG_ASCII ) ),
mpDatStream ( pInStream ),
mnStreamPos( pInStream ? pInStream->Tell() : 0 ),
@@ -251,41 +276,39 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
aTextSepList( ScResId( SCSTR_TEXTSEP ) ),
mcTextSep ( ScAsciiOptions::cDefaultTextSep ),
maStrTextToColumns( ScResId( STR_TEXTTOCOLUMNS ) ),
- mbFileImport(true)
+ meCall(eCall)
{
FreeResource();
- mbFileImport = aDatName.Len() > 0;
String aName = GetText();
- // aDatName is empty if invoked during paste from clipboard.
- if (mbFileImport)
+ if (meCall==SC_IMPORTFILE)
{
aName.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" - ["));
aName += aDatName;
aName += ']';
}
- SetText( aName );
+ if(meCall == SC_TEXTTOCOLUMNS)
+ {
+ SetText( maStrTextToColumns );
+ }
+ else
+ {
+ SetText( aName );
+ }
- // Default options
+ // Default options are set in officecfg/registry/schema/org/openoffice/Office/Calc.xcs
OUString sFieldSeparators(RTL_CONSTASCII_USTRINGPARAM(",;\t"));
OUString sTextSeparators(mcTextSep);
bool bMergeDelimiters = false;
bool bFixedWidth = false;
bool bQuotedFieldAsText = false;
- bool bDetectSpecialNum = false;
+ bool bDetectSpecialNum = true;
sal_Int32 nFromRow = 1;
sal_Int32 nCharSet = -1;
sal_Int32 nLanguage = 0;
- if (mbFileImport)
- // load separators only when importing csv files.
- load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
- bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage);
- else
- {
- // #i115474# otherwise use sensible defaults
- sFieldSeparators = OUString( cSep );
- sTextSeparators = OUString( ScAsciiOptions::cDefaultTextSep );
- }
+ load_Separators (sFieldSeparators, sTextSeparators, bMergeDelimiters,
+ bQuotedFieldAsText, bDetectSpecialNum, bFixedWidth, nFromRow, nCharSet, nLanguage, meCall);
+ // load from saved settings
maFieldSeparators = String(sFieldSeparators);
if( bMergeDelimiters )
@@ -299,29 +322,14 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
if( nFromRow != 1 )
aNfRow.SetValue( nFromRow );
- 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] ) );
- }
- }
+ // Set Separators in the dialog from maFieldSeparators (empty are not set)
+ SetSeparators();
- // Get Separators from the dialog
+ // Get Separators from the dialog (empty are set from default)
maFieldSeparators = GetSeparators();
// Clipboard is always Unicode, else detect.
- rtl_TextEncoding ePreselectUnicode = (mbFileImport ?
+ rtl_TextEncoding ePreselectUnicode = (meCall == SC_IMPORTFILE ?
RTL_TEXTENCODING_DONTKNOW : RTL_TEXTENCODING_UNICODE);
// Sniff for Unicode / not
if( ePreselectUnicode == RTL_TEXTENCODING_DONTKNOW && mpDatStream )
@@ -430,6 +438,25 @@ ScImportAsciiDlg::ScImportAsciiDlg( Window* pParent,String aDatName,
aEdOther.SetAccessibleName(aCkbOther.GetText());
aEdOther.SetAccessibleRelationLabeledBy(&aCkbOther);
+
+ if(meCall == SC_TEXTTOCOLUMNS)
+ {
+ aFtCharSet.Disable();
+ aLbCharSet.Disable();
+ aFtCustomLang.Disable();
+ aLbCustomLang.SelectLanguage(LANGUAGE_SYSTEM);
+ aLbCustomLang.Disable();
+ aFtRow.Disable();
+ aNfRow.Disable();
+
+ // Quoted field as text option is not used for text-to-columns mode.
+ aCkbQuotedAsText.Check(false);
+ aCkbQuotedAsText.Disable();
+
+ // Always detect special numbers for text-to-columns mode.
+ aCkbDetectNumber.Check();
+ aCkbDetectNumber.Disable();
+ }
}
@@ -527,38 +554,35 @@ void ScImportAsciiDlg::GetOptions( ScAsciiOptions& rOpt )
rOpt.SetDetectSpecialNumber(aCkbDetectNumber.IsChecked());
}
-void ScImportAsciiDlg::SetTextToColumnsMode()
-{
- SetText( maStrTextToColumns );
- aFtCharSet.Disable();
- aLbCharSet.Disable();
- aFtCustomLang.Disable();
- aLbCustomLang.SelectLanguage(LANGUAGE_SYSTEM);
- aLbCustomLang.Disable();
- aFtRow.Disable();
- aNfRow.Disable();
-
- // Quoted field as text option is not used for text-to-columns mode.
- aCkbQuotedAsText.Check(false);
- aCkbQuotedAsText.Disable();
-
- // Always detect special numbers for text-to-columns mode.
- aCkbDetectNumber.Check();
- aCkbDetectNumber.Disable();
-}
-
void ScImportAsciiDlg::SaveParameters()
{
- if (!mbFileImport)
- // We save parameters only for file import.
- return;
-
save_Separators( maFieldSeparators, aCbTextSep.GetText(), aCkbAsOnce.IsChecked(),
aCkbQuotedAsText.IsChecked(), aCkbDetectNumber.IsChecked(),
aRbFixed.IsChecked(),
static_cast<sal_Int32>(aNfRow.GetValue()),
static_cast<sal_Int32>(aLbCharSet.GetSelectEntryPos()),
- static_cast<sal_Int32>(aLbCustomLang.GetSelectLanguage()) );
+ static_cast<sal_Int32>(aLbCustomLang.GetSelectLanguage()), meCall );
+}
+
+void ScImportAsciiDlg::SetSeparators()
+{
+ 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/asciiopt.hxx b/sc/source/ui/inc/asciiopt.hxx
index 53a22dd6dec5..45107c19ad22 100644
--- a/sc/source/ui/inc/asciiopt.hxx
+++ b/sc/source/ui/inc/asciiopt.hxx
@@ -107,6 +107,12 @@ public:
void SetColumnInfo( const ScCsvExpDataVec& rDataVec );
};
+/// How ScImportAsciiDlg is called
+enum ScImportAsciiCall {
+ SC_IMPORTFILE, // with File > Open: Text - CSV
+ SC_PASTETEXT, // with Paste > Unformatted Text
+ SC_TEXTTOCOLUMNS }; // with Data > Text to Columns
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/scuiasciiopt.hxx b/sc/source/ui/inc/scuiasciiopt.hxx
index c45b9acd1d08..e95103cdf62e 100644
--- a/sc/source/ui/inc/scuiasciiopt.hxx
+++ b/sc/source/ui/inc/scuiasciiopt.hxx
@@ -94,21 +94,22 @@ class ScImportAsciiDlg : public ModalDialog
CharSet meCharSet; /// Selected char set.
bool mbCharSetSystem; /// Is System char set selected?
- bool mbFileImport; /// Is this dialog involked for csv file import ?
+ ScImportAsciiCall meCall; /// How the dialog is called (see asciiopt.hxx)
public:
ScImportAsciiDlg(
Window* pParent, String aDatName,
- SvStream* pInStream, sal_Unicode cSep = '\t' );
+ SvStream* pInStream, ScImportAsciiCall eCall );
~ScImportAsciiDlg();
void GetOptions( ScAsciiOptions& rOpt );
- void SetTextToColumnsMode();
void SaveParameters();
private:
/** Sets the selected char set data to meCharSet and mbCharSetSystem. */
void SetSelectedCharSet();
+ /** Set separators in ui from maFieldSeparators */
+ void SetSeparators();
/** Returns all separator characters in a string. */
String GetSeparators() const;
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index 61807431e970..1d35a9c9048f 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -211,19 +211,12 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute() throw(uno::RuntimeException)
// ascii import is special...
INetURLObject aURL( aFileName );
- String aExt(aURL.getExtension());
String aPrivDatName(aURL.getName());
- sal_Unicode cAsciiDel;
- if (aExt.EqualsIgnoreCaseAscii("CSV"))
- cAsciiDel = ',';
- else
- cAsciiDel = '\t';
-
SvStream* pInStream = NULL;
if ( xInputStream.is() )
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
- AbstractScImportAsciiDlg* pDlg = pFact->CreateScImportAsciiDlg( NULL, aPrivDatName, pInStream, RID_SCDLG_ASCII, cAsciiDel);
+ AbstractScImportAsciiDlg* pDlg = pFact->CreateScImportAsciiDlg( NULL, aPrivDatName, pInStream, RID_SCDLG_ASCII,SC_IMPORTFILE);
OSL_ENSURE(pDlg, "Dialog create fail!");
if ( pDlg->Execute() == RET_OK )
{
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 65f89f834310..325e71362797 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -936,9 +936,8 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
OSL_ENSURE( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" );
AbstractScImportAsciiDlg *pDlg = pFact->CreateScImportAsciiDlg(
- NULL, String(), &aStream, RID_SCDLG_ASCII );
+ NULL, String(), &aStream, RID_SCDLG_ASCII,SC_TEXTTOCOLUMNS);
OSL_ENSURE( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" );
- pDlg->SetTextToColumnsMode();
if ( pDlg->Execute() == RET_OK )
{
@@ -951,6 +950,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
ScImportExport aImport( pDoc, aRange.aStart );
ScAsciiOptions aOptions;
pDlg->GetOptions( aOptions );
+ pDlg->SaveParameters();
aImport.SetExtOptions( aOptions );
aImport.SetApi( false );
aStream.Seek( 0 );
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index 6f7e890bec72..be970f4250c7 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -340,12 +340,13 @@ sal_Bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
ScAbstractDialogFactory::Create();
AbstractScImportAsciiDlg *pDlg =
pFact->CreateScImportAsciiDlg( NULL, String(), &aStrm,
- RID_SCDLG_ASCII);
+ RID_SCDLG_ASCII, SC_PASTETEXT);
if (pDlg->Execute() == RET_OK)
{
ScAsciiOptions aOptions;
pDlg->GetOptions( aOptions );
+ pDlg->SaveParameters();
aObj.SetExtOptions( aOptions );
bRet = aObj.ImportString( aStr, nFormatId );