Kaydet (Commit) 74706c40 authored tarafından Caolán McNamara's avatar Caolán McNamara

on using 'add' color button, don't frighten with an error

that the name already exists if the user didn't use the
edit entry yet. Just always, like the gradient one, put
up the dialog to enter a name, use the entry text if
that name isn't taken, and generate a new one if its is.

Change-Id: Ibd3d37db73ecdbae7998884d3397cbc2bc6b7c3f
üst 7368b6ca
...@@ -685,55 +685,68 @@ IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl) ...@@ -685,55 +685,68 @@ IMPL_LINK_NOARG(SvxColorTabPage, ModifiedHdl_Impl)
IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl) IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl)
{ {
vcl::Window *pWindow = this; OUString aNewName( SVX_RES( RID_SVXSTR_COLOR ) );
while( pWindow ) OUString aDesc( CUI_RES( RID_SVXSTR_DESC_COLOR ) );
{
pWindow = pWindow->GetParent();
}
ResMgr& rMgr = CUI_MGR();
OUString aDesc( ResId( RID_SVXSTR_DESC_COLOR, rMgr ) );
OUString aName( m_pEdtName->GetText() ); OUString aName( m_pEdtName->GetText() );
long nCount = pColorList->Count(); long nCount = pColorList->Count();
bool bDifferent = true; long j = 1;
// check if name is already existing // check if name is already existing
for ( long i = 0; i < nCount && bDifferent; i++ ) while (1)
if ( aName == pColorList->GetColor( i )->GetName() ) {
bDifferent = false; bool bDifferent = true;
for( long i = 0; i < nCount && bDifferent; i++ )
if ( aName == pColorList->GetColor( i )->GetName() )
bDifferent = false;
if (bDifferent)
break;
// if yes, it is repeated and a new name is demanded aName = aNewName;
if ( !bDifferent ) aName += " ";
aName += OUString::number( j++ );
}
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
ScopedVclPtr<MessageDialog> pWarnBox;
sal_uInt16 nError = 1;
while (pDlg->Execute() == RET_OK)
{ {
ScopedVclPtrInstance<MessageDialog> aWarningBox( GetParentDialog() pDlg->GetName( aName );
,"DuplicateNameDialog"
,"cui/ui/queryduplicatedialog.ui");
aWarningBox->Execute();
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); bool bDifferent = true;
boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
bool bLoop = true;
while ( !bDifferent && bLoop && pDlg->Execute() == RET_OK ) for (long i = 0; i < nCount && bDifferent; ++i)
{ {
pDlg->GetName( aName ); if( aName == pColorList->GetColor( i )->GetName() )
bDifferent = true; bDifferent = false;
}
for( long i = 0; i < nCount && bDifferent; i++ ) if (bDifferent)
{ {
if( aName == pColorList->GetColor( i )->GetName() ) nError = 0;
bDifferent = false; break;
} }
if( bDifferent ) if( !pWarnBox )
bLoop = false; {
else pWarnBox.reset(new MessageDialog( GetParentDialog()
aWarningBox->Execute(); ,"DuplicateNameDialog"
,"cui/ui/queryduplicatedialog.ui"));
} }
if( pWarnBox->Execute() != RET_OK )
break;
} }
// if not existing the entry is entered pDlg.reset();
if( bDifferent ) pWarnBox.reset();
if (!nError)
{ {
XColorEntry* pEntry = new XColorEntry( aCurrentColor, aName ); XColorEntry* pEntry = new XColorEntry( aCurrentColor, aName );
...@@ -749,6 +762,7 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl) ...@@ -749,6 +762,7 @@ IMPL_LINK_NOARG(SvxColorTabPage, ClickAddHdl_Impl)
SelectColorLBHdl_Impl( this ); SelectColorLBHdl_Impl( this );
} }
UpdateModified(); UpdateModified();
return 0; return 0;
......
...@@ -454,23 +454,23 @@ IMPL_LINK_NOARG(SvxGradientTabPage, ClickAddHdl_Impl) ...@@ -454,23 +454,23 @@ IMPL_LINK_NOARG(SvxGradientTabPage, ClickAddHdl_Impl)
} }
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
DBG_ASSERT(pFact, "Dialog creation failed!");
boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc )); boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ));
DBG_ASSERT(pDlg, "Dialog creation failed!");
ScopedVclPtr<MessageDialog> pWarnBox; ScopedVclPtr<MessageDialog> pWarnBox;
sal_uInt16 nError = 1; sal_uInt16 nError = 1;
while( pDlg->Execute() == RET_OK ) while (pDlg->Execute() == RET_OK)
{ {
pDlg->GetName( aName ); pDlg->GetName( aName );
bDifferent = true; bDifferent = true;
for( long i = 0; i < nCount && bDifferent; i++ ) for (long i = 0; i < nCount && bDifferent; ++i)
{
if( aName == pGradientList->GetGradient( i )->GetName() ) if( aName == pGradientList->GetGradient( i )->GetName() )
bDifferent = false; bDifferent = false;
}
if( bDifferent ) if (bDifferent)
{ {
nError = 0; nError = 0;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment