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