bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / propctrlr / newdatatype.cxx
blobc6d76be1433defee9fca2c29f6299943c29a13da
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 namespace pcr
29 //= NewDataTypeDialog
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");
38 get(m_pOK, "ok");
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' ) )
50 if ( nChar == ' ' )
51 --nStripUntil; // strip the space, too
52 break;
56 OUString sNameBase( _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) );
57 sNameBase += " ";
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()
72 disposeOnce();
75 void NewDataTypeDialog::dispose()
77 m_pName.clear();
78 m_pOK.clear();
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 );
90 return 0L;
94 } // namespace pcr
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */