LibreOffice Module sw (master) 1
swrenamexnameddlg.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 <osl/diagnose.h>
21
22#include <swrenamexnameddlg.hxx>
23
24using namespace ::com::sun::star;
25
27 uno::Reference< container::XNamed > & xN,
28 uno::Reference< container::XNameAccess > & xNA )
29 : GenericDialogController(pParent, "modules/swriter/ui/renameobjectdialog.ui", "RenameObjectDialog")
30 , m_xNamed(xN)
31 , m_xNameAccess(xNA)
32 , m_xNewNameED(m_xBuilder->weld_entry("entry"))
33 , m_xOk(m_xBuilder->weld_button("ok"))
34{
35 m_xNewNameED->connect_insert_text(LINK(this, SwRenameXNamedDlg, TextFilterHdl));
36
37 OUString sTmp(m_xDialog->get_title());
38 m_xNewNameED->set_text(m_xNamed->getName());
39 m_xNewNameED->select_region(0, -1);
40 sTmp += m_xNamed->getName();
41 m_xDialog->set_title(sTmp);
42
43 m_xOk->connect_clicked(LINK(this, SwRenameXNamedDlg, OkHdl));
44 m_xNewNameED->connect_changed(LINK(this, SwRenameXNamedDlg, ModifyHdl));
45 m_xOk->set_sensitive(false);
46}
47
48IMPL_LINK(SwRenameXNamedDlg, TextFilterHdl, OUString&, rTest, bool)
49{
50 rTest = m_aTextFilter.filter(rTest);
51 return true;
52}
53
55{
56 try
57 {
58 m_xNamed->setName(m_xNewNameED->get_text());
59 }
60 catch (const uno::RuntimeException&)
61 {
62 OSL_FAIL("name wasn't changed");
63 }
64 m_xDialog->response(RET_OK);
65}
66
67IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, weld::Entry&, rEdit, void)
68{
69 OUString sTmp(rEdit.get_text());
70
71 m_xOk->set_sensitive(!sTmp.isEmpty()
72 && !m_xNameAccess->hasByName(sTmp)
73 && (!m_xSecondAccess.is() || !m_xSecondAccess->hasByName(sTmp))
74 && (!m_xThirdAccess.is() || !m_xThirdAccess->hasByName(sTmp))
75 );
76}
77
78/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
SwRenameXNamedDlg(weld::Widget *pParent, css::uno::Reference< css::container::XNamed > &xNamed, css::uno::Reference< css::container::XNameAccess > &xNameAccess)
std::unique_ptr< weld::Entry > m_xNewNameED
std::unique_ptr< weld::Button > m_xOk
css::uno::Reference< css::container::XNamed > & m_xNamed
std::shared_ptr< weld::Dialog > m_xDialog
IMPL_LINK(SwRenameXNamedDlg, TextFilterHdl, OUString &, rTest, bool)
IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl, weld::Button &, void)
RET_OK