Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / extensions / source / propctrlr / newdatatype.cxx
blob1b0f4e1c094784d18122d4d88516dbdd867cab3c
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 <strings.hrc>
24 namespace pcr
28 //= NewDataTypeDialog
31 NewDataTypeDialog::NewDataTypeDialog(weld::Window* pParent, const OUString& _rNameBase, const std::vector< OUString >& _rProhibitedNames)
32 : GenericDialogController(pParent, "modules/spropctrlr/ui/datatypedialog.ui", "DataTypeDialog")
33 , m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() )
34 , m_xName(m_xBuilder->weld_entry("entry"))
35 , m_xOK(m_xBuilder->weld_button("ok"))
37 m_xName->connect_changed(LINK(this, NewDataTypeDialog, OnNameModified));
39 // find an initial name
40 // for this, first remove trailing digits
41 sal_Int32 nStripUntil = _rNameBase.getLength();
42 while ( nStripUntil > 0 )
44 sal_Unicode nChar = _rNameBase[ --nStripUntil ];
45 if ( ( nChar < '0' ) || ( nChar > '9' ) )
47 if ( nChar == ' ' )
48 --nStripUntil; // strip the space, too
49 break;
53 OUString sNameBase = _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) + " ";
54 OUString sInitialName;
55 sal_Int32 nPostfixNumber = 1;
58 sInitialName = sNameBase + OUString::number(nPostfixNumber++);
60 while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
62 m_xName->set_text(sInitialName);
63 OnNameModified(*m_xName);
66 NewDataTypeDialog::~NewDataTypeDialog()
70 IMPL_LINK_NOARG(NewDataTypeDialog, OnNameModified, weld::Entry&, void)
72 OUString sCurrentName = GetName();
73 bool bNameIsOK = ( !sCurrentName.isEmpty() )
74 && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
76 m_xOK->set_sensitive(bNameIsOK);
78 } // namespace pcr
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */