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 <swtypes.hxx>
21 #include <globals.hrc>
22 
23 #include <unoprnms.hxx>
24 #include <osl/diagnose.h>
25 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
26 #include <com/sun/star/view/XScreenCursor.hpp>
27 #include <com/sun/star/view/DocumentZoomType.hpp>
28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <com/sun/star/style/XStyle.hpp>
30 #include <com/sun/star/text/XText.hpp>
31 #include <com/sun/star/text/XTextDocument.hpp>
32 #include <com/sun/star/awt/PosSize.hpp>
33 #include <com/sun/star/view/XViewSettingsSupplier.hpp>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <sfx2/dispatch.hxx>
36 #include <svl/stritem.hxx>
37 #include <shellio.hxx>
38 #include <docsh.hxx>
39 #include <view.hxx>
40 #include <wrtsh.hxx>
41 #include <swmodule.hxx>
42 #include <unocrsr.hxx>
43 
44 #include <swrenamexnameddlg.hxx>
45 
46 using namespace ::com::sun::star;
47 
49  uno::Reference< container::XNamed > & xN,
50  uno::Reference< container::XNameAccess > & xNA )
51  : GenericDialogController(pWin, "modules/swriter/ui/renameobjectdialog.ui", "RenameObjectDialog")
52  , xNamed(xN)
53  , xNameAccess(xNA)
54  , m_xNewNameED(m_xBuilder->weld_entry("entry"))
55  , m_xOk(m_xBuilder->weld_button("ok"))
56 {
57  m_xNewNameED->connect_insert_text(LINK(this, SwRenameXNamedDlg, TextFilterHdl));
58 
59  OUString sTmp(m_xDialog->get_title());
60  m_xNewNameED->set_text(xNamed->getName());
61  m_xNewNameED->select_region(0, -1);
62  sTmp += xNamed->getName();
63  m_xDialog->set_title(sTmp);
64 
65  m_xOk->connect_clicked(LINK(this, SwRenameXNamedDlg, OkHdl));
66  m_xNewNameED->connect_changed(LINK(this, SwRenameXNamedDlg, ModifyHdl));
67  m_xOk->set_sensitive(false);
68 }
69 
70 IMPL_LINK(SwRenameXNamedDlg, TextFilterHdl, OUString&, rTest, bool)
71 {
72  rTest = m_aTextFilter.filter(rTest);
73  return true;
74 }
75 
77 {
78  try
79  {
80  xNamed->setName(m_xNewNameED->get_text());
81  }
82  catch (const uno::RuntimeException&)
83  {
84  OSL_FAIL("name wasn't changed");
85  }
86  m_xDialog->response(RET_OK);
87 }
88 
89 IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, weld::Entry&, rEdit, void)
90 {
91  OUString sTmp(rEdit.get_text());
92 
93  m_xOk->set_sensitive(!sTmp.isEmpty()
94  && !xNameAccess->hasByName(sTmp)
95  && (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
96  && (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp))
97  );
98 }
99 
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< weld::Dialog > m_xDialog
IMPL_LINK(SwRenameXNamedDlg, TextFilterHdl, OUString &, rTest, bool)
css::uno::Reference< css::container::XNamed > & xNamed
IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl, weld::Button &, void)
virtual OUString get_text() const =0
std::shared_ptr< weld::Entry > m_xNewNameED
SwRenameXNamedDlg(weld::Window *pParent, css::uno::Reference< css::container::XNamed > &xNamed, css::uno::Reference< css::container::XNameAccess > &xNameAccess)
weld::Entry & rEdit
RET_OK
std::shared_ptr< weld::Button > m_xOk