diff options
author | Szymon Kłos <eszkadev@gmail.com> | 2016-09-29 21:06:19 +0200 |
---|---|---|
committer | Szymon Kłos <eszkadev@gmail.com> | 2016-09-29 20:42:55 +0000 |
commit | be68bf55c303ce8aaaa79578178e6ff9a5e18d18 (patch) | |
tree | b28fa662446c6deead68b9ee868d5dbaa5178fed | |
parent | 663e26f24f1fa1abadc37838983bebd7407d65f8 (diff) |
tdf#102776 : toolbar mode changing in multiple windows
This patch provides better toolbar mode switching:
- only in current module (if eg. Writer and Calc opened)
- in multiple windows with the same module (two Writer docs)
Change-Id: I81bfe626b677bc0168c4a7cd6ce5563ceed5c14b
Reviewed-on: https://gerrit.libreoffice.org/29394
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <eszkadev@gmail.com>
-rw-r--r-- | sfx2/source/appl/appserv.cxx | 317 |
1 files changed, 172 insertions, 145 deletions
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index e841d2edadd7..40811c2ccba8 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -698,195 +698,222 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); - Reference<XDesktop2> xDesktop = Desktop::create( xContext ); - Reference<XFrame> xFrame = xDesktop->getActiveFrame(); + // Get information about current frame and module + Reference<XFrame> xCurrentFrame; + vcl::EnumContext::Application eCurrentApp = vcl::EnumContext::Application::Application_None; + OUString aCurrentMode; - const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext ); - vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) ); - - OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); - aPath.append( lcl_getAppName(eApp) ); - - const utl::OConfigurationTreeRoot aAppNode( - xContext, - aPath.makeStringAndClear(), - true); - if ( !aAppNode.isValid() ) + SfxViewFrame* pViewFrame = SfxViewFrame::Current(); + if( pViewFrame ) { - bDone = true; - break; - } + xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface(); - OUString aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) ); + const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext ); + eCurrentApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xCurrentFrame ) ); - if ( aCurrentMode.compareTo( aNewName ) == 0 ) - { - bDone = true; - break; - } - - aAppNode.setNodeValue( "Active", makeAny( aNewName ) ); - aAppNode.commit(); + OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); + aPath.append( lcl_getAppName( eCurrentApp ) ); - Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY ); - Reference<css::frame::XLayoutManager> xLayoutManager; - if ( xPropSet.is() ) - { - try - { - Any aValue = xPropSet->getPropertyValue( "LayoutManager" ); - aValue >>= xLayoutManager; - } - catch ( const css::uno::RuntimeException& ) + const utl::OConfigurationTreeRoot aAppNode( + xContext, + aPath.makeStringAndClear(), + true); + if ( !aAppNode.isValid() ) { - throw; + bDone = true; + break; } - catch ( css::uno::Exception& ) + + aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) ); + + if ( aCurrentMode.compareTo( aNewName ) == 0 ) { + bDone = true; + break; } + + // Save new toolar mode for a current module + aAppNode.setNodeValue( "Active", makeAny( aNewName ) ); + aAppNode.commit(); } - if ( xLayoutManager.is() ) + // Apply settings for all frames + pViewFrame = SfxViewFrame::GetFirst(); + while( pViewFrame ) { - css::uno::Sequence<OUString> aMandatoryToolbars; - css::uno::Sequence<OUString> aUserToolbars; - std::vector<OUString> aBackupList; - OUString aSidebarMode; - bool bCorrectMode = true; - - aPath = OUStringBuffer("org.openoffice.Office.UI.ToolbarMode/Applications/"); - aPath.append( lcl_getAppName(eApp) ); - aPath.append( "/Modes" ); - - // Read mode settings - const utl::OConfigurationTreeRoot aModesNode( - xContext, - aPath.makeStringAndClear(), - true); - if ( !aModesNode.isValid() ) + Reference<XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface(); + + // We want to change mode only for a current app module, ignore other apps + const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext ); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) ); + if ( eApp != eCurrentApp ) { - bDone = true; - break; + pViewFrame = SfxViewFrame::GetNext( *pViewFrame ); + continue; } - const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() ); - const sal_Int32 nCount( aModeNodeNames.getLength() ); + Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY ); + Reference<css::frame::XLayoutManager> xLayoutManager; + if ( xPropSet.is() ) + { + try + { + Any aValue = xPropSet->getPropertyValue( "LayoutManager" ); + aValue >>= xLayoutManager; + } + catch ( const css::uno::RuntimeException& ) + { + throw; + } + catch ( css::uno::Exception& ) + { + } + } - for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) + if ( xLayoutManager.is() ) { - const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); - if ( !aModeNode.isValid() ) - continue; + css::uno::Sequence<OUString> aMandatoryToolbars; + css::uno::Sequence<OUString> aUserToolbars; + std::vector<OUString> aBackupList; + OUString aSidebarMode; + bool bCorrectMode = true; + + OUStringBuffer aPath = OUStringBuffer( "org.openoffice.Office.UI.ToolbarMode/Applications/" ); + aPath.append( lcl_getAppName( eApp ) ); + aPath.append( "/Modes" ); + + // Read mode settings + const utl::OConfigurationTreeRoot aModesNode( + xContext, + aPath.makeStringAndClear(), + true); + if ( !aModesNode.isValid() ) + { + bDone = true; + break; + } - OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() ); + const sal_Int32 nCount( aModeNodeNames.getLength() ); - if ( aCommandArg.compareTo( aNewName ) == 0 ) + for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) { - aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence<OUString> >(); - aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence<OUString> >(); - aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) ); - break; + const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); + if ( !aModeNode.isValid() ) + continue; + + OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + + if ( aCommandArg.compareTo( aNewName ) == 0 ) + { + aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence<OUString> >(); + aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence<OUString> >(); + aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) ); + break; + } } - } - if ( bCorrectMode ) - { - // Backup visible toolbar list and hide all toolbars - Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements(); - for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ ) + if ( bCorrectMode ) { - Reference< XUIElement > xUIElement( aUIElements[i] ); - Reference< XPropertySet > xPropertySet( aUIElements[i], UNO_QUERY ); - if ( xPropertySet.is() && xUIElement.is() ) + // Backup visible toolbar list and hide all toolbars + Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements(); + for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ ) { - try + Reference< XUIElement > xUIElement( aUIElements[i] ); + Reference< XPropertySet > xPropertySet( aUIElements[i], UNO_QUERY ); + if ( xPropertySet.is() && xUIElement.is() ) { - OUString aResName; - sal_Int16 nType( -1 ); - xPropertySet->getPropertyValue( "Type" ) >>= nType; - xPropertySet->getPropertyValue( "ResourceURL" ) >>= aResName; - - if (( nType == css::ui::UIElementType::TOOLBAR ) && - !aResName.isEmpty() ) + try + { + OUString aResName; + sal_Int16 nType( -1 ); + xPropertySet->getPropertyValue( "Type" ) >>= nType; + xPropertySet->getPropertyValue( "ResourceURL" ) >>= aResName; + + if (( nType == css::ui::UIElementType::TOOLBAR ) && + !aResName.isEmpty() ) + { + if ( xLayoutManager->isElementVisible( aResName ) ) + { + aBackupList.push_back( aResName ); + } + xLayoutManager->hideElement( aResName ); + } + } + catch ( const Exception& ) { - if ( xLayoutManager->isElementVisible( aResName ) ) - aBackupList.push_back( aResName ); - xLayoutManager->hideElement( aResName ); } - } - catch ( const Exception& ) - { } } - } - // Show toolbars - for ( OUString& rName : aMandatoryToolbars ) - { - xLayoutManager->createElement( rName ); - xLayoutManager->showElement( rName ); - } - - for ( OUString& rName : aUserToolbars ) - { - xLayoutManager->createElement( rName ); - xLayoutManager->showElement( rName ); - } - - // Sidebar - if ( SfxViewFrame::Current() ) - SfxViewFrame::Current()->ShowChildWindow( SID_SIDEBAR ); - - sfx2::sidebar::SidebarController* pSidebar = - sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame ); - if ( pSidebar ) - { - if ( aSidebarMode.compareTo( "Arrow" ) == 0 ) + // Show toolbars + for ( OUString& rName : aMandatoryToolbars ) { - pSidebar->FadeOut(); + xLayoutManager->createElement( rName ); + xLayoutManager->showElement( rName ); } - else if ( aSidebarMode.compareTo( "Tabs" ) == 0 ) + + for ( OUString& rName : aUserToolbars ) { - pSidebar->FadeIn(); - pSidebar->RequestOpenDeck(); - pSidebar->RequestCloseDeck(); + xLayoutManager->createElement( rName ); + xLayoutManager->showElement( rName ); } - else if ( aSidebarMode.compareTo( "Opened" ) == 0 ) + + // Sidebar + pViewFrame->ShowChildWindow( SID_SIDEBAR ); + + sfx2::sidebar::SidebarController* pSidebar = + sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame ); + if ( pSidebar ) { - pSidebar->FadeIn(); - pSidebar->RequestOpenDeck(); + if ( aSidebarMode.compareTo( "Arrow" ) == 0 ) + { + pSidebar->FadeOut(); + } + else if ( aSidebarMode.compareTo( "Tabs" ) == 0 ) + { + pSidebar->FadeIn(); + pSidebar->RequestOpenDeck(); + pSidebar->RequestCloseDeck(); + } + else if ( aSidebarMode.compareTo( "Opened" ) == 0 ) + { + pSidebar->FadeIn(); + pSidebar->RequestOpenDeck(); + } } - } - // Show/Hide the Notebookbar - SfxObjectShell* pCurrentShell = SfxObjectShell::Current(); - if ( pCurrentShell ) - { - const SfxPoolItem *pItem; - pCurrentShell->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, pItem); - } + // Show/Hide the Notebookbar + const SfxPoolItem* pItem; + pViewFrame->GetDispatcher()->QueryState( SID_NOTEBOOKBAR, pItem ); - // Save settings - css::uno::Sequence<OUString> aBackup( aBackupList.size() ); - for ( size_t i = 0; i < aBackupList.size(); ++i ) - aBackup[i] = aBackupList[i]; + // Save settings + if ( pViewFrame == SfxViewFrame::Current() ) + { + css::uno::Sequence<OUString> aBackup( aBackupList.size() ); + for ( size_t i = 0; i < aBackupList.size(); ++i ) + aBackup[i] = aBackupList[i]; - for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) - { - const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); - if ( !aModeNode.isValid() ) - continue; + for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) + { + const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); + if ( !aModeNode.isValid() ) + continue; - OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); - if ( aCommandArg.compareTo( aCurrentMode ) == 0 ) - { - aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) ); - break; + if ( aCommandArg.compareTo( aCurrentMode ) == 0 ) + { + aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) ); + break; + } + } + aModesNode.commit(); } } - aModesNode.commit(); } + + pViewFrame = SfxViewFrame::GetNext(*pViewFrame); } bDone = true; |