LCOV - code coverage report
Current view: top level - cui/source/dialogs - scriptdlg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 713 0.0 %
Date: 2014-04-11 Functions: 0 53 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <memory>
      21             : 
      22             : #include <sfx2/objsh.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <osl/mutex.hxx>
      26             : 
      27             : #include <cuires.hrc>
      28             : #include "scriptdlg.hrc"
      29             : #include "scriptdlg.hxx"
      30             : #include <dialmgr.hxx>
      31             : #include "selector.hxx"
      32             : 
      33             : #include <com/sun/star/uno/XComponentContext.hpp>
      34             : #include <com/sun/star/frame/XDesktop.hpp>
      35             : #include <com/sun/star/script/provider/XScriptProviderSupplier.hpp>
      36             : #include <com/sun/star/script/provider/XScriptProvider.hpp>
      37             : #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
      38             : #include <com/sun/star/script/browse/XBrowseNodeFactory.hpp>
      39             : #include <com/sun/star/script/browse/BrowseNodeFactoryViewTypes.hpp>
      40             : #include <com/sun/star/script/browse/theBrowseNodeFactory.hpp>
      41             : #include <com/sun/star/script/provider/ScriptErrorRaisedException.hpp>
      42             : #include <com/sun/star/script/provider/ScriptExceptionRaisedException.hpp>
      43             : #include <com/sun/star/script/provider/ScriptFrameworkErrorType.hpp>
      44             : #include <com/sun/star/frame/Desktop.hpp>
      45             : #include <com/sun/star/frame/ModuleManager.hpp>
      46             : #include <com/sun/star/script/XInvocation.hpp>
      47             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      48             : 
      49             : #include <cppuhelper/implbase1.hxx>
      50             : #include <comphelper/documentinfo.hxx>
      51             : #include <comphelper/uno3.hxx>
      52             : #include <comphelper/processfactory.hxx>
      53             : #include <comphelper/broadcasthelper.hxx>
      54             : #include <comphelper/propertycontainer.hxx>
      55             : #include <comphelper/proparrhlp.hxx>
      56             : 
      57             : #include <basic/sbx.hxx>
      58             : #include <svtools/imagemgr.hxx>
      59             : #include "svtools/treelistentry.hxx"
      60             : #include <tools/urlobj.hxx>
      61             : #include <vector>
      62             : #include <algorithm>
      63             : #include <boost/scoped_ptr.hpp>
      64             : 
      65             : using namespace ::com::sun::star;
      66             : using namespace ::com::sun::star::uno;
      67             : using namespace ::com::sun::star::script;
      68             : using namespace ::com::sun::star::frame;
      69             : using namespace ::com::sun::star::document;
      70             : 
      71           0 : void ShowErrorDialog( const Any& aException )
      72             : {
      73           0 :     SvxScriptErrorDialog* pDlg = new SvxScriptErrorDialog( NULL, aException );
      74           0 :     pDlg->Execute();
      75           0 :     delete pDlg;
      76           0 : }
      77             : 
      78           0 : SFTreeListBox::SFTreeListBox(Window* pParent)
      79             :     : SvTreeListBox(pParent)
      80           0 :     , m_hdImage(CUI_RES(RID_CUIIMG_HARDDISK))
      81           0 :     , m_libImage(CUI_RES(RID_CUIIMG_LIB))
      82           0 :     , m_macImage(CUI_RES(RID_CUIIMG_MACRO))
      83           0 :     , m_docImage(CUI_RES(RID_CUIIMG_DOC))
      84           0 :     , m_sMyMacros(CUI_RESSTR(RID_SVXSTR_MYMACROS))
      85           0 :     , m_sProdMacros(CUI_RESSTR(RID_SVXSTR_PRODMACROS))
      86             : {
      87           0 :     SetSelectionMode( SINGLE_SELECTION );
      88             : 
      89           0 :     SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL |
      90             :                    WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HIDESELECTION |
      91           0 :                    WB_HASLINES | WB_HASLINESATROOT | WB_TABSTOP );
      92           0 :     SetNodeDefaultImages();
      93             : 
      94           0 :     nMode = 0xFF;    // everything
      95           0 : }
      96             : 
      97           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSFTreeListBox(Window *pParent, VclBuilder::stringmap &)
      98             : {
      99           0 :     return new SFTreeListBox(pParent);
     100             : }
     101             : 
     102           0 : SFTreeListBox::~SFTreeListBox()
     103             : {
     104           0 :     deleteAllTree();
     105           0 : }
     106             : 
     107           0 : void SFTreeListBox::delUserData( SvTreeListEntry* pEntry )
     108             : {
     109           0 :     if ( pEntry )
     110             :     {
     111           0 :         SFEntry* pUserData = (SFEntry*)pEntry->GetUserData();
     112           0 :         if ( pUserData )
     113             :         {
     114           0 :             delete pUserData;
     115             :             // TBD seem to get a Select event on node that is remove ( below )
     116             :             // so need to be able to detect that this node is not to be
     117             :             // processed in order to do this, setting userData to NULL ( must
     118             :             // be a better way to do this )
     119           0 :             pUserData = 0;
     120           0 :             pEntry->SetUserData( pUserData );
     121             :         }
     122             :     }
     123           0 : }
     124             : 
     125           0 : void SFTreeListBox::deleteTree( SvTreeListEntry* pEntry )
     126             : {
     127             : 
     128           0 :     delUserData( pEntry );
     129           0 :     pEntry = FirstChild( pEntry );
     130           0 :     while ( pEntry )
     131             :     {
     132           0 :         SvTreeListEntry* pNextEntry = NextSibling( pEntry );
     133           0 :         deleteTree( pEntry );
     134           0 :         GetModel()->Remove( pEntry );
     135           0 :         pEntry = pNextEntry;
     136             :     }
     137           0 : }
     138             : 
     139           0 : void SFTreeListBox::deleteAllTree()
     140             : {
     141           0 :     SvTreeListEntry* pEntry =  GetEntry( 0 );
     142             : 
     143             :     // TBD - below is a candidate for a destroyAllTrees method
     144           0 :     if ( pEntry )
     145             :     {
     146           0 :         while ( pEntry )
     147             :         {
     148           0 :             SvTreeListEntry* pNextEntry = NextSibling( pEntry ) ;
     149           0 :             deleteTree( pEntry );
     150           0 :             GetModel()->Remove( pEntry );
     151           0 :             pEntry = pNextEntry;
     152             :         }
     153             :     }
     154           0 : }
     155             : 
     156           0 : void SFTreeListBox::Init( const OUString& language  )
     157             : {
     158           0 :     SetUpdateMode( false );
     159             : 
     160           0 :     deleteAllTree();
     161             : 
     162           0 :     Reference< browse::XBrowseNode > rootNode;
     163             :     Reference< XComponentContext > xCtx(
     164           0 :         comphelper::getProcessComponentContext() );
     165             : 
     166           0 :     Sequence< Reference< browse::XBrowseNode > > children;
     167             : 
     168           0 :     OUString userStr("user");
     169           0 :     OUString shareStr("share");
     170             : 
     171             :     try
     172             :     {
     173           0 :         Reference< browse::XBrowseNodeFactory > xFac = browse::theBrowseNodeFactory::get(xCtx);
     174             : 
     175           0 :         rootNode.set( xFac->createView(
     176           0 :             browse::BrowseNodeFactoryViewTypes::MACROORGANIZER ) );
     177             : 
     178           0 :         if (  rootNode.is() && rootNode->hasChildNodes() == sal_True )
     179             :         {
     180           0 :             children = rootNode->getChildNodes();
     181           0 :         }
     182             :     }
     183           0 :     catch( Exception& e )
     184             :     {
     185             :         OSL_TRACE("Exception getting root browse node from factory: %s",
     186             :             OUStringToOString(
     187             :                 e.Message , RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     188             :         // TODO exception handling
     189             :     }
     190             : 
     191           0 :     Reference<XModel> xDocumentModel;
     192           0 :     for ( sal_Int32 n = 0; n < children.getLength(); n++ )
     193             :     {
     194           0 :         bool app = false;
     195           0 :         OUString uiName = children[ n ]->getName();
     196           0 :         OUString factoryURL;
     197           0 :         if ( uiName.equals( userStr ) || uiName.equals( shareStr ) )
     198             :         {
     199           0 :             app = true;
     200           0 :             if ( uiName.equals( userStr ) )
     201             :             {
     202           0 :                 uiName = m_sMyMacros;
     203             :             }
     204             :             else
     205             :             {
     206           0 :                 uiName = m_sProdMacros;
     207             :             }
     208             :         }
     209             :         else
     210             :         {
     211           0 :             xDocumentModel.set(getDocumentModel(xCtx, uiName ), UNO_QUERY);
     212             : 
     213           0 :             if ( xDocumentModel.is() )
     214             :             {
     215           0 :                 Reference< frame::XModuleManager2 > xModuleManager( frame::ModuleManager::create(xCtx) );
     216             : 
     217             :                 // get the long name of the document:
     218           0 :                 Sequence<beans::PropertyValue> moduleDescr;
     219             :                 try{
     220           0 :                     OUString appModule = xModuleManager->identify( xDocumentModel );
     221           0 :                     xModuleManager->getByName(appModule) >>= moduleDescr;
     222           0 :                 } catch(const uno::Exception&)
     223             :                     {}
     224             : 
     225             :                 beans::PropertyValue const * pmoduleDescr =
     226           0 :                     moduleDescr.getConstArray();
     227           0 :                 for ( sal_Int32 pos = moduleDescr.getLength(); pos--; )
     228             :                 {
     229           0 :                     if ( pmoduleDescr[ pos ].Name == "ooSetupFactoryEmptyDocumentURL" )
     230             :                     {
     231           0 :                         pmoduleDescr[ pos ].Value >>= factoryURL;
     232           0 :                         break;
     233             :                     }
     234           0 :                 }
     235             :             }
     236             :         }
     237             : 
     238           0 :         OUString lang( language );
     239             :         Reference< browse::XBrowseNode > langEntries =
     240           0 :             getLangNodeFromRootNode( children[ n ], lang );
     241             : 
     242             :         SAL_WNODEPRECATED_DECLARATIONS_PUSH
     243             :         insertEntry( uiName, app ? RID_CUIIMG_HARDDISK : RID_CUIIMG_DOC,
     244           0 :             0, true, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_SFROOT, langEntries, xDocumentModel )), factoryURL );
     245             :         SAL_WNODEPRECATED_DECLARATIONS_POP
     246           0 :     }
     247             : 
     248           0 :     SetUpdateMode( true );
     249           0 : }
     250             : 
     251             : Reference< XInterface  >
     252           0 : SFTreeListBox::getDocumentModel( Reference< XComponentContext >& xCtx, OUString& docName )
     253             : {
     254           0 :     Reference< XInterface > xModel;
     255           0 :     Reference< frame::XDesktop2 > desktop  = frame::Desktop::create(xCtx);
     256             : 
     257             :     Reference< container::XEnumerationAccess > componentsAccess =
     258           0 :         desktop->getComponents();
     259             :     Reference< container::XEnumeration > components =
     260           0 :         componentsAccess->createEnumeration();
     261           0 :     while (components->hasMoreElements())
     262             :     {
     263             :         Reference< frame::XModel > model(
     264           0 :             components->nextElement(), UNO_QUERY );
     265           0 :         if ( model.is() )
     266             :         {
     267           0 :             OUString sTdocUrl = ::comphelper::DocumentInfo::getDocumentTitle( model );
     268           0 :             if( sTdocUrl.equals( docName ) )
     269             :             {
     270           0 :                 xModel = model;
     271           0 :                 break;
     272           0 :             }
     273             :         }
     274           0 :     }
     275           0 :     return xModel;
     276             : }
     277             : 
     278             : Reference< browse::XBrowseNode >
     279           0 : SFTreeListBox::getLangNodeFromRootNode( Reference< browse::XBrowseNode >& rootNode, OUString& language )
     280             : {
     281           0 :     Reference< browse::XBrowseNode > langNode;
     282             : 
     283             :     try
     284             :     {
     285           0 :         Sequence < Reference< browse::XBrowseNode > > children = rootNode->getChildNodes();
     286           0 :         for ( sal_Int32 n = 0; n < children.getLength(); n++ )
     287             :         {
     288           0 :             if ( children[ n ]->getName().equals( language ) )
     289             :             {
     290           0 :                 langNode = children[ n ];
     291           0 :                 break;
     292             :             }
     293           0 :         }
     294             :     }
     295           0 :     catch ( Exception& )
     296             :     {
     297             :         // if getChildNodes() throws an exception we just return
     298             :         // the empty Reference
     299             :     }
     300           0 :     return langNode;
     301             : }
     302             : 
     303           0 : void SFTreeListBox:: RequestSubEntries( SvTreeListEntry* pRootEntry, Reference< ::com::sun::star::script::browse::XBrowseNode >& node,
     304             :                                        Reference< XModel >& model )
     305             : {
     306           0 :     if (! node.is() )
     307             :     {
     308           0 :         return;
     309             :     }
     310             : 
     311           0 :     Sequence< Reference< browse::XBrowseNode > > children;
     312             :     try
     313             :     {
     314           0 :         children = node->getChildNodes();
     315             :     }
     316           0 :     catch ( Exception& )
     317             :     {
     318             :         // if we catch an exception in getChildNodes then no entries are added
     319             :     }
     320             : 
     321           0 :     for ( sal_Int32 n = 0; n < children.getLength(); n++ )
     322             :     {
     323           0 :         OUString name( children[ n ]->getName() );
     324           0 :         if (  children[ n ]->getType() !=  browse::BrowseNodeTypes::SCRIPT)
     325             :         {
     326             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
     327           0 :             insertEntry( name, RID_CUIIMG_LIB, pRootEntry, true, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_SCRIPTCONTAINER, children[ n ],model )));
     328             :             SAL_WNODEPRECATED_DECLARATIONS_POP
     329             :         }
     330             :         else
     331             :         {
     332           0 :             if ( children[ n ]->getType() == browse::BrowseNodeTypes::SCRIPT )
     333             :             {
     334             :                 SAL_WNODEPRECATED_DECLARATIONS_PUSH
     335           0 :                 insertEntry( name, RID_CUIIMG_MACRO, pRootEntry, false, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_METHOD, children[ n ],model )));
     336             :                 SAL_WNODEPRECATED_DECLARATIONS_POP
     337             : 
     338             :             }
     339             :         }
     340           0 :     }
     341             : }
     342             : 
     343           0 : bool SFTreeListBox::ExpandingHdl()
     344             : {
     345           0 :     return true;
     346             : }
     347             : 
     348           0 : void SFTreeListBox::ExpandAllTrees()
     349             : {
     350           0 : }
     351             : 
     352             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     353           0 : SvTreeListEntry * SFTreeListBox::insertEntry(
     354             :     OUString const & rText, sal_uInt16 nBitmap, SvTreeListEntry * pParent,
     355             :     bool bChildrenOnDemand, std::auto_ptr< SFEntry > aUserData, const OUString& factoryURL )
     356             : {
     357             :     SvTreeListEntry * p;
     358           0 :     if( nBitmap == RID_CUIIMG_DOC && !factoryURL.isEmpty() )
     359             :     {
     360           0 :         Image aImage = SvFileInformationManager::GetFileImage( INetURLObject(factoryURL), false );
     361             :         p = InsertEntry(
     362             :             rText, aImage, aImage, pParent, bChildrenOnDemand, TREELIST_APPEND,
     363           0 :             aUserData.release()); // XXX possible leak
     364             :     }
     365             :     else
     366             :     {
     367           0 :         p = insertEntry( rText, nBitmap, pParent, bChildrenOnDemand, aUserData );
     368             :     }
     369           0 :     return p;
     370             : }
     371             : SAL_WNODEPRECATED_DECLARATIONS_POP
     372             : 
     373             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     374           0 : SvTreeListEntry * SFTreeListBox::insertEntry(
     375             :     OUString const & rText, sal_uInt16 nBitmap, SvTreeListEntry * pParent,
     376             :     bool bChildrenOnDemand, std::auto_ptr< SFEntry > aUserData )
     377             : {
     378           0 :     Image aImage;
     379           0 :     if( nBitmap == RID_CUIIMG_HARDDISK )
     380             :     {
     381           0 :         aImage = m_hdImage;
     382             :     }
     383           0 :     else if( nBitmap == RID_CUIIMG_LIB )
     384             :     {
     385           0 :         aImage = m_libImage;
     386             :     }
     387           0 :     else if( nBitmap == RID_CUIIMG_MACRO )
     388             :     {
     389           0 :         aImage = m_macImage;
     390             :     }
     391           0 :     else if( nBitmap == RID_CUIIMG_DOC )
     392             :     {
     393           0 :         aImage = m_docImage;
     394             :     }
     395             :     SvTreeListEntry * p = InsertEntry(
     396             :         rText, aImage, aImage, pParent, bChildrenOnDemand, TREELIST_APPEND,
     397           0 :         aUserData.release()); // XXX possible leak
     398           0 :    return p;
     399             : }
     400             : SAL_WNODEPRECATED_DECLARATIONS_POP
     401             : 
     402           0 : void SFTreeListBox::RequestingChildren( SvTreeListEntry* pEntry )
     403             : {
     404           0 :     SFEntry* userData = 0;
     405           0 :     if ( !pEntry )
     406             :     {
     407           0 :         return;
     408             :     }
     409           0 :     userData = (SFEntry*)pEntry->GetUserData();
     410             : 
     411           0 :     Reference< browse::XBrowseNode > node;
     412           0 :     Reference< XModel > model;
     413           0 :     if ( userData && !userData->isLoaded() )
     414             :     {
     415           0 :         node = userData->GetNode();
     416           0 :         model = userData->GetModel();
     417           0 :         RequestSubEntries( pEntry, node, model );
     418           0 :         userData->setLoaded();
     419           0 :     }
     420             : }
     421             : 
     422           0 : void SFTreeListBox::ExpandedHdl()
     423             : {
     424           0 : }
     425             : 
     426             : 
     427             : // CuiInputDialog ------------------------------------------------------------
     428             : 
     429           0 : CuiInputDialog::CuiInputDialog(Window * pParent, sal_uInt16 nMode )
     430             :     : ModalDialog(pParent, "NewLibDialog",
     431           0 :         "cui/ui/newlibdialog.ui")
     432             : {
     433           0 :     get(m_pEdit, "entry");
     434           0 :     m_pEdit->GrabFocus();
     435             : 
     436           0 :     FixedText *pNewLibFT = get<FixedText>("newlibft");
     437             : 
     438           0 :     if ( nMode == INPUTMODE_NEWMACRO )
     439             :     {
     440           0 :         pNewLibFT->Hide();
     441           0 :         FixedText *pNewMacroFT = get<FixedText>("newmacroft");
     442           0 :         pNewMacroFT->Show();
     443           0 :         SetText(get<FixedText>("altmacrotitle")->GetText());
     444             :     }
     445           0 :     else if ( nMode == INPUTMODE_RENAME )
     446             :     {
     447           0 :         pNewLibFT->Hide();
     448           0 :         FixedText *pRenameFT = get<FixedText>("renameft");
     449           0 :         pRenameFT->Show();
     450           0 :         SetText(get<FixedText>("altrenametitle")->GetText());
     451             :     }
     452           0 : }
     453             : 
     454             : 
     455             : // ScriptOrgDialog ------------------------------------------------------------
     456             : 
     457           0 : SvxScriptOrgDialog::SvxScriptOrgDialog( Window* pParent, const OUString& language )
     458             :     : SfxModalDialog(pParent, "ScriptOrganizerDialog",
     459             :         "cui/ui/scriptorganizer.ui")
     460             :     , m_sLanguage(language)
     461           0 :     , m_delErrStr(CUI_RESSTR(RID_SVXSTR_DELFAILED))
     462           0 :     , m_delErrTitleStr(CUI_RESSTR(RID_SVXSTR_DELFAILED_TITLE))
     463           0 :     , m_delQueryStr(CUI_RES(RID_SVXSTR_DELQUERY))
     464           0 :     , m_delQueryTitleStr(CUI_RESSTR(RID_SVXSTR_DELQUERY_TITLE))
     465           0 :     , m_createErrStr(CUI_RESSTR(RID_SVXSTR_CREATEFAILED))
     466           0 :     , m_createDupStr(CUI_RESSTR(RID_SVXSTR_CREATEFAILEDDUP))
     467           0 :     , m_createErrTitleStr(CUI_RESSTR(RID_SVXSTR_CREATEFAILED_TITLE))
     468           0 :     , m_renameErrStr(CUI_RESSTR(RID_SVXSTR_RENAMEFAILED))
     469           0 :     , m_renameErrTitleStr(CUI_RESSTR(RID_SVXSTR_RENAMEFAILED_TITLE))
     470             : {
     471           0 :     get(m_pScriptsBox, "scripts");
     472           0 :     get(m_pRunButton, "run");
     473           0 :     get(m_pCloseButton, "close");
     474           0 :     get(m_pCreateButton, "create");
     475           0 :     get(m_pEditButton, "edit");
     476           0 :     get(m_pRenameButton, "rename");
     477           0 :     get(m_pDelButton, "delete");
     478             :     // must be a neater way to deal with the strings than as above
     479             :     // append the language to the dialog title
     480           0 :     OUString winTitle( GetText() );
     481           0 :     winTitle = winTitle.replaceFirst( "%MACROLANG", m_sLanguage );
     482           0 :     SetText( winTitle );
     483             : 
     484           0 :     m_pScriptsBox->SetSelectHdl( LINK( this, SvxScriptOrgDialog, ScriptSelectHdl ) );
     485           0 :     m_pRunButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     486           0 :     m_pCloseButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     487           0 :     m_pRenameButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     488           0 :     m_pEditButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     489           0 :     m_pDelButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     490           0 :     m_pCreateButton->SetClickHdl( LINK( this, SvxScriptOrgDialog, ButtonHdl ) );
     491             : 
     492           0 :     m_pRunButton->Disable();
     493           0 :     m_pRenameButton->Disable();
     494           0 :     m_pEditButton->Disable();
     495           0 :     m_pDelButton->Disable();
     496           0 :     m_pCreateButton->Disable();
     497             : 
     498           0 :     m_pScriptsBox->Init( m_sLanguage );
     499           0 :     RestorePreviousSelection();
     500           0 : }
     501             : 
     502           0 : SvxScriptOrgDialog::~SvxScriptOrgDialog()
     503             : {
     504             :     // clear the SelectHdl so that it isn't called during the dtor
     505           0 :     m_pScriptsBox->SetSelectHdl( Link() );
     506           0 : };
     507             : 
     508           0 : short SvxScriptOrgDialog::Execute()
     509             : {
     510             : 
     511           0 :     SfxObjectShell *pDoc = SfxObjectShell::GetFirst();
     512             : 
     513             :     // force load of MSPs for all documents
     514           0 :     while ( pDoc )
     515             :     {
     516             :         Reference< provider::XScriptProviderSupplier > xSPS =
     517             :             Reference< provider::XScriptProviderSupplier >
     518           0 :                                         ( pDoc->GetModel(), UNO_QUERY );
     519           0 :         if ( xSPS.is() )
     520             :         {
     521             :             Reference< provider::XScriptProvider > ScriptProvider =
     522           0 :             xSPS->getScriptProvider();
     523             :         }
     524             : 
     525           0 :         pDoc = SfxObjectShell::GetNext(*pDoc);
     526           0 :     }
     527           0 :     m_pScriptsBox->ExpandAllTrees();
     528             : 
     529           0 :     Window* pPrevDlgParent = Application::GetDefDialogParent();
     530           0 :     Application::SetDefDialogParent( this );
     531           0 :     short nRet = ModalDialog::Execute();
     532           0 :     Application::SetDefDialogParent( pPrevDlgParent );
     533           0 :     return nRet;
     534             : }
     535             : 
     536           0 : void SvxScriptOrgDialog::CheckButtons( Reference< browse::XBrowseNode >& node )
     537             : {
     538           0 :     if ( node.is() )
     539             :     {
     540           0 :         if ( node->getType() == browse::BrowseNodeTypes::SCRIPT)
     541             :         {
     542           0 :             m_pRunButton->Enable();
     543             :         }
     544             :         else
     545             :         {
     546           0 :             m_pRunButton->Disable();
     547             :         }
     548           0 :         Reference< beans::XPropertySet > xProps( node, UNO_QUERY );
     549             : 
     550           0 :         if ( !xProps.is() )
     551             :         {
     552           0 :             m_pEditButton->Disable();
     553           0 :             m_pDelButton->Disable();
     554           0 :             m_pCreateButton->Disable();
     555           0 :             m_pRunButton->Disable();
     556           0 :             return;
     557             :         }
     558             : 
     559           0 :         OUString sName("Editable");
     560             : 
     561           0 :         if ( getBoolProperty( xProps, sName ) )
     562             :         {
     563           0 :             m_pEditButton->Enable();
     564             :         }
     565             :         else
     566             :         {
     567           0 :             m_pEditButton->Disable();
     568             :         }
     569             : 
     570           0 :         sName = "Deletable";
     571             : 
     572           0 :         if ( getBoolProperty( xProps, sName ) )
     573             :         {
     574           0 :             m_pDelButton->Enable();
     575             :         }
     576             :         else
     577             :         {
     578           0 :             m_pDelButton->Disable();
     579             :         }
     580             : 
     581           0 :         sName = "Creatable";
     582             : 
     583           0 :         if ( getBoolProperty( xProps, sName ) )
     584             :         {
     585           0 :             m_pCreateButton->Enable();
     586             :         }
     587             :         else
     588             :         {
     589           0 :             m_pCreateButton->Disable();
     590             :         }
     591             : 
     592           0 :         sName = "Renamable";
     593             : 
     594           0 :         if ( getBoolProperty( xProps, sName ) )
     595             :         {
     596           0 :             m_pRenameButton->Enable();
     597             :         }
     598             :         else
     599             :         {
     600           0 :             m_pRenameButton->Disable();
     601           0 :         }
     602             :     }
     603             :     else
     604             :     {
     605             :         // no node info available, disable all configurable actions
     606           0 :         m_pDelButton->Disable();
     607           0 :         m_pCreateButton->Disable();
     608           0 :         m_pEditButton->Disable();
     609           0 :         m_pRunButton->Disable();
     610           0 :         m_pRenameButton->Disable();
     611             :     }
     612             : }
     613             : 
     614           0 : IMPL_LINK( SvxScriptOrgDialog, ScriptSelectHdl, SvTreeListBox *, pBox )
     615             : {
     616           0 :     if ( !pBox->IsSelected( pBox->GetHdlEntry() ) )
     617             :     {
     618           0 :         return 0;
     619             :     }
     620             : 
     621           0 :     SvTreeListEntry* pEntry = pBox->GetHdlEntry();
     622             : 
     623           0 :     SFEntry* userData = 0;
     624           0 :     if ( !pEntry )
     625             :     {
     626           0 :         return 0;
     627             :     }
     628           0 :     userData = (SFEntry*)pEntry->GetUserData();
     629             : 
     630           0 :     Reference< browse::XBrowseNode > node;
     631           0 :     if ( userData )
     632             :     {
     633           0 :               node = userData->GetNode();
     634           0 :         CheckButtons( node );
     635             :     }
     636             : 
     637           0 :     return 0;
     638             : }
     639             : 
     640           0 : IMPL_LINK( SvxScriptOrgDialog, ButtonHdl, Button *, pButton )
     641             : {
     642           0 :     if ( pButton == m_pCloseButton )
     643             :     {
     644           0 :         StoreCurrentSelection();
     645           0 :         EndDialog( 0 );
     646             :     }
     647           0 :     if ( pButton == m_pEditButton ||
     648           0 :             pButton == m_pCreateButton ||
     649           0 :             pButton == m_pDelButton ||
     650           0 :             pButton == m_pRunButton ||
     651           0 :             pButton == m_pRenameButton )
     652             : 
     653             :     {
     654           0 :         if ( m_pScriptsBox->IsSelected( m_pScriptsBox->GetHdlEntry() ) )
     655             :         {
     656           0 :             SvTreeListEntry* pEntry = m_pScriptsBox->GetHdlEntry();
     657           0 :             SFEntry* userData = 0;
     658           0 :             if ( !pEntry )
     659             :             {
     660           0 :                 return 0;
     661             :             }
     662           0 :             userData = (SFEntry*)pEntry->GetUserData();
     663           0 :             if ( userData )
     664             :             {
     665           0 :                 Reference< browse::XBrowseNode > node;
     666           0 :                 Reference< XModel > xModel;
     667             : 
     668           0 :                 node = userData->GetNode();
     669           0 :                 xModel = userData->GetModel();
     670             : 
     671           0 :                 if ( !node.is() )
     672             :                 {
     673           0 :                     return 0;
     674             :                 }
     675             : 
     676           0 :                 if ( pButton == m_pRunButton )
     677             :                 {
     678           0 :                     OUString tmpString;
     679           0 :                     Reference< beans::XPropertySet > xProp( node, UNO_QUERY );
     680           0 :                     Reference< provider::XScriptProvider > mspNode;
     681           0 :                     if( !xProp.is() )
     682             :                     {
     683           0 :                         return 0;
     684             :                     }
     685             : 
     686           0 :                     if ( xModel.is() )
     687             :                     {
     688           0 :                         Reference< XEmbeddedScripts >  xEmbeddedScripts( xModel, UNO_QUERY);
     689           0 :                         if( !xEmbeddedScripts.is() )
     690             :                         {
     691           0 :                             return 0;
     692             :                         }
     693             : 
     694           0 :                         if (!xEmbeddedScripts->getAllowMacroExecution())
     695             :                         {
     696             :                             // Please FIXME: Show a message box if AllowMacroExecution is false
     697           0 :                             return 0;
     698           0 :                         }
     699             :                     }
     700             : 
     701             : 
     702           0 :                     SvTreeListEntry* pParent = m_pScriptsBox->GetParent( pEntry );
     703           0 :                     while ( pParent && !mspNode.is() )
     704             :                     {
     705           0 :                         SFEntry* mspUserData = (SFEntry*)pParent->GetUserData();
     706           0 :                         mspNode.set( mspUserData->GetNode() , UNO_QUERY );
     707           0 :                         pParent = m_pScriptsBox->GetParent( pParent );
     708             :                     }
     709           0 :                     xProp->getPropertyValue("URI") >>= tmpString;
     710           0 :                     const OUString scriptURL( tmpString );
     711             : 
     712           0 :                     if ( mspNode.is() )
     713             :                     {
     714             :                         try
     715             :                         {
     716             :                             Reference< provider::XScript > xScript(
     717           0 :                             mspNode->getScript( scriptURL ), UNO_QUERY_THROW );
     718             : 
     719           0 :                             const Sequence< Any > args(0);
     720           0 :                             Any aRet;
     721           0 :                             Sequence< sal_Int16 > outIndex;
     722           0 :                             Sequence< Any > outArgs( 0 );
     723           0 :                             aRet = xScript->invoke( args, outIndex, outArgs );
     724             :                         }
     725           0 :                         catch ( reflection::InvocationTargetException& ite )
     726             :                         {
     727           0 :                             ::com::sun::star::uno::Any a = makeAny(ite);
     728           0 :                             ShowErrorDialog(a);
     729             :                         }
     730           0 :                         catch ( provider::ScriptFrameworkErrorException& ite )
     731             :                         {
     732           0 :                             ::com::sun::star::uno::Any a = makeAny(ite);
     733           0 :                             ShowErrorDialog(a);
     734             :                         }
     735           0 :                         catch ( RuntimeException& re )
     736             :                         {
     737           0 :                             ::com::sun::star::uno::Any a = makeAny(re);
     738           0 :                             ShowErrorDialog(a);
     739             :                         }
     740           0 :                         catch ( Exception& e )
     741             :                         {
     742           0 :                             ::com::sun::star::uno::Any a = makeAny(e);
     743           0 :                             ShowErrorDialog(a);
     744             :                         }
     745             :                     }
     746           0 :                     StoreCurrentSelection();
     747           0 :                     EndDialog( 0 );
     748             :                 }
     749           0 :                 else if ( pButton == m_pEditButton )
     750             :                 {
     751           0 :                     Reference< script::XInvocation > xInv( node, UNO_QUERY );
     752           0 :                     if ( xInv.is() )
     753             :                     {
     754           0 :                         StoreCurrentSelection();
     755           0 :                         EndDialog( 0 );
     756           0 :                         Sequence< Any > args(0);
     757           0 :                         Sequence< Any > outArgs( 0 );
     758           0 :                         Sequence< sal_Int16 > outIndex;
     759             :                         try
     760             :                         {
     761             :                             // ISSUE need code to run script here
     762           0 :                             xInv->invoke( "Editable", args, outIndex, outArgs );
     763             :                         }
     764           0 :                         catch( Exception& e )
     765             :                         {
     766             :                             OSL_TRACE("Caught exception trying to invoke %s", OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     767             : 
     768           0 :                         }
     769           0 :                     }
     770             :                 }
     771           0 :                 else if ( pButton == m_pCreateButton )
     772             :                 {
     773           0 :                     createEntry( pEntry );
     774             :                 }
     775           0 :                 else if ( pButton == m_pDelButton )
     776             :                 {
     777           0 :                     deleteEntry( pEntry );
     778             :                 }
     779           0 :                 else if ( pButton == m_pRenameButton )
     780             :                 {
     781           0 :                     renameEntry( pEntry );
     782           0 :                 }
     783             :             }
     784             :         }
     785             :     }
     786           0 :     return 0;
     787             : }
     788             : 
     789           0 : Reference< browse::XBrowseNode > SvxScriptOrgDialog::getBrowseNode( SvTreeListEntry* pEntry )
     790             : {
     791           0 :     Reference< browse::XBrowseNode > node;
     792           0 :     if ( pEntry )
     793             :     {
     794           0 :         SFEntry* userData = (SFEntry*)pEntry->GetUserData();
     795           0 :         if ( userData )
     796             :         {
     797           0 :             node = userData->GetNode();
     798             :         }
     799             :     }
     800             : 
     801           0 :     return node;
     802             : }
     803             : 
     804           0 : Reference< XModel > SvxScriptOrgDialog::getModel( SvTreeListEntry* pEntry )
     805             : {
     806           0 :     Reference< XModel > model;
     807           0 :     if ( pEntry )
     808             :     {
     809           0 :         SFEntry* userData = (SFEntry*)pEntry->GetUserData();
     810           0 :         if ( userData )
     811             :         {
     812           0 :             model = userData->GetModel();
     813             :         }
     814             :     }
     815             : 
     816           0 :     return model;
     817             : }
     818             : 
     819           0 : void SvxScriptOrgDialog::createEntry( SvTreeListEntry* pEntry )
     820             : {
     821             : 
     822           0 :     Reference< browse::XBrowseNode >  aChildNode;
     823           0 :     Reference< browse::XBrowseNode > node = getBrowseNode( pEntry );
     824           0 :     Reference< script::XInvocation > xInv( node, UNO_QUERY );
     825             : 
     826           0 :     if ( xInv.is() )
     827             :     {
     828           0 :         OUString aNewName;
     829           0 :         OUString aNewStdName;
     830           0 :         sal_uInt16 nMode = INPUTMODE_NEWLIB;
     831           0 :         if( m_pScriptsBox->GetModel()->GetDepth( pEntry ) == 0 )
     832             :         {
     833           0 :             aNewStdName = "Library" ;
     834             :         }
     835             :         else
     836             :         {
     837           0 :             aNewStdName = "Macro" ;
     838           0 :             nMode = INPUTMODE_NEWMACRO;
     839             :         }
     840             :         //do we need L10N for this? ie somethng like:
     841             :         //String aNewStdName( ResId( STR_STDMODULENAME ) );
     842           0 :         sal_Bool bValid = sal_False;
     843           0 :         sal_Int32 i = 1;
     844             : 
     845           0 :         Sequence< Reference< browse::XBrowseNode > > childNodes;
     846             :         // no children => ok to create Parcel1 or Script1 without checking
     847             :         try
     848             :         {
     849           0 :             if( node->hasChildNodes() == sal_False )
     850             :             {
     851           0 :                 aNewName = aNewStdName + OUString::number(i);
     852           0 :                 bValid = sal_True;
     853             :             }
     854             :             else
     855             :             {
     856           0 :                 childNodes = node->getChildNodes();
     857             :             }
     858             :         }
     859           0 :         catch ( Exception& )
     860             :         {
     861             :             // ignore, will continue on with empty sequence
     862             :         }
     863             : 
     864           0 :         OUString extn;
     865           0 :         while ( !bValid )
     866             :         {
     867           0 :             aNewName = aNewStdName + OUString::number(i);
     868           0 :             sal_Bool bFound = sal_False;
     869           0 :             if(childNodes.getLength() > 0 )
     870             :             {
     871           0 :                 OUString nodeName = childNodes[0]->getName();
     872           0 :                 sal_Int32 extnPos = nodeName.lastIndexOf( '.' );
     873           0 :                 if(extnPos>0)
     874           0 :                     extn = nodeName.copy(extnPos);
     875             :             }
     876           0 :             for( sal_Int32 index = 0; index < childNodes.getLength(); index++ )
     877             :             {
     878           0 :                 if (aNewName+extn == childNodes[index]->getName())
     879             :                 {
     880           0 :                     bFound = sal_True;
     881           0 :                     break;
     882             :                 }
     883             :             }
     884           0 :             if( bFound )
     885             :             {
     886           0 :                 i++;
     887             :             }
     888             :             else
     889             :             {
     890           0 :                 bValid = sal_True;
     891             :             }
     892             :         }
     893             : 
     894           0 :         boost::scoped_ptr< CuiInputDialog > xNewDlg( new CuiInputDialog( static_cast<Window*>(this), nMode ) );
     895           0 :         xNewDlg->SetObjectName( aNewName );
     896             : 
     897           0 :         do
     898             :         {
     899           0 :             if ( xNewDlg->Execute() && !xNewDlg->GetObjectName().isEmpty() )
     900             :             {
     901           0 :                 OUString aUserSuppliedName = xNewDlg->GetObjectName();
     902           0 :                 bValid = sal_True;
     903           0 :                 for( sal_Int32 index = 0; index < childNodes.getLength(); index++ )
     904             :                 {
     905           0 :                     if (aUserSuppliedName+extn == childNodes[index]->getName())
     906             :                     {
     907           0 :                         bValid = sal_False;
     908           0 :                         OUString aError( m_createErrStr );
     909           0 :                         aError += m_createDupStr;
     910           0 :                         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
     911           0 :                         aErrorBox.SetText( m_createErrTitleStr );
     912           0 :                         aErrorBox.Execute();
     913           0 :                         xNewDlg->SetObjectName( aNewName );
     914           0 :                         break;
     915             :                     }
     916             :                 }
     917           0 :                 if( bValid )
     918           0 :                     aNewName = aUserSuppliedName;
     919             :             }
     920             :             else
     921             :             {
     922             :                 // user hit cancel or hit OK with nothing in the editbox
     923             : 
     924           0 :                 return;
     925             :             }
     926             :         }
     927             :         while ( !bValid );
     928             : 
     929             :         // open up parent node (which ensures it's loaded)
     930           0 :         m_pScriptsBox->RequestingChildren( pEntry );
     931             : 
     932           0 :         Sequence< Any > args( 1 );
     933           0 :         args[ 0 ] <<= aNewName;
     934           0 :         Sequence< Any > outArgs( 0 );
     935           0 :         Sequence< sal_Int16 > outIndex;
     936             :         try
     937             :         {
     938           0 :             Any aResult;
     939           0 :             aResult = xInv->invoke( "Creatable", args, outIndex, outArgs );
     940           0 :             Reference< browse::XBrowseNode > newNode( aResult, UNO_QUERY );
     941           0 :             aChildNode = newNode;
     942             : 
     943             :         }
     944           0 :         catch( Exception& e )
     945             :         {
     946             :             OSL_TRACE("Caught exception trying to Create %s",
     947             :                 OUStringToOString(
     948             :                     e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
     949           0 :         }
     950             :     }
     951           0 :     if ( aChildNode.is() )
     952             :     {
     953           0 :         OUString aChildName = aChildNode->getName();
     954           0 :         SvTreeListEntry* pNewEntry = NULL;
     955             : 
     956           0 :         Reference<XModel> xDocumentModel = getModel( pEntry );
     957             : 
     958             :         // ISSUE do we need to remove all entries for parent
     959             :         // to achieve sort? Just need to determine position
     960             :         // SvTreeListBox::InsertEntry can take position arg
     961             :         // -- Basic doesn't do this on create.
     962             :         // Suppose we could avoid this too. -> created nodes are
     963             :         // not in alphabetical order
     964           0 :         if ( aChildNode->getType() == browse::BrowseNodeTypes::SCRIPT )
     965             :         {
     966             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
     967             :             pNewEntry = m_pScriptsBox->insertEntry( aChildName,
     968           0 :                     RID_CUIIMG_MACRO, pEntry, false, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_METHOD, aChildNode,xDocumentModel ) ) );
     969             :             SAL_WNODEPRECATED_DECLARATIONS_POP
     970             : 
     971             :         }
     972             :         else
     973             :         {
     974             :             SAL_WNODEPRECATED_DECLARATIONS_PUSH
     975             :             pNewEntry = m_pScriptsBox->insertEntry( aChildName,
     976           0 :                 RID_CUIIMG_LIB, pEntry, false, std::auto_ptr< SFEntry >(new SFEntry( OBJTYPE_SCRIPTCONTAINER, aChildNode,xDocumentModel ) ) );
     977             :             SAL_WNODEPRECATED_DECLARATIONS_POP
     978             : 
     979             :             // If the Parent is not loaded then set to
     980             :             // loaded, this will prevent RequestingChildren ( called
     981             :             // from vcl via RequestingChildren ) from
     982             :             // creating new ( duplicate ) children
     983           0 :             SFEntry* userData = (SFEntry*)pEntry->GetUserData();
     984           0 :             if ( userData &&  !userData->isLoaded() )
     985             :             {
     986           0 :                 userData->setLoaded();
     987             :             }
     988             :         }
     989           0 :         m_pScriptsBox->SetCurEntry( pNewEntry );
     990           0 :         m_pScriptsBox->Select( m_pScriptsBox->GetCurEntry() );
     991             : 
     992             :     }
     993             :     else
     994             :     {
     995             :         //ISSUE L10N & message from exception?
     996           0 :         OUString aError( m_createErrStr );
     997           0 :         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
     998           0 :         aErrorBox.SetText( m_createErrTitleStr );
     999           0 :         aErrorBox.Execute();
    1000           0 :     }
    1001             : }
    1002             : 
    1003           0 : void SvxScriptOrgDialog::renameEntry( SvTreeListEntry* pEntry )
    1004             : {
    1005             : 
    1006           0 :     Reference< browse::XBrowseNode >  aChildNode;
    1007           0 :     Reference< browse::XBrowseNode > node = getBrowseNode( pEntry );
    1008           0 :     Reference< script::XInvocation > xInv( node, UNO_QUERY );
    1009             : 
    1010           0 :     if ( xInv.is() )
    1011             :     {
    1012           0 :         OUString aNewName = node->getName();
    1013           0 :         sal_Int32 extnPos = aNewName.lastIndexOf( '.' );
    1014           0 :         OUString extn;
    1015           0 :         if(extnPos>0)
    1016             :         {
    1017           0 :             extn = aNewName.copy(extnPos);
    1018           0 :             aNewName = aNewName.copy(0,extnPos);
    1019             :         }
    1020           0 :         sal_uInt16 nMode = INPUTMODE_RENAME;
    1021             : 
    1022           0 :         boost::scoped_ptr< CuiInputDialog > xNewDlg( new CuiInputDialog( static_cast<Window*>(this), nMode ) );
    1023           0 :         xNewDlg->SetObjectName( aNewName );
    1024             : 
    1025             :         sal_Bool bValid;
    1026           0 :         do
    1027             :         {
    1028           0 :             if ( xNewDlg->Execute() && !xNewDlg->GetObjectName().isEmpty() )
    1029             :             {
    1030           0 :                 OUString aUserSuppliedName = xNewDlg->GetObjectName();
    1031           0 :                 bValid = sal_True;
    1032           0 :                 if( bValid )
    1033           0 :                     aNewName = aUserSuppliedName;
    1034             :             }
    1035             :             else
    1036             :             {
    1037             :                 // user hit cancel or hit OK with nothing in the editbox
    1038           0 :                 return;
    1039             :             }
    1040             :         }
    1041             :         while ( !bValid );
    1042             : 
    1043           0 :         Sequence< Any > args( 1 );
    1044           0 :         args[ 0 ] <<= aNewName;
    1045           0 :         Sequence< Any > outArgs( 0 );
    1046           0 :         Sequence< sal_Int16 > outIndex;
    1047             :         try
    1048             :         {
    1049           0 :             Any aResult;
    1050           0 :             aResult = xInv->invoke( "Renamable", args, outIndex, outArgs );
    1051           0 :             Reference< browse::XBrowseNode > newNode( aResult, UNO_QUERY );
    1052           0 :             aChildNode = newNode;
    1053             : 
    1054             :         }
    1055           0 :         catch( Exception& e )
    1056             :         {
    1057             :             OSL_TRACE("Caught exception trying to Rename %s",
    1058             :                 OUStringToOString(
    1059             :                     e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
    1060           0 :         }
    1061             :     }
    1062           0 :     if ( aChildNode.is() )
    1063             :     {
    1064           0 :         m_pScriptsBox->SetEntryText( pEntry, aChildNode->getName() );
    1065           0 :         m_pScriptsBox->SetCurEntry( pEntry );
    1066           0 :         m_pScriptsBox->Select( m_pScriptsBox->GetCurEntry() );
    1067             : 
    1068             :     }
    1069             :     else
    1070             :     {
    1071             :         //ISSUE L10N & message from exception?
    1072           0 :         OUString aError( m_renameErrStr );
    1073           0 :         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, aError );
    1074           0 :         aErrorBox.SetText( m_renameErrTitleStr );
    1075           0 :         aErrorBox.Execute();
    1076           0 :     }
    1077             : }
    1078           0 : void SvxScriptOrgDialog::deleteEntry( SvTreeListEntry* pEntry )
    1079             : {
    1080           0 :     sal_Bool result = sal_False;
    1081           0 :     Reference< browse::XBrowseNode > node = getBrowseNode( pEntry );
    1082             :     // ISSUE L10N string & can we centre list?
    1083           0 :     OUString aQuery = m_delQueryStr + getListOfChildren( node, 0 );
    1084           0 :     QueryBox aQueryBox( static_cast<Window*>(this), WB_YES_NO | WB_DEF_YES, aQuery );
    1085           0 :     aQueryBox.SetText( m_delQueryTitleStr );
    1086           0 :     if ( aQueryBox.Execute() == RET_NO )
    1087             :     {
    1088           0 :         return;
    1089             :     }
    1090             : 
    1091           0 :     Reference< script::XInvocation > xInv( node, UNO_QUERY );
    1092           0 :     if ( xInv.is() )
    1093             :     {
    1094           0 :         Sequence< Any > args( 0 );
    1095           0 :         Sequence< Any > outArgs( 0 );
    1096           0 :         Sequence< sal_Int16 > outIndex;
    1097             :         try
    1098             :         {
    1099           0 :             Any aResult;
    1100           0 :             aResult = xInv->invoke( "Deletable", args, outIndex, outArgs );
    1101           0 :             aResult >>= result; // or do we just assume true if no exception ?
    1102             :         }
    1103           0 :         catch( Exception& e )
    1104             :         {
    1105             :             OSL_TRACE("Caught exception trying to delete %s",
    1106             :                 OUStringToOString(
    1107             :                     e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
    1108           0 :         }
    1109             :     }
    1110             : 
    1111           0 :     if ( result == sal_True )
    1112             :     {
    1113           0 :         m_pScriptsBox->deleteTree( pEntry );
    1114           0 :         m_pScriptsBox->GetModel()->Remove( pEntry );
    1115             :     }
    1116             :     else
    1117             :     {
    1118             :         //ISSUE L10N & message from exception?
    1119           0 :         ErrorBox aErrorBox( static_cast<Window*>(this), WB_OK | RET_OK, m_delErrStr );
    1120           0 :         aErrorBox.SetText( m_delErrTitleStr );
    1121           0 :         aErrorBox.Execute();
    1122           0 :     }
    1123             : 
    1124             : }
    1125             : 
    1126           0 : sal_Bool SvxScriptOrgDialog::getBoolProperty( Reference< beans::XPropertySet >& xProps,
    1127             :                 OUString& propName )
    1128             : {
    1129           0 :     sal_Bool result = false;
    1130             :     try
    1131             :     {
    1132           0 :         sal_Bool bTemp = sal_False;
    1133           0 :         xProps->getPropertyValue( propName ) >>= bTemp;
    1134           0 :         result = ( bTemp == sal_True );
    1135             :     }
    1136           0 :     catch ( Exception& )
    1137             :     {
    1138           0 :         return result;
    1139             :     }
    1140           0 :     return result;
    1141             : }
    1142             : 
    1143           0 : OUString SvxScriptOrgDialog::getListOfChildren( Reference< browse::XBrowseNode > node, int depth )
    1144             : {
    1145           0 :     OUString result = "\n";
    1146           0 :     for( int i=0;i<=depth;i++ )
    1147             :     {
    1148           0 :         result += "\t";
    1149             :     }
    1150           0 :     result += node->getName();
    1151             : 
    1152             :     try
    1153             :     {
    1154           0 :         if ( node->hasChildNodes() == sal_True )
    1155             :         {
    1156             :             Sequence< Reference< browse::XBrowseNode > > children
    1157           0 :                 = node->getChildNodes();
    1158           0 :             for ( sal_Int32 n = 0; n < children.getLength(); n++ )
    1159             :             {
    1160           0 :                 result += getListOfChildren( children[ n ] , depth+1 );
    1161           0 :             }
    1162             :         }
    1163             :     }
    1164           0 :     catch ( Exception& )
    1165             :     {
    1166             :         // ignore, will return an empty string
    1167             :     }
    1168             : 
    1169           0 :     return result;
    1170             : }
    1171             : 
    1172           0 : Selection_hash SvxScriptOrgDialog::m_lastSelection;
    1173             : 
    1174           0 : void SvxScriptOrgDialog::StoreCurrentSelection()
    1175             : {
    1176           0 :     OUString aDescription;
    1177           0 :     if ( m_pScriptsBox->IsSelected( m_pScriptsBox->GetHdlEntry() ) )
    1178             :     {
    1179           0 :         SvTreeListEntry* pEntry = m_pScriptsBox->GetHdlEntry();
    1180           0 :         while( pEntry )
    1181             :         {
    1182           0 :             aDescription = m_pScriptsBox->GetEntryText( pEntry ) + aDescription;
    1183           0 :             pEntry = m_pScriptsBox->GetParent( pEntry );
    1184           0 :             if ( pEntry )
    1185           0 :                 aDescription = ";" + aDescription;
    1186             :         }
    1187           0 :         OUString sDesc( aDescription );
    1188           0 :         m_lastSelection[ m_sLanguage ] = sDesc;
    1189           0 :     }
    1190           0 : }
    1191             : 
    1192           0 : void SvxScriptOrgDialog::RestorePreviousSelection()
    1193             : {
    1194           0 :     OUString aStoredEntry = m_lastSelection[ m_sLanguage ];
    1195           0 :     if( aStoredEntry.isEmpty() )
    1196           0 :         return;
    1197           0 :     SvTreeListEntry* pEntry = 0;
    1198           0 :     sal_Int32 nIndex = 0;
    1199           0 :     while ( nIndex != -1 )
    1200             :     {
    1201           0 :         OUString aTmp( aStoredEntry.getToken( 0, ';', nIndex ) );
    1202           0 :         SvTreeListEntry* pTmpEntry = m_pScriptsBox->FirstChild( pEntry );
    1203           0 :         while ( pTmpEntry )
    1204             :         {
    1205           0 :             if ( m_pScriptsBox->GetEntryText( pTmpEntry ) == aTmp )
    1206             :             {
    1207           0 :                 pEntry = pTmpEntry;
    1208           0 :                 break;
    1209             :             }
    1210           0 :             pTmpEntry = m_pScriptsBox->NextSibling( pTmpEntry );
    1211             :         }
    1212           0 :         if ( !pTmpEntry )
    1213           0 :             break;
    1214           0 :         m_pScriptsBox->RequestingChildren( pEntry );
    1215           0 :     }
    1216           0 :     m_pScriptsBox->SetCurEntry( pEntry );
    1217             : }
    1218             : 
    1219           0 : OUString ReplaceString(
    1220             :     const OUString& source,
    1221             :     const OUString& token,
    1222             :     const OUString& value )
    1223             : {
    1224           0 :     sal_Int32 pos = source.indexOf( token );
    1225             : 
    1226           0 :     if ( pos != -1 && !value.isEmpty() )
    1227             :     {
    1228           0 :         return source.replaceAt( pos, token.getLength(), value );
    1229             :     }
    1230             :     else
    1231             :     {
    1232           0 :         return source;
    1233             :     }
    1234             : }
    1235             : 
    1236           0 : OUString FormatErrorString(
    1237             :     const OUString& unformatted,
    1238             :     const OUString& language,
    1239             :     const OUString& script,
    1240             :     const OUString& line,
    1241             :     const OUString& type,
    1242             :     const OUString& message )
    1243             : {
    1244           0 :     OUString result = unformatted.copy( 0 );
    1245             : 
    1246           0 :     result = ReplaceString(result, "%LANGUAGENAME", language );
    1247           0 :     result = ReplaceString(result, "%SCRIPTNAME", script );
    1248           0 :     result = ReplaceString(result, "%LINENUMBER", line );
    1249             : 
    1250           0 :     if ( !type.isEmpty() )
    1251             :     {
    1252           0 :         result += "\n\n" +
    1253           0 :                   OUString(CUI_RES(RID_SVXSTR_ERROR_TYPE_LABEL)) +
    1254           0 :                   " " +
    1255           0 :                   type;
    1256             :     }
    1257             : 
    1258           0 :     if ( !message.isEmpty() )
    1259             :     {
    1260           0 :         result += "\n\n" +
    1261           0 :                   OUString(CUI_RES(RID_SVXSTR_ERROR_MESSAGE_LABEL)) +
    1262           0 :                   " " +
    1263           0 :                   message;
    1264             :     }
    1265             : 
    1266           0 :     return result;
    1267             : }
    1268             : 
    1269           0 : OUString GetErrorMessage(
    1270             :     const provider::ScriptErrorRaisedException& eScriptError )
    1271             : {
    1272           0 :     OUString unformatted = CUI_RES( RID_SVXSTR_ERROR_AT_LINE );
    1273             : 
    1274           0 :     OUString unknown("UNKNOWN");
    1275           0 :     OUString language = unknown;
    1276           0 :     OUString script = unknown;
    1277           0 :     OUString line = unknown;
    1278           0 :     OUString type = "";
    1279           0 :     OUString message = eScriptError.Message;
    1280             : 
    1281           0 :         if ( !eScriptError.language.isEmpty() )
    1282             :         {
    1283           0 :             language = eScriptError.language;
    1284             :         }
    1285             : 
    1286           0 :         if ( !eScriptError.scriptName.isEmpty() )
    1287             :         {
    1288           0 :             script = eScriptError.scriptName;
    1289             :         }
    1290             : 
    1291           0 :         if ( !eScriptError.Message.isEmpty() )
    1292             :         {
    1293           0 :             message = eScriptError.Message;
    1294             :         }
    1295           0 :         if ( eScriptError.lineNum != -1 )
    1296             :         {
    1297           0 :             line = OUString::number( eScriptError.lineNum );
    1298           0 :             unformatted = CUI_RES( RID_SVXSTR_ERROR_AT_LINE );
    1299             :         }
    1300             :         else
    1301             :         {
    1302           0 :             unformatted = CUI_RES( RID_SVXSTR_ERROR_RUNNING );
    1303             :         }
    1304             : 
    1305             :     return FormatErrorString(
    1306           0 :         unformatted, language, script, line, type, message );
    1307             : }
    1308             : 
    1309           0 : OUString GetErrorMessage(
    1310             :     const provider::ScriptExceptionRaisedException& eScriptException )
    1311             : {
    1312           0 :     OUString unformatted = CUI_RES( RID_SVXSTR_EXCEPTION_AT_LINE );
    1313             : 
    1314           0 :     OUString unknown("UNKNOWN");
    1315           0 :     OUString language = unknown;
    1316           0 :     OUString script = unknown;
    1317           0 :     OUString line = unknown;
    1318           0 :     OUString type = unknown;
    1319           0 :     OUString message = eScriptException.Message;
    1320             : 
    1321           0 :     if ( !eScriptException.language.isEmpty() )
    1322             :     {
    1323           0 :         language = eScriptException.language;
    1324             :     }
    1325           0 :     if ( !eScriptException.scriptName.isEmpty() )
    1326             :     {
    1327           0 :         script = eScriptException.scriptName;
    1328             :     }
    1329             : 
    1330           0 :     if ( !eScriptException.Message.isEmpty() )
    1331             :     {
    1332           0 :         message = eScriptException.Message;
    1333             :     }
    1334             : 
    1335           0 :     if ( eScriptException.lineNum != -1 )
    1336             :     {
    1337           0 :         line = OUString::number( eScriptException.lineNum );
    1338           0 :         unformatted = CUI_RES( RID_SVXSTR_EXCEPTION_AT_LINE );
    1339             :     }
    1340             :     else
    1341             :     {
    1342           0 :         unformatted = CUI_RES( RID_SVXSTR_EXCEPTION_RUNNING );
    1343             :     }
    1344             : 
    1345           0 :     if ( !eScriptException.exceptionType.isEmpty() )
    1346             :     {
    1347           0 :         type = eScriptException.exceptionType;
    1348             :     }
    1349             : 
    1350             :     return FormatErrorString(
    1351           0 :         unformatted, language, script, line, type, message );
    1352             : 
    1353             : }
    1354           0 : OUString GetErrorMessage(
    1355             :     const provider::ScriptFrameworkErrorException& sError )
    1356             : {
    1357           0 :     OUString unformatted = CUI_RES( RID_SVXSTR_FRAMEWORK_ERROR_RUNNING );
    1358             : 
    1359           0 :     OUString language("UNKNOWN");
    1360             : 
    1361           0 :     OUString script("UNKNOWN");
    1362             : 
    1363           0 :     OUString message;
    1364             : 
    1365           0 :     if ( !sError.scriptName.isEmpty() )
    1366             :     {
    1367           0 :         script = sError.scriptName;
    1368             :     }
    1369           0 :     if ( !sError.language.isEmpty() )
    1370             :     {
    1371           0 :         language = sError.language;
    1372             :     }
    1373           0 :     if ( sError.errorType == provider::ScriptFrameworkErrorType::NOTSUPPORTED )
    1374             :     {
    1375           0 :         message = OUString(
    1376           0 :             CUI_RES(  RID_SVXSTR_ERROR_LANG_NOT_SUPPORTED ) );
    1377           0 :         message = ReplaceString(message, "%LANGUAGENAME", language );
    1378             : 
    1379             :     }
    1380             :     else
    1381             :     {
    1382           0 :         message = sError.Message;
    1383             :     }
    1384             :     return FormatErrorString(
    1385           0 :         unformatted, language, script, OUString(), OUString(), message );
    1386             : }
    1387             : 
    1388           0 : OUString GetErrorMessage( const RuntimeException& re )
    1389             : {
    1390           0 :     Type t = ::getCppuType( &re );
    1391           0 :     OUString message = t.getTypeName();
    1392           0 :     message += re.Message;
    1393             : 
    1394           0 :     return message;
    1395             : }
    1396             : 
    1397           0 : OUString GetErrorMessage( const Exception& e )
    1398             : {
    1399           0 :     Type t = ::getCppuType( &e );
    1400           0 :     OUString message = t.getTypeName();
    1401           0 :     message += e.Message;
    1402             : 
    1403           0 :     return message;
    1404             : }
    1405             : 
    1406           0 : OUString GetErrorMessage( const com::sun::star::uno::Any& aException )
    1407             : {
    1408           0 :     if ( aException.getValueType() ==
    1409           0 :          ::getCppuType( (const reflection::InvocationTargetException* ) NULL ) )
    1410             :     {
    1411           0 :         reflection::InvocationTargetException ite;
    1412           0 :         aException >>= ite;
    1413           0 :         if ( ite.TargetException.getValueType() == ::getCppuType( ( const provider::ScriptErrorRaisedException* ) NULL ) )
    1414             :         {
    1415             :             // Error raised by script
    1416           0 :             provider::ScriptErrorRaisedException scriptError;
    1417           0 :             ite.TargetException >>= scriptError;
    1418           0 :             return GetErrorMessage( scriptError );
    1419             :         }
    1420           0 :         else if ( ite.TargetException.getValueType() == ::getCppuType( ( const provider::ScriptExceptionRaisedException* ) NULL ) )
    1421             :         {
    1422             :             // Exception raised by script
    1423           0 :             provider::ScriptExceptionRaisedException scriptException;
    1424           0 :             ite.TargetException >>= scriptException;
    1425           0 :             return GetErrorMessage( scriptException );
    1426             :         }
    1427             :         else
    1428             :         {
    1429             :             // Unknown error, shouldn't happen
    1430             :             // OSL_ASSERT(...)
    1431           0 :         }
    1432             : 
    1433             :     }
    1434           0 :     else if ( aException.getValueType() == ::getCppuType( ( const provider::ScriptFrameworkErrorException* ) NULL ) )
    1435             :     {
    1436             :         // A Script Framework error has occurred
    1437           0 :         provider::ScriptFrameworkErrorException sfe;
    1438           0 :         aException >>= sfe;
    1439           0 :         return GetErrorMessage( sfe );
    1440             : 
    1441             :     }
    1442             :     // unknown exception
    1443           0 :     Exception e;
    1444           0 :     RuntimeException rte;
    1445           0 :     if ( aException >>= rte )
    1446             :     {
    1447           0 :         return GetErrorMessage( rte );
    1448             :     }
    1449             : 
    1450           0 :     aException >>= e;
    1451           0 :     return GetErrorMessage( e );
    1452             : 
    1453             : }
    1454             : 
    1455           0 : SvxScriptErrorDialog::SvxScriptErrorDialog(
    1456             :     Window* , ::com::sun::star::uno::Any aException )
    1457           0 :     : m_sMessage()
    1458             : {
    1459           0 :     SolarMutexGuard aGuard;
    1460           0 :     m_sMessage = GetErrorMessage( aException );
    1461           0 : }
    1462             : 
    1463           0 : SvxScriptErrorDialog::~SvxScriptErrorDialog()
    1464             : {
    1465           0 : }
    1466             : 
    1467           0 : short SvxScriptErrorDialog::Execute()
    1468             : {
    1469             :     // Show Error dialog asynchronously
    1470             : 
    1471             :     // Pass a copy of the message to the ShowDialog method as the
    1472             :     // SvxScriptErrorDialog may be deleted before ShowDialog is called
    1473             :     Application::PostUserEvent(
    1474             :         LINK( this, SvxScriptErrorDialog, ShowDialog ),
    1475           0 :         new OUString( m_sMessage ) );
    1476             : 
    1477           0 :     return 0;
    1478             : }
    1479             : 
    1480           0 : IMPL_LINK( SvxScriptErrorDialog, ShowDialog, OUString*, pMessage )
    1481             : {
    1482           0 :     OUString message;
    1483             : 
    1484           0 :     if ( pMessage && !pMessage->isEmpty() )
    1485             :     {
    1486           0 :         message = *pMessage;
    1487             :     }
    1488             :     else
    1489             :     {
    1490           0 :         message = OUString( CUI_RES( RID_SVXSTR_ERROR_TITLE ) );
    1491             :     }
    1492             : 
    1493           0 :     MessBox* pBox = new WarningBox( NULL, WB_OK, message );
    1494           0 :     pBox->SetText( CUI_RES( RID_SVXSTR_ERROR_TITLE ) );
    1495           0 :     pBox->Execute();
    1496             : 
    1497           0 :     delete pBox;
    1498           0 :     delete pMessage;
    1499             : 
    1500           0 :     return 0;
    1501           0 : }
    1502             : 
    1503             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10