Line data Source code
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 <utlui.hrc>
24 : #include <../../uibase/utlui/unotools.hrc>
25 : #include <unoprnms.hxx>
26 : #include <osl/diagnose.h>
27 : #include <vcl/msgbox.hxx>
28 : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
29 : #include <com/sun/star/view/XScreenCursor.hpp>
30 : #include <com/sun/star/view/DocumentZoomType.hpp>
31 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
32 : #include <com/sun/star/style/XStyle.hpp>
33 : #include <com/sun/star/frame/XFrame.hpp>
34 : #include <com/sun/star/text/XText.hpp>
35 : #include <com/sun/star/text/XTextDocument.hpp>
36 : #include <com/sun/star/awt/PosSize.hpp>
37 : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
38 : #include <com/sun/star/container/XNameContainer.hpp>
39 : #include <comphelper/processfactory.hxx>
40 : #include <comphelper/string.hxx>
41 : #include <sfx2/dispatch.hxx>
42 : #include <svl/stritem.hxx>
43 : #include <shellio.hxx>
44 : #include <docsh.hxx>
45 : #include <view.hxx>
46 : #include <wrtsh.hxx>
47 : #include <swmodule.hxx>
48 : #include <unocrsr.hxx>
49 :
50 : #include "swrenamexnameddlg.hxx"
51 :
52 : using namespace ::com::sun::star;
53 :
54 0 : SwRenameXNamedDlg::SwRenameXNamedDlg( vcl::Window* pWin,
55 : uno::Reference< container::XNamed > & xN,
56 : uno::Reference< container::XNameAccess > & xNA )
57 : : ModalDialog(pWin, "RenameObjectDialog",
58 : "modules/swriter/ui/renameobjectdialog.ui")
59 : , xNamed(xN)
60 0 : , xNameAccess(xNA)
61 : {
62 0 : get(m_pNewNameED, "entry");
63 0 : m_pNewNameED->SetTextFilter(&m_aTextFilter);
64 0 : get(m_pOk, "ok");
65 :
66 0 : OUString sTmp(GetText());
67 0 : m_pNewNameED->SetText(xNamed->getName());
68 0 : m_pNewNameED->SetSelection(Selection(SELECTION_MIN, SELECTION_MAX));
69 0 : sTmp += xNamed->getName();
70 0 : SetText(sTmp);
71 :
72 0 : m_pOk->SetClickHdl(LINK(this, SwRenameXNamedDlg, OkHdl));
73 0 : m_pNewNameED->SetModifyHdl(LINK(this, SwRenameXNamedDlg, ModifyHdl));
74 0 : m_pOk->Enable(false);
75 0 : }
76 :
77 0 : IMPL_LINK_NOARG(SwRenameXNamedDlg, OkHdl)
78 : {
79 : try
80 : {
81 0 : xNamed->setName(m_pNewNameED->GetText());
82 : }
83 0 : catch (const uno::RuntimeException&)
84 : {
85 : OSL_FAIL("name wasn't changed");
86 : }
87 0 : EndDialog(RET_OK);
88 0 : return 0;
89 : }
90 :
91 0 : IMPL_LINK(SwRenameXNamedDlg, ModifyHdl, Edit*, pEdit)
92 : {
93 0 : OUString sTmp(pEdit->GetText());
94 :
95 0 : m_pOk->Enable(!sTmp.isEmpty()
96 0 : && !xNameAccess->hasByName(sTmp)
97 0 : && (!xSecondAccess.is() || !xSecondAccess->hasByName(sTmp))
98 0 : && (!xThirdAccess.is() || !xThirdAccess->hasByName(sTmp))
99 0 : );
100 0 : return 0;
101 0 : }
102 :
103 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|