LibreOffice Module sw (master) 1
javaedit.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 <com/sun/star/ui/dialogs/TemplateDescription.hpp>
21#include <svl/urihelper.hxx>
22#include <view.hxx>
23#include <sfx2/docfile.hxx>
25#include <docsh.hxx>
26#include <wrtsh.hxx>
27#include <fldbas.hxx>
28#include <fldmgr.hxx>
29#include <docufld.hxx>
30#include <javaedit.hxx>
31
32#include <strings.hrc>
33
34using namespace ::com::sun::star;
35
37 : GenericDialogController(pParent, "modules/swriter/ui/insertscript.ui", "InsertScriptDialog")
38 , m_bNew(true)
39 , m_bIsUrl(false)
40 , m_pSh(pWrtSh)
41 , m_xTypeED(m_xBuilder->weld_entry("scripttype"))
42 , m_xUrlRB(m_xBuilder->weld_radio_button("url"))
43 , m_xEditRB(m_xBuilder->weld_radio_button("text"))
44 , m_xUrlPB(m_xBuilder->weld_button("browse"))
45 , m_xUrlED(m_xBuilder->weld_entry("urlentry"))
46 , m_xEditED(m_xBuilder->weld_text_view("textentry"))
47 , m_xOKBtn(m_xBuilder->weld_button("ok"))
48 , m_xPrevBtn(m_xBuilder->weld_button("previous"))
49 , m_xNextBtn(m_xBuilder->weld_button("next"))
50{
51 // install handler
52 m_xPrevBtn->connect_clicked( LINK( this, SwJavaEditDialog, PrevHdl ) );
53 m_xNextBtn->connect_clicked( LINK( this, SwJavaEditDialog, NextHdl ) );
54 m_xOKBtn->connect_clicked( LINK( this, SwJavaEditDialog, OKHdl ) );
55
56 Link<weld::Toggleable&,void> aLk = LINK(this, SwJavaEditDialog, RadioButtonHdl);
57 m_xUrlRB->connect_toggled(aLk);
58 m_xEditRB->connect_toggled(aLk);
59 m_xUrlPB->connect_clicked(LINK(this, SwJavaEditDialog, InsertFileHdl));
60
61 m_pMgr.reset(new SwFieldMgr(m_pSh));
62 m_pField = static_cast<SwScriptField*>(m_pMgr->GetCurField());
63
65
67
68 if (!m_bNew)
69 m_xDialog->set_title(SwResId(STR_JAVA_EDIT));
70
72}
73
75{
77 m_pMgr.reset();
78 m_pFileDlg.reset();
79}
80
82{
83 m_pSh->EnterStdMode();
84
85 SetField();
86 m_pMgr->GoPrev();
87 m_pField = static_cast<SwScriptField*>(m_pMgr->GetCurField());
88 CheckTravel();
89 UpdateFromRadioButtons();
90}
91
93{
94 m_pSh->EnterStdMode();
95
96 SetField();
97 m_pMgr->GoNext();
98 m_pField = static_cast<SwScriptField*>(m_pMgr->GetCurField());
99 CheckTravel();
100 UpdateFromRadioButtons();
101}
102
104{
105 SetField();
106 m_xDialog->response(RET_OK);
107}
108
110{
111 bool bTravel = false;
112 bool bNext(false), bPrev(false);
113
114 if (!m_bNew)
115 {
116 // Traveling only when more than one field
119
120 bNext = m_pMgr->GoNext();
121 if( bNext )
122 m_pMgr->GoPrev();
123
124 bPrev = m_pMgr->GoPrev();
125 if( bPrev )
126 m_pMgr->GoNext();
127 bTravel |= bNext || bPrev;
128
130 m_pSh->EndAction();
131
132 if (m_pField->IsCodeURL())
133 {
134 OUString sURL(m_pField->GetPar2());
135 if(!sURL.isEmpty())
136 {
137 INetURLObject aINetURL(sURL);
138 if(INetProtocol::File == aINetURL.GetProtocol())
139 sURL = aINetURL.PathToFileName();
140 }
141 m_xUrlED->set_text(sURL);
142 m_xEditED->set_text(OUString());
143 m_xUrlRB->set_active(true);
144 }
145 else
146 {
147 m_xEditED->set_text(m_pField->GetPar2());
148 m_xUrlED->set_text(OUString());
149 m_xEditRB->set_active(true);
150 }
151 m_xTypeED->set_text(m_pField->GetPar1());
152 }
153
154 if ( !bTravel )
155 {
156 m_xPrevBtn->hide();
157 m_xNextBtn->hide();
158 }
159 else
160 {
161 m_xPrevBtn->set_sensitive(bPrev);
162 m_xNextBtn->set_sensitive(bNext);
163 }
164}
165
167{
168 if( !m_xOKBtn->get_sensitive() )
169 return ;
170
171 m_aType = m_xTypeED->get_text();
172 m_bIsUrl = m_xUrlRB->get_active();
173
174 if (m_bIsUrl)
175 {
176 m_aText = m_xUrlED->get_text();
177 if (!m_aText.isEmpty())
178 {
179 SfxMedium* pMedium = m_pSh->GetView().GetDocShell()->GetMedium();
180 INetURLObject aAbs;
181 if( pMedium )
182 aAbs = pMedium->GetURLObject();
183
186 }
187 }
188 else
189 m_aText = m_xEditED->get_text();
190
191 if (m_aType.isEmpty())
192 m_aType = "JavaScript";
193}
194
196{
197 return m_pField && ( sal_uInt32(m_bIsUrl ? 1 : 0) != m_pField->GetFormat() || m_pField->GetPar2() != m_aType || m_pField->GetPar1() != m_aText );
198}
199
200IMPL_LINK(SwJavaEditDialog, RadioButtonHdl, weld::Toggleable&, rButton, void)
201{
202 if (!rButton.get_active())
203 return;
204 UpdateFromRadioButtons();
205}
206
208{
209 bool bEnable = m_xUrlRB->get_active();
210 m_xUrlPB->set_sensitive(bEnable);
211 m_xUrlED->set_sensitive(bEnable);
212 m_xEditED->set_sensitive(!bEnable);
213
214 if (!m_bNew)
215 {
216 bEnable = !m_pSh->IsReadOnlyAvailable() || !m_pSh->HasReadonlySel();
217 m_xOKBtn->set_sensitive(bEnable);
218 m_xUrlED->set_editable(bEnable);
219 m_xEditED->set_editable(bEnable);
220 m_xTypeED->set_editable(bEnable);
221 if( m_xUrlPB->get_sensitive() && !bEnable )
222 m_xUrlPB->set_sensitive( false );
223 }
224}
225
227{
228 if (!m_pFileDlg)
229 {
230 m_pFileDlg.reset(new ::sfx2::FileDialogHelper(
231 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
232 FileDialogFlags::Insert, "swriter", SfxFilterFlags::NONE, SfxFilterFlags::NONE, m_xDialog.get()));
233 }
234 m_pFileDlg->SetContext(sfx2::FileDialogHelper::WriterInsertScript);
235 m_pFileDlg->StartExecuteModal( LINK( this, SwJavaEditDialog, DlgClosedHdl ) );
236}
237
239{
240 if (m_pFileDlg->GetError() == ERRCODE_NONE)
241 {
242 OUString sFileName = m_pFileDlg->GetPath();
243 if ( !sFileName.isEmpty() )
244 {
245 INetURLObject aINetURL( sFileName );
246 if ( INetProtocol::File == aINetURL.GetProtocol() )
247 sFileName = aINetURL.PathToFileName();
248 }
249 m_xUrlED->set_text(sFileName);
250 }
251}
252
253/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
OUString PathToFileName() const
INetProtocol GetProtocol() const
const INetURLObject & GetURLObject() const
SfxMedium * GetMedium() const
bool IsReadOnlyAvailable() const
Definition: crsrsh.hxx:483
void StartAction()
Definition: crsrsh.cxx:225
SwPaM * CreateCursor()
delete the current cursor and make the following into the current
Definition: crsrsh.cxx:122
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:242
void DestroyCursor()
transform TableCursor to normal cursor, nullify Tablemode
Definition: crsrsh.cxx:150
bool HasReadonlySel(bool isReplace=false) const
Definition: crsrsh.cxx:3357
SwFieldIds Which() const
Definition: fldbas.hxx:273
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:403
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
std::unique_ptr< weld::Button > m_xPrevBtn
Definition: javaedit.hxx:50
std::unique_ptr< weld::Button > m_xOKBtn
Definition: javaedit.hxx:49
std::unique_ptr< weld::RadioButton > m_xEditRB
Definition: javaedit.hxx:45
std::unique_ptr< weld::TextView > m_xEditED
Definition: javaedit.hxx:48
virtual ~SwJavaEditDialog() override
Definition: javaedit.cxx:74
std::unique_ptr< sfx2::FileDialogHelper > m_pFileDlg
Definition: javaedit.hxx:41
void UpdateFromRadioButtons()
Definition: javaedit.cxx:207
std::unique_ptr< SwFieldMgr > m_pMgr
Definition: javaedit.hxx:39
std::unique_ptr< weld::Button > m_xUrlPB
Definition: javaedit.hxx:46
OUString m_aType
Definition: javaedit.hxx:33
OUString m_aText
Definition: javaedit.hxx:32
std::unique_ptr< weld::Entry > m_xTypeED
Definition: javaedit.hxx:43
std::unique_ptr< weld::RadioButton > m_xUrlRB
Definition: javaedit.hxx:44
SwWrtShell * m_pSh
Definition: javaedit.hxx:40
bool IsUpdate() const
Definition: javaedit.cxx:195
SwScriptField * m_pField
Definition: javaedit.hxx:38
void CheckTravel()
Definition: javaedit.cxx:109
std::unique_ptr< weld::Button > m_xNextBtn
Definition: javaedit.hxx:51
SwJavaEditDialog(weld::Window *pParent, SwWrtShell *pWrtSh)
Definition: javaedit.cxx:36
std::unique_ptr< weld::Entry > m_xUrlED
Definition: javaedit.hxx:47
bool IsCodeURL() const
Definition: docufld.hxx:722
virtual OUString GetPar1() const override
Type.
Definition: scrptfld.cxx:66
virtual OUString GetPar2() const override
Text.
Definition: scrptfld.cxx:77
SwDocShell * GetDocShell()
Definition: view.cxx:1159
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void EnterStdMode()
Definition: select.cxx:551
const SwView & GetView() const
Definition: wrtsh.hxx:438
std::shared_ptr< weld::Dialog > m_xDialog
#define ERRCODE_NONE
IMPL_LINK_NOARG(SwJavaEditDialog, PrevHdl, weld::Button &, void)
Definition: javaedit.cxx:81
IMPL_LINK(SwJavaEditDialog, RadioButtonHdl, weld::Toggleable &, rButton, void)
Definition: javaedit.cxx:200
SVL_DLLPUBLIC Link< OUString *, bool > const & GetMaybeFileHdl()
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
RET_OK