tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / extensions / source / propctrlr / newdatatype.cxx
blob648f05199b4d0ac971a6fe2167b3c685dd48237e
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"
22 namespace pcr
26 //= NewDataTypeDialog
29 NewDataTypeDialog::NewDataTypeDialog(weld::Window* pParent, std::u16string_view _rNameBase, const std::vector< OUString >& _rProhibitedNames)
30 : GenericDialogController(pParent, u"modules/spropctrlr/ui/datatypedialog.ui"_ustr, u"DataTypeDialog"_ustr)
31 , m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() )
32 , m_xName(m_xBuilder->weld_entry(u"entry"_ustr))
33 , m_xOK(m_xBuilder->weld_button(u"ok"_ustr))
35 m_xName->connect_changed(LINK(this, NewDataTypeDialog, OnNameModified));
37 // find an initial name
38 // for this, first remove trailing digits
39 sal_Int32 nStripUntil = _rNameBase.size();
40 while ( nStripUntil > 0 )
42 sal_Unicode nChar = _rNameBase[ --nStripUntil ];
43 if ( ( nChar < '0' ) || ( nChar > '9' ) )
45 if ( nChar == ' ' )
46 --nStripUntil; // strip the space, too
47 break;
51 OUString sNameBase = OUString::Concat(_rNameBase.substr( 0, nStripUntil ? nStripUntil + 1 : 0 )) + " ";
52 OUString sInitialName;
53 sal_Int32 nPostfixNumber = 1;
56 sInitialName = sNameBase + OUString::number(nPostfixNumber++);
58 while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
60 m_xName->set_text(sInitialName);
61 OnNameModified(*m_xName);
64 NewDataTypeDialog::~NewDataTypeDialog()
68 IMPL_LINK_NOARG(NewDataTypeDialog, OnNameModified, weld::Entry&, void)
70 OUString sCurrentName = GetName();
71 bool bNameIsOK = ( !sCurrentName.isEmpty() )
72 && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
74 m_xOK->set_sensitive(bNameIsOK);
76 } // namespace pcr
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */