1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basctl.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #define GLOBALOVERFLOW 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <ide_pch.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <svtools/filedlg.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <sot/storinfo.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <moduldlg.hrc> 42*cdf0e10cSrcweir #include <moduldlg.hxx> 43*cdf0e10cSrcweir #include <basidesh.hrc> 44*cdf0e10cSrcweir #include <basidesh.hxx> 45*cdf0e10cSrcweir #include <bastypes.hxx> 46*cdf0e10cSrcweir #include <basobj.hxx> 47*cdf0e10cSrcweir #include <baside2.hrc> 48*cdf0e10cSrcweir #include <iderdll.hxx> 49*cdf0e10cSrcweir #include <iderdll2.hxx> 50*cdf0e10cSrcweir #include <svx/passwd.hxx> 51*cdf0e10cSrcweir #include <sbxitem.hxx> 52*cdf0e10cSrcweir #include <basdoc.hxx> 53*cdf0e10cSrcweir #include <ucbhelper/content.hxx> 54*cdf0e10cSrcweir #include "rtl/uri.hxx" 55*cdf0e10cSrcweir #include <tools/urlobj.hxx> 56*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <sot/storage.hxx> 59*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 63*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_ 64*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer2.hpp> 65*cdf0e10cSrcweir #endif 66*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainerPassword.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainerExport.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 69*cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp" 70*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 71*cdf0e10cSrcweir #include "com/sun/star/packages/manifest/XManifestWriter.hpp" 72*cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 73*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir #include <com/sun/star/util/VetoException.hpp> 76*cdf0e10cSrcweir #include <com/sun/star/script/ModuleSizeExceededRequest.hpp> 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir using namespace ::comphelper; 79*cdf0e10cSrcweir using ::rtl::OUString; 80*cdf0e10cSrcweir using namespace ::com::sun::star; 81*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 82*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 83*cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 84*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1< task::XInteractionHandler > HandlerImpl_BASE; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir class DummyInteractionHandler : public HandlerImpl_BASE 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir Reference< task::XInteractionHandler > m_xHandler; 92*cdf0e10cSrcweir public: 93*cdf0e10cSrcweir DummyInteractionHandler( const Reference< task::XInteractionHandler >& xHandler ) : m_xHandler( xHandler ){} 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir virtual void SAL_CALL handle( const Reference< task::XInteractionRequest >& rRequest ) throw (::com::sun::star::uno::RuntimeException) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir if ( m_xHandler.is() ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir script::ModuleSizeExceededRequest aModSizeException; 100*cdf0e10cSrcweir if ( rRequest->getRequest() >>= aModSizeException ) 101*cdf0e10cSrcweir m_xHandler->handle( rRequest ); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir }; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir //---------------------------------------------------------------------------- 107*cdf0e10cSrcweir // BasicLibUserData 108*cdf0e10cSrcweir //---------------------------------------------------------------------------- 109*cdf0e10cSrcweir class BasicLibUserData 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir private: 112*cdf0e10cSrcweir ScriptDocument m_aDocument; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir public: 115*cdf0e10cSrcweir BasicLibUserData( const ScriptDocument& rDocument ) : m_aDocument( rDocument ) { } 116*cdf0e10cSrcweir virtual ~BasicLibUserData() {}; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir const ScriptDocument& 119*cdf0e10cSrcweir GetDocument() const { return m_aDocument; } 120*cdf0e10cSrcweir }; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir //---------------------------------------------------------------------------- 124*cdf0e10cSrcweir // BasicLibLBoxString 125*cdf0e10cSrcweir //---------------------------------------------------------------------------- 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir class BasicLibLBoxString : public SvLBoxString 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir public: 130*cdf0e10cSrcweir BasicLibLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rTxt ) : 131*cdf0e10cSrcweir SvLBoxString( pEntry, nFlags, rTxt ) {} 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry ); 134*cdf0e10cSrcweir }; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //---------------------------------------------------------------------------- 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void BasicLibLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16, SvLBoxEntry* pEntry ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir // Change text color if library is read only: 141*cdf0e10cSrcweir bool bReadOnly = false; 142*cdf0e10cSrcweir if (pEntry && pEntry->GetUserData()) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir ScriptDocument aDocument( 145*cdf0e10cSrcweir static_cast< BasicLibUserData * >(pEntry->GetUserData())-> 146*cdf0e10cSrcweir GetDocument() ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir rtl::OUString aLibName( 149*cdf0e10cSrcweir static_cast< SvLBoxString * >(pEntry->GetItem(1))->GetText()); 150*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( 151*cdf0e10cSrcweir aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY); 152*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( 153*cdf0e10cSrcweir aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY); 154*cdf0e10cSrcweir bReadOnly 155*cdf0e10cSrcweir = (xModLibContainer.is() && xModLibContainer->hasByName(aLibName) 156*cdf0e10cSrcweir && xModLibContainer->isLibraryReadOnly(aLibName)) 157*cdf0e10cSrcweir || (xDlgLibContainer.is() && xDlgLibContainer->hasByName(aLibName) 158*cdf0e10cSrcweir && xDlgLibContainer->isLibraryReadOnly(aLibName)); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir if (bReadOnly) 161*cdf0e10cSrcweir rDev.DrawCtrlText(rPos, GetText(), 0, STRING_LEN, TEXT_DRAW_DISABLE); 162*cdf0e10cSrcweir else 163*cdf0e10cSrcweir rDev.DrawText(rPos, GetText()); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir //---------------------------------------------------------------------------- 168*cdf0e10cSrcweir // BasicCheckBox 169*cdf0e10cSrcweir //---------------------------------------------------------------------------- 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir BasicCheckBox::BasicCheckBox( Window* pParent, const ResId& rResId ) 172*cdf0e10cSrcweir :SvTabListBox( pParent, rResId ) 173*cdf0e10cSrcweir ,m_aDocument( ScriptDocument::getApplicationScriptDocument() ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir nMode = LIBMODE_MANAGER; 176*cdf0e10cSrcweir long aTabs_[] = { 1, 12 }; // Mindestens einen braucht die TabPos... 177*cdf0e10cSrcweir // 12 wegen der Checkbox 178*cdf0e10cSrcweir SetTabs( aTabs_ ); 179*cdf0e10cSrcweir Init(); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //---------------------------------------------------------------------------- 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir __EXPORT BasicCheckBox::~BasicCheckBox() 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir delete pCheckButton; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // delete user data 189*cdf0e10cSrcweir SvLBoxEntry* pEntry = First(); 190*cdf0e10cSrcweir while ( pEntry ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir delete (BasicLibUserData*)pEntry->GetUserData(); 193*cdf0e10cSrcweir pEntry = Next( pEntry ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir //---------------------------------------------------------------------------- 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir void BasicCheckBox::Init() 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir pCheckButton = new SvLBoxButtonData(this); 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if ( nMode == LIBMODE_CHOOSER ) 204*cdf0e10cSrcweir EnableCheckButton( pCheckButton ); 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir EnableCheckButton( 0 ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir SetHighlightRange(); 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir //---------------------------------------------------------------------------- 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir void BasicCheckBox::SetMode( sal_uInt16 n ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir nMode = n; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir if ( nMode == LIBMODE_CHOOSER ) 218*cdf0e10cSrcweir EnableCheckButton( pCheckButton ); 219*cdf0e10cSrcweir else 220*cdf0e10cSrcweir EnableCheckButton( 0 ); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir //---------------------------------------------------------------------------- 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir SvLBoxEntry* BasicCheckBox::DoInsertEntry( const String& rStr, sal_uLong nPos ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir return SvTabListBox::InsertEntryToColumn( rStr, nPos, 0 ); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir //---------------------------------------------------------------------------- 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir SvLBoxEntry* BasicCheckBox::FindEntry( const String& rName ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir sal_uLong nCount = GetEntryCount(); 235*cdf0e10cSrcweir for ( sal_uLong i = 0; i < nCount; i++ ) 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir SvLBoxEntry* pEntry = GetEntry( i ); 238*cdf0e10cSrcweir DBG_ASSERT( pEntry, "pEntry?!" ); 239*cdf0e10cSrcweir if ( rName.CompareIgnoreCaseToAscii( GetEntryText( pEntry, 0 ) ) == COMPARE_EQUAL ) 240*cdf0e10cSrcweir return pEntry; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir return 0; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir //---------------------------------------------------------------------------- 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir void BasicCheckBox::CheckEntryPos( sal_uLong nPos, sal_Bool bCheck ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir if ( nPos < GetEntryCount() ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir SvLBoxEntry* pEntry = GetEntry( nPos ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir if ( bCheck != GetCheckButtonState( pEntry ) ) 254*cdf0e10cSrcweir SetCheckButtonState( pEntry, 255*cdf0e10cSrcweir bCheck 256*cdf0e10cSrcweir ? SvButtonState(SV_BUTTON_CHECKED) 257*cdf0e10cSrcweir : SvButtonState(SV_BUTTON_UNCHECKED) ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //---------------------------------------------------------------------------- 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir sal_Bool BasicCheckBox::IsChecked( sal_uLong nPos ) const 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir if ( nPos < GetEntryCount() ) 266*cdf0e10cSrcweir return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED); 267*cdf0e10cSrcweir return sal_False; 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir //---------------------------------------------------------------------------- 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir void BasicCheckBox::InitEntry( SvLBoxEntry* pEntry, const XubString& rTxt, const Image& rImg1, const Image& rImg2, SvLBoxButtonKind eButtonKind ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir SvTabListBox::InitEntry( pEntry, rTxt, rImg1, rImg2, eButtonKind ); 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir if ( nMode == LIBMODE_MANAGER ) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir // initialize all columns with own string class (column 0 == bitmap) 279*cdf0e10cSrcweir sal_uInt16 nCount = pEntry->ItemCount(); 280*cdf0e10cSrcweir for ( sal_uInt16 nCol = 1; nCol < nCount; ++nCol ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nCol ); 283*cdf0e10cSrcweir BasicLibLBoxString* pStr = new BasicLibLBoxString( pEntry, 0, pCol->GetText() ); 284*cdf0e10cSrcweir pEntry->ReplaceItem( pStr, nCol ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir } 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir //---------------------------------------------------------------------------- 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir sal_Bool __EXPORT BasicCheckBox::EditingEntry( SvLBoxEntry* pEntry, Selection& ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir if ( nMode != LIBMODE_MANAGER ) 294*cdf0e10cSrcweir return sal_False; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir DBG_ASSERT( pEntry, "Kein Eintrag?" ); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // check, if Standard library 299*cdf0e10cSrcweir String aLibName = GetEntryText( pEntry, 0 ); 300*cdf0e10cSrcweir if ( aLibName.EqualsIgnoreCaseAscii( "Standard" ) ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_CANNOTCHANGENAMESTDLIB ) ) ).Execute(); 303*cdf0e10cSrcweir return sal_False; 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir // check, if library is readonly 307*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 308*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 309*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 310*cdf0e10cSrcweir if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) && !xModLibContainer->isLibraryLink( aOULibName ) ) || 311*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) && !xDlgLibContainer->isLibraryLink( aOULibName ) ) ) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_LIBISREADONLY ) ) ).Execute(); 314*cdf0e10cSrcweir return sal_False; 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir // i24094: Password verification necessary for renaming 318*cdf0e10cSrcweir sal_Bool bOK = sal_True; 319*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir // check password 322*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 323*cdf0e10cSrcweir if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir String aPassword; 326*cdf0e10cSrcweir Reference< script::XLibraryContainer > xModLibContainer1( xModLibContainer, UNO_QUERY ); 327*cdf0e10cSrcweir bOK = QueryPassword( xModLibContainer1, aLibName, aPassword ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir if ( !bOK ) 330*cdf0e10cSrcweir return sal_False; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir // TODO: check if library is reference/link 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir // Prueffen, ob Referenz... 336*cdf0e10cSrcweir /* 337*cdf0e10cSrcweir sal_uInt16 nLib = pBasMgr->GetLibId( GetEntryText( pEntry, 0 ) ); 338*cdf0e10cSrcweir DBG_ASSERT( nLib != LIB_NOTFOUND, "LibId ?!" ); 339*cdf0e10cSrcweir if ( pBasMgr->IsReference( nLib ) ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_CANNOTCHANGENAMEREFLIB ) ) ).Execute(); 342*cdf0e10cSrcweir return sal_False; 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir */ 345*cdf0e10cSrcweir return sal_True; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir //---------------------------------------------------------------------------- 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir sal_Bool __EXPORT BasicCheckBox::EditedEntry( SvLBoxEntry* pEntry, const String& rNewText ) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir sal_Bool bValid = ( rNewText.Len() <= 30 ) && BasicIDE::IsValidSbxName( rNewText ); 353*cdf0e10cSrcweir String aCurText( GetEntryText( pEntry, 0 ) ); 354*cdf0e10cSrcweir if ( bValid && ( aCurText != rNewText ) ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir try 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir ::rtl::OUString aOUOldName( aCurText ); 359*cdf0e10cSrcweir ::rtl::OUString aOUNewName( rNewText ); 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 362*cdf0e10cSrcweir if ( xModLibContainer.is() ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir xModLibContainer->renameLibrary( aOUOldName, aOUNewName ); 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 368*cdf0e10cSrcweir if ( xDlgLibContainer.is() ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir xDlgLibContainer->renameLibrary( aOUOldName, aOUNewName ); 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( m_aDocument ); 374*cdf0e10cSrcweir SfxBindings* pBindings = BasicIDE::GetBindingsPtr(); 375*cdf0e10cSrcweir if ( pBindings ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR ); 378*cdf0e10cSrcweir pBindings->Update( SID_BASICIDE_LIBSELECTOR ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir catch ( container::ElementExistException& ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_SBXNAMEALLREADYUSED ) ) ).Execute(); 384*cdf0e10cSrcweir return sal_False; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir catch ( container::NoSuchElementException& ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 389*cdf0e10cSrcweir return sal_False; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir if ( !bValid ) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir if ( rNewText.Len() > 30 ) 396*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_LIBNAMETOLONG ) ) ).Execute(); 397*cdf0e10cSrcweir else 398*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir return bValid; 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir //---------------------------------------------------------------------------- 405*cdf0e10cSrcweir // NewObjectDialog 406*cdf0e10cSrcweir //---------------------------------------------------------------------------- 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir IMPL_LINK(NewObjectDialog, OkButtonHandler, Button *, EMPTYARG) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir if (BasicIDE::IsValidSbxName(aEdit.GetText())) 411*cdf0e10cSrcweir EndDialog(1); 412*cdf0e10cSrcweir else 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir ErrorBox(this, WB_OK | WB_DEF_OK, 415*cdf0e10cSrcweir String(IDEResId(RID_STR_BADSBXNAME))).Execute(); 416*cdf0e10cSrcweir aEdit.GrabFocus(); 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir return 0; 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir NewObjectDialog::NewObjectDialog(Window * pParent, sal_uInt16 nMode, 422*cdf0e10cSrcweir bool bCheckName) 423*cdf0e10cSrcweir : ModalDialog( pParent, IDEResId( RID_DLG_NEWLIB ) ), 424*cdf0e10cSrcweir aText( this, IDEResId( RID_FT_NEWLIB ) ), 425*cdf0e10cSrcweir aEdit( this, IDEResId( RID_ED_LIBNAME ) ), 426*cdf0e10cSrcweir aOKButton( this, IDEResId( RID_PB_OK ) ), 427*cdf0e10cSrcweir aCancelButton( this, IDEResId( RID_PB_CANCEL ) ) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir FreeResource(); 430*cdf0e10cSrcweir aEdit.GrabFocus(); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir if ( nMode == NEWOBJECTMODE_LIB ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir SetText( String( IDEResId( RID_STR_NEWLIB ) ) ); 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir else if ( nMode == NEWOBJECTMODE_MOD ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir SetText( String( IDEResId( RID_STR_NEWMOD ) ) ); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir else if ( nMode == NEWOBJECTMODE_METH ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir SetText( String( IDEResId( RID_STR_NEWMETH ) ) ); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir else 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir SetText( String( IDEResId( RID_STR_NEWDLG ) ) ); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir if (bCheckName) 450*cdf0e10cSrcweir aOKButton.SetClickHdl(LINK(this, NewObjectDialog, OkButtonHandler)); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir //---------------------------------------------------------------------------- 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir NewObjectDialog::~NewObjectDialog() 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir //---------------------------------------------------------------------------- 460*cdf0e10cSrcweir // ExportDialog 461*cdf0e10cSrcweir //---------------------------------------------------------------------------- 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir IMPL_LINK(ExportDialog, OkButtonHandler, Button *, EMPTYARG) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir mbExportAsPackage = maExportAsPackageButton.IsChecked(); 466*cdf0e10cSrcweir EndDialog(1); 467*cdf0e10cSrcweir return 0; 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir ExportDialog::ExportDialog( Window * pParent ) 471*cdf0e10cSrcweir : ModalDialog( pParent, IDEResId( RID_DLG_EXPORT ) ), 472*cdf0e10cSrcweir maExportAsPackageButton( this, IDEResId( RB_EXPORTASPACKAGE ) ), 473*cdf0e10cSrcweir maExportAsBasicButton( this, IDEResId( RB_EXPORTASBASIC ) ), 474*cdf0e10cSrcweir maOKButton( this, IDEResId( RID_PB_OK ) ), 475*cdf0e10cSrcweir maCancelButton( this, IDEResId( RID_PB_CANCEL ) ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir FreeResource(); 478*cdf0e10cSrcweir maExportAsPackageButton.Check(); 479*cdf0e10cSrcweir maOKButton.SetClickHdl(LINK(this, ExportDialog, OkButtonHandler)); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir //---------------------------------------------------------------------------- 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir ExportDialog::~ExportDialog() 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir //---------------------------------------------------------------------------- 489*cdf0e10cSrcweir // LibPage 490*cdf0e10cSrcweir //---------------------------------------------------------------------------- 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir LibPage::LibPage( Window * pParent ) 493*cdf0e10cSrcweir :TabPage( pParent, IDEResId( RID_TP_LIBS ) ) 494*cdf0e10cSrcweir ,aBasicsText( this, IDEResId( RID_STR_BASICS ) ) 495*cdf0e10cSrcweir ,aBasicsBox( this, IDEResId( RID_LB_BASICS ) ) 496*cdf0e10cSrcweir ,aLibText( this, IDEResId( RID_STR_LIB ) ) 497*cdf0e10cSrcweir ,aLibBox( this, IDEResId( RID_TRLBOX ) ) 498*cdf0e10cSrcweir ,aEditButton( this, IDEResId( RID_PB_EDIT ) ) 499*cdf0e10cSrcweir ,aCloseButton( this, IDEResId( RID_PB_CLOSE ) ) 500*cdf0e10cSrcweir ,aPasswordButton( this, IDEResId( RID_PB_PASSWORD ) ) 501*cdf0e10cSrcweir ,aNewLibButton( this, IDEResId( RID_PB_NEWLIB ) ) 502*cdf0e10cSrcweir ,aInsertLibButton( this, IDEResId( RID_PB_APPEND ) ) 503*cdf0e10cSrcweir ,aExportButton( this, IDEResId( RID_PB_EXPORT ) ) 504*cdf0e10cSrcweir ,aDelButton( this, IDEResId( RID_PB_DELETE ) ) 505*cdf0e10cSrcweir ,m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ) 506*cdf0e10cSrcweir ,m_eCurLocation( LIBRARY_LOCATION_UNKNOWN ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir FreeResource(); 509*cdf0e10cSrcweir pTabDlg = 0; 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir aEditButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 512*cdf0e10cSrcweir aNewLibButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 513*cdf0e10cSrcweir aPasswordButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 514*cdf0e10cSrcweir aExportButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 515*cdf0e10cSrcweir aInsertLibButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 516*cdf0e10cSrcweir aDelButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 517*cdf0e10cSrcweir aCloseButton.SetClickHdl( LINK( this, LibPage, ButtonHdl ) ); 518*cdf0e10cSrcweir aLibBox.SetSelectHdl( LINK( this, LibPage, TreeListHighlightHdl ) ); 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir aBasicsBox.SetSelectHdl( LINK( this, LibPage, BasicSelectHdl ) ); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir aLibBox.SetMode( LIBMODE_MANAGER ); 523*cdf0e10cSrcweir aLibBox.EnableInplaceEditing( sal_True ); 524*cdf0e10cSrcweir aLibBox.SetStyle( WB_HSCROLL | WB_BORDER | WB_TABSTOP ); 525*cdf0e10cSrcweir aCloseButton.GrabFocus(); 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir long aTabs[] = { 2, 30, 120 }; 528*cdf0e10cSrcweir aLibBox.SetTabs( aTabs, MAP_PIXEL ); 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir FillListBox(); 531*cdf0e10cSrcweir aBasicsBox.SelectEntryPos( 0 ); 532*cdf0e10cSrcweir SetCurLib(); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir CheckButtons(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir //---------------------------------------------------------------------------- 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir LibPage::~LibPage() 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir sal_uInt16 nCount = aBasicsBox.GetEntryCount(); 542*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir BasicDocumentEntry* pEntry = (BasicDocumentEntry*)aBasicsBox.GetEntryData( i ); 545*cdf0e10cSrcweir delete pEntry; 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir //---------------------------------------------------------------------------- 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir void LibPage::CheckButtons() 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir SvLBoxEntry* pCur = aLibBox.GetCurEntry(); 554*cdf0e10cSrcweir if ( pCur ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir String aLibName = aLibBox.GetEntryText( pCur, 0 ); 557*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 558*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 559*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 560*cdf0e10cSrcweir 561*cdf0e10cSrcweir if ( m_eCurLocation == LIBRARY_LOCATION_SHARE ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir aPasswordButton.Disable(); 564*cdf0e10cSrcweir aNewLibButton.Disable(); 565*cdf0e10cSrcweir aInsertLibButton.Disable(); 566*cdf0e10cSrcweir aDelButton.Disable(); 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir else if ( aLibName.EqualsIgnoreCaseAscii( "Standard" ) ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir aPasswordButton.Disable(); 571*cdf0e10cSrcweir aNewLibButton.Enable(); 572*cdf0e10cSrcweir aInsertLibButton.Enable(); 573*cdf0e10cSrcweir aExportButton.Disable(); 574*cdf0e10cSrcweir aDelButton.Disable(); 575*cdf0e10cSrcweir if ( !aLibBox.HasFocus() ) 576*cdf0e10cSrcweir aCloseButton.GrabFocus(); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir else if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) || 579*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) ) 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir aPasswordButton.Disable(); 582*cdf0e10cSrcweir aNewLibButton.Enable(); 583*cdf0e10cSrcweir aInsertLibButton.Enable(); 584*cdf0e10cSrcweir if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) && !xModLibContainer->isLibraryLink( aOULibName ) ) || 585*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) && !xDlgLibContainer->isLibraryLink( aOULibName ) ) ) 586*cdf0e10cSrcweir aDelButton.Disable(); 587*cdf0e10cSrcweir else 588*cdf0e10cSrcweir aDelButton.Enable(); 589*cdf0e10cSrcweir } 590*cdf0e10cSrcweir else 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir if ( xModLibContainer.is() && !xModLibContainer->hasByName( aOULibName ) ) 593*cdf0e10cSrcweir aPasswordButton.Disable(); 594*cdf0e10cSrcweir else 595*cdf0e10cSrcweir aPasswordButton.Enable(); 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir aNewLibButton.Enable(); 598*cdf0e10cSrcweir aInsertLibButton.Enable(); 599*cdf0e10cSrcweir aExportButton.Enable(); 600*cdf0e10cSrcweir aDelButton.Enable(); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir //---------------------------------------------------------------------------- 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir void __EXPORT LibPage::ActivatePage() 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir SetCurLib(); 610*cdf0e10cSrcweir } 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir //---------------------------------------------------------------------------- 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir void __EXPORT LibPage::DeactivatePage() 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir //---------------------------------------------------------------------------- 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir IMPL_LINK_INLINE_START( LibPage, TreeListHighlightHdl, SvTreeListBox *, pBox ) 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir if ( pBox->IsSelected( pBox->GetHdlEntry() ) ) 625*cdf0e10cSrcweir CheckButtons(); 626*cdf0e10cSrcweir return 0; 627*cdf0e10cSrcweir } 628*cdf0e10cSrcweir IMPL_LINK_INLINE_END( LibPage, TreeListHighlightHdl, SvTreeListBox *, pBox ) 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir //---------------------------------------------------------------------------- 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir IMPL_LINK_INLINE_START( LibPage, BasicSelectHdl, ListBox *, pBox ) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir (void)pBox; 635*cdf0e10cSrcweir SetCurLib(); 636*cdf0e10cSrcweir CheckButtons(); 637*cdf0e10cSrcweir return 0; 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir IMPL_LINK_INLINE_END( LibPage, BasicSelectHdl, ListBox *, pBox ) 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir //---------------------------------------------------------------------------- 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir IMPL_LINK( LibPage, ButtonHdl, Button *, pButton ) 644*cdf0e10cSrcweir { 645*cdf0e10cSrcweir if ( pButton == &aEditButton ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 648*cdf0e10cSrcweir SfxRequest aRequest( SID_BASICIDE_APPEAR, SFX_CALLMODE_SYNCHRON, aArgs ); 649*cdf0e10cSrcweir SFX_APP()->ExecuteSlot( aRequest ); 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( m_aCurDocument.getDocumentOrNull() ) ); 652*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry(); 653*cdf0e10cSrcweir DBG_ASSERT( pCurEntry, "Entry?!" ); 654*cdf0e10cSrcweir String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) ); 655*cdf0e10cSrcweir SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName ); 656*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 657*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 658*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 659*cdf0e10cSrcweir if ( pDispatcher ) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_LIBSELECTED, 662*cdf0e10cSrcweir SFX_CALLMODE_ASYNCHRON, &aDocItem, &aLibNameItem, 0L ); 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir EndTabDialog( 1 ); 665*cdf0e10cSrcweir return 0; 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir else if ( pButton == &aNewLibButton ) 668*cdf0e10cSrcweir NewLib(); 669*cdf0e10cSrcweir else if ( pButton == &aInsertLibButton ) 670*cdf0e10cSrcweir InsertLib(); 671*cdf0e10cSrcweir else if ( pButton == &aExportButton ) 672*cdf0e10cSrcweir Export(); 673*cdf0e10cSrcweir else if ( pButton == &aDelButton ) 674*cdf0e10cSrcweir DeleteCurrent(); 675*cdf0e10cSrcweir else if ( pButton == &aCloseButton ) 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir EndTabDialog( 0 ); 678*cdf0e10cSrcweir return 0; 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir else if ( pButton == &aPasswordButton ) 681*cdf0e10cSrcweir { 682*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry(); 683*cdf0e10cSrcweir String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) ); 684*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir // load module library (if not loaded) 687*cdf0e10cSrcweir Reference< script::XLibraryContainer > xModLibContainer = m_aCurDocument.getLibraryContainer( E_SCRIPTS ); 688*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 691*cdf0e10cSrcweir if ( pIDEShell ) 692*cdf0e10cSrcweir pIDEShell->GetViewFrame()->GetWindow().EnterWait(); 693*cdf0e10cSrcweir xModLibContainer->loadLibrary( aOULibName ); 694*cdf0e10cSrcweir if ( pIDEShell ) 695*cdf0e10cSrcweir pIDEShell->GetViewFrame()->GetWindow().LeaveWait(); 696*cdf0e10cSrcweir } 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir // load dialog library (if not loaded) 699*cdf0e10cSrcweir Reference< script::XLibraryContainer > xDlgLibContainer = m_aCurDocument.getLibraryContainer( E_DIALOGS ); 700*cdf0e10cSrcweir if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && !xDlgLibContainer->isLibraryLoaded( aOULibName ) ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 703*cdf0e10cSrcweir if ( pIDEShell ) 704*cdf0e10cSrcweir pIDEShell->GetViewFrame()->GetWindow().EnterWait(); 705*cdf0e10cSrcweir xDlgLibContainer->loadLibrary( aOULibName ); 706*cdf0e10cSrcweir if ( pIDEShell ) 707*cdf0e10cSrcweir pIDEShell->GetViewFrame()->GetWindow().LeaveWait(); 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir // check, if library is password protected 711*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) 712*cdf0e10cSrcweir { 713*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 714*cdf0e10cSrcweir if ( xPasswd.is() ) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir sal_Bool bProtected = xPasswd->isLibraryPasswordProtected( aOULibName ); 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir // change password dialog 719*cdf0e10cSrcweir SvxPasswordDialog* pDlg = new SvxPasswordDialog( this, sal_True, !bProtected ); 720*cdf0e10cSrcweir pDlg->SetCheckPasswordHdl( LINK( this, LibPage, CheckPasswordHdl ) ); 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK ) 723*cdf0e10cSrcweir { 724*cdf0e10cSrcweir sal_Bool bNewProtected = xPasswd->isLibraryPasswordProtected( aOULibName ); 725*cdf0e10cSrcweir 726*cdf0e10cSrcweir if ( bNewProtected != bProtected ) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir sal_uLong nPos = (sal_uLong)aLibBox.GetModel()->GetAbsPos( pCurEntry ); 729*cdf0e10cSrcweir aLibBox.GetModel()->Remove( pCurEntry ); 730*cdf0e10cSrcweir ImpInsertLibEntry( aLibName, nPos ); 731*cdf0e10cSrcweir aLibBox.SetCurEntry( aLibBox.GetEntry( nPos ) ); 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( m_aCurDocument ); 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir delete pDlg; 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir CheckButtons(); 741*cdf0e10cSrcweir return 0; 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir //---------------------------------------------------------------------------- 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir IMPL_LINK_INLINE_START( LibPage, CheckPasswordHdl, SvxPasswordDialog *, pDlg ) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir long nRet = 0; 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry(); 751*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibBox.GetEntryText( pCurEntry, 0 ) ); 752*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir if ( xPasswd.is() ) 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir try 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir ::rtl::OUString aOUOldPassword( pDlg->GetOldPassword() ); 759*cdf0e10cSrcweir ::rtl::OUString aOUNewPassword( pDlg->GetNewPassword() ); 760*cdf0e10cSrcweir xPasswd->changeLibraryPassword( aOULibName, aOUOldPassword, aOUNewPassword ); 761*cdf0e10cSrcweir nRet = 1; 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir catch (...) 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir } 766*cdf0e10cSrcweir } 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir return nRet; 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir IMPL_LINK_INLINE_END( LibPage, CheckPasswordHdl, SvxPasswordDialog *, pDlg ) 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir //---------------------------------------------------------------------------- 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir void LibPage::NewLib() 775*cdf0e10cSrcweir { 776*cdf0e10cSrcweir createLibImpl( static_cast<Window*>( this ), m_aCurDocument, &aLibBox, NULL); 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir //---------------------------------------------------------------------------- 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir void LibPage::InsertLib() 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir // file open dialog 784*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() ); 785*cdf0e10cSrcweir Reference < XFilePicker > xFP; 786*cdf0e10cSrcweir if( xMSF.is() ) 787*cdf0e10cSrcweir { 788*cdf0e10cSrcweir Sequence <Any> aServiceType(1); 789*cdf0e10cSrcweir aServiceType[0] <<= TemplateDescription::FILEOPEN_SIMPLE; 790*cdf0e10cSrcweir xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments( 791*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY ); 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir xFP->setTitle( String( IDEResId( RID_STR_APPENDLIBS ) ) ); 794*cdf0e10cSrcweir 795*cdf0e10cSrcweir // filter 796*cdf0e10cSrcweir ::rtl::OUString aTitle = String( IDEResId( RID_STR_BASIC ) ); 797*cdf0e10cSrcweir ::rtl::OUString aFilter; 798*cdf0e10cSrcweir aFilter = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.sbl;*.xlc;*.xlb" ) ); // library files 799*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sdw;*.sxw;*.odt" ) ); // text 800*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.vor;*.stw;*.ott" ) ); // text template 801*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sgl;*.sxg;*.odm" ) ); // master document 802*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.oth" ) ); // html document template 803*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sdc;*.sxc;*.ods" ) ); // spreadsheet 804*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.stc;*.ots" ) ); // spreadsheet template 805*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sda;*.sxd;*.odg" ) ); // drawing 806*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.std;*.otg" ) ); // drawing template 807*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sdd;*.sxi;*.odp" ) ); // presentation 808*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sti;*.otp" ) ); // presentation template 809*cdf0e10cSrcweir aFilter += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";*.sxm;*.odf" ) ); // formula 810*cdf0e10cSrcweir Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY); 811*cdf0e10cSrcweir xFltMgr->appendFilter( aTitle, aFilter ); 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir // set display directory and filter 814*cdf0e10cSrcweir String aPath( IDE_DLL()->GetExtraData()->GetAddLibPath() ); 815*cdf0e10cSrcweir if ( aPath.Len() ) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir xFP->setDisplayDirectory( aPath ); 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir else 820*cdf0e10cSrcweir { 821*cdf0e10cSrcweir // macro path from configuration management 822*cdf0e10cSrcweir xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() ); 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir 825*cdf0e10cSrcweir String aLastFilter( IDE_DLL()->GetExtraData()->GetAddLibFilter() ); 826*cdf0e10cSrcweir if ( aLastFilter.Len() ) 827*cdf0e10cSrcweir { 828*cdf0e10cSrcweir xFltMgr->setCurrentFilter( aLastFilter ); 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir else 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir xFltMgr->setCurrentFilter( String( IDEResId( RID_STR_BASIC ) ) ); 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir if ( xFP->execute() == RET_OK ) 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir IDE_DLL()->GetExtraData()->SetAddLibPath( xFP->getDisplayDirectory() ); 838*cdf0e10cSrcweir IDE_DLL()->GetExtraData()->SetAddLibFilter( xFltMgr->getCurrentFilter() ); 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir // library containers for import 841*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContImport; 842*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContImport; 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir // file URLs 845*cdf0e10cSrcweir Sequence< ::rtl::OUString > aFiles = xFP->getFiles(); 846*cdf0e10cSrcweir INetURLObject aURLObj( aFiles[0] ); 847*cdf0e10cSrcweir INetURLObject aModURLObj( aURLObj ); 848*cdf0e10cSrcweir INetURLObject aDlgURLObj( aURLObj ); 849*cdf0e10cSrcweir 850*cdf0e10cSrcweir String aBase = aURLObj.getBase(); 851*cdf0e10cSrcweir String aModBase = String::CreateFromAscii( "script" ); 852*cdf0e10cSrcweir String aDlgBase = String::CreateFromAscii( "dialog" ); 853*cdf0e10cSrcweir 854*cdf0e10cSrcweir if ( aBase == aModBase || aBase == aDlgBase ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir aModURLObj.setBase( aModBase ); 857*cdf0e10cSrcweir aDlgURLObj.setBase( aDlgBase ); 858*cdf0e10cSrcweir } 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir if ( xMSF.is() ) 861*cdf0e10cSrcweir { 862*cdf0e10cSrcweir Reference< XSimpleFileAccess > xSFA( xMSF->createInstance( 863*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), UNO_QUERY ); 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir if ( xSFA.is() ) 866*cdf0e10cSrcweir { 867*cdf0e10cSrcweir ::rtl::OUString aModURL( aModURLObj.GetMainURL( INetURLObject::NO_DECODE ) ); 868*cdf0e10cSrcweir if ( xSFA->exists( aModURL ) ) 869*cdf0e10cSrcweir { 870*cdf0e10cSrcweir Sequence <Any> aSeqModURL(1); 871*cdf0e10cSrcweir aSeqModURL[0] <<= aModURL; 872*cdf0e10cSrcweir xModLibContImport = Reference< script::XLibraryContainer2 >( xMSF->createInstanceWithArguments( 873*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.DocumentScriptLibraryContainer" ) ), aSeqModURL ), UNO_QUERY ); 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir ::rtl::OUString aDlgURL( aDlgURLObj.GetMainURL( INetURLObject::NO_DECODE ) ); 877*cdf0e10cSrcweir if ( xSFA->exists( aDlgURL ) ) 878*cdf0e10cSrcweir { 879*cdf0e10cSrcweir Sequence <Any> aSeqDlgURL(1); 880*cdf0e10cSrcweir aSeqDlgURL[0] <<= aDlgURL; 881*cdf0e10cSrcweir xDlgLibContImport = Reference< script::XLibraryContainer2 >( xMSF->createInstanceWithArguments( 882*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.script.DocumentDialogLibraryContainer" ) ), aSeqDlgURL ), UNO_QUERY ); 883*cdf0e10cSrcweir } 884*cdf0e10cSrcweir } 885*cdf0e10cSrcweir } 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir if ( xModLibContImport.is() || xDlgLibContImport.is() ) 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir LibDialog* pLibDlg = 0; 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir Reference< script::XLibraryContainer > xModLibContImp( xModLibContImport, UNO_QUERY ); 892*cdf0e10cSrcweir Reference< script::XLibraryContainer > xDlgLibContImp( xDlgLibContImport, UNO_QUERY ); 893*cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibNames = BasicIDE::GetMergedLibraryNames( xModLibContImp, xDlgLibContImp ); 894*cdf0e10cSrcweir sal_Int32 nLibCount = aLibNames.getLength(); 895*cdf0e10cSrcweir const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); 896*cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nLibCount ; i++ ) 897*cdf0e10cSrcweir { 898*cdf0e10cSrcweir // library import dialog 899*cdf0e10cSrcweir if ( !pLibDlg ) 900*cdf0e10cSrcweir { 901*cdf0e10cSrcweir pLibDlg = new LibDialog( this ); 902*cdf0e10cSrcweir pLibDlg->SetStorageName( aURLObj.getName() ); 903*cdf0e10cSrcweir pLibDlg->GetLibBox().SetMode( LIBMODE_CHOOSER ); 904*cdf0e10cSrcweir } 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir // libbox entries 907*cdf0e10cSrcweir String aLibName( pLibNames[ i ] ); 908*cdf0e10cSrcweir String aOULibName( aLibName ); 909*cdf0e10cSrcweir if ( !( ( xModLibContImport.is() && xModLibContImport->hasByName( aOULibName ) && xModLibContImport->isLibraryLink( aOULibName ) ) || 910*cdf0e10cSrcweir ( xDlgLibContImport.is() && xDlgLibContImport->hasByName( aOULibName ) && xDlgLibContImport->isLibraryLink( aOULibName ) ) ) ) 911*cdf0e10cSrcweir { 912*cdf0e10cSrcweir SvLBoxEntry* pEntry = pLibDlg->GetLibBox().DoInsertEntry( aLibName ); 913*cdf0e10cSrcweir sal_uInt16 nPos = (sal_uInt16) pLibDlg->GetLibBox().GetModel()->GetAbsPos( pEntry ); 914*cdf0e10cSrcweir pLibDlg->GetLibBox().CheckEntryPos( nPos, sal_True); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir } 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir if ( !pLibDlg ) 919*cdf0e10cSrcweir InfoBox( this, String( IDEResId( RID_STR_NOLIBINSTORAGE ) ) ).Execute(); 920*cdf0e10cSrcweir else 921*cdf0e10cSrcweir { 922*cdf0e10cSrcweir sal_Bool bChanges = sal_False; 923*cdf0e10cSrcweir String aExtension( aURLObj.getExtension() ); 924*cdf0e10cSrcweir String aLibExtension( String::CreateFromAscii( "xlb" ) ); 925*cdf0e10cSrcweir String aContExtension( String::CreateFromAscii( "xlc" ) ); 926*cdf0e10cSrcweir 927*cdf0e10cSrcweir // disable reference checkbox for documents and sbls 928*cdf0e10cSrcweir if ( aExtension != aLibExtension && aExtension != aContExtension ) 929*cdf0e10cSrcweir pLibDlg->EnableReference( sal_False ); 930*cdf0e10cSrcweir 931*cdf0e10cSrcweir if ( pLibDlg->Execute() ) 932*cdf0e10cSrcweir { 933*cdf0e10cSrcweir sal_uLong nNewPos = aLibBox.GetEntryCount(); 934*cdf0e10cSrcweir sal_Bool bRemove = sal_False; 935*cdf0e10cSrcweir sal_Bool bReplace = pLibDlg->IsReplace(); 936*cdf0e10cSrcweir sal_Bool bReference = pLibDlg->IsReference(); 937*cdf0e10cSrcweir for ( sal_uInt16 nLib = 0; nLib < pLibDlg->GetLibBox().GetEntryCount(); nLib++ ) 938*cdf0e10cSrcweir { 939*cdf0e10cSrcweir if ( pLibDlg->GetLibBox().IsChecked( nLib ) ) 940*cdf0e10cSrcweir { 941*cdf0e10cSrcweir SvLBoxEntry* pEntry = pLibDlg->GetLibBox().GetEntry( nLib ); 942*cdf0e10cSrcweir DBG_ASSERT( pEntry, "Entry?!" ); 943*cdf0e10cSrcweir String aLibName( pLibDlg->GetLibBox().GetEntryText( pEntry, 0 ) ); 944*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 945*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 946*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir // check, if the library is already existing 949*cdf0e10cSrcweir if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) || 950*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) ) ) 951*cdf0e10cSrcweir { 952*cdf0e10cSrcweir if ( bReplace ) 953*cdf0e10cSrcweir { 954*cdf0e10cSrcweir // check, if the library is the Standard library 955*cdf0e10cSrcweir if ( aLibName.EqualsAscii( "Standard" ) ) 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_REPLACESTDLIB ) ) ).Execute(); 958*cdf0e10cSrcweir continue; 959*cdf0e10cSrcweir } 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir // check, if the library is readonly and not a link 962*cdf0e10cSrcweir if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) && !xModLibContainer->isLibraryLink( aOULibName ) ) || 963*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) && !xDlgLibContainer->isLibraryLink( aOULibName ) ) ) 964*cdf0e10cSrcweir { 965*cdf0e10cSrcweir String aErrStr( IDEResId( RID_STR_REPLACELIB ) ); 966*cdf0e10cSrcweir aErrStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aLibName ); 967*cdf0e10cSrcweir aErrStr += '\n'; 968*cdf0e10cSrcweir aErrStr += String( IDEResId( RID_STR_LIBISREADONLY ) ); 969*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute(); 970*cdf0e10cSrcweir continue; 971*cdf0e10cSrcweir } 972*cdf0e10cSrcweir 973*cdf0e10cSrcweir // remove existing libraries 974*cdf0e10cSrcweir bRemove = sal_True; 975*cdf0e10cSrcweir } 976*cdf0e10cSrcweir else 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir String aErrStr; 979*cdf0e10cSrcweir if ( bReference ) 980*cdf0e10cSrcweir aErrStr = String( IDEResId( RID_STR_REFNOTPOSSIBLE ) ); 981*cdf0e10cSrcweir else 982*cdf0e10cSrcweir aErrStr = String( IDEResId( RID_STR_IMPORTNOTPOSSIBLE ) ); 983*cdf0e10cSrcweir aErrStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aLibName ); 984*cdf0e10cSrcweir aErrStr += '\n'; 985*cdf0e10cSrcweir aErrStr += String( IDEResId( RID_STR_SBXNAMEALLREADYUSED ) ); 986*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute(); 987*cdf0e10cSrcweir continue; 988*cdf0e10cSrcweir } 989*cdf0e10cSrcweir } 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir // check, if the library is password protected 992*cdf0e10cSrcweir sal_Bool bOK = sal_False; 993*cdf0e10cSrcweir String aPassword; 994*cdf0e10cSrcweir if ( xModLibContImport.is() && xModLibContImport->hasByName( aOULibName ) ) 995*cdf0e10cSrcweir { 996*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContImport, UNO_QUERY ); 997*cdf0e10cSrcweir if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) && !bReference ) 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir bOK = QueryPassword( xModLibContImp, aLibName, aPassword, sal_True, sal_True ); 1000*cdf0e10cSrcweir 1001*cdf0e10cSrcweir if ( !bOK ) 1002*cdf0e10cSrcweir { 1003*cdf0e10cSrcweir String aErrStr( IDEResId( RID_STR_NOIMPORT ) ); 1004*cdf0e10cSrcweir aErrStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aLibName ); 1005*cdf0e10cSrcweir ErrorBox( this, WB_OK | WB_DEF_OK, aErrStr ).Execute(); 1006*cdf0e10cSrcweir continue; 1007*cdf0e10cSrcweir } 1008*cdf0e10cSrcweir } 1009*cdf0e10cSrcweir } 1010*cdf0e10cSrcweir 1011*cdf0e10cSrcweir // remove existing libraries 1012*cdf0e10cSrcweir if ( bRemove ) 1013*cdf0e10cSrcweir { 1014*cdf0e10cSrcweir // remove listbox entry 1015*cdf0e10cSrcweir SvLBoxEntry* pEntry_ = aLibBox.FindEntry( aLibName ); 1016*cdf0e10cSrcweir if ( pEntry_ ) 1017*cdf0e10cSrcweir aLibBox.SvTreeListBox::GetModel()->Remove( pEntry_ ); 1018*cdf0e10cSrcweir 1019*cdf0e10cSrcweir // remove module library 1020*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) 1021*cdf0e10cSrcweir xModLibContainer->removeLibrary( aOULibName ); 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir // remove dialog library 1024*cdf0e10cSrcweir if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) ) 1025*cdf0e10cSrcweir xDlgLibContainer->removeLibrary( aOULibName ); 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir // copy module library 1029*cdf0e10cSrcweir if ( xModLibContImport.is() && xModLibContImport->hasByName( aOULibName ) && xModLibContainer.is() && !xModLibContainer->hasByName( aOULibName ) ) 1030*cdf0e10cSrcweir { 1031*cdf0e10cSrcweir Reference< container::XNameContainer > xModLib; 1032*cdf0e10cSrcweir if ( bReference ) 1033*cdf0e10cSrcweir { 1034*cdf0e10cSrcweir // storage URL 1035*cdf0e10cSrcweir INetURLObject aModStorageURLObj( aModURLObj ); 1036*cdf0e10cSrcweir if ( aExtension == aContExtension ) 1037*cdf0e10cSrcweir { 1038*cdf0e10cSrcweir sal_Int32 nCount = aModStorageURLObj.getSegmentCount(); 1039*cdf0e10cSrcweir aModStorageURLObj.insertName( aLibName, false, nCount-1 ); 1040*cdf0e10cSrcweir aModStorageURLObj.setExtension( aLibExtension ); 1041*cdf0e10cSrcweir aModStorageURLObj.setFinalSlash(); 1042*cdf0e10cSrcweir } 1043*cdf0e10cSrcweir ::rtl::OUString aModStorageURL( aModStorageURLObj.GetMainURL( INetURLObject::NO_DECODE ) ); 1044*cdf0e10cSrcweir 1045*cdf0e10cSrcweir // create library link 1046*cdf0e10cSrcweir xModLib = Reference< container::XNameContainer >( xModLibContainer->createLibraryLink( aOULibName, aModStorageURL, sal_True ), UNO_QUERY); 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir else 1049*cdf0e10cSrcweir { 1050*cdf0e10cSrcweir // create library 1051*cdf0e10cSrcweir xModLib = xModLibContainer->createLibrary( aOULibName ); 1052*cdf0e10cSrcweir if ( xModLib.is() ) 1053*cdf0e10cSrcweir { 1054*cdf0e10cSrcweir // get import library 1055*cdf0e10cSrcweir Reference< container::XNameContainer > xModLibImport; 1056*cdf0e10cSrcweir Any aElement = xModLibContImport->getByName( aOULibName ); 1057*cdf0e10cSrcweir aElement >>= xModLibImport; 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir if ( xModLibImport.is() ) 1060*cdf0e10cSrcweir { 1061*cdf0e10cSrcweir // load library 1062*cdf0e10cSrcweir if ( !xModLibContImport->isLibraryLoaded( aOULibName ) ) 1063*cdf0e10cSrcweir xModLibContImport->loadLibrary( aOULibName ); 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir // copy all modules 1066*cdf0e10cSrcweir Sequence< ::rtl::OUString > aModNames = xModLibImport->getElementNames(); 1067*cdf0e10cSrcweir sal_Int32 nModCount = aModNames.getLength(); 1068*cdf0e10cSrcweir const ::rtl::OUString* pModNames = aModNames.getConstArray(); 1069*cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nModCount ; i++ ) 1070*cdf0e10cSrcweir { 1071*cdf0e10cSrcweir ::rtl::OUString aOUModName( pModNames[ i ] ); 1072*cdf0e10cSrcweir Any aElement_ = xModLibImport->getByName( aOUModName ); 1073*cdf0e10cSrcweir xModLib->insertByName( aOUModName, aElement_ ); 1074*cdf0e10cSrcweir } 1075*cdf0e10cSrcweir 1076*cdf0e10cSrcweir // set password 1077*cdf0e10cSrcweir if ( bOK ) 1078*cdf0e10cSrcweir { 1079*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 1080*cdf0e10cSrcweir if ( xPasswd.is() ) 1081*cdf0e10cSrcweir { 1082*cdf0e10cSrcweir try 1083*cdf0e10cSrcweir { 1084*cdf0e10cSrcweir ::rtl::OUString aOUPassword( aPassword ); 1085*cdf0e10cSrcweir xPasswd->changeLibraryPassword( aOULibName, ::rtl::OUString(), aOUPassword ); 1086*cdf0e10cSrcweir } 1087*cdf0e10cSrcweir catch (...) 1088*cdf0e10cSrcweir { 1089*cdf0e10cSrcweir } 1090*cdf0e10cSrcweir } 1091*cdf0e10cSrcweir } 1092*cdf0e10cSrcweir } 1093*cdf0e10cSrcweir } 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir 1097*cdf0e10cSrcweir // copy dialog library 1098*cdf0e10cSrcweir if ( xDlgLibContImport.is() && xDlgLibContImport->hasByName( aOULibName ) && xDlgLibContainer.is() && !xDlgLibContainer->hasByName( aOULibName ) ) 1099*cdf0e10cSrcweir { 1100*cdf0e10cSrcweir Reference< container::XNameContainer > xDlgLib; 1101*cdf0e10cSrcweir if ( bReference ) 1102*cdf0e10cSrcweir { 1103*cdf0e10cSrcweir // storage URL 1104*cdf0e10cSrcweir INetURLObject aDlgStorageURLObj( aDlgURLObj ); 1105*cdf0e10cSrcweir if ( aExtension == aContExtension ) 1106*cdf0e10cSrcweir { 1107*cdf0e10cSrcweir sal_Int32 nCount = aDlgStorageURLObj.getSegmentCount(); 1108*cdf0e10cSrcweir aDlgStorageURLObj.insertName( aLibName, false, nCount - 1 ); 1109*cdf0e10cSrcweir aDlgStorageURLObj.setExtension( aLibExtension ); 1110*cdf0e10cSrcweir aDlgStorageURLObj.setFinalSlash(); 1111*cdf0e10cSrcweir } 1112*cdf0e10cSrcweir ::rtl::OUString aDlgStorageURL( aDlgStorageURLObj.GetMainURL( INetURLObject::NO_DECODE ) ); 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir // create library link 1115*cdf0e10cSrcweir xDlgLib = Reference< container::XNameContainer >( xDlgLibContainer->createLibraryLink( aOULibName, aDlgStorageURL, sal_True ), UNO_QUERY); 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir else 1118*cdf0e10cSrcweir { 1119*cdf0e10cSrcweir // create library 1120*cdf0e10cSrcweir xDlgLib = xDlgLibContainer->createLibrary( aOULibName ); 1121*cdf0e10cSrcweir if ( xDlgLib.is() ) 1122*cdf0e10cSrcweir { 1123*cdf0e10cSrcweir // get import library 1124*cdf0e10cSrcweir Reference< container::XNameContainer > xDlgLibImport; 1125*cdf0e10cSrcweir Any aElement = xDlgLibContImport->getByName( aOULibName ); 1126*cdf0e10cSrcweir aElement >>= xDlgLibImport; 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir if ( xDlgLibImport.is() ) 1129*cdf0e10cSrcweir { 1130*cdf0e10cSrcweir // load library 1131*cdf0e10cSrcweir if ( !xDlgLibContImport->isLibraryLoaded( aOULibName ) ) 1132*cdf0e10cSrcweir xDlgLibContImport->loadLibrary( aOULibName ); 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir // copy all dialogs 1135*cdf0e10cSrcweir Sequence< ::rtl::OUString > aDlgNames = xDlgLibImport->getElementNames(); 1136*cdf0e10cSrcweir sal_Int32 nDlgCount = aDlgNames.getLength(); 1137*cdf0e10cSrcweir const ::rtl::OUString* pDlgNames = aDlgNames.getConstArray(); 1138*cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nDlgCount ; i++ ) 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir ::rtl::OUString aOUDlgName( pDlgNames[ i ] ); 1141*cdf0e10cSrcweir Any aElement_ = xDlgLibImport->getByName( aOUDlgName ); 1142*cdf0e10cSrcweir xDlgLib->insertByName( aOUDlgName, aElement_ ); 1143*cdf0e10cSrcweir } 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir } 1146*cdf0e10cSrcweir } 1147*cdf0e10cSrcweir } 1148*cdf0e10cSrcweir 1149*cdf0e10cSrcweir // insert listbox entry 1150*cdf0e10cSrcweir ImpInsertLibEntry( aLibName, aLibBox.GetEntryCount() ); 1151*cdf0e10cSrcweir bChanges = sal_True; 1152*cdf0e10cSrcweir } 1153*cdf0e10cSrcweir } 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir SvLBoxEntry* pFirstNew = aLibBox.GetEntry( nNewPos ); 1156*cdf0e10cSrcweir if ( pFirstNew ) 1157*cdf0e10cSrcweir aLibBox.SetCurEntry( pFirstNew ); 1158*cdf0e10cSrcweir } 1159*cdf0e10cSrcweir 1160*cdf0e10cSrcweir delete pLibDlg; 1161*cdf0e10cSrcweir if ( bChanges ) 1162*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( m_aCurDocument ); 1163*cdf0e10cSrcweir } 1164*cdf0e10cSrcweir } 1165*cdf0e10cSrcweir } 1166*cdf0e10cSrcweir } 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir void LibPage::Export( void ) 1171*cdf0e10cSrcweir { 1172*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry(); 1173*cdf0e10cSrcweir String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) ); 1174*cdf0e10cSrcweir 1175*cdf0e10cSrcweir // Password verification 1176*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 1177*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && !xModLibContainer->isLibraryLoaded( aOULibName ) ) 1180*cdf0e10cSrcweir { 1181*cdf0e10cSrcweir sal_Bool bOK = sal_True; 1182*cdf0e10cSrcweir 1183*cdf0e10cSrcweir // check password 1184*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 1185*cdf0e10cSrcweir if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) ) 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir String aPassword; 1188*cdf0e10cSrcweir Reference< script::XLibraryContainer > xModLibContainer1( xModLibContainer, UNO_QUERY ); 1189*cdf0e10cSrcweir bOK = QueryPassword( xModLibContainer1, aLibName, aPassword ); 1190*cdf0e10cSrcweir } 1191*cdf0e10cSrcweir if ( !bOK ) 1192*cdf0e10cSrcweir return; 1193*cdf0e10cSrcweir } 1194*cdf0e10cSrcweir 1195*cdf0e10cSrcweir 1196*cdf0e10cSrcweir Window* pWin = static_cast<Window*>( this ); 1197*cdf0e10cSrcweir std::auto_ptr< ExportDialog > xNewDlg( new ExportDialog( pWin ) ); 1198*cdf0e10cSrcweir 1199*cdf0e10cSrcweir if ( xNewDlg->Execute() == RET_OK ) 1200*cdf0e10cSrcweir { 1201*cdf0e10cSrcweir try 1202*cdf0e10cSrcweir { 1203*cdf0e10cSrcweir if( xNewDlg->isExportAsPackage() ) 1204*cdf0e10cSrcweir ExportAsPackage( aLibName ); 1205*cdf0e10cSrcweir else 1206*cdf0e10cSrcweir ExportAsBasic( aLibName ); 1207*cdf0e10cSrcweir } 1208*cdf0e10cSrcweir catch( util::VetoException& ) // user cancled operation 1209*cdf0e10cSrcweir { 1210*cdf0e10cSrcweir } 1211*cdf0e10cSrcweir } 1212*cdf0e10cSrcweir } 1213*cdf0e10cSrcweir 1214*cdf0e10cSrcweir void LibPage::implExportLib( const String& aLibName, const String& aTargetURL, 1215*cdf0e10cSrcweir const Reference< task::XInteractionHandler >& Handler ) 1216*cdf0e10cSrcweir { 1217*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 1218*cdf0e10cSrcweir Reference< script::XLibraryContainerExport > xModLibContainerExport 1219*cdf0e10cSrcweir ( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 1220*cdf0e10cSrcweir Reference< script::XLibraryContainerExport > xDlgLibContainerExport 1221*cdf0e10cSrcweir ( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 1222*cdf0e10cSrcweir if ( xModLibContainerExport.is() ) 1223*cdf0e10cSrcweir xModLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler ); 1224*cdf0e10cSrcweir 1225*cdf0e10cSrcweir if ( xDlgLibContainerExport.is() ) 1226*cdf0e10cSrcweir xDlgLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler ); 1227*cdf0e10cSrcweir } 1228*cdf0e10cSrcweir 1229*cdf0e10cSrcweir 1230*cdf0e10cSrcweir //=========================================================================== 1231*cdf0e10cSrcweir // Implementation XCommandEnvironment 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir typedef cppu::WeakImplHelper1< XCommandEnvironment > LibCommandEnvironmentHelper; 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir class OLibCommandEnvironment : public LibCommandEnvironmentHelper 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir Reference< task::XInteractionHandler > mxInteraction; 1238*cdf0e10cSrcweir 1239*cdf0e10cSrcweir public: 1240*cdf0e10cSrcweir OLibCommandEnvironment( Reference< task::XInteractionHandler > xInteraction ) 1241*cdf0e10cSrcweir : mxInteraction( xInteraction ) 1242*cdf0e10cSrcweir {} 1243*cdf0e10cSrcweir 1244*cdf0e10cSrcweir // Methods 1245*cdf0e10cSrcweir virtual Reference< task::XInteractionHandler > SAL_CALL getInteractionHandler() 1246*cdf0e10cSrcweir throw(RuntimeException); 1247*cdf0e10cSrcweir virtual Reference< XProgressHandler > SAL_CALL getProgressHandler() 1248*cdf0e10cSrcweir throw(RuntimeException); 1249*cdf0e10cSrcweir }; 1250*cdf0e10cSrcweir 1251*cdf0e10cSrcweir Reference< task::XInteractionHandler > OLibCommandEnvironment::getInteractionHandler() 1252*cdf0e10cSrcweir throw(RuntimeException) 1253*cdf0e10cSrcweir { 1254*cdf0e10cSrcweir return mxInteraction; 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir 1257*cdf0e10cSrcweir Reference< XProgressHandler > OLibCommandEnvironment::getProgressHandler() 1258*cdf0e10cSrcweir throw(RuntimeException) 1259*cdf0e10cSrcweir { 1260*cdf0e10cSrcweir Reference< XProgressHandler > xRet; 1261*cdf0e10cSrcweir return xRet; 1262*cdf0e10cSrcweir } 1263*cdf0e10cSrcweir 1264*cdf0e10cSrcweir 1265*cdf0e10cSrcweir 1266*cdf0e10cSrcweir void LibPage::ExportAsPackage( const String& aLibName ) 1267*cdf0e10cSrcweir { 1268*cdf0e10cSrcweir // file open dialog 1269*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() ); 1270*cdf0e10cSrcweir Reference< task::XInteractionHandler > xHandler; 1271*cdf0e10cSrcweir Reference< XSimpleFileAccess > xSFA; 1272*cdf0e10cSrcweir Reference < XFilePicker > xFP; 1273*cdf0e10cSrcweir if( xMSF.is() ) 1274*cdf0e10cSrcweir { 1275*cdf0e10cSrcweir xHandler = Reference< task::XInteractionHandler >( xMSF->createInstance 1276*cdf0e10cSrcweir ( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), UNO_QUERY ); 1277*cdf0e10cSrcweir 1278*cdf0e10cSrcweir xSFA = Reference< XSimpleFileAccess > ( xMSF->createInstance( 1279*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), UNO_QUERY ); 1280*cdf0e10cSrcweir if( !xSFA.is() ) 1281*cdf0e10cSrcweir { 1282*cdf0e10cSrcweir DBG_ERROR( "No simpleFileAccess" ); 1283*cdf0e10cSrcweir return; 1284*cdf0e10cSrcweir } 1285*cdf0e10cSrcweir 1286*cdf0e10cSrcweir Sequence <Any> aServiceType(1); 1287*cdf0e10cSrcweir aServiceType[0] <<= TemplateDescription::FILESAVE_SIMPLE; 1288*cdf0e10cSrcweir xFP = Reference< XFilePicker >( xMSF->createInstanceWithArguments( 1289*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ), aServiceType ), UNO_QUERY ); 1290*cdf0e10cSrcweir } 1291*cdf0e10cSrcweir xFP->setTitle( String( IDEResId( RID_STR_EXPORTPACKAGE ) ) ); 1292*cdf0e10cSrcweir 1293*cdf0e10cSrcweir // filter 1294*cdf0e10cSrcweir ::rtl::OUString aTitle = String( IDEResId( RID_STR_PACKAGE_BUNDLE ) ); 1295*cdf0e10cSrcweir ::rtl::OUString aFilter; 1296*cdf0e10cSrcweir aFilter = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*.oxt" ) ); // library files 1297*cdf0e10cSrcweir Reference< XFilterManager > xFltMgr(xFP, UNO_QUERY); 1298*cdf0e10cSrcweir xFltMgr->appendFilter( aTitle, aFilter ); 1299*cdf0e10cSrcweir 1300*cdf0e10cSrcweir // set display directory and filter 1301*cdf0e10cSrcweir String aPath( IDE_DLL()->GetExtraData()->GetAddLibPath() ); 1302*cdf0e10cSrcweir if ( aPath.Len() ) 1303*cdf0e10cSrcweir { 1304*cdf0e10cSrcweir xFP->setDisplayDirectory( aPath ); 1305*cdf0e10cSrcweir } 1306*cdf0e10cSrcweir else 1307*cdf0e10cSrcweir { 1308*cdf0e10cSrcweir // macro path from configuration management 1309*cdf0e10cSrcweir xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() ); 1310*cdf0e10cSrcweir } 1311*cdf0e10cSrcweir xFltMgr->setCurrentFilter( aTitle ); 1312*cdf0e10cSrcweir 1313*cdf0e10cSrcweir if ( xFP->execute() == RET_OK ) 1314*cdf0e10cSrcweir { 1315*cdf0e10cSrcweir IDE_DLL()->GetExtraData()->SetAddLibPath( xFP->getDisplayDirectory() ); 1316*cdf0e10cSrcweir 1317*cdf0e10cSrcweir Sequence< ::rtl::OUString > aFiles = xFP->getFiles(); 1318*cdf0e10cSrcweir INetURLObject aURL( aFiles[0] ); 1319*cdf0e10cSrcweir if( !aURL.getExtension().getLength() ) 1320*cdf0e10cSrcweir aURL.setExtension( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "oxt" ) ) ); 1321*cdf0e10cSrcweir 1322*cdf0e10cSrcweir ::rtl::OUString aPackageURL( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); 1323*cdf0e10cSrcweir 1324*cdf0e10cSrcweir String aTmpPath = SvtPathOptions().GetTempPath(); 1325*cdf0e10cSrcweir INetURLObject aInetObj( aTmpPath ); 1326*cdf0e10cSrcweir aInetObj.insertName( aLibName, sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL ); 1327*cdf0e10cSrcweir OUString aSourcePath = aInetObj.GetMainURL( INetURLObject::NO_DECODE ); 1328*cdf0e10cSrcweir if( xSFA->exists( aSourcePath ) ) 1329*cdf0e10cSrcweir xSFA->kill( aSourcePath ); 1330*cdf0e10cSrcweir Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) ); 1331*cdf0e10cSrcweir implExportLib( aLibName, aTmpPath, xDummyHandler ); 1332*cdf0e10cSrcweir 1333*cdf0e10cSrcweir Reference< XCommandEnvironment > xCmdEnv = 1334*cdf0e10cSrcweir static_cast<XCommandEnvironment*>( new OLibCommandEnvironment( xHandler ) ); 1335*cdf0e10cSrcweir 1336*cdf0e10cSrcweir ::ucbhelper::Content sourceContent( aSourcePath, xCmdEnv ); 1337*cdf0e10cSrcweir 1338*cdf0e10cSrcweir ::rtl::OUStringBuffer buf; 1339*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.zip://") ); 1340*cdf0e10cSrcweir buf.append( ::rtl::Uri::encode( aPackageURL, 1341*cdf0e10cSrcweir rtl_UriCharClassRegName, 1342*cdf0e10cSrcweir rtl_UriEncodeIgnoreEscapes, 1343*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ) ); 1344*cdf0e10cSrcweir buf.append( static_cast<sal_Unicode>('/') ); 1345*cdf0e10cSrcweir OUString destFolder( buf.makeStringAndClear() ); 1346*cdf0e10cSrcweir 1347*cdf0e10cSrcweir if( xSFA->exists( aPackageURL ) ) 1348*cdf0e10cSrcweir xSFA->kill( aPackageURL ); 1349*cdf0e10cSrcweir 1350*cdf0e10cSrcweir ::ucbhelper::Content destFolderContent( destFolder, xCmdEnv ); 1351*cdf0e10cSrcweir destFolderContent.transferContent( 1352*cdf0e10cSrcweir sourceContent, ::ucbhelper::InsertOperation_COPY, 1353*cdf0e10cSrcweir OUString(), NameClash::OVERWRITE ); 1354*cdf0e10cSrcweir 1355*cdf0e10cSrcweir INetURLObject aMetaInfInetObj( aTmpPath ); 1356*cdf0e10cSrcweir aMetaInfInetObj.insertName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ), 1357*cdf0e10cSrcweir sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL ); 1358*cdf0e10cSrcweir OUString aMetaInfFolder = aMetaInfInetObj.GetMainURL( INetURLObject::NO_DECODE ); 1359*cdf0e10cSrcweir if( xSFA->exists( aMetaInfFolder ) ) 1360*cdf0e10cSrcweir xSFA->kill( aMetaInfFolder ); 1361*cdf0e10cSrcweir xSFA->createFolder( aMetaInfFolder ); 1362*cdf0e10cSrcweir 1363*cdf0e10cSrcweir ::std::vector< Sequence<beans::PropertyValue> > manifest; 1364*cdf0e10cSrcweir const OUString strMediaType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); 1365*cdf0e10cSrcweir const OUString strFullPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FullPath" ) ); 1366*cdf0e10cSrcweir const OUString strBasicMediaType = ::rtl::OUString 1367*cdf0e10cSrcweir ( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.star.basic-library" ) ); 1368*cdf0e10cSrcweir 1369*cdf0e10cSrcweir Sequence<beans::PropertyValue> attribs( 2 ); 1370*cdf0e10cSrcweir beans::PropertyValue * pattribs = attribs.getArray(); 1371*cdf0e10cSrcweir pattribs[ 0 ].Name = strFullPath; 1372*cdf0e10cSrcweir OUString fullPath = aLibName; 1373*cdf0e10cSrcweir fullPath += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/") ); 1374*cdf0e10cSrcweir pattribs[ 0 ].Value <<= fullPath; 1375*cdf0e10cSrcweir pattribs[ 1 ].Name = strMediaType; 1376*cdf0e10cSrcweir pattribs[ 1 ].Value <<= strBasicMediaType; 1377*cdf0e10cSrcweir manifest.push_back( attribs ); 1378*cdf0e10cSrcweir 1379*cdf0e10cSrcweir // write into pipe: 1380*cdf0e10cSrcweir Reference<packages::manifest::XManifestWriter> xManifestWriter( xMSF->createInstance 1381*cdf0e10cSrcweir ( DEFINE_CONST_UNICODE("com.sun.star.packages.manifest.ManifestWriter") ), UNO_QUERY ); 1382*cdf0e10cSrcweir Reference<io::XOutputStream> xPipe( xMSF->createInstance 1383*cdf0e10cSrcweir ( DEFINE_CONST_UNICODE("com.sun.star.io.Pipe") ), UNO_QUERY ); 1384*cdf0e10cSrcweir xManifestWriter->writeManifestSequence( 1385*cdf0e10cSrcweir xPipe, Sequence< Sequence<beans::PropertyValue> >( 1386*cdf0e10cSrcweir &manifest[ 0 ], manifest.size() ) ); 1387*cdf0e10cSrcweir 1388*cdf0e10cSrcweir aMetaInfInetObj.insertName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) ), 1389*cdf0e10cSrcweir sal_True, INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::ENCODE_ALL ); 1390*cdf0e10cSrcweir 1391*cdf0e10cSrcweir // write buffered pipe data to content: 1392*cdf0e10cSrcweir ::ucbhelper::Content manifestContent( aMetaInfInetObj.GetMainURL( INetURLObject::NO_DECODE ), xCmdEnv ); 1393*cdf0e10cSrcweir manifestContent.writeStream( Reference<io::XInputStream>( xPipe, UNO_QUERY_THROW ), true ); 1394*cdf0e10cSrcweir 1395*cdf0e10cSrcweir ::ucbhelper::Content MetaInfContent( aMetaInfFolder, xCmdEnv ); 1396*cdf0e10cSrcweir destFolderContent.transferContent( 1397*cdf0e10cSrcweir MetaInfContent, ::ucbhelper::InsertOperation_COPY, 1398*cdf0e10cSrcweir OUString(), NameClash::OVERWRITE ); 1399*cdf0e10cSrcweir 1400*cdf0e10cSrcweir if( xSFA->exists( aSourcePath ) ) 1401*cdf0e10cSrcweir xSFA->kill( aSourcePath ); 1402*cdf0e10cSrcweir if( xSFA->exists( aMetaInfFolder ) ) 1403*cdf0e10cSrcweir xSFA->kill( aMetaInfFolder ); 1404*cdf0e10cSrcweir } 1405*cdf0e10cSrcweir } 1406*cdf0e10cSrcweir 1407*cdf0e10cSrcweir void LibPage::ExportAsBasic( const String& aLibName ) 1408*cdf0e10cSrcweir { 1409*cdf0e10cSrcweir // Folder picker 1410*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() ); 1411*cdf0e10cSrcweir Reference< XFolderPicker > xFolderPicker; 1412*cdf0e10cSrcweir Reference< task::XInteractionHandler > xHandler; 1413*cdf0e10cSrcweir if( xMSF.is() ) 1414*cdf0e10cSrcweir { 1415*cdf0e10cSrcweir xFolderPicker = Reference< XFolderPicker >( xMSF->createInstance( 1416*cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FolderPicker" ) ) ), UNO_QUERY ); 1417*cdf0e10cSrcweir 1418*cdf0e10cSrcweir xHandler = Reference< task::XInteractionHandler >( xMSF->createInstance 1419*cdf0e10cSrcweir ( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), UNO_QUERY ); 1420*cdf0e10cSrcweir } 1421*cdf0e10cSrcweir 1422*cdf0e10cSrcweir if( xFolderPicker.is() ) 1423*cdf0e10cSrcweir { 1424*cdf0e10cSrcweir xFolderPicker->setTitle( String( IDEResId( RID_STR_EXPORTBASIC ) ) ); 1425*cdf0e10cSrcweir 1426*cdf0e10cSrcweir // set display directory and filter 1427*cdf0e10cSrcweir String aPath( IDE_DLL()->GetExtraData()->GetAddLibPath() ); 1428*cdf0e10cSrcweir if( !aPath.Len() ) 1429*cdf0e10cSrcweir aPath = SvtPathOptions().GetWorkPath(); 1430*cdf0e10cSrcweir 1431*cdf0e10cSrcweir // INetURLObject aURL(m_sSavePath, INET_PROT_FILE); 1432*cdf0e10cSrcweir xFolderPicker->setDisplayDirectory( aPath ); 1433*cdf0e10cSrcweir short nRet = xFolderPicker->execute(); 1434*cdf0e10cSrcweir if( nRet == RET_OK ) 1435*cdf0e10cSrcweir { 1436*cdf0e10cSrcweir String aTargetURL = xFolderPicker->getDirectory(); 1437*cdf0e10cSrcweir IDE_DLL()->GetExtraData()->SetAddLibPath( aTargetURL ); 1438*cdf0e10cSrcweir 1439*cdf0e10cSrcweir Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) ); 1440*cdf0e10cSrcweir implExportLib( aLibName, aTargetURL, xDummyHandler ); 1441*cdf0e10cSrcweir } 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir } 1444*cdf0e10cSrcweir 1445*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1446*cdf0e10cSrcweir 1447*cdf0e10cSrcweir void LibPage::DeleteCurrent() 1448*cdf0e10cSrcweir { 1449*cdf0e10cSrcweir SvLBoxEntry* pCurEntry = aLibBox.GetCurEntry(); 1450*cdf0e10cSrcweir String aLibName( aLibBox.GetEntryText( pCurEntry, 0 ) ); 1451*cdf0e10cSrcweir 1452*cdf0e10cSrcweir // check, if library is link 1453*cdf0e10cSrcweir sal_Bool bIsLibraryLink = sal_False; 1454*cdf0e10cSrcweir ::rtl::OUString aOULibName( aLibName ); 1455*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 1456*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY ); 1457*cdf0e10cSrcweir if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLink( aOULibName ) ) || 1458*cdf0e10cSrcweir ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryLink( aOULibName ) ) ) 1459*cdf0e10cSrcweir { 1460*cdf0e10cSrcweir bIsLibraryLink = sal_True; 1461*cdf0e10cSrcweir } 1462*cdf0e10cSrcweir 1463*cdf0e10cSrcweir if ( QueryDelLib( aLibName, bIsLibraryLink, this ) ) 1464*cdf0e10cSrcweir { 1465*cdf0e10cSrcweir // inform BasicIDE 1466*cdf0e10cSrcweir SfxUsrAnyItem aDocItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( m_aCurDocument.getDocumentOrNull() ) ); 1467*cdf0e10cSrcweir SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName ); 1468*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 1469*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 1470*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 1471*cdf0e10cSrcweir if( pDispatcher ) 1472*cdf0e10cSrcweir { 1473*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_LIBREMOVED, 1474*cdf0e10cSrcweir SFX_CALLMODE_SYNCHRON, &aDocItem, &aLibNameItem, 0L ); 1475*cdf0e10cSrcweir } 1476*cdf0e10cSrcweir 1477*cdf0e10cSrcweir // remove library from module and dialog library containers 1478*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) 1479*cdf0e10cSrcweir xModLibContainer->removeLibrary( aOULibName ); 1480*cdf0e10cSrcweir if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) ) 1481*cdf0e10cSrcweir xDlgLibContainer->removeLibrary( aOULibName ); 1482*cdf0e10cSrcweir 1483*cdf0e10cSrcweir ((SvLBox&)aLibBox).GetModel()->Remove( pCurEntry ); 1484*cdf0e10cSrcweir BasicIDE::MarkDocumentModified( m_aCurDocument ); 1485*cdf0e10cSrcweir } 1486*cdf0e10cSrcweir } 1487*cdf0e10cSrcweir 1488*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1489*cdf0e10cSrcweir 1490*cdf0e10cSrcweir void LibPage::EndTabDialog( sal_uInt16 nRet ) 1491*cdf0e10cSrcweir { 1492*cdf0e10cSrcweir DBG_ASSERT( pTabDlg, "TabDlg nicht gesetzt!" ); 1493*cdf0e10cSrcweir if ( pTabDlg ) 1494*cdf0e10cSrcweir pTabDlg->EndDialog( nRet ); 1495*cdf0e10cSrcweir } 1496*cdf0e10cSrcweir 1497*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1498*cdf0e10cSrcweir 1499*cdf0e10cSrcweir void LibPage::FillListBox() 1500*cdf0e10cSrcweir { 1501*cdf0e10cSrcweir InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER ); 1502*cdf0e10cSrcweir InsertListBoxEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE ); 1503*cdf0e10cSrcweir 1504*cdf0e10cSrcweir ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted ) ); 1505*cdf0e10cSrcweir for ( ScriptDocuments::const_iterator doc = aDocuments.begin(); 1506*cdf0e10cSrcweir doc != aDocuments.end(); 1507*cdf0e10cSrcweir ++doc 1508*cdf0e10cSrcweir ) 1509*cdf0e10cSrcweir { 1510*cdf0e10cSrcweir InsertListBoxEntry( *doc, LIBRARY_LOCATION_DOCUMENT ); 1511*cdf0e10cSrcweir } 1512*cdf0e10cSrcweir } 1513*cdf0e10cSrcweir 1514*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1515*cdf0e10cSrcweir 1516*cdf0e10cSrcweir void LibPage::InsertListBoxEntry( const ScriptDocument& rDocument, LibraryLocation eLocation ) 1517*cdf0e10cSrcweir { 1518*cdf0e10cSrcweir String aEntryText( rDocument.getTitle( eLocation ) ); 1519*cdf0e10cSrcweir sal_uInt16 nPos = aBasicsBox.InsertEntry( aEntryText, LISTBOX_APPEND ); 1520*cdf0e10cSrcweir aBasicsBox.SetEntryData( nPos, new BasicDocumentEntry( rDocument, eLocation ) ); 1521*cdf0e10cSrcweir } 1522*cdf0e10cSrcweir 1523*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1524*cdf0e10cSrcweir 1525*cdf0e10cSrcweir void LibPage::SetCurLib() 1526*cdf0e10cSrcweir { 1527*cdf0e10cSrcweir sal_uInt16 nSelPos = aBasicsBox.GetSelectEntryPos(); 1528*cdf0e10cSrcweir BasicDocumentEntry* pEntry = (BasicDocumentEntry*)aBasicsBox.GetEntryData( nSelPos ); 1529*cdf0e10cSrcweir if ( pEntry ) 1530*cdf0e10cSrcweir { 1531*cdf0e10cSrcweir ScriptDocument aDocument( pEntry->GetDocument() ); 1532*cdf0e10cSrcweir DBG_ASSERT( aDocument.isAlive(), "LibPage::SetCurLib: no document, or document is dead!" ); 1533*cdf0e10cSrcweir if ( !aDocument.isAlive() ) 1534*cdf0e10cSrcweir return; 1535*cdf0e10cSrcweir LibraryLocation eLocation = pEntry->GetLocation(); 1536*cdf0e10cSrcweir if ( aDocument != m_aCurDocument || eLocation != m_eCurLocation ) 1537*cdf0e10cSrcweir { 1538*cdf0e10cSrcweir m_aCurDocument = aDocument; 1539*cdf0e10cSrcweir m_eCurLocation = eLocation; 1540*cdf0e10cSrcweir aLibBox.SetDocument( aDocument ); 1541*cdf0e10cSrcweir aLibBox.Clear(); 1542*cdf0e10cSrcweir 1543*cdf0e10cSrcweir // get a sorted list of library names 1544*cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibNames = aDocument.getLibraryNames(); 1545*cdf0e10cSrcweir sal_Int32 nLibCount = aLibNames.getLength(); 1546*cdf0e10cSrcweir const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); 1547*cdf0e10cSrcweir 1548*cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nLibCount ; i++ ) 1549*cdf0e10cSrcweir { 1550*cdf0e10cSrcweir String aLibName( pLibNames[ i ] ); 1551*cdf0e10cSrcweir if ( eLocation == aDocument.getLibraryLocation( aLibName ) ) 1552*cdf0e10cSrcweir ImpInsertLibEntry( aLibName, i ); 1553*cdf0e10cSrcweir } 1554*cdf0e10cSrcweir 1555*cdf0e10cSrcweir SvLBoxEntry* pEntry_ = aLibBox.FindEntry( String::CreateFromAscii( "Standard" ) ); 1556*cdf0e10cSrcweir if ( !pEntry_ ) 1557*cdf0e10cSrcweir pEntry_ = aLibBox.GetEntry( 0 ); 1558*cdf0e10cSrcweir aLibBox.SetCurEntry( pEntry_ ); 1559*cdf0e10cSrcweir } 1560*cdf0e10cSrcweir } 1561*cdf0e10cSrcweir } 1562*cdf0e10cSrcweir 1563*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1564*cdf0e10cSrcweir 1565*cdf0e10cSrcweir SvLBoxEntry* LibPage::ImpInsertLibEntry( const String& rLibName, sal_uLong nPos ) 1566*cdf0e10cSrcweir { 1567*cdf0e10cSrcweir // check, if library is password protected 1568*cdf0e10cSrcweir sal_Bool bProtected = sal_False; 1569*cdf0e10cSrcweir ::rtl::OUString aOULibName( rLibName ); 1570*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY ); 1571*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) ) 1572*cdf0e10cSrcweir { 1573*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY ); 1574*cdf0e10cSrcweir if ( xPasswd.is() ) 1575*cdf0e10cSrcweir { 1576*cdf0e10cSrcweir bProtected = xPasswd->isLibraryPasswordProtected( aOULibName ); 1577*cdf0e10cSrcweir } 1578*cdf0e10cSrcweir } 1579*cdf0e10cSrcweir 1580*cdf0e10cSrcweir SvLBoxEntry* pNewEntry = aLibBox.DoInsertEntry( rLibName, nPos ); 1581*cdf0e10cSrcweir pNewEntry->SetUserData( new BasicLibUserData( m_aCurDocument ) ); 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir if (bProtected) 1584*cdf0e10cSrcweir { 1585*cdf0e10cSrcweir Image aImage(IDEResId(RID_IMG_LOCKED)); 1586*cdf0e10cSrcweir aLibBox.SetExpandedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL); 1587*cdf0e10cSrcweir aLibBox.SetCollapsedEntryBmp(pNewEntry, aImage, BMP_COLOR_NORMAL); 1588*cdf0e10cSrcweir aImage = Image(IDEResId(RID_IMG_LOCKED_HC)); 1589*cdf0e10cSrcweir aLibBox.SetExpandedEntryBmp(pNewEntry, aImage, 1590*cdf0e10cSrcweir BMP_COLOR_HIGHCONTRAST); 1591*cdf0e10cSrcweir aLibBox.SetCollapsedEntryBmp(pNewEntry, aImage, 1592*cdf0e10cSrcweir BMP_COLOR_HIGHCONTRAST); 1593*cdf0e10cSrcweir } 1594*cdf0e10cSrcweir 1595*cdf0e10cSrcweir // check, if library is link 1596*cdf0e10cSrcweir if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLink( aOULibName ) ) 1597*cdf0e10cSrcweir { 1598*cdf0e10cSrcweir String aLinkURL = xModLibContainer->getLibraryLinkURL( aOULibName ); 1599*cdf0e10cSrcweir aLibBox.SetEntryText( aLinkURL, pNewEntry, 1 ); 1600*cdf0e10cSrcweir } 1601*cdf0e10cSrcweir 1602*cdf0e10cSrcweir return pNewEntry; 1603*cdf0e10cSrcweir } 1604*cdf0e10cSrcweir 1605*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1606*cdf0e10cSrcweir 1607*cdf0e10cSrcweir // Helper function 1608*cdf0e10cSrcweir void createLibImpl( Window* pWin, const ScriptDocument& rDocument, 1609*cdf0e10cSrcweir BasicCheckBox* pLibBox, BasicTreeListBox* pBasicBox ) 1610*cdf0e10cSrcweir { 1611*cdf0e10cSrcweir OSL_ENSURE( rDocument.isAlive(), "createLibImpl: invalid document!" ); 1612*cdf0e10cSrcweir if ( !rDocument.isAlive() ) 1613*cdf0e10cSrcweir return; 1614*cdf0e10cSrcweir 1615*cdf0e10cSrcweir // create library name 1616*cdf0e10cSrcweir String aLibName; 1617*cdf0e10cSrcweir String aLibStdName( String( RTL_CONSTASCII_USTRINGPARAM( "Library" ) ) ); 1618*cdf0e10cSrcweir //String aLibStdName( IDEResId( RID_STR_STDLIBNAME ) ); 1619*cdf0e10cSrcweir sal_Bool bValid = sal_False; 1620*cdf0e10cSrcweir sal_uInt16 i = 1; 1621*cdf0e10cSrcweir while ( !bValid ) 1622*cdf0e10cSrcweir { 1623*cdf0e10cSrcweir aLibName = aLibStdName; 1624*cdf0e10cSrcweir aLibName += String::CreateFromInt32( i ); 1625*cdf0e10cSrcweir if ( !rDocument.hasLibrary( E_SCRIPTS, aLibName ) && !rDocument.hasLibrary( E_DIALOGS, aLibName ) ) 1626*cdf0e10cSrcweir bValid = sal_True; 1627*cdf0e10cSrcweir i++; 1628*cdf0e10cSrcweir } 1629*cdf0e10cSrcweir 1630*cdf0e10cSrcweir std::auto_ptr< NewObjectDialog > xNewDlg( new NewObjectDialog( pWin, NEWOBJECTMODE_LIB ) ); 1631*cdf0e10cSrcweir xNewDlg->SetObjectName( aLibName ); 1632*cdf0e10cSrcweir 1633*cdf0e10cSrcweir if ( xNewDlg->Execute() ) 1634*cdf0e10cSrcweir { 1635*cdf0e10cSrcweir if ( xNewDlg->GetObjectName().Len() ) 1636*cdf0e10cSrcweir aLibName = xNewDlg->GetObjectName(); 1637*cdf0e10cSrcweir 1638*cdf0e10cSrcweir if ( aLibName.Len() > 30 ) 1639*cdf0e10cSrcweir { 1640*cdf0e10cSrcweir ErrorBox( pWin, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_LIBNAMETOLONG ) ) ).Execute(); 1641*cdf0e10cSrcweir } 1642*cdf0e10cSrcweir else if ( !BasicIDE::IsValidSbxName( aLibName ) ) 1643*cdf0e10cSrcweir { 1644*cdf0e10cSrcweir ErrorBox( pWin, WB_OK | WB_DEF_OK, 1645*cdf0e10cSrcweir String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute(); 1646*cdf0e10cSrcweir } 1647*cdf0e10cSrcweir else if ( rDocument.hasLibrary( E_SCRIPTS, aLibName ) || rDocument.hasLibrary( E_DIALOGS, aLibName ) ) 1648*cdf0e10cSrcweir { 1649*cdf0e10cSrcweir ErrorBox( pWin, WB_OK | WB_DEF_OK, 1650*cdf0e10cSrcweir String( IDEResId( RID_STR_SBXNAMEALLREADYUSED2 ) ) ).Execute(); 1651*cdf0e10cSrcweir } 1652*cdf0e10cSrcweir else 1653*cdf0e10cSrcweir { 1654*cdf0e10cSrcweir try 1655*cdf0e10cSrcweir { 1656*cdf0e10cSrcweir // create module and dialog library 1657*cdf0e10cSrcweir Reference< container::XNameContainer > xModLib( rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName ) ); 1658*cdf0e10cSrcweir Reference< container::XNameContainer > xDlgLib( rDocument.getOrCreateLibrary( E_DIALOGS, aLibName ) ); 1659*cdf0e10cSrcweir 1660*cdf0e10cSrcweir if( pLibBox ) 1661*cdf0e10cSrcweir { 1662*cdf0e10cSrcweir SvLBoxEntry* pEntry = pLibBox->DoInsertEntry( aLibName ); 1663*cdf0e10cSrcweir pEntry->SetUserData( new BasicLibUserData( rDocument ) ); 1664*cdf0e10cSrcweir pLibBox->SetCurEntry( pEntry ); 1665*cdf0e10cSrcweir } 1666*cdf0e10cSrcweir 1667*cdf0e10cSrcweir // create a module 1668*cdf0e10cSrcweir String aModName = rDocument.createObjectName( E_SCRIPTS, aLibName ); 1669*cdf0e10cSrcweir ::rtl::OUString sModuleCode; 1670*cdf0e10cSrcweir if ( !rDocument.createModule( aLibName, aModName, sal_True, sModuleCode ) ) 1671*cdf0e10cSrcweir throw Exception(); 1672*cdf0e10cSrcweir 1673*cdf0e10cSrcweir SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDocument, aLibName, aModName, BASICIDE_TYPE_MODULE ); 1674*cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 1675*cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 1676*cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 1677*cdf0e10cSrcweir if( pDispatcher ) 1678*cdf0e10cSrcweir { 1679*cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_SBXINSERTED, 1680*cdf0e10cSrcweir SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L ); 1681*cdf0e10cSrcweir } 1682*cdf0e10cSrcweir 1683*cdf0e10cSrcweir if( pBasicBox ) 1684*cdf0e10cSrcweir { 1685*cdf0e10cSrcweir SvLBoxEntry* pEntry = pBasicBox->GetCurEntry(); 1686*cdf0e10cSrcweir SvLBoxEntry* pRootEntry = NULL; 1687*cdf0e10cSrcweir while( pEntry ) 1688*cdf0e10cSrcweir { 1689*cdf0e10cSrcweir pRootEntry = pEntry; 1690*cdf0e10cSrcweir pEntry = pBasicBox->GetParent( pEntry ); 1691*cdf0e10cSrcweir } 1692*cdf0e10cSrcweir 1693*cdf0e10cSrcweir sal_uInt16 nMode = pBasicBox->GetMode(); 1694*cdf0e10cSrcweir bool bDlgMode = ( nMode & BROWSEMODE_DIALOGS ) && !( nMode & BROWSEMODE_MODULES ); 1695*cdf0e10cSrcweir sal_uInt16 nId = bDlgMode ? RID_IMG_DLGLIB : RID_IMG_MODLIB; 1696*cdf0e10cSrcweir sal_uInt16 nIdHC = bDlgMode ? RID_IMG_DLGLIB_HC : RID_IMG_MODLIB_HC; 1697*cdf0e10cSrcweir SvLBoxEntry* pNewLibEntry = pBasicBox->AddEntry( 1698*cdf0e10cSrcweir aLibName, 1699*cdf0e10cSrcweir Image( IDEResId( nId ) ), 1700*cdf0e10cSrcweir Image( IDEResId( nIdHC ) ), 1701*cdf0e10cSrcweir pRootEntry, false, 1702*cdf0e10cSrcweir std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_LIBRARY ) ) ); 1703*cdf0e10cSrcweir DBG_ASSERT( pNewLibEntry, "InsertEntry fehlgeschlagen!" ); 1704*cdf0e10cSrcweir 1705*cdf0e10cSrcweir if( pNewLibEntry ) 1706*cdf0e10cSrcweir { 1707*cdf0e10cSrcweir SvLBoxEntry* pEntry_ = pBasicBox->AddEntry( 1708*cdf0e10cSrcweir aModName, 1709*cdf0e10cSrcweir Image( IDEResId( RID_IMG_MODULE ) ), 1710*cdf0e10cSrcweir Image( IDEResId( RID_IMG_MODULE_HC ) ), 1711*cdf0e10cSrcweir pNewLibEntry, false, 1712*cdf0e10cSrcweir std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) ); 1713*cdf0e10cSrcweir DBG_ASSERT( pEntry_, "InsertEntry fehlgeschlagen!" ); 1714*cdf0e10cSrcweir pBasicBox->SetCurEntry( pEntry_ ); 1715*cdf0e10cSrcweir pBasicBox->Select( pBasicBox->GetCurEntry() ); // OV-Bug?! 1716*cdf0e10cSrcweir } 1717*cdf0e10cSrcweir } 1718*cdf0e10cSrcweir } 1719*cdf0e10cSrcweir catch ( uno::Exception& ) 1720*cdf0e10cSrcweir { 1721*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 1722*cdf0e10cSrcweir } 1723*cdf0e10cSrcweir } 1724*cdf0e10cSrcweir } 1725*cdf0e10cSrcweir } 1726*cdf0e10cSrcweir 1727*cdf0e10cSrcweir //---------------------------------------------------------------------------- 1728*cdf0e10cSrcweir 1729