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