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 
24 using namespace ::com::sun::star;
25 
27  uno::Reference< container::XNamed > & xN,
28  uno::Reference< container::XNameAccess > & xNA )
29  : GenericDialogController(pWin, "modules/swriter/ui/renameobjectdialog.ui", "RenameObjectDialog")
30  , xNamed(xN)
31  , 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(xNamed->getName());
39  m_xNewNameED->select_region(0, -1);
40  sTmp += 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 
48 IMPL_LINK(SwRenameXNamedDlg, TextFilterHdl, OUString&, rTest, bool)
49 {
50  rTest = m_aTextFilter.filter(rTest);
51  return true;
52 }
53 
55 {
56  try
57  {
58  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 
67 IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, weld::Entry&, rEdit, void)
68 {
69  OUString sTmp(rEdit.get_text());
70 
71  m_xOk->set_sensitive(!sTmp.isEmpty()
72  && !xNameAccess->hasByName(sTmp)
73  && (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
74  && (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp))
75  );
76 }
77 
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::Button > m_xOk
IMPL_LINK(SwRenameXNamedDlg, TextFilterHdl, OUString &, rTest, bool)
css::uno::Reference< css::container::XNamed > & xNamed
IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl, weld::Button &, void)
std::unique_ptr< weld::Entry > m_xNewNameED
virtual OUString get_text() const =0
SwRenameXNamedDlg(weld::Window *pParent, css::uno::Reference< css::container::XNamed > &xNamed, css::uno::Reference< css::container::XNameAccess > &xNameAccess)
weld::Entry & rEdit
RET_OK
Reference< XExecutableDialog > m_xDialog