[Libreoffice-commits] core.git: Branch 'feature/extract-tooltip' - sfx2/source

Markus Mohrhard markus.mohrhard at googlemail.com
Sun Apr 14 16:28:06 PDT 2013


 sfx2/source/appl/sfxhelp.cxx |  125 +++++++++++++++++++++++++++++--------------
 1 file changed, 87 insertions(+), 38 deletions(-)

New commits:
commit dd80b754ca901e69323fe72a3ef62ed716c67b1f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Apr 15 01:26:29 2013 +0200

    initial work on extracting tooltips from the help
    
    Change-Id: I8cbef3b5bbc63fae946f9e53f2e8e11d7fa51df2

diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index 7a8ec78..7ddc8c6 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -56,6 +56,7 @@
 #include <vcl/msgbox.hxx>
 #include <svtools/ehdl.hxx>
 #include <svtools/sfxecode.hxx>
+#include <rtl/bootstrap.hxx>
 
 #include "newhelp.hxx"
 #include <sfx2/objsh.hxx>
@@ -69,6 +70,8 @@
 #include <rtl/strbuf.hxx>
 #include <rtl/string.hxx>
 
+#include <boost/scoped_ptr.hpp>
+
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::frame;
 using namespace ::com::sun::star::uno;
@@ -206,28 +209,19 @@ private:
     std::set < OString > m_aIds;
 
 public:
-                    SfxHelpOptions_Impl();
-                    ~SfxHelpOptions_Impl();
+    SfxHelpOptions_Impl();
+    ~SfxHelpOptions_Impl();
 
-    bool            HasId( const OString& rId ) { return m_aIds.size() ? m_aIds.find( rId ) != m_aIds.end() : false; }
-    virtual void            Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames );
-    virtual void            Commit();
+    bool HasId( const OString& rId ) { return m_aIds.size() ? m_aIds.find( rId ) != m_aIds.end() : false; }
+    virtual void Notify( const com::sun::star::uno::Sequence< OUString >& aPropertyNames );
+    virtual void Commit();
 };
 
 static Sequence< OUString > GetPropertyNames()
 {
-    static const char* aPropNames[] =
-    {
-        "HelpAgentStarterList",
-    };
-
-    const int nCount = sizeof( aPropNames ) / sizeof( const char* );
-    Sequence< OUString > aNames( nCount );
+    Sequence< OUString > aNames( 1 );
     OUString* pNames = aNames.getArray();
-    OUString* pEnd   = pNames + aNames.getLength();
-    int i = 0;
-    for ( ; pNames != pEnd; ++pNames )
-        *pNames = OUString::createFromAscii( aPropNames[i++] );
+    pNames[0] = OUString( "HelpAgentStarterList" );
 
     return aNames;
 }
@@ -298,21 +292,25 @@ void SfxHelpOptions_Impl::Commit()
 class SfxHelp_Impl
 {
 private:
-    SfxHelpOptions_Impl*                m_pOpt;         // the options
-    ::std::vector< OUString >    m_aModulesList; // list of all installed modules
+    SfxHelpOptions_Impl* m_pOpt; // the options
+
+    typedef std::map< OUString, OUString > IdToTextType;
+    typedef std::map< OUString, IdToTextType > ModuleToTooltipsType;
+    ModuleToTooltipsType maToolTips;
+
+    OUString GetHelpText_Impl( const OUString& rCommandURL, const OUString& rModule );
+    IdToTextType loadHelpStrings( const OUString& rModule );
 
 public:
     SfxHelp_Impl();
     ~SfxHelp_Impl();
 
-    SfxHelpOptions_Impl*    GetOptions();
-    static OUString         GetHelpText( const OUString& aCommandURL, const OUString& rModule );
+    SfxHelpOptions_Impl* GetOptions();
+    OUString GetHelpText( const OUString& aCommandURL, const OUString& rModule );
 };
 
 SfxHelp_Impl::SfxHelp_Impl() :
-
-    m_pOpt          ( NULL )
-
+    m_pOpt ( NULL )
 {
 }
 
@@ -321,17 +319,70 @@ SfxHelp_Impl::~SfxHelp_Impl()
     delete m_pOpt;
 }
 
