1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "newdatatype.hxx"
21 #include "modulepcr.hxx"
22 #include "formresid.hrc"
32 NewDataTypeDialog::NewDataTypeDialog( vcl::Window
* _pParent
, const OUString
& _rNameBase
, const ::std::vector
< OUString
>& _rProhibitedNames
)
33 : ModalDialog( _pParent
, "DataTypeDialog",
34 "modules/spropctrlr/ui/datatypedialog.ui" )
35 , m_aProhibitedNames( _rProhibitedNames
.begin(), _rProhibitedNames
.end() )
37 get(m_pName
, "entry");
40 m_pName
->SetModifyHdl( LINK( this, NewDataTypeDialog
, OnNameModified
) );
42 // find an initial name
43 // for this, first remove trailing digits
44 sal_Int32 nStripUntil
= _rNameBase
.getLength();
45 while ( nStripUntil
> 0 )
47 sal_Unicode nChar
= _rNameBase
[ --nStripUntil
];
48 if ( ( nChar
< '0' ) || ( nChar
> '9' ) )
51 --nStripUntil
; // strip the space, too
56 OUString
sNameBase( _rNameBase
.copy( 0, nStripUntil
? nStripUntil
+ 1 : 0 ) );
58 OUString sInitialName
;
59 sal_Int32 nPostfixNumber
= 1;
62 ( sInitialName
= sNameBase
) += OUString::number(nPostfixNumber
++);
64 while ( m_aProhibitedNames
.find( sInitialName
) != m_aProhibitedNames
.end() );
66 m_pName
->SetText( sInitialName
);
67 OnNameModified( NULL
);
70 NewDataTypeDialog::~NewDataTypeDialog()
75 void NewDataTypeDialog::dispose()
79 ModalDialog::dispose();
82 IMPL_LINK_NOARG( NewDataTypeDialog
, OnNameModified
)
84 OUString sCurrentName
= GetName();
85 bool bNameIsOK
= ( !sCurrentName
.isEmpty() )
86 && ( m_aProhibitedNames
.find( sCurrentName
) == m_aProhibitedNames
.end() );
88 m_pOK
->Enable( bNameIsOK
);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */