update ooo310-m15
[ooovba.git] / applied_patches / 0408-vba-improve-toolbarapi-macro-search.diff
blobb09e923037ba53a79a891645feeb5d57c611b41d
1 diff --git vbahelper/source/vbahelper/vbacommandbarcontrol.cxx vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
2 index fdea661..718cdd0 100644
3 --- vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
4 +++ vbahelper/source/vbahelper/vbacommandbarcontrol.cxx
5 @@ -290,19 +290,51 @@ ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (u
6 rtl::OUString aCommandURL;
7 rtl::OUString sScheme = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
8 SbModule* pModule = StarBASIC::GetActiveModule();
9 - if( pModule )
10 + StarBASIC* pLib = pModule ? dynamic_cast< StarBASIC* >( pModule->GetParent() ) : NULL;
12 + // Ok, we should be able to deal with the following params for onAction
13 + // a) macro ( we assume the macro lives in this Project ( that is not really a valid assumption but we can't currently search outside this Library yet )
14 + // b) module.macro ( again assume the macro is in this Project )
15 + // c) project.module.macro fully specified
17 + if( pModule && pLib )
19 - String sTmp = _onaction;
20 - if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pModule->Find( sTmp, SbxCLASS_METHOD ) ) )
21 + String sProject;
22 + String sModule;
23 + String sMacro = _onaction;
25 + sal_Int32 nMacroDot = _onaction.lastIndexOf( '.' );
27 + if ( nMacroDot != -1 )
28 + {
29 + sMacro = _onaction.copy( nMacroDot + 1 );
31 + sal_Int32 nProjectDot = _onaction.lastIndexOf( '.', nMacroDot - 1 );
32 + if ( nProjectDot != -1 )
33 + {
34 + sModule = _onaction.copy( nProjectDot + 1, nMacroDot - nProjectDot - 1 );
35 + pModule = NULL; // force full spec. no search
37 + }
38 + else
39 + sModule = _onaction.copy( 0, nMacroDot );
40 + pModule = pLib->FindModule( sModule );
41 + }
43 + // Hopefully eventually if no project is specified 'Find' below
44 + // will do the right thing
45 + if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pModule ? pModule->Find( sMacro, SbxCLASS_METHOD ) : NULL ) )
47 if( pMethod )
49 - sTmp.Insert( '.', 0 ).Insert( pModule->GetName(), 0 ).Insert( '.', 0 ).Insert( pModule->GetParent()->GetName(), 0 );
50 + sModule = pModule->GetName();
51 + sProject = pModule->GetParent()->GetName();
54 + sMacro.Insert( '.', 0 ).Insert( sModule, 0 ).Insert( '.', 0 ).Insert( sProject, 0 );
56 rtl::OUString sUrlPart2 = rtl::OUString::createFromAscii( "?language=Basic&location=document");
57 - aCommandURL = sScheme.concat( sTmp ).concat( sUrlPart2 );
58 + aCommandURL = sScheme.concat( sMacro ).concat( sUrlPart2 );
59 OSL_TRACE("**** METHOD IS %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() );
61 else