2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-10-27 12:00:22 +00:00
|
|
|
|
2013-08-19 00:41:12 +03:00
|
|
|
#include <config_features.h>
|
|
|
|
|
2012-08-10 20:50:33 +02:00
|
|
|
#include "moduledbu.hxx"
|
2004-10-27 12:00:22 +00:00
|
|
|
#include "TextConnectionHelper.hxx"
|
|
|
|
#include "sqlmessage.hxx"
|
|
|
|
#include "dbu_dlg.hrc"
|
|
|
|
#include "dbu_resource.hrc"
|
2011-07-23 10:13:13 +02:00
|
|
|
#include "AutoControls.hrc"
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/itemset.hxx>
|
|
|
|
#include <svl/stritem.hxx>
|
|
|
|
#include <svl/eitem.hxx>
|
|
|
|
#include <svl/intitem.hxx>
|
2004-10-27 12:00:22 +00:00
|
|
|
#include "dsitems.hxx"
|
|
|
|
#include "dbfindex.hxx"
|
|
|
|
#include "dbaccess_helpid.hrc"
|
|
|
|
#include "localresaccess.hxx"
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
#include <vcl/mnemonic.hxx>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/cjkoptions.hxx>
|
2013-08-19 00:41:12 +03:00
|
|
|
#if HAVE_FEATURE_JAVA
|
2004-10-27 12:00:22 +00:00
|
|
|
#include <jvmaccess/virtualmachine.hxx>
|
2013-04-04 22:46:53 +02:00
|
|
|
#endif
|
2004-10-27 12:00:22 +00:00
|
|
|
#include <connectivity/CommonTools.hxx>
|
|
|
|
#include "DriverSettings.hxx"
|
|
|
|
#include "dbadmin.hxx"
|
2012-01-02 10:55:27 +00:00
|
|
|
#include <comphelper/string.hxx>
|
2004-10-27 12:00:22 +00:00
|
|
|
#include <comphelper/types.hxx>
|
|
|
|
#include <com/sun/star/task/XInteractionHandler.hpp>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/filenotation.hxx>
|
2004-10-27 12:00:22 +00:00
|
|
|
#include <unotools/localfilehelper.hxx>
|
|
|
|
#include <unotools/ucbhelper.hxx>
|
|
|
|
#include <ucbhelper/commandenvironment.hxx>
|
|
|
|
#include "finteraction.hxx"
|
|
|
|
#include "DBSetupConnectionPages.hxx"
|
2009-10-06 07:38:24 +02:00
|
|
|
#include <unotools/pathoptions.hxx>
|
2004-10-27 12:00:22 +00:00
|
|
|
#include <svtools/roadmapwizard.hxx>
|
|
|
|
|
|
|
|
namespace dbaui
|
|
|
|
{
|
2012-08-10 20:50:33 +02:00
|
|
|
|
2008-03-07 10:21:27 +00:00
|
|
|
OTextConnectionHelper::OTextConnectionHelper( Window* pParent, const short _nAvailableSections )
|
|
|
|
:Control( pParent, WB_DIALOGCONTROL )
|
|
|
|
,m_aFTExtensionHeader (this, ModuleRes(FT_AUTOEXTENSIONHEADER))
|
|
|
|
,m_aRBAccessTextFiles (this, ModuleRes(RB_AUTOACCESSCTEXTFILES))
|
|
|
|
,m_aRBAccessCSVFiles (this, ModuleRes(RB_AUTOACCESSCCSVFILES))
|
|
|
|
,m_aRBAccessOtherFiles (this, ModuleRes(RB_AUTOACCESSOTHERS))
|
|
|
|
,m_aETOwnExtension (this, ModuleRes(ET_AUTOOWNEXTENSION))
|
|
|
|
,m_aFTExtensionExample (this, ModuleRes(FT_AUTOOWNEXTENSIONAPPENDIX))
|
|
|
|
,m_aLineFormat (this, ModuleRes(FL_AUTOSEPARATOR2))
|
|
|
|
,m_aFieldSeparatorLabel (this, ModuleRes(FT_AUTOFIELDSEPARATOR))
|
|
|
|
,m_aFieldSeparator (this, ModuleRes(CM_AUTOFIELDSEPARATOR))
|
|
|
|
,m_aTextSeparatorLabel (this, ModuleRes(FT_AUTOTEXTSEPARATOR))
|
|
|
|
,m_aTextSeparator (this, ModuleRes(CM_AUTOTEXTSEPARATOR))
|
|
|
|
,m_aDecimalSeparatorLabel (this, ModuleRes(FT_AUTODECIMALSEPARATOR))
|
|
|
|
,m_aDecimalSeparator (this, ModuleRes(CM_AUTODECIMALSEPARATOR))
|
|
|
|
,m_aThousandsSeparatorLabel (this, ModuleRes(FT_AUTOTHOUSANDSSEPARATOR))
|
|
|
|
,m_aThousandsSeparator (this, ModuleRes(CM_AUTOTHOUSANDSSEPARATOR))
|
|
|
|
,m_aRowHeader (this, ModuleRes(CB_AUTOHEADER))
|
|
|
|
,m_aCharSetHeader (this, ModuleRes(FL_DATACONVERT))
|
|
|
|
,m_aCharSetLabel (this, ModuleRes(FT_CHARSET))
|
|
|
|
,m_aCharSet (this, ModuleRes(LB_CHARSET))
|
2007-04-26 06:57:16 +00:00
|
|
|
,m_aFieldSeparatorList (ModuleRes(STR_AUTOFIELDSEPARATORLIST))
|
|
|
|
,m_aTextSeparatorList (ModuleRes(STR_AUTOTEXTSEPARATORLIST))
|
|
|
|
,m_aTextNone (ModuleRes(STR_AUTOTEXT_FIELD_SEP_NONE))
|
2008-03-07 10:21:27 +00:00
|
|
|
,m_nAvailableSections( _nAvailableSections )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2005-09-23 11:27:26 +00:00
|
|
|
|
2013-10-28 13:20:52 +02:00
|
|
|
sal_Int32 nCnt = comphelper::string::getTokenCount(m_aFieldSeparatorList, '\t');
|
2014-01-15 15:26:41 +00:00
|
|
|
sal_Int32 i;
|
2004-10-27 12:00:22 +00:00
|
|
|
|
|
|
|
for( i = 0 ; i < nCnt ; i += 2 )
|
2013-09-26 12:17:53 +02:00
|
|
|
m_aFieldSeparator.InsertEntry( m_aFieldSeparatorList.getToken( i, '\t' ) );
|
2004-10-27 12:00:22 +00:00
|
|
|
|
2012-01-02 10:55:27 +00:00
|
|
|
nCnt = comphelper::string::getTokenCount(m_aTextSeparatorList, '\t');
|
2004-10-27 12:00:22 +00:00
|
|
|
for( i=0 ; i<nCnt ; i+=2 )
|
2013-09-26 12:17:53 +02:00
|
|
|
m_aTextSeparator.InsertEntry( m_aTextSeparatorList.getToken( i, '\t' ) );
|
2004-10-27 12:00:22 +00:00
|
|
|
m_aTextSeparator.InsertEntry(m_aTextNone);
|
|
|
|
|
|
|
|
// set the modify handlers
|
|
|
|
m_aFieldSeparator.SetUpdateDataHdl(getControlModifiedLink());
|
|
|
|
m_aFieldSeparator.SetSelectHdl(getControlModifiedLink());
|
|
|
|
m_aTextSeparator.SetUpdateDataHdl(getControlModifiedLink());
|
|
|
|
m_aTextSeparator.SetSelectHdl(getControlModifiedLink());
|
2008-03-07 10:21:27 +00:00
|
|
|
m_aCharSet.SetSelectHdl(getControlModifiedLink());
|
2004-10-27 12:00:22 +00:00
|
|
|
|
|
|
|
m_aFieldSeparator.SetModifyHdl(getControlModifiedLink());
|
|
|
|
m_aTextSeparator.SetModifyHdl(getControlModifiedLink());
|
|
|
|
m_aDecimalSeparator.SetModifyHdl(getControlModifiedLink());
|
|
|
|
m_aThousandsSeparator.SetModifyHdl(getControlModifiedLink());
|
|
|
|
m_aETOwnExtension.SetModifyHdl(LINK(this, OTextConnectionHelper, OnEditModified));
|
|
|
|
m_aRBAccessTextFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl));
|
|
|
|
m_aRBAccessCSVFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl));
|
|
|
|
m_aRBAccessOtherFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl));
|
2014-02-21 12:53:51 +01:00
|
|
|
m_aRBAccessCSVFiles.Check(true);
|
2008-03-07 10:21:27 +00:00
|
|
|
|
|
|
|
struct SectionDescriptor
|
|
|
|
{
|
|
|
|
short nFlag;
|
|
|
|
Window* pFirstControl;
|
|
|
|
} aSections[] = {
|
|
|
|
{ TC_EXTENSION, &m_aFTExtensionHeader },
|
|
|
|
{ TC_SEPARATORS, &m_aLineFormat },
|
|
|
|
{ TC_HEADER, &m_aRowHeader },
|
|
|
|
{ TC_CHARSET, &m_aCharSetHeader },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2012-05-31 12:36:21 +01:00
|
|
|
for ( size_t section=0; section < sizeof( aSections ) / sizeof( aSections[0] ) - 1; ++section )
|
2008-03-07 10:21:27 +00:00
|
|
|
{
|
|
|
|
if ( ( m_nAvailableSections & aSections[section].nFlag ) != 0 )
|
|
|
|
{
|
|
|
|
// the section is visible, no need to do anything here
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window* pThisSection = aSections[section].pFirstControl;
|
|
|
|
Window* pNextSection = aSections[section+1].pFirstControl;
|
|
|
|
|
|
|
|
// hide all elements from this section
|
|
|
|
Window* pControl = pThisSection;
|
|
|
|
while ( ( pControl != pNextSection ) && pControl )
|
|
|
|
{
|
|
|
|
Window* pRealWindow = pControl->GetWindow( WINDOW_CLIENT );
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString sWindowText( pRealWindow->GetText() );
|
2008-03-07 10:21:27 +00:00
|
|
|
(void)sWindowText;
|
|
|
|
#endif
|
|
|
|
pRealWindow->Hide();
|
|
|
|
pControl = pControl->GetWindow( WINDOW_NEXT );
|
|
|
|
}
|
|
|
|
|
|
|
|
// move all controls in following sections up
|
|
|
|
if ( !pNextSection )
|
|
|
|
continue;
|
|
|
|
const long nThisSectionStart = pThisSection->GetPosPixel().Y();
|
|
|
|
const long nNextSectionStart = pNextSection->GetPosPixel().Y();
|
|
|
|
const long nMoveOffset( nThisSectionStart - nNextSectionStart );
|
|
|
|
while ( pControl )
|
|
|
|
{
|
|
|
|
Point aPos = pControl->GetPosPixel();
|
|
|
|
aPos.Move( 0, nMoveOffset );
|
|
|
|
pControl->SetPosPixel( aPos );
|
|
|
|
pControl = pControl->GetWindow( WINDOW_NEXT );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle aControlRectUnion;
|
|
|
|
for ( Window* pControl = aSections[0].pFirstControl;
|
|
|
|
pControl != NULL;
|
|
|
|
pControl = pControl->GetWindow( WINDOW_NEXT )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
aControlRectUnion = aControlRectUnion.Union( Rectangle( pControl->GetPosPixel(), pControl->GetSizePixel() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// need some adjustments to the positions, since the resource-specified
|
|
|
|
// positions for the control were relative to *our* parent, while by now
|
|
|
|
// the controls have |this| as parent.
|
|
|
|
|
|
|
|
// first, move ourself to the upper left of the area occupied by all controls
|
|
|
|
SetPosPixel( aControlRectUnion.TopLeft() );
|
|
|
|
|
|
|
|
// then, compensate in the control positions, by moving them the up/left
|
|
|
|
for ( Window* pControl = aSections[0].pFirstControl;
|
|
|
|
pControl != NULL;
|
|
|
|
pControl = pControl->GetWindow( WINDOW_NEXT )
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Point aPos( pControl->GetPosPixel() );
|
|
|
|
aPos.Move( -aControlRectUnion.Left(), -aControlRectUnion.Top() );
|
|
|
|
pControl->SetPosPixel( aPos );
|
|
|
|
|
|
|
|
// while we are here ... the controls should not have an own background
|
|
|
|
// (this would not be needed when our outer dialog were also the parent
|
|
|
|
// of the controls)
|
|
|
|
pControl->SetBackground();
|
|
|
|
}
|
|
|
|
|
|
|
|
// now, change our own size so all controls fit
|
|
|
|
SetSizePixel( aControlRectUnion.GetSize() );
|
|
|
|
|
|
|
|
SetBackground();
|
2004-10-27 12:00:22 +00:00
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
OTextConnectionHelper::~OTextConnectionHelper()
|
|
|
|
{
|
2005-09-23 11:27:26 +00:00
|
|
|
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
|
2006-06-20 02:04:20 +00:00
|
|
|
IMPL_LINK(OTextConnectionHelper, OnControlModified, Control*, /*EMPTYARG*/)
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
|
|
|
callModifiedHdl();
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
2006-06-20 02:04:20 +00:00
|
|
|
IMPL_LINK(OTextConnectionHelper, OnEditModified, Edit*, /*_pEdit*/)
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
|
|
|
m_aGetExtensionHandler.Call(this);
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
2006-06-20 02:04:20 +00:00
|
|
|
IMPL_LINK(OTextConnectionHelper, OnSetExtensionHdl, RadioButton*, /*_pRadioButton*/)
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
|
|
|
sal_Bool bDoEnable = m_aRBAccessOtherFiles.IsChecked();
|
|
|
|
m_aETOwnExtension.Enable(bDoEnable);
|
|
|
|
m_aFTExtensionExample.Enable(bDoEnable);
|
|
|
|
m_aGetExtensionHandler.Call(this);
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OTextConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
|
|
|
|
{
|
|
|
|
_rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aFieldSeparator));
|
|
|
|
_rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aTextSeparator));
|
|
|
|
_rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aDecimalSeparator));
|
|
|
|
_rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aThousandsSeparator));
|
2008-03-07 10:21:27 +00:00
|
|
|
_rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aRowHeader));
|
|
|
|
_rControlList.push_back(new OSaveValueWrapper<ListBox>(&m_aCharSet));
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
2012-08-10 20:50:33 +02:00
|
|
|
|
2004-10-27 12:00:22 +00:00
|
|
|
void OTextConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
|
|
|
|
{
|
|
|
|
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFieldSeparatorLabel));
|
|
|
|
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTextSeparatorLabel));
|
|
|
|
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDecimalSeparatorLabel));
|
|
|
|
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aThousandsSeparatorLabel));
|
2008-03-07 10:21:27 +00:00
|
|
|
_rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aCharSetHeader));
|
|
|
|
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aCharSetLabel));
|
|
|
|
_rControlList.push_back(new ODisableWrapper<ListBox>(&m_aCharSet));
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
|
2008-03-07 10:21:27 +00:00
|
|
|
void OTextConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bValid)
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2008-03-07 10:21:27 +00:00
|
|
|
if ( !_bValid )
|
|
|
|
return;
|
|
|
|
|
2014-02-19 21:49:02 +01:00
|
|
|
SFX_ITEMSET_GET( _rSet, pDelItem, SfxStringItem, DSID_FIELDDELIMITER, true );
|
|
|
|
SFX_ITEMSET_GET( _rSet, pStrItem, SfxStringItem, DSID_TEXTDELIMITER, true );
|
|
|
|
SFX_ITEMSET_GET( _rSet, pDecdelItem, SfxStringItem, DSID_DECIMALDELIMITER, true );
|
|
|
|
SFX_ITEMSET_GET( _rSet, pThodelItem, SfxStringItem, DSID_THOUSANDSDELIMITER, true );
|
|
|
|
SFX_ITEMSET_GET( _rSet, pExtensionItem, SfxStringItem, DSID_TEXTFILEEXTENSION, true );
|
|
|
|
SFX_ITEMSET_GET( _rSet, pCharsetItem, SfxStringItem, DSID_CHARSET, true );
|
2008-03-07 10:21:27 +00:00
|
|
|
|
|
|
|
if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
|
|
|
m_aOldExtension = pExtensionItem->GetValue();
|
2008-03-07 10:21:27 +00:00
|
|
|
SetExtension( m_aOldExtension );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( m_nAvailableSections & TC_HEADER ) != 0 )
|
|
|
|
{
|
2014-02-19 21:49:02 +01:00
|
|
|
SFX_ITEMSET_GET( _rSet, pHdrItem, SfxBoolItem, DSID_TEXTFILEHEADER, true );
|
2008-03-07 10:21:27 +00:00
|
|
|
m_aRowHeader.Check( pHdrItem->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 )
|
|
|
|
{
|
|
|
|
SetSeparator( m_aFieldSeparator, m_aFieldSeparatorList, pDelItem->GetValue() );
|
|
|
|
SetSeparator( m_aTextSeparator, m_aTextSeparatorList, pStrItem->GetValue() );
|
|
|
|
m_aDecimalSeparator.SetText( pDecdelItem->GetValue() );
|
|
|
|
m_aThousandsSeparator.SetText( pThodelItem->GetValue() );
|
|
|
|
}
|
2004-10-27 12:00:22 +00:00
|
|
|
|
2008-03-07 10:21:27 +00:00
|
|
|
if ( ( m_nAvailableSections & TC_CHARSET ) != 0 )
|
|
|
|
{
|
|
|
|
m_aCharSet.SelectEntryByIanaName( pCharsetItem->GetValue() );
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-10 09:24:01 +00:00
|
|
|
sal_Bool OTextConnectionHelper::prepareLeave()
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2006-05-04 07:40:47 +00:00
|
|
|
LocalResourceAccess aStringResAccess(PAGE_TEXT, RSC_TABPAGE);
|
2004-10-27 12:00:22 +00:00
|
|
|
// for accessing the strings which are local to our own resource block
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString sExtension = GetExtension();
|
|
|
|
OUString aErrorText;
|
2004-10-27 12:00:22 +00:00
|
|
|
Control* pErrorWin = NULL;
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString aDelText(m_aFieldSeparator.GetText());
|
|
|
|
if(aDelText.isEmpty())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // No FieldSeparator
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MISSING);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aFieldSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aFieldSeparator;
|
|
|
|
}
|
2013-01-21 14:32:09 +01:00
|
|
|
else if (m_aDecimalSeparator.GetText().isEmpty())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // No DecimalSeparator
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MISSING);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aDecimalSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aDecimalSeparator;
|
|
|
|
}
|
|
|
|
else if (m_aTextSeparator.GetText() == m_aFieldSeparator.GetText())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // Field and TextSeparator must not be the same
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MUST_DIFFER);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aTextSeparatorLabel.GetText());
|
|
|
|
aErrorText = aErrorText.replaceFirst("#2",m_aFieldSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aTextSeparator;
|
|
|
|
}
|
|
|
|
else if (m_aDecimalSeparator.GetText() == m_aThousandsSeparator.GetText())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // Thousands and DecimalSeparator must not be the same
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MUST_DIFFER);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aDecimalSeparatorLabel.GetText());
|
|
|
|
aErrorText = aErrorText.replaceFirst("#2",m_aThousandsSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aDecimalSeparator;
|
|
|
|
}
|
|
|
|
else if (m_aFieldSeparator.GetText() == m_aThousandsSeparator.GetText())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // Thousands and FieldSeparator must not be the same
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MUST_DIFFER);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aFieldSeparatorLabel.GetText());
|
|
|
|
aErrorText = aErrorText.replaceFirst("#2",m_aThousandsSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aFieldSeparator;
|
|
|
|
}
|
|
|
|
else if (m_aFieldSeparator.GetText() == m_aDecimalSeparator.GetText())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // Tenner and FieldSeparator must not be the same
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MUST_DIFFER);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aFieldSeparatorLabel.GetText());
|
|
|
|
aErrorText = aErrorText.replaceFirst("#2",m_aDecimalSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aFieldSeparator;
|
|
|
|
}
|
|
|
|
else if (m_aTextSeparator.GetText() == m_aThousandsSeparator.GetText())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // Thousands and TextSeparator must not be the same
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MUST_DIFFER);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aTextSeparatorLabel.GetText());
|
|
|
|
aErrorText = aErrorText.replaceFirst("#2",m_aThousandsSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aTextSeparator;
|
|
|
|
}
|
|
|
|
else if (m_aTextSeparator.GetText() == m_aDecimalSeparator.GetText())
|
2012-08-10 20:53:16 +02:00
|
|
|
{ // Tenner and TextSeparator must not be the same
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTODELIMITER_MUST_DIFFER);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",m_aTextSeparatorLabel.GetText());
|
|
|
|
aErrorText = aErrorText.replaceFirst("#2",m_aDecimalSeparatorLabel.GetText());
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aTextSeparator;
|
|
|
|
}
|
2013-09-26 12:17:53 +02:00
|
|
|
else if ((sExtension.indexOf('*') != -1) || (sExtension.indexOf('?') != -1))
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
aErrorText = ModuleRes(STR_AUTONO_WILDCARDS);
|
|
|
|
aErrorText = aErrorText.replaceFirst("#1",sExtension);
|
2004-10-27 12:00:22 +00:00
|
|
|
pErrorWin = &m_aETOwnExtension;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return sal_True;
|
|
|
|
ErrorBox(NULL, WB_OK, MnemonicGenerator::EraseAllMnemonicChars( aErrorText)).Execute();
|
|
|
|
pErrorWin->GrabFocus();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool OTextConnectionHelper::FillItemSet( SfxItemSet& rSet, const sal_Bool _bChangedSomething )
|
|
|
|
{
|
|
|
|
sal_Bool bChangedSomething = _bChangedSomething;
|
|
|
|
|
2008-03-07 10:21:27 +00:00
|
|
|
if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString sExtension = GetExtension();
|
|
|
|
if( m_aOldExtension != sExtension )
|
2008-03-07 10:21:27 +00:00
|
|
|
{
|
|
|
|
rSet.Put( SfxStringItem( DSID_TEXTFILEEXTENSION, sExtension ) );
|
|
|
|
bChangedSomething = sal_True;
|
|
|
|
}
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
2008-03-07 10:21:27 +00:00
|
|
|
|
|
|
|
if ( ( m_nAvailableSections & TC_HEADER ) != 0 )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2008-03-07 10:21:27 +00:00
|
|
|
if( (m_aRowHeader.GetState() != m_aRowHeader.GetSavedValue()) )
|
|
|
|
{
|
|
|
|
rSet.Put(SfxBoolItem(DSID_TEXTFILEHEADER, m_aRowHeader.IsChecked()));
|
|
|
|
bChangedSomething = sal_True;
|
|
|
|
}
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
|
2008-03-07 10:21:27 +00:00
|
|
|
if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-01-24 15:12:43 +01:00
|
|
|
if( m_aFieldSeparator.GetText() != m_aFieldSeparator.GetSavedValue() )
|
2008-03-07 10:21:27 +00:00
|
|
|
{
|
|
|
|
rSet.Put( SfxStringItem(DSID_FIELDDELIMITER, GetSeparator( m_aFieldSeparator, m_aFieldSeparatorList) ) );
|
|
|
|
bChangedSomething = sal_True;
|
|
|
|
}
|
2013-01-24 15:12:43 +01:00
|
|
|
if( m_aTextSeparator.GetText() != m_aTextSeparator.GetSavedValue() )
|
2008-03-07 10:21:27 +00:00
|
|
|
{
|
|
|
|
rSet.Put( SfxStringItem(DSID_TEXTDELIMITER, GetSeparator( m_aTextSeparator, m_aTextSeparatorList) ) );
|
|
|
|
bChangedSomething = sal_True;
|
|
|
|
}
|
|
|
|
|
2013-01-24 15:12:43 +01:00
|
|
|
if( m_aDecimalSeparator.GetText() != m_aDecimalSeparator.GetSavedValue() )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-01-21 14:32:09 +01:00
|
|
|
rSet.Put( SfxStringItem(DSID_DECIMALDELIMITER, m_aDecimalSeparator.GetText().copy(0, 1) ) );
|
2004-10-27 12:00:22 +00:00
|
|
|
bChangedSomething = sal_True;
|
|
|
|
}
|
2013-01-24 15:12:43 +01:00
|
|
|
if( m_aThousandsSeparator.GetText() != m_aThousandsSeparator.GetSavedValue() )
|
2008-03-07 10:21:27 +00:00
|
|
|
{
|
2013-01-21 14:32:09 +01:00
|
|
|
rSet.Put( SfxStringItem(DSID_THOUSANDSDELIMITER, m_aThousandsSeparator.GetText().copy(0,1) ) );
|
2008-03-07 10:21:27 +00:00
|
|
|
bChangedSomething = sal_True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( m_nAvailableSections & TC_CHARSET ) != 0 )
|
|
|
|
{
|
|
|
|
if ( m_aCharSet.StoreSelectedCharSet( rSet, DSID_CHARSET ) )
|
|
|
|
bChangedSomething = sal_True;
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
2008-03-07 10:21:27 +00:00
|
|
|
|
2004-10-27 12:00:22 +00:00
|
|
|
return bChangedSomething;
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:17:53 +02:00
|
|
|
void OTextConnectionHelper::SetExtension(const OUString& _rVal)
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
if (_rVal == "txt")
|
2014-02-21 12:53:51 +01:00
|
|
|
m_aRBAccessTextFiles.Check(true);
|
2013-09-26 12:17:53 +02:00
|
|
|
else if (_rVal == "csv")
|
2014-02-21 12:53:51 +01:00
|
|
|
m_aRBAccessCSVFiles.Check(true);
|
2004-10-27 12:00:22 +00:00
|
|
|
else
|
|
|
|
{
|
2014-02-21 12:53:51 +01:00
|
|
|
m_aRBAccessOtherFiles.Check(true);
|
2004-10-27 12:00:22 +00:00
|
|
|
m_aFTExtensionExample.SetText(_rVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString OTextConnectionHelper::GetExtension()
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString sExtension;
|
2004-10-27 12:00:22 +00:00
|
|
|
if (m_aRBAccessTextFiles.IsChecked())
|
2013-09-26 12:17:53 +02:00
|
|
|
sExtension = "txt";
|
2004-10-27 12:00:22 +00:00
|
|
|
else if (m_aRBAccessCSVFiles.IsChecked())
|
2013-09-26 12:17:53 +02:00
|
|
|
sExtension = "csv";
|
2004-10-27 12:00:22 +00:00
|
|
|
else
|
2005-03-10 15:48:52 +00:00
|
|
|
{
|
|
|
|
sExtension = m_aETOwnExtension.GetText();
|
2013-09-26 12:17:53 +02:00
|
|
|
if ( comphelper::string::equals(sExtension.getToken(0,'.'), '*') )
|
|
|
|
sExtension = sExtension.copy(2);
|
2005-03-10 15:48:52 +00:00
|
|
|
}
|
|
|
|
return sExtension;
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString OTextConnectionHelper::GetSeparator( const ComboBox& rBox, const OUString& rList )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
|
|
|
sal_Unicode nTok = '\t';
|
2014-01-15 15:26:41 +00:00
|
|
|
sal_uInt16 nPos(rBox.GetEntryPos( rBox.GetText() ));
|
2004-10-27 12:00:22 +00:00
|
|
|
|
|
|
|
if( nPos == COMBOBOX_ENTRY_NOTFOUND )
|
2013-01-21 14:32:09 +01:00
|
|
|
return rBox.GetText().copy(0);
|
2004-10-27 12:00:22 +00:00
|
|
|
|
|
|
|
if ( !( &m_aTextSeparator == &rBox && nPos == (rBox.GetEntryCount()-1) ) )
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString(
|
2013-09-26 12:17:53 +02:00
|
|
|
static_cast< sal_Unicode >( rList.getToken((nPos*2)+1, nTok ).toInt32() ));
|
2004-10-27 12:00:22 +00:00
|
|
|
// somewhat strange ... translates for instance an "32" into " "
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString();
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 12:17:53 +02:00
|
|
|
void OTextConnectionHelper::SetSeparator( ComboBox& rBox, const OUString& rList, const OUString& rVal )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
|
|
|
char nTok = '\t';
|
2013-10-28 13:20:52 +02:00
|
|
|
sal_Int32 nCnt = comphelper::string::getTokenCount(rList, nTok);
|
2014-01-15 15:26:41 +00:00
|
|
|
sal_Int32 i;
|
2004-10-27 12:00:22 +00:00
|
|
|
|
|
|
|
for( i=0 ; i<nCnt ; i+=2 )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTVal(
|
2013-09-26 12:17:53 +02:00
|
|
|
static_cast< sal_Unicode >( rList.getToken( (i+1), nTok ).toInt32() ));
|
2004-10-27 12:00:22 +00:00
|
|
|
|
2012-07-04 23:58:05 +01:00
|
|
|
if( sTVal.equals(rVal) )
|
2004-10-27 12:00:22 +00:00
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
rBox.SetText( rList.getToken( i, nTok ) );
|
2004-10-27 12:00:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( i >= nCnt )
|
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
if ( &m_aTextSeparator == &rBox && rVal.isEmpty() )
|
2004-10-27 12:00:22 +00:00
|
|
|
rBox.SetText(m_aTextNone);
|
|
|
|
else
|
2013-09-26 12:17:53 +02:00
|
|
|
rBox.SetText( rVal.copy(0, 1) );
|
2004-10-27 12:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-10 20:50:33 +02:00
|
|
|
}
|
2010-10-12 15:59:03 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|