LibreOffice Module extensions (master) 1
newdatatype.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "newdatatype.hxx"
21
22namespace pcr
23{
24
25
26 //= NewDataTypeDialog
27
28
29 NewDataTypeDialog::NewDataTypeDialog(weld::Window* pParent, std::u16string_view _rNameBase, const std::vector< OUString >& _rProhibitedNames)
30 : GenericDialogController(pParent, "modules/spropctrlr/ui/datatypedialog.ui", "DataTypeDialog")
31 , m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() )
32 , m_xName(m_xBuilder->weld_entry("entry"))
33 , m_xOK(m_xBuilder->weld_button("ok"))
34 {
35 m_xName->connect_changed(LINK(this, NewDataTypeDialog, OnNameModified));
36
37 // find an initial name
38 // for this, first remove trailing digits
39 sal_Int32 nStripUntil = _rNameBase.size();
40 while ( nStripUntil > 0 )
41 {
42 sal_Unicode nChar = _rNameBase[ --nStripUntil ];
43 if ( ( nChar < '0' ) || ( nChar > '9' ) )
44 {
45 if ( nChar == ' ' )
46 --nStripUntil; // strip the space, too
47 break;
48 }
49 }
50
51 OUString sNameBase = OUString::Concat(_rNameBase.substr( 0, nStripUntil ? nStripUntil + 1 : 0 )) + " ";
52 OUString sInitialName;
53 sal_Int32 nPostfixNumber = 1;
54 do
55 {
56 sInitialName = sNameBase + OUString::number(nPostfixNumber++);
57 }
58 while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
59
60 m_xName->set_text(sInitialName);
61 OnNameModified(*m_xName);
62 }
63
65 {
66 }
67
69 {
70 OUString sCurrentName = GetName();
71 bool bNameIsOK = ( !sCurrentName.isEmpty() )
72 && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
73
74 m_xOK->set_sensitive(bNameIsOK);
75 }
76} // namespace pcr
77
78
79/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~NewDataTypeDialog() override
Definition: newdatatype.cxx:64
NewDataTypeDialog(weld::Window *_pParent, std::u16string_view _rNameBase, const std::vector< OUString > &_rProhibitedNames)
Definition: newdatatype.cxx:29
std::set< OUString > m_aProhibitedNames
Definition: newdatatype.hxx:34
std::unique_ptr< weld::Entry > m_xName
Definition: newdatatype.hxx:36
virtual OUString GetName() const override
enumrange< T >::Iterator begin(enumrange< T >)
end
a property handler for any virtual string properties
Definition: browserline.cxx:39
IMPL_LINK_NOARG(OBrowserLine, OnButtonFocus, weld::Widget &, void)
sal_uInt16 sal_Unicode