+std::map<OUString, OUString> SfxHelp_Impl::loadHelpStrings( const OUString& rModule)
+{
+    IdToTextType aRet;
+    OUString uri("$BRAND_BASE_DIR/program/resource/");
+    rtl::Bootstrap::expandMacros(uri);
+    OUString aFileURL = uri + rModule + ".properties";
+    SAL_WARN("sfx2.appl", "file url: " << aFileURL);
+    boost::scoped_ptr<SvFileStream> pStrm( new SvFileStream( aFileURL, (STREAM_READ| STREAM_SHARE_DENYWRITE | STREAM_NOCREATE) ) );
+    if( pStrm->GetError() == 0 )
+    {
+        bool bRead = true;
+        while(bRead)
+        {
+            OUString aLine;
+            bRead = pStrm->ReadByteStringLine(aLine, RTL_TEXTENCODING_UTF8);
+            if(bRead)
+            {
+                sal_Int32 nIndex = 0;
+                OUString aId = aLine.getToken(0, '=', nIndex);
+                SAL_WARN_IF(nIndex == -1, "sfx.appl", "not a valid line");
+                if(nIndex != -1)
+                {
+                    OUString aValue = aLine.copy(nIndex);
+                    aRet.insert( std::pair< OUString, OUString >( aId, aValue ) );
+                    SAL_WARN("sfx2.appl", "added help string with id: " << aId << " and value: " << aValue);
+                }
+            }
+        }
+    }
+    else
+    {
+        SAL_WARN("sfx2.appl", "problem opening tooltip file: " << aFileURL);
+    }
+
+    return aRet;
+}
+
+OUString SfxHelp_Impl::GetHelpText_Impl( const OUString& rCommandURL, const OUString& rModule )
+{
+    ModuleToTooltipsType::const_iterator itr = maToolTips.find(rModule);
+
+    if(itr == maToolTips.end())
+    {
+        IdToTextType aHelpTexts = loadHelpStrings(rModule);
+        itr = maToolTips.insert( std::pair< OUString, IdToTextType >( rModule, aHelpTexts ) ).first;
+    }
+
+    assert(itr != maToolTips.end());
+
+    IdToTextType::const_iterator it = itr->second.find(rCommandURL);
+    if(it != itr->second.end())
+        return it->second;
+
+    SAL_WARN("sfx2.appl", "could not find help text for " << rCommandURL << " in Module: " << rModule);
+    return OUString();
+}
+
 OUString SfxHelp_Impl::GetHelpText( const OUString& aCommandURL, const OUString& rModule )
 {
-    // create help url
-    OUStringBuffer aHelpURL( SfxHelp::CreateHelpURL( aCommandURL, rModule ) );
-    // added 'active' parameter
-    sal_Int32 nIndex = aHelpURL.lastIndexOf( '#' );
-    if ( nIndex < 0 )
-        nIndex = aHelpURL.getLength();
-    aHelpURL.insert( nIndex, "&Active=true" );
-    // load help string
-    return SfxContentHelper::GetActiveHelpString( aHelpURL.makeStringAndClear() );
+    OUString aHelpText = GetHelpText_Impl( aCommandURL, rModule );
+    if(aHelpText.isEmpty())
+        aHelpText = GetHelpText_Impl( aCommandURL, "common" );
+
+    return aHelpText;
 }
 
 SfxHelpOptions_Impl* SfxHelp_Impl::GetOptions()
@@ -343,10 +394,8 @@ SfxHelpOptions_Impl* SfxHelp_Impl::GetOptions()
 }
 
 SfxHelp::SfxHelp() :
-
     bIsDebug( sal_False ),
     pImp    ( NULL )
-
 {
     // read the environment variable "HELP_DEBUG"
     // if it's set, you will see debug output on active help
@@ -639,9 +688,9 @@ static bool impl_hasHelpInstalled( const OUString &rLang = OUString() )
 {
     OUStringBuffer aHelpRootURL("vnd.sun.star.help://");
     AppendConfigToken(aHelpRootURL, sal_True, rLang);
-    Sequence< OUString > aFactories = SfxContentHelper::GetResultSet(aHelpRootURL.makeStringAndClear());
+    std::vector< OUString > aFactories = SfxContentHelper::GetResultSet(aHelpRootURL.makeStringAndClear());
 
-    return ( aFactories.getLength() != 0   );
+    return !aFactories.empty();
 }
 
 sal_Bool SfxHelp::SearchKeyword( const OUString& rKeyword )
@@ -681,7 +730,7 @@ sal_Bool SfxHelp::Start_Impl(const OUString& rURL, const Window* pWindow, const
 {
     OUStringBuffer aHelpRootURL("vnd.sun.star.help://");
     AppendConfigToken(aHelpRootURL, sal_True);
-    Sequence< OUString > aFactories = SfxContentHelper::GetResultSet(aHelpRootURL.makeStringAndClear());
+    SfxContentHelper::GetResultSet(aHelpRootURL.makeStringAndClear());
 
     /* rURL may be
         - a "real" URL
@@ -697,7 +746,6 @@ sal_Bool SfxHelp::Start_Impl(const OUString& rURL, const Window* pWindow, const
     OUString aHelpURL;
     INetURLObject aParser( rURL );
     INetProtocol nProtocol = aParser.GetProtocol();
-    OUString aHelpModuleName( GetHelpModuleName_Impl() );
 
     switch ( nProtocol )
     {
@@ -707,6 +755,7 @@ sal_Bool SfxHelp::Start_Impl(const OUString& rURL, const Window* pWindow, const
             break;
         default:
         {
+            OUString aHelpModuleName( GetHelpModuleName_Impl() );
             // no URL, just a HelpID (maybe empty in case of keyword search)
             aHelpURL = CreateHelpURL_Impl( rURL, aHelpModuleName );
 


More information about the Libreoffice-commits mailing list