From dabb20ebd5fa3b0d4bdb063b32f6ffbe2f59c3a2 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Sat, 6 Aug 2016 23:31:18 +0200 Subject: GSoC: tdf#101249 Toolbar Mode switching + added registry entry for storing current toolbar mode for each application + registry entries to store toolbar mode configuration, remember additional visible toolbars activated by user + changing toolbar mode hides and shows suitable toolbars + added menu controller for toolbar mode + notebookbar implementation entries are disabled when notebookbar mode is not active + each mode can open/collapse the sidebar Change-Id: I2b03f87c6dce53190d12102892d9ad30fbfd3bf6 Reviewed-on: https://gerrit.libreoffice.org/27991 Reviewed-by: Samuel Mehrbrodt Tested-by: Samuel Mehrbrodt --- sfx2/sdi/appslots.sdi | 5 + sfx2/sdi/sfx.sdi | 16 ++ sfx2/source/appl/appserv.cxx | 242 +++++++++++++++++++++++++++++ sfx2/source/notebookbar/SfxNotebookBar.cxx | 92 +++++++++-- sfx2/source/sidebar/SidebarController.cxx | 12 ++ 5 files changed, 354 insertions(+), 13 deletions(-) (limited to 'sfx2') diff --git a/sfx2/sdi/appslots.sdi b/sfx2/sdi/appslots.sdi index 85191e6666fb..d103b962669a 100644 --- a/sfx2/sdi/appslots.sdi +++ b/sfx2/sdi/appslots.sdi @@ -166,6 +166,11 @@ interface Application SID_RECENTFILELIST [ ] + SID_TOOLBAR_MODE + [ + ExecMethod = MiscExec_Impl ; + StateMethod = MiscState_Impl ; + ] SID_AVAILABLE_TOOLBARS [ ExecMethod = MiscExec_Impl ; diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index b80b5fdde711..3afeb51b32d2 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -5401,6 +5401,22 @@ SfxVoidItem RecentFileList SID_RECENTFILELIST GroupId = GID_APPLICATION; ] +SfxVoidItem ToolbarMode SID_TOOLBAR_MODE +(SfxStringItem Mode SID_TOOLBAR_MODE) +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = FALSE, + MenuConfig = TRUE, + ToolBoxConfig = FALSE, + GroupId = GID_APPLICATION; +] SfxVoidItem AvailableToolbars SID_AVAILABLE_TOOLBARS (SfxStringItem Toolbar SID_AVAILABLE_TOOLBARS) diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 7a0d18a3f7ee..0014f059c469 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -70,9 +72,11 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -118,8 +122,14 @@ #include #include #include +#include +#include +#include +#include #include +#include +#include #include #include @@ -133,9 +143,32 @@ using namespace ::com::sun::star::script; using namespace ::com::sun::star::system; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::document; +using namespace ::com::sun::star::ui; namespace { + OUString lcl_getAppName( vcl::EnumContext::Application eApp ) + { + switch ( eApp ) + { + case vcl::EnumContext::Application::Application_Writer: + return OUString( "Writer" ); + break; + case vcl::EnumContext::Application::Application_Calc: + return OUString( "Calc" ); + break; + case vcl::EnumContext::Application::Application_Impress: + return OUString( "Impress" ); + break; + case vcl::EnumContext::Application::Application_Draw: + return OUString( "Draw" ); + break; + default: + return OUString( "" ); + break; + } + } + // lp#527938, debian#602953, fdo#33266, i#105408 bool lcl_isBaseAvailable() { @@ -652,6 +685,215 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) break; } + case SID_TOOLBAR_MODE: + { + const SfxStringItem* pModeName = rReq.GetArg( SID_TOOLBAR_MODE ); + + if ( !pModeName ) + { + bDone = true; + break; + } + + OUString aNewName(pModeName->GetValue()); + uno::Reference< uno::XComponentContext > xContext = + ::comphelper::getProcessComponentContext(); + + Reference xDesktop = Desktop::create( xContext ); + Reference xFrame = xDesktop->getActiveFrame(); + + const Reference 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() ) + { + bDone = true; + break; + } + + OUString aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) ); + + if ( aCurrentMode.compareTo( aNewName ) == 0 ) + { + bDone = true; + break; + } + + aAppNode.setNodeValue( "Active", makeAny( aNewName ) ); + aAppNode.commit(); + + Reference xPropSet( xFrame, UNO_QUERY ); + Reference xLayoutManager; + if ( xPropSet.is() ) + { + try + { + Any aValue = xPropSet->getPropertyValue( "LayoutManager" ); + aValue >>= xLayoutManager; + } + catch ( const css::uno::RuntimeException& ) + { + throw; + } + catch ( css::uno::Exception& ) + { + } + } + + if ( xLayoutManager.is() ) + { + css::uno::Sequence aMandatoryToolbars; + css::uno::Sequence aUserToolbars; + std::vector 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() ) + { + bDone = true; + break; + } + + const Sequence aModeNodeNames( aModesNode.getNodeNames() ); + const sal_Int32 nCount( aModeNodeNames.getLength() ); + + 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" ) ); + + if ( aCommandArg.compareTo( aNewName ) == 0 ) + { + aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence >(); + aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence >(); + aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) ); + break; + } + } + + if ( bCorrectMode ) + { + // Backup visible toolbar list and hide all toolbars + Sequence> aUIElements = xLayoutManager->getElements(); + for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ ) + { + Reference< XUIElement > xUIElement( aUIElements[i] ); + Reference< XPropertySet > xPropertySet( aUIElements[i], UNO_QUERY ); + if ( xPropertySet.is() && xUIElement.is() ) + { + 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& ) + { + } + } + } + + // 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 ) + { + 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 + for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst(); + pObjSh; + pObjSh = SfxObjectShell::GetNext( *pObjSh ) ) + { + const SfxPoolItem *pItem; + pObjSh->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, pItem); + } + + // Save settings + css::uno::Sequence 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; + + OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + + if ( aCommandArg.compareTo( aCurrentMode ) == 0 ) + { + aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) ); + break; + } + } + aModesNode.commit(); + } + } + + bDone = true; + break; + } case SID_AVAILABLE_TOOLBARS: { const SfxStringItem* pToolbarName = rReq.GetArg(SID_AVAILABLE_TOOLBARS); diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index c20e35e865a8..64be63f50da0 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -22,10 +22,15 @@ #include #include "NotebookBarPopupMenu.hxx" #include +#include +#include +#include +#include using namespace sfx2; using namespace css::uno; using namespace css::ui; +using namespace css; #define MENUBAR_STR "private:resource/menubar/menubar" @@ -41,35 +46,94 @@ void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) { - if (pSysWindow && pSysWindow->GetNotebookBar()) - pSysWindow->CloseNotebookBar(); + if (pSysWindow) + { + RemoveListeners(pSysWindow); + if(pSysWindow->GetNotebookBar()) + pSysWindow->CloseNotebookBar(); + } m_xLayoutManager.clear(); m_xFrame.clear(); } bool SfxNotebookBar::IsActive() { - SvtViewOptions aViewOpt(E_WINDOW, "notebookbar"); - return aViewOpt.IsVisible(); + const Reference xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame)); + + OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); + switch ( eApp ) + { + case vcl::EnumContext::Application::Application_Writer: + aPath.append("Writer"); + break; + case vcl::EnumContext::Application::Application_Calc: + aPath.append("Calc"); + break; + case vcl::EnumContext::Application::Application_Impress: + aPath.append("Impress"); + break; + case vcl::EnumContext::Application::Application_Draw: + aPath.append("Draw"); + break; + default: + break; + } + + const utl::OConfigurationTreeRoot aAppNode( + ::comphelper::getProcessComponentContext(), + aPath.makeStringAndClear(), + false); + if ( !aAppNode.isValid() ) + return false; + + OUString aActive = comphelper::getString( aAppNode.getNodeValue( "Active" ) ); + + const utl::OConfigurationNode aModesNode = aAppNode.openNode("Modes"); + const Sequence aModeNodeNames( aModesNode.getNodeNames() ); + const sal_Int32 nCount( aModeNodeNames.getLength() ); + bool bNotebookbarVisible = false; + + 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" ) ); + + if ( aCommandArg.compareTo( aActive ) == 0 ) + { + bNotebookbarVisible = comphelper::getBOOL( aModeNode.getNodeValue( "HasNotebookbar" ) ); + break; + } + } + return bNotebookbarVisible; } -void SfxNotebookBar::ExecMethod(SfxBindings& rBindings) +void SfxNotebookBar::ExecMethod(SfxBindings& rBindings, const OUString& rUIName) { - SvtViewOptions aViewOpt(E_WINDOW, "notebookbar"); - aViewOpt.SetVisible(!aViewOpt.IsVisible()); + // Save active UI file name + if ( !rUIName.isEmpty() ) + { + std::shared_ptr batch( + comphelper::ConfigurationChanges::create( ::comphelper::getProcessComponentContext() ) ); + officecfg::Office::UI::Notebookbar::Active::set( rUIName, batch ); + batch->commit(); + } // trigger the StateMethod rBindings.Invalidate(SID_NOTEBOOKBAR); rBindings.Update(); } -void SfxNotebookBar::StateMethod(SfxBindings& rBindings, const OUString& rUIFile) +bool SfxNotebookBar::StateMethod(SfxBindings& rBindings, const OUString& rUIFile) { SfxFrame& rFrame = rBindings.GetDispatcher_Impl()->GetFrame()->GetFrame(); - StateMethod(rFrame.GetSystemWindow(), rFrame.GetFrameInterface(), rUIFile); + return StateMethod(rFrame.GetSystemWindow(), rFrame.GetFrameInterface(), rUIFile); } -void SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, +bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, const Reference & xFrame, const OUString& rUIFile) { @@ -88,9 +152,7 @@ void SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, } } - SvtViewOptions aViewOpt(E_WINDOW, "notebookbar"); - - if (aViewOpt.IsVisible()) + if (IsActive()) { RemoveListeners(pSysWindow); @@ -122,9 +184,13 @@ void SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, } } } + + return true; } else if (auto pNotebookBar = pSysWindow->GetNotebookBar()) pNotebookBar->Hide(); + + return false; } void SfxNotebookBar::RemoveListeners(SystemWindow* pSysWindow) diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index e61cd8431f09..0aa352c1666f 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -1303,6 +1303,18 @@ void SidebarController::updateModel(const css::uno::ReferenceUpdateModel(xModel); } +void SidebarController::FadeOut() +{ + if (mpSplitWindow) + mpSplitWindow->FadeOut(); +} + +void SidebarController::FadeIn() +{ + if (mpSplitWindow) + mpSplitWindow->FadeIn(); +} + } } // end of namespace sfx2::sidebar -- cgit