1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "moduldlg.hxx"
22 #include <basidesh.hxx>
23 #include <strings.hrc>
24 #include <bitmaps.hlst>
25 #include <iderdll.hxx>
26 #include "iderdll2.hxx"
29 #include <svx/passwd.hxx>
30 #include <ucbhelper/content.hxx>
31 #include <rtl/uri.hxx>
32 #include <sfx2/app.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/filedlghelper.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/sfxsids.hrc>
37 #include <sfx2/viewfrm.hxx>
38 #include <svl/stritem.hxx>
39 #include <tools/debug.hxx>
40 #include <tools/urlobj.hxx>
41 #include <tools/diagnose_ex.h>
42 #include <vcl/svapp.hxx>
43 #include <vcl/weld.hxx>
45 #include <com/sun/star/io/Pipe.hpp>
46 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
47 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
48 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
49 #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
50 #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
51 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
52 #include <com/sun/star/script/XLibraryContainerExport.hpp>
53 #include <com/sun/star/task/InteractionHandler.hpp>
54 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
55 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
56 #include <com/sun/star/ucb/NameClash.hpp>
57 #include <com/sun/star/packages/manifest/ManifestWriter.hpp>
58 #include <unotools/pathoptions.hxx>
60 #include <com/sun/star/util/VetoException.hpp>
61 #include <com/sun/star/script/ModuleSizeExceededRequest.hpp>
63 #include <comphelper/processfactory.hxx>
64 #include <comphelper/propertysequence.hxx>
65 #include <cppuhelper/implbase.hxx>
68 #include <string_view>
73 using namespace ::com::sun::star
;
74 using namespace ::com::sun::star::uno
;
75 using namespace ::com::sun::star::lang
;
76 using namespace ::com::sun::star::ucb
;
77 using namespace ::com::sun::star::ui::dialogs
;
82 class DummyInteractionHandler
: public ::cppu::WeakImplHelper
< task::XInteractionHandler
>
84 Reference
< task::XInteractionHandler2
> m_xHandler
;
86 explicit DummyInteractionHandler(const Reference
<task::XInteractionHandler2
>& xHandler
)
87 : m_xHandler(xHandler
)
91 virtual void SAL_CALL
handle( const Reference
< task::XInteractionRequest
>& rRequest
) override
93 if ( m_xHandler
.is() )
95 script::ModuleSizeExceededRequest aModSizeException
;
96 if ( rRequest
->getRequest() >>= aModSizeException
)
97 m_xHandler
->handle( rRequest
);
106 int FindEntry(const weld::TreeView
& rBox
, const OUString
& rName
)
108 int nCount
= rBox
.n_children();
109 for (int i
= 0; i
< nCount
; ++i
)
111 if (rName
.equalsIgnoreAsciiCase(rBox
.get_text(i
, 0)))
119 IMPL_LINK_NOARG(NewObjectDialog
, OkButtonHandler
, weld::Button
&, void)
121 if (!m_bCheckName
|| IsValidSbxName(m_xEdit
->get_text()))
122 m_xDialog
->response(RET_OK
);
125 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_xDialog
.get(),
126 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_BADSBXNAME
)));
128 m_xEdit
->grab_focus();
132 NewObjectDialog::NewObjectDialog(weld::Window
* pParent
, ObjectMode eMode
, bool bCheckName
)
133 : GenericDialogController(pParent
, "modules/BasicIDE/ui/newlibdialog.ui", "NewLibDialog")
134 , m_xEdit(m_xBuilder
->weld_entry("entry"))
135 , m_xOKButton(m_xBuilder
->weld_button("ok"))
136 , m_bCheckName(bCheckName
)
140 case ObjectMode::Library
:
141 m_xDialog
->set_title(IDEResId(RID_STR_NEWLIB
));
143 case ObjectMode::Module
:
144 m_xDialog
->set_title(IDEResId(RID_STR_NEWMOD
));
146 case ObjectMode::Dialog
:
147 m_xDialog
->set_title(IDEResId(RID_STR_NEWDLG
));
152 m_xOKButton
->connect_clicked(LINK(this, NewObjectDialog
, OkButtonHandler
));
156 GotoLineDialog::GotoLineDialog(weld::Window
* pParent
)
157 : GenericDialogController(pParent
, "modules/BasicIDE/ui/gotolinedialog.ui", "GotoLineDialog")
158 , m_xEdit(m_xBuilder
->weld_entry("entry"))
159 , m_xOKButton(m_xBuilder
->weld_button("ok"))
161 m_xEdit
->grab_focus();
162 m_xOKButton
->connect_clicked(LINK(this, GotoLineDialog
, OkButtonHandler
));
165 GotoLineDialog::~GotoLineDialog()
169 sal_Int32
GotoLineDialog::GetLineNumber() const
171 return m_xEdit
->get_text().toInt32();
174 IMPL_LINK_NOARG(GotoLineDialog
, OkButtonHandler
, weld::Button
&, void)
177 m_xDialog
->response(RET_OK
);
179 m_xEdit
->select_region(0, -1);
183 IMPL_LINK_NOARG(ExportDialog
, OkButtonHandler
, weld::Button
&, void)
185 m_bExportAsPackage
= m_xExportAsPackageButton
->get_active();
186 m_xDialog
->response(RET_OK
);
189 ExportDialog::ExportDialog(weld::Window
* pParent
)
190 : GenericDialogController(pParent
, "modules/BasicIDE/ui/exportdialog.ui", "ExportDialog")
191 , m_bExportAsPackage(false)
192 , m_xExportAsPackageButton(m_xBuilder
->weld_radio_button("extension"))
193 , m_xOKButton(m_xBuilder
->weld_button("ok"))
195 m_xExportAsPackageButton
->set_active(true);
196 m_xOKButton
->connect_clicked(LINK(this, ExportDialog
, OkButtonHandler
));
199 ExportDialog::~ExportDialog()
204 LibPage::LibPage(weld::Container
* pParent
, OrganizeDialog
* pDialog
)
205 : OrganizePage(pParent
, "modules/BasicIDE/ui/libpage.ui", "LibPage", pDialog
)
206 , m_xBasicsBox(m_xBuilder
->weld_combo_box("location"))
207 , m_xLibBox(m_xBuilder
->weld_tree_view("library"))
208 , m_xEditButton(m_xBuilder
->weld_button("edit"))
209 , m_xPasswordButton(m_xBuilder
->weld_button("password"))
210 , m_xNewLibButton(m_xBuilder
->weld_button("new"))
211 , m_xInsertLibButton(m_xBuilder
->weld_button("import"))
212 , m_xExportButton(m_xBuilder
->weld_button("export"))
213 , m_xDelButton(m_xBuilder
->weld_button("delete"))
214 , m_aCurDocument(ScriptDocument::getApplicationScriptDocument())
215 , m_eCurLocation(LIBRARY_LOCATION_UNKNOWN
)
217 Size
aSize(m_xLibBox
->get_approximate_digit_width() * 40,
218 m_xLibBox
->get_height_rows(10));
219 m_xLibBox
->set_size_request(aSize
.Width(), aSize
.Height());
221 // tdf#93476 The libraries should be listed alphabetically
222 m_xLibBox
->make_sorted();
224 m_xEditButton
->connect_clicked( LINK( this, LibPage
, ButtonHdl
) );
225 m_xNewLibButton
->connect_clicked( LINK( this, LibPage
, ButtonHdl
) );
226 m_xPasswordButton
->connect_clicked( LINK( this, LibPage
, ButtonHdl
) );
227 m_xExportButton
->connect_clicked( LINK( this, LibPage
, ButtonHdl
) );
228 m_xInsertLibButton
->connect_clicked( LINK( this, LibPage
, ButtonHdl
) );
229 m_xDelButton
->connect_clicked( LINK( this, LibPage
, ButtonHdl
) );
230 m_xLibBox
->connect_changed( LINK( this, LibPage
, TreeListHighlightHdl
) );
232 m_xBasicsBox
->connect_changed( LINK( this, LibPage
, BasicSelectHdl
) );
234 m_xLibBox
->connect_editing(LINK(this, LibPage
, EditingEntryHdl
),
235 LINK(this, LibPage
, EditedEntryHdl
));
238 m_xBasicsBox
->set_active(0);
244 IMPL_LINK(LibPage
, EditingEntryHdl
, const weld::TreeIter
&, rIter
, bool)
246 // check, if Standard library
247 OUString aLibName
= m_xLibBox
->get_text(rIter
, 0);
249 if ( aLibName
.equalsIgnoreAsciiCase( "Standard" ) )
251 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
252 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_CANNOTCHANGENAMESTDLIB
)));
257 // check, if library is readonly
258 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
259 Reference
< script::XLibraryContainer2
> xDlgLibContainer( m_aCurDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
260 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && xModLibContainer
->isLibraryReadOnly( aLibName
) && !xModLibContainer
->isLibraryLink( aLibName
) ) ||
261 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) && xDlgLibContainer
->isLibraryReadOnly( aLibName
) && !xDlgLibContainer
->isLibraryLink( aLibName
) ) )
263 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
264 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_LIBISREADONLY
)));
269 // i24094: Password verification necessary for renaming
270 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && !xModLibContainer
->isLibraryLoaded( aLibName
) )
274 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
275 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aLibName
) && !xPasswd
->isLibraryPasswordVerified( aLibName
) )
278 bOK
= QueryPassword(m_pDialog
->getDialog(), xModLibContainer
, aLibName
, aPassword
);
284 // TODO: check if library is reference/link
289 IMPL_LINK(LibPage
, EditedEntryHdl
, const IterString
&, rIterString
, bool)
291 const weld::TreeIter
& rIter
= rIterString
.first
;
292 OUString sNewName
= rIterString
.second
;
294 bool bValid
= sNewName
.getLength() <= 30 && IsValidSbxName(sNewName
);
295 OUString
aOldName(m_xLibBox
->get_text(rIter
, 0));
297 if (bValid
&& aOldName
!= sNewName
)
301 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
302 if ( xModLibContainer
.is() )
303 xModLibContainer
->renameLibrary( aOldName
, sNewName
);
305 Reference
< script::XLibraryContainer2
> xDlgLibContainer( m_aCurDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
306 if ( xDlgLibContainer
.is() )
307 xDlgLibContainer
->renameLibrary( aOldName
, sNewName
);
309 MarkDocumentModified( m_aCurDocument
);
310 if (SfxBindings
* pBindings
= GetBindingsPtr())
312 pBindings
->Invalidate( SID_BASICIDE_LIBSELECTOR
);
313 pBindings
->Update( SID_BASICIDE_LIBSELECTOR
);
316 catch (const container::ElementExistException
& )
318 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
319 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_SBXNAMEALLREADYUSED
)));
323 catch (const container::NoSuchElementException
& )
325 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
332 OUString
sWarning(sNewName
.getLength() > 30 ? IDEResId(RID_STR_LIBNAMETOLONG
) : IDEResId(RID_STR_BADSBXNAME
));
333 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
334 VclMessageType::Warning
, VclButtonsType::Ok
, sWarning
));
346 const sal_Int32 nCount
= m_xBasicsBox
->get_count();
347 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
349 DocumentEntry
* pEntry
= reinterpret_cast<DocumentEntry
*>(m_xBasicsBox
->get_id(i
).toInt64());
355 void LibPage::CheckButtons()
357 std::unique_ptr
<weld::TreeIter
> xCur(m_xLibBox
->make_iterator());
358 if (!m_xLibBox
->get_cursor(xCur
.get()))
361 OUString aLibName
= m_xLibBox
->get_text(*xCur
, 0);
362 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
363 Reference
< script::XLibraryContainer2
> xDlgLibContainer( m_aCurDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
365 if ( m_eCurLocation
== LIBRARY_LOCATION_SHARE
)
367 m_xPasswordButton
->set_sensitive(false);
368 m_xNewLibButton
->set_sensitive(false);
369 m_xInsertLibButton
->set_sensitive(false);
370 m_xDelButton
->set_sensitive(false);
372 else if ( aLibName
.equalsIgnoreAsciiCase( "Standard" ) )
374 m_xPasswordButton
->set_sensitive(false);
375 m_xNewLibButton
->set_sensitive(true);
376 m_xInsertLibButton
->set_sensitive(true);
377 m_xExportButton
->set_sensitive(false);
378 m_xDelButton
->set_sensitive(false);
380 else if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && xModLibContainer
->isLibraryReadOnly( aLibName
) ) ||
381 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) && xDlgLibContainer
->isLibraryReadOnly( aLibName
) ) )
383 m_xPasswordButton
->set_sensitive(false);
384 m_xNewLibButton
->set_sensitive(true);
385 m_xInsertLibButton
->set_sensitive(true);
386 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && xModLibContainer
->isLibraryReadOnly( aLibName
) && !xModLibContainer
->isLibraryLink( aLibName
) ) ||
387 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) && xDlgLibContainer
->isLibraryReadOnly( aLibName
) && !xDlgLibContainer
->isLibraryLink( aLibName
) ) )
388 m_xDelButton
->set_sensitive(false);
390 m_xDelButton
->set_sensitive(true);
394 if ( xModLibContainer
.is() && !xModLibContainer
->hasByName( aLibName
) )
395 m_xPasswordButton
->set_sensitive(false);
397 m_xPasswordButton
->set_sensitive(true);
399 m_xNewLibButton
->set_sensitive(true);
400 m_xInsertLibButton
->set_sensitive(true);
401 m_xExportButton
->set_sensitive(true);
402 m_xDelButton
->set_sensitive(true);
406 void LibPage::ActivatePage()
411 IMPL_LINK_NOARG(LibPage
, TreeListHighlightHdl
, weld::TreeView
&, void)
416 IMPL_LINK_NOARG( LibPage
, BasicSelectHdl
, weld::ComboBox
&, void )
422 IMPL_LINK( LibPage
, ButtonHdl
, weld::Button
&, rButton
, void )
424 if (&rButton
== m_xEditButton
.get())
426 SfxAllItemSet
aArgs( SfxGetpApp()->GetPool() );
427 SfxRequest
aRequest( SID_BASICIDE_APPEAR
, SfxCallMode::SYNCHRON
, aArgs
);
428 SfxGetpApp()->ExecuteSlot( aRequest
);
430 SfxUnoAnyItem
aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL
, Any( m_aCurDocument
.getDocumentOrNull() ) );
432 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xLibBox
->make_iterator());
433 if (!m_xLibBox
->get_cursor(xCurEntry
.get()))
435 OUString
aLibName(m_xLibBox
->get_text(*xCurEntry
, 0));
436 SfxStringItem
aLibNameItem( SID_BASICIDE_ARG_LIBNAME
, aLibName
);
437 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
438 pDispatcher
->ExecuteList( SID_BASICIDE_LIBSELECTED
,
439 SfxCallMode::ASYNCHRON
, { &aDocItem
, &aLibNameItem
});
443 else if (&rButton
== m_xNewLibButton
.get())
445 else if (&rButton
== m_xInsertLibButton
.get())
447 else if (&rButton
== m_xExportButton
.get())
449 else if (&rButton
== m_xDelButton
.get())
451 else if (&rButton
== m_xPasswordButton
.get())
453 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xLibBox
->make_iterator());
454 if (!m_xLibBox
->get_cursor(xCurEntry
.get()))
456 OUString
aLibName(m_xLibBox
->get_text(*xCurEntry
, 0));
458 // load module library (if not loaded)
459 Reference
< script::XLibraryContainer
> xModLibContainer
= m_aCurDocument
.getLibraryContainer( E_SCRIPTS
);
460 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && !xModLibContainer
->isLibraryLoaded( aLibName
) )
462 Shell
* pShell
= GetShell();
464 pShell
->GetViewFrame()->GetWindow().EnterWait();
465 xModLibContainer
->loadLibrary( aLibName
);
467 pShell
->GetViewFrame()->GetWindow().LeaveWait();
470 // load dialog library (if not loaded)
471 Reference
< script::XLibraryContainer
> xDlgLibContainer
= m_aCurDocument
.getLibraryContainer( E_DIALOGS
);
472 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) && !xDlgLibContainer
->isLibraryLoaded( aLibName
) )
474 Shell
* pShell
= GetShell();
476 pShell
->GetViewFrame()->GetWindow().EnterWait();
477 xDlgLibContainer
->loadLibrary( aLibName
);
479 pShell
->GetViewFrame()->GetWindow().LeaveWait();
482 // check, if library is password protected
483 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) )
485 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
488 bool const bProtected
= xPasswd
->isLibraryPasswordProtected( aLibName
);
490 // change password dialog
491 SvxPasswordDialog
aDlg(m_pDialog
->getDialog(), !bProtected
);
492 aDlg
.SetCheckPasswordHdl(LINK(this, LibPage
, CheckPasswordHdl
));
494 if (aDlg
.run() == RET_OK
)
496 bool const bNewProtected
= xPasswd
->isLibraryPasswordProtected( aLibName
);
498 if ( bNewProtected
!= bProtected
)
500 int nPos
= m_xLibBox
->get_iter_index_in_parent(*xCurEntry
);
501 m_xLibBox
->remove(*xCurEntry
);
502 ImpInsertLibEntry(aLibName
, nPos
);
503 m_xLibBox
->set_cursor(nPos
);
506 MarkDocumentModified( m_aCurDocument
);
514 IMPL_LINK( LibPage
, CheckPasswordHdl
, SvxPasswordDialog
*, pDlg
, bool )
518 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xLibBox
->make_iterator());
519 if (!m_xLibBox
->get_cursor(xCurEntry
.get()))
522 OUString
aLibName(m_xLibBox
->get_text(*xCurEntry
, 0));
523 Reference
< script::XLibraryContainerPassword
> xPasswd( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
529 OUString
aOldPassword( pDlg
->GetOldPassword() );
530 OUString
aNewPassword( pDlg
->GetNewPassword() );
531 xPasswd
->changeLibraryPassword( aLibName
, aOldPassword
, aNewPassword
);
542 void LibPage::NewLib()
544 createLibImpl(m_pDialog
->getDialog(), m_aCurDocument
, m_xLibBox
.get(), nullptr);
547 void LibPage::InsertLib()
549 Reference
< uno::XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
551 sfx2::FileDialogHelper
aDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
, FileDialogFlags::NONE
, m_pDialog
->getDialog());
552 aDlg
.SetContext(sfx2::FileDialogHelper::BasicInsertLib
);
553 const Reference
<XFilePicker3
>& xFP
= aDlg
.GetFilePicker();
555 xFP
->setTitle(IDEResId(RID_STR_APPENDLIBS
));
558 OUString
aTitle(IDEResId(RID_STR_BASIC
));
559 xFP
->appendFilter( aTitle
, "*.sbl;*.xlc;*.xlb" // library files
560 ";*.sdw;*.sxw;*.odt" // text
561 ";*.vor;*.stw;*.ott" // text template
562 ";*.sgl;*.sxg;*.odm" // master document
563 ";*.oth" // html document template
564 ";*.sdc;*.sxc;*.ods" // spreadsheet
565 ";*.stc;*.ots" // spreadsheet template
566 ";*.sda;*.sxd;*.odg" // drawing
567 ";*.std;*.otg" // drawing template
568 ";*.sdd;*.sxi;*.odp" // presentation
569 ";*.sti;*.otp" // presentation template
570 ";*.sxm;*.odf" ); // formula
572 OUString
aLastFilter(GetExtraData()->GetAddLibFilter());
573 if ( !aLastFilter
.isEmpty() )
574 xFP
->setCurrentFilter( aLastFilter
);
576 xFP
->setCurrentFilter( IDEResId(RID_STR_BASIC
) );
578 if ( xFP
->execute() != RET_OK
)
581 GetExtraData()->SetAddLibPath( xFP
->getDisplayDirectory() );
582 GetExtraData()->SetAddLibFilter( xFP
->getCurrentFilter() );
584 // library containers for import
585 Reference
< script::XLibraryContainer2
> xModLibContImport
;
586 Reference
< script::XLibraryContainer2
> xDlgLibContImport
;
589 Sequence
< OUString
> aFiles
= xFP
->getSelectedFiles();
590 INetURLObject
aURLObj( aFiles
[0] );
591 auto xModURLObj
= std::make_shared
<INetURLObject
>(aURLObj
);
592 auto xDlgURLObj
= std::make_shared
<INetURLObject
>(aURLObj
);
594 OUString aBase
= aURLObj
.getBase();
595 OUString
aModBase( "script" );
596 OUString
aDlgBase( "dialog" );
598 if ( aBase
== aModBase
|| aBase
== aDlgBase
)
600 xModURLObj
->setBase( aModBase
);
601 xDlgURLObj
->setBase( aDlgBase
);
604 Reference
< XSimpleFileAccess3
> xSFA( SimpleFileAccess::create(comphelper::getProcessComponentContext()) );
606 OUString
aModURL( xModURLObj
->GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
607 if ( xSFA
->exists( aModURL
) )
609 xModLibContImport
= script::DocumentScriptLibraryContainer::createWithURL(xContext
, aModURL
);
612 OUString
aDlgURL( xDlgURLObj
->GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
613 if ( xSFA
->exists( aDlgURL
) )
615 xDlgLibContImport
= script::DocumentDialogLibraryContainer::createWithURL(xContext
, aDlgURL
);
618 if ( !xModLibContImport
.is() && !xDlgLibContImport
.is() )
621 std::shared_ptr
<LibDialog
> xLibDlg
;
623 Sequence
< OUString
> aLibNames
= GetMergedLibraryNames( xModLibContImport
, xDlgLibContImport
);
624 sal_Int32 nLibCount
= aLibNames
.getLength();
627 // library import dialog
628 xLibDlg
= std::make_shared
<LibDialog
>(m_pDialog
->getDialog());
629 xLibDlg
->SetStorageName(aURLObj
.getName());
630 weld::TreeView
& rView
= xLibDlg
->GetLibBox();
631 rView
.make_unsorted();
634 const OUString
* pLibNames
= aLibNames
.getConstArray();
635 for (sal_Int32 i
= 0 ; i
< nLibCount
; ++i
)
638 OUString
aLibName( pLibNames
[ i
] );
639 if ( !( ( xModLibContImport
.is() && xModLibContImport
->hasByName( aLibName
) && xModLibContImport
->isLibraryLink( aLibName
) ) ||
640 ( xDlgLibContImport
.is() && xDlgLibContImport
->hasByName( aLibName
) && xDlgLibContImport
->isLibraryLink( aLibName
) ) ) )
643 const int nRow
= rView
.n_children() - 1;
644 rView
.set_toggle(nRow
, TRISTATE_TRUE
);
645 rView
.set_text(nRow
, aLibName
, 0);
652 if (rView
.n_children())
658 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
659 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_NOLIBINSTORAGE
)));
664 OUString
aExtension( aURLObj
.getExtension() );
665 OUString
aLibExtension( "xlb" );
666 OUString
aContExtension( "xlc" );
668 // disable reference checkbox for documents and sbls
669 if ( aExtension
!= aLibExtension
&& aExtension
!= aContExtension
)
670 xLibDlg
->EnableReference(false);
672 weld::DialogController::runAsync(xLibDlg
, [aContExtension
, xDlgURLObj
, aExtension
, aLibExtension
, xModURLObj
, xLibDlg
, xDlgLibContImport
, xModLibContImport
, this](sal_Int32 nResult
)
677 bool bChanges
= false;
678 bool bRemove
= false;
679 bool bReplace
= xLibDlg
->IsReplace();
680 bool bReference
= xLibDlg
->IsReference();
681 weld::TreeView
& rView
= xLibDlg
->GetLibBox();
682 for (int nLib
= 0, nChildren
= rView
.n_children(); nLib
< nChildren
; ++nLib
)
684 if (rView
.get_toggle(nLib
) == TRISTATE_TRUE
)
686 OUString
aLibName(rView
.get_text(nLib
));
687 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
688 Reference
< script::XLibraryContainer2
> xDlgLibContainer( m_aCurDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
690 // check, if the library is already existing
691 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) ) ||
692 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) ) )
696 // check, if the library is the Standard library
697 if ( aLibName
== "Standard" )
699 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
700 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_REPLACESTDLIB
)));
705 // check, if the library is readonly and not a link
706 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && xModLibContainer
->isLibraryReadOnly( aLibName
) && !xModLibContainer
->isLibraryLink( aLibName
) ) ||
707 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) && xDlgLibContainer
->isLibraryReadOnly( aLibName
) && !xDlgLibContainer
->isLibraryLink( aLibName
) ) )
709 OUString
aErrStr( IDEResId(RID_STR_REPLACELIB
) );
710 aErrStr
= aErrStr
.replaceAll("XX", aLibName
) + "\n" + IDEResId(RID_STR_LIBISREADONLY
);
711 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
712 VclMessageType::Warning
, VclButtonsType::Ok
, aErrStr
));
717 // remove existing libraries
724 aErrStr
= IDEResId(RID_STR_REFNOTPOSSIBLE
);
726 aErrStr
= IDEResId(RID_STR_IMPORTNOTPOSSIBLE
);
727 aErrStr
= aErrStr
.replaceAll("XX", aLibName
) + "\n" +IDEResId(RID_STR_SBXNAMEALLREADYUSED
);
728 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
729 VclMessageType::Warning
, VclButtonsType::Ok
, aErrStr
));
735 // check, if the library is password protected
738 if ( xModLibContImport
.is() && xModLibContImport
->hasByName( aLibName
) )
740 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContImport
, UNO_QUERY
);
741 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aLibName
) && !xPasswd
->isLibraryPasswordVerified( aLibName
) && !bReference
)
743 bOK
= QueryPassword(m_pDialog
->getDialog(), xModLibContImport
, aLibName
, aPassword
, true, true);
747 OUString
aErrStr( IDEResId(RID_STR_NOIMPORT
) );
748 aErrStr
= aErrStr
.replaceAll("XX", aLibName
);
749 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(m_pDialog
->getDialog(),
750 VclMessageType::Warning
, VclButtonsType::Ok
, aErrStr
));
757 // remove existing libraries
760 // remove listbox entry
761 int nEntry_
= FindEntry(*m_xLibBox
, aLibName
);
763 m_xLibBox
->remove(nEntry_
);
765 // remove module library
766 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) )
767 xModLibContainer
->removeLibrary( aLibName
);
769 // remove dialog library
770 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) )
771 xDlgLibContainer
->removeLibrary( aLibName
);
774 // copy module library
775 if ( xModLibContImport
.is() && xModLibContImport
->hasByName( aLibName
) && xModLibContainer
.is() && !xModLibContainer
->hasByName( aLibName
) )
777 Reference
< container::XNameContainer
> xModLib
;
781 INetURLObject
aModStorageURLObj(*xModURLObj
);
782 if ( aExtension
== aContExtension
)
784 sal_Int32 nCount
= aModStorageURLObj
.getSegmentCount();
785 aModStorageURLObj
.insertName( aLibName
, false, nCount
-1 );
786 aModStorageURLObj
.setExtension( aLibExtension
);
787 aModStorageURLObj
.setFinalSlash();
789 OUString
aModStorageURL( aModStorageURLObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
791 // create library link
792 xModLib
.set( xModLibContainer
->createLibraryLink( aLibName
, aModStorageURL
, true ), UNO_QUERY
);
797 xModLib
= xModLibContainer
->createLibrary( aLibName
);
800 // get import library
801 Reference
< container::XNameContainer
> xModLibImport
;
802 Any aElement
= xModLibContImport
->getByName( aLibName
);
803 aElement
>>= xModLibImport
;
805 if ( xModLibImport
.is() )
808 if ( !xModLibContImport
->isLibraryLoaded( aLibName
) )
809 xModLibContImport
->loadLibrary( aLibName
);
812 Sequence
< OUString
> aModNames
= xModLibImport
->getElementNames();
813 sal_Int32 nModCount
= aModNames
.getLength();
814 const OUString
* pModNames
= aModNames
.getConstArray();
815 for ( sal_Int32 i
= 0 ; i
< nModCount
; i
++ )
817 OUString
aModName( pModNames
[ i
] );
818 Any aElement_
= xModLibImport
->getByName( aModName
);
819 xModLib
->insertByName( aModName
, aElement_
);
825 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
830 xPasswd
->changeLibraryPassword( aLibName
, OUString(), aPassword
);
842 // copy dialog library
843 if ( xDlgLibContImport
.is() && xDlgLibContImport
->hasByName( aLibName
) && xDlgLibContainer
.is() && !xDlgLibContainer
->hasByName( aLibName
) )
845 Reference
< container::XNameContainer
> xDlgLib
;
849 INetURLObject
aDlgStorageURLObj( *xDlgURLObj
);
850 if ( aExtension
== aContExtension
)
852 sal_Int32 nCount
= aDlgStorageURLObj
.getSegmentCount();
853 aDlgStorageURLObj
.insertName( aLibName
, false, nCount
- 1 );
854 aDlgStorageURLObj
.setExtension( aLibExtension
);
855 aDlgStorageURLObj
.setFinalSlash();
857 OUString
aDlgStorageURL( aDlgStorageURLObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
859 // create library link
860 xDlgLib
.set( xDlgLibContainer
->createLibraryLink( aLibName
, aDlgStorageURL
, true ), UNO_QUERY
);
865 xDlgLib
= xDlgLibContainer
->createLibrary( aLibName
);
868 // get import library
869 Reference
< container::XNameContainer
> xDlgLibImport
;
870 Any aElement
= xDlgLibContImport
->getByName( aLibName
);
871 aElement
>>= xDlgLibImport
;
873 if ( xDlgLibImport
.is() )
876 if ( !xDlgLibContImport
->isLibraryLoaded( aLibName
) )
877 xDlgLibContImport
->loadLibrary( aLibName
);
880 Sequence
< OUString
> aDlgNames
= xDlgLibImport
->getElementNames();
881 sal_Int32 nDlgCount
= aDlgNames
.getLength();
882 const OUString
* pDlgNames
= aDlgNames
.getConstArray();
883 for ( sal_Int32 i
= 0 ; i
< nDlgCount
; i
++ )
885 OUString
aDlgName( pDlgNames
[ i
] );
886 Any aElement_
= xDlgLibImport
->getByName( aDlgName
);
887 xDlgLib
->insertByName( aDlgName
, aElement_
);
894 // insert listbox entry
895 ImpInsertLibEntry( aLibName
, m_xLibBox
->n_children() );
896 m_xLibBox
->set_cursor( m_xLibBox
->find_text(aLibName
) );
902 MarkDocumentModified( m_aCurDocument
);
906 void LibPage::Export()
908 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xLibBox
->make_iterator());
909 if (!m_xLibBox
->get_cursor(xCurEntry
.get()))
911 OUString
aLibName(m_xLibBox
->get_text(*xCurEntry
, 0));
913 // Password verification
914 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
916 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && !xModLibContainer
->isLibraryLoaded( aLibName
) )
921 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
922 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aLibName
) && !xPasswd
->isLibraryPasswordVerified( aLibName
) )
925 bOK
= QueryPassword(m_pDialog
->getDialog(), xModLibContainer
, aLibName
, aPassword
);
931 std::unique_ptr
<ExportDialog
> xNewDlg(new ExportDialog(m_pDialog
->getDialog()));
932 if (xNewDlg
->run() != RET_OK
)
937 bool bExportAsPackage
= xNewDlg
->isExportAsPackage();
938 //tdf#112063 ensure closing xNewDlg is not selected as
939 //parent of file dialog from ExportAs...
941 if (bExportAsPackage
)
942 ExportAsPackage( aLibName
);
944 ExportAsBasic( aLibName
);
946 catch(const util::VetoException
& ) // user canceled operation
951 void LibPage::implExportLib( const OUString
& aLibName
, const OUString
& aTargetURL
,
952 const Reference
< task::XInteractionHandler
>& Handler
)
954 Reference
< script::XLibraryContainerExport
> xModLibContainerExport
955 ( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
956 Reference
< script::XLibraryContainerExport
> xDlgLibContainerExport
957 ( m_aCurDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
958 if ( xModLibContainerExport
.is() )
959 xModLibContainerExport
->exportLibrary( aLibName
, aTargetURL
, Handler
);
961 if (!xDlgLibContainerExport
.is())
963 Reference
<container::XNameAccess
> xNameAcc(xDlgLibContainerExport
, UNO_QUERY
);
966 if (!xNameAcc
->hasByName(aLibName
))
968 xDlgLibContainerExport
->exportLibrary(aLibName
, aTargetURL
, Handler
);
971 // Implementation XCommandEnvironment
975 class OLibCommandEnvironment
: public cppu::WeakImplHelper
< XCommandEnvironment
>
977 Reference
< task::XInteractionHandler
> mxInteraction
;
980 explicit OLibCommandEnvironment(const Reference
<task::XInteractionHandler
>& xInteraction
)
981 : mxInteraction( xInteraction
)
985 virtual Reference
< task::XInteractionHandler
> SAL_CALL
getInteractionHandler() override
;
986 virtual Reference
< XProgressHandler
> SAL_CALL
getProgressHandler() override
;
991 Reference
< task::XInteractionHandler
> OLibCommandEnvironment::getInteractionHandler()
993 return mxInteraction
;
996 Reference
< XProgressHandler
> OLibCommandEnvironment::getProgressHandler()
998 Reference
< XProgressHandler
> xRet
;
1002 void LibPage::ExportAsPackage( const OUString
& aLibName
)
1005 sfx2::FileDialogHelper
aDlg(ui::dialogs::TemplateDescription::FILESAVE_SIMPLE
, FileDialogFlags::NONE
, m_pDialog
->getDialog());
1006 aDlg
.SetContext(sfx2::FileDialogHelper::BasicExportPackage
);
1007 const Reference
<XFilePicker3
>& xFP
= aDlg
.GetFilePicker();
1009 Reference
< uno::XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
1010 Reference
< task::XInteractionHandler2
> xHandler( task::InteractionHandler::createWithParent(xContext
, nullptr) );
1011 Reference
< XSimpleFileAccess3
> xSFA
= SimpleFileAccess::create(xContext
);
1013 xFP
->setTitle(IDEResId(RID_STR_EXPORTPACKAGE
));
1016 OUString
aTitle(IDEResId(RID_STR_PACKAGE_BUNDLE
));
1017 xFP
->appendFilter( aTitle
, "*.oxt" ); // library files
1019 xFP
->setCurrentFilter( aTitle
);
1021 if ( xFP
->execute() != RET_OK
)
1024 GetExtraData()->SetAddLibPath(xFP
->getDisplayDirectory());
1026 Sequence
< OUString
> aFiles
= xFP
->getSelectedFiles();
1027 INetURLObject
aURL( aFiles
[0] );
1028 if( aURL
.getExtension().isEmpty() )
1029 aURL
.setExtension( u
"oxt" );
1031 OUString
aPackageURL( aURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
1033 OUString aTmpPath
= SvtPathOptions().GetTempPath();
1034 INetURLObject
aInetObj( aTmpPath
);
1035 aInetObj
.insertName( aLibName
, true, INetURLObject::LAST_SEGMENT
, INetURLObject::EncodeMechanism::All
);
1036 OUString aSourcePath
= aInetObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
1037 if( xSFA
->exists( aSourcePath
) )
1038 xSFA
->kill( aSourcePath
);
1039 Reference
< task::XInteractionHandler
> xDummyHandler( new DummyInteractionHandler( xHandler
) );
1040 implExportLib( aLibName
, aTmpPath
, xDummyHandler
);
1042 Reference
< XCommandEnvironment
> xCmdEnv
= new OLibCommandEnvironment(xHandler
);
1044 ::ucbhelper::Content
sourceContent( aSourcePath
, xCmdEnv
, comphelper::getProcessComponentContext() );
1046 OUString destFolder
= "vnd.sun.star.zip://" +
1047 ::rtl::Uri::encode( aPackageURL
,
1048 rtl_UriCharClassRegName
,
1049 rtl_UriEncodeIgnoreEscapes
,
1050 RTL_TEXTENCODING_UTF8
) +
1053 if( xSFA
->exists( aPackageURL
) )
1054 xSFA
->kill( aPackageURL
);
1056 ::ucbhelper::Content
destFolderContent( destFolder
, xCmdEnv
, comphelper::getProcessComponentContext() );
1057 destFolderContent
.transferContent(
1058 sourceContent
, ::ucbhelper::InsertOperation::Copy
,
1059 OUString(), NameClash::OVERWRITE
);
1061 INetURLObject
aMetaInfInetObj( aTmpPath
);
1062 aMetaInfInetObj
.insertName( u
"META-INF",
1063 true, INetURLObject::LAST_SEGMENT
, INetURLObject::EncodeMechanism::All
);
1064 OUString aMetaInfFolder
= aMetaInfInetObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
1065 if( xSFA
->exists( aMetaInfFolder
) )
1066 xSFA
->kill( aMetaInfFolder
);
1067 xSFA
->createFolder( aMetaInfFolder
);
1069 std::vector
< Sequence
<beans::PropertyValue
> > manifest
;
1071 OUString fullPath
= aLibName
1073 auto attribs(::comphelper::InitPropertySequence({
1074 { "FullPath", Any(fullPath
) },
1075 { "MediaType", Any(OUString("application/vnd.sun.star.basic-library")) }
1077 manifest
.push_back( attribs
);
1080 Reference
<packages::manifest::XManifestWriter
> xManifestWriter
= packages::manifest::ManifestWriter::create( xContext
);
1081 Reference
<io::XOutputStream
> xPipe( io::Pipe::create( xContext
), UNO_QUERY_THROW
);
1082 xManifestWriter
->writeManifestSequence(
1083 xPipe
, Sequence
< Sequence
<beans::PropertyValue
> >(
1084 manifest
.data(), manifest
.size() ) );
1086 aMetaInfInetObj
.insertName( u
"manifest.xml",
1087 true, INetURLObject::LAST_SEGMENT
, INetURLObject::EncodeMechanism::All
);
1089 // write buffered pipe data to content:
1090 ::ucbhelper::Content
manifestContent( aMetaInfInetObj
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), xCmdEnv
, comphelper::getProcessComponentContext() );
1091 manifestContent
.writeStream( Reference
<io::XInputStream
>( xPipe
, UNO_QUERY_THROW
), true );
1093 ::ucbhelper::Content
MetaInfContent( aMetaInfFolder
, xCmdEnv
, comphelper::getProcessComponentContext() );
1094 destFolderContent
.transferContent(
1095 MetaInfContent
, ::ucbhelper::InsertOperation::Copy
,
1096 OUString(), NameClash::OVERWRITE
);
1098 if( xSFA
->exists( aSourcePath
) )
1099 xSFA
->kill( aSourcePath
);
1100 if( xSFA
->exists( aMetaInfFolder
) )
1101 xSFA
->kill( aMetaInfFolder
);
1104 void LibPage::ExportAsBasic( const OUString
& aLibName
)
1107 Reference
< uno::XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
1108 Reference
< XFolderPicker2
> xFolderPicker
= sfx2::createFolderPicker(xContext
, m_pDialog
->getDialog());
1109 Reference
< task::XInteractionHandler2
> xHandler( task::InteractionHandler::createWithParent(xContext
, nullptr) );
1111 xFolderPicker
->setTitle(IDEResId(RID_STR_EXPORTBASIC
));
1113 // set display directory and filter
1114 OUString aPath
=GetExtraData()->GetAddLibPath();
1115 if( aPath
.isEmpty() )
1116 aPath
= SvtPathOptions().GetWorkPath();
1118 // INetURLObject aURL(m_sSavePath, INetProtocol::File);
1119 xFolderPicker
->setDisplayDirectory( aPath
);
1120 short nRet
= xFolderPicker
->execute();
1121 if( nRet
== RET_OK
)
1123 OUString aTargetURL
= xFolderPicker
->getDirectory();
1124 GetExtraData()->SetAddLibPath(aTargetURL
);
1126 Reference
< task::XInteractionHandler
> xDummyHandler( new DummyInteractionHandler( xHandler
) );
1127 implExportLib( aLibName
, aTargetURL
, xDummyHandler
);
1131 void LibPage::DeleteCurrent()
1133 std::unique_ptr
<weld::TreeIter
> xCurEntry(m_xLibBox
->make_iterator());
1134 if (!m_xLibBox
->get_cursor(xCurEntry
.get()))
1136 OUString
aLibName(m_xLibBox
->get_text(*xCurEntry
, 0));
1138 // check, if library is link
1139 bool bIsLibraryLink
= false;
1140 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
1141 Reference
< script::XLibraryContainer2
> xDlgLibContainer( m_aCurDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
1142 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) && xModLibContainer
->isLibraryLink( aLibName
) ) ||
1143 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) && xDlgLibContainer
->isLibraryLink( aLibName
) ) )
1145 bIsLibraryLink
= true;
1148 if (!QueryDelLib(aLibName
, bIsLibraryLink
, m_pDialog
->getDialog()))
1152 SfxUnoAnyItem
aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL
, Any( m_aCurDocument
.getDocumentOrNull() ) );
1153 SfxStringItem
aLibNameItem( SID_BASICIDE_ARG_LIBNAME
, aLibName
);
1154 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
1155 pDispatcher
->ExecuteList(SID_BASICIDE_LIBREMOVED
,
1156 SfxCallMode::SYNCHRON
, { &aDocItem
, &aLibNameItem
});
1158 // remove library from module and dialog library containers
1159 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) )
1160 xModLibContainer
->removeLibrary( aLibName
);
1161 if ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aLibName
) )
1162 xDlgLibContainer
->removeLibrary( aLibName
);
1164 m_xLibBox
->remove(*xCurEntry
);
1165 MarkDocumentModified( m_aCurDocument
);
1168 void LibPage::EndTabDialog()
1170 m_pDialog
->response(RET_OK
);
1173 void LibPage::FillListBox()
1175 InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER
);
1176 InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE
);
1178 ScriptDocuments
aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted
) );
1179 for (auto const& doc
: aDocuments
)
1181 InsertListBoxEntry( doc
, LIBRARY_LOCATION_DOCUMENT
);
1185 void LibPage::InsertListBoxEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
1187 OUString
aEntryText(rDocument
.getTitle(eLocation
));
1188 OUString
sId(OUString::number(reinterpret_cast<sal_Int64
>(new DocumentEntry(rDocument
, eLocation
))));
1189 m_xBasicsBox
->append(sId
, aEntryText
);
1192 void LibPage::SetCurLib()
1194 DocumentEntry
* pEntry
= reinterpret_cast<DocumentEntry
*>(m_xBasicsBox
->get_active_id().toInt64());
1198 const ScriptDocument
& aDocument( pEntry
->GetDocument() );
1199 DBG_ASSERT( aDocument
.isAlive(), "LibPage::SetCurLib: no document, or document is dead!" );
1200 if ( !aDocument
.isAlive() )
1202 LibraryLocation eLocation
= pEntry
->GetLocation();
1203 if ( aDocument
== m_aCurDocument
&& eLocation
== m_eCurLocation
)
1206 m_aCurDocument
= aDocument
;
1207 m_eCurLocation
= eLocation
;
1210 // get a sorted list of library names
1211 Sequence
< OUString
> aLibNames
= aDocument
.getLibraryNames();
1212 sal_Int32 nLibCount
= aLibNames
.getLength();
1213 const OUString
* pLibNames
= aLibNames
.getConstArray();
1216 for (int i
= 0 ; i
< nLibCount
; ++i
)
1218 OUString
aLibName(pLibNames
[i
]);
1219 if (eLocation
== aDocument
.getLibraryLocation(aLibName
))
1220 ImpInsertLibEntry(aLibName
, nEntry
++);
1223 int nEntry_
= FindEntry(*m_xLibBox
, "Standard");
1224 if (nEntry_
== -1 && m_xLibBox
->n_children())
1226 m_xLibBox
->set_cursor(nEntry_
);
1229 void LibPage::ImpInsertLibEntry( const OUString
& rLibName
, int nPos
)
1231 // check, if library is password protected
1232 bool bProtected
= false;
1233 Reference
< script::XLibraryContainer2
> xModLibContainer( m_aCurDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
1234 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( rLibName
) )
1236 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
1239 bProtected
= xPasswd
->isLibraryPasswordProtected( rLibName
);
1243 m_xLibBox
->insert_text(nPos
, rLibName
);
1246 m_xLibBox
->set_image(nPos
, RID_BMP_LOCKED
);
1248 // check, if library is link
1249 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( rLibName
) && xModLibContainer
->isLibraryLink( rLibName
) )
1251 OUString aLinkURL
= xModLibContainer
->getLibraryLinkURL( rLibName
);
1252 m_xLibBox
->set_text(nPos
, aLinkURL
, 1);
1257 void createLibImpl(weld::Window
* pWin
, const ScriptDocument
& rDocument
,
1258 weld::TreeView
* pLibBox
, SbTreeListBox
* pBasicBox
)
1260 OSL_ENSURE( rDocument
.isAlive(), "createLibImpl: invalid document!" );
1261 if ( !rDocument
.isAlive() )
1264 // create library name
1266 bool bValid
= false;
1270 aLibName
= "Library" + OUString::number( i
);
1271 if ( !rDocument
.hasLibrary( E_SCRIPTS
, aLibName
) && !rDocument
.hasLibrary( E_DIALOGS
, aLibName
) )
1276 NewObjectDialog
aNewDlg(pWin
, ObjectMode::Library
);
1277 aNewDlg
.SetObjectName(aLibName
);
1282 if (!aNewDlg
.GetObjectName().isEmpty())
1283 aLibName
= aNewDlg
.GetObjectName();
1285 if ( aLibName
.getLength() > 30 )
1287 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(pWin
,
1288 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_LIBNAMETOLONG
)));
1291 else if ( !IsValidSbxName( aLibName
) )
1293 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(pWin
,
1294 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_BADSBXNAME
)));
1297 else if ( rDocument
.hasLibrary( E_SCRIPTS
, aLibName
) || rDocument
.hasLibrary( E_DIALOGS
, aLibName
) )
1299 std::unique_ptr
<weld::MessageDialog
> xErrorBox(Application::CreateMessageDialog(pWin
,
1300 VclMessageType::Warning
, VclButtonsType::Ok
, IDEResId(RID_STR_SBXNAMEALLREADYUSED2
)));
1307 // create module and dialog library
1308 rDocument
.getOrCreateLibrary( E_SCRIPTS
, aLibName
);
1309 rDocument
.getOrCreateLibrary( E_DIALOGS
, aLibName
);
1313 pLibBox
->append_text(aLibName
);
1314 pLibBox
->set_cursor(pLibBox
->find_text(aLibName
));
1318 OUString aModName
= rDocument
.createObjectName( E_SCRIPTS
, aLibName
);
1319 OUString sModuleCode
;
1320 if ( !rDocument
.createModule( aLibName
, aModName
, true, sModuleCode
) )
1321 throw Exception("could not create module " + aModName
, nullptr);
1323 SbxItem
aSbxItem( SID_BASICIDE_ARG_SBX
, rDocument
, aLibName
, aModName
, TYPE_MODULE
);
1324 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
1325 pDispatcher
->ExecuteList(SID_BASICIDE_SBXINSERTED
,
1326 SfxCallMode::SYNCHRON
, { &aSbxItem
});
1330 std::unique_ptr
<weld::TreeIter
> xIter(pBasicBox
->make_iterator(nullptr));
1331 bool bValidIter
= pBasicBox
->get_cursor(xIter
.get());
1332 std::unique_ptr
<weld::TreeIter
> xRootEntry(pBasicBox
->make_iterator(xIter
.get()));
1335 pBasicBox
->copy_iterator(*xIter
, *xRootEntry
);
1336 bValidIter
= pBasicBox
->iter_parent(*xIter
);
1339 BrowseMode nMode
= pBasicBox
->GetMode();
1340 bool bDlgMode
= ( nMode
& BrowseMode::Dialogs
) && !( nMode
& BrowseMode::Modules
);
1341 const auto sId
= bDlgMode
? OUString(RID_BMP_DLGLIB
) : OUString(RID_BMP_MODLIB
);
1342 pBasicBox
->AddEntry(aLibName
, sId
, xRootEntry
.get(), false, std::make_unique
<Entry
>(OBJ_TYPE_LIBRARY
));
1343 pBasicBox
->AddEntry(aModName
, RID_BMP_MODULE
, xRootEntry
.get(), false, std::make_unique
<Entry
>(OBJ_TYPE_MODULE
));
1344 pBasicBox
->set_cursor(*xRootEntry
);
1345 pBasicBox
->select(*xRootEntry
);
1348 catch (const uno::Exception
& )
1350 DBG_UNHANDLED_EXCEPTION("basctl.basicide");
1355 } // namespace basctl
1357 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */