include/sfx2/notebookbar/SfxNotebookBar.hxx |    3 +++
 sfx2/source/notebookbar/SfxNotebookBar.cxx  |   27 ++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

New commits:
commit ed94d44c5130373c721a8345492a8ee47fd651a3
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Feb 22 13:03:24 2022 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Apr 25 11:31:54 2022 +0200

    lok: reset ui mode state when switch to notebookbar cancelled
    
    We have to keep state in the register in sync with the view.
    When we cancelled notebookbar usage we need to revert Default state
    so next time we will be able to activate notebookbar.
    
    Change-Id: Ie5f7d0160c9c22c6621aca73b2cdd7197f86ff78
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130341
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/include/sfx2/notebookbar/SfxNotebookBar.hxx 
b/include/sfx2/notebookbar/SfxNotebookBar.hxx
index acc5a9c50250..0bf6aee29ba7 100644
--- a/include/sfx2/notebookbar/SfxNotebookBar.hxx
+++ b/include/sfx2/notebookbar/SfxNotebookBar.hxx
@@ -12,6 +12,7 @@
 
 #include <sfx2/dllapi.h>
 #include <rtl/ustring.hxx>
+#include <vcl/EnumContext.hxx>
 #include <map>
 
 namespace com::sun::star::frame
@@ -72,6 +73,8 @@ private:
     static std::map<const SfxViewShell*, 
std::shared_ptr<WeldedTabbedNotebookbar>>
         m_pNotebookBarWeldedWrapper;
 
+    static void ResetActiveToolbarModeToDefault(vcl::EnumContext::Application 
eApp);
+
     DECL_STATIC_LINK(SfxNotebookBar, VclDisposeHdl, const SfxViewShell*, void);
 };
 
diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx 
b/sfx2/source/notebookbar/SfxNotebookBar.cxx
index e991ac9e6877..4c08e7b60bab 100644
--- a/sfx2/source/notebookbar/SfxNotebookBar.cxx
+++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx
@@ -300,6 +300,26 @@ bool SfxNotebookBar::IsActive()
     return false;
 }
 
+void 
SfxNotebookBar::ResetActiveToolbarModeToDefault(vcl::EnumContext::Application 
eApp)
+{
+    const OUString appName( lcl_getAppName( eApp ) );
+
+    if ( appName.isEmpty() )
+        return;
+
+    const OUString aPath = 
"org.openoffice.Office.UI.ToolbarMode/Applications/" + appName;
+
+    utl::OConfigurationTreeRoot aAppNode(
+                                        
::comphelper::getProcessComponentContext(),
+                                        aPath,
+                                        true);
+    if ( !aAppNode.isValid() )
+        return;
+
+    aAppNode.setNodeValue( "Active", makeAny( OUString( "Default" ) ) );
+    aAppNode.commit();
+}
+
 void SfxNotebookBar::ExecMethod(SfxBindings& rBindings, const OUString& 
rUIName)
 {
     // Save active UI file name
@@ -345,9 +365,13 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
         const Reference<frame::XModuleManager> xModuleManager  = 
frame::ModuleManager::create( xContext );
         OUString aModuleName = xModuleManager->identify( xFrame );
         vcl::EnumContext::Application eApp = 
vcl::EnumContext::GetApplicationEnum( aModuleName );
-        OUString sFile = lcl_getNotebookbarFileName( eApp );
+
+        OUString sFile;
         if (comphelper::LibreOfficeKit::isActive())
             sFile = "notebookbar_online.ui";
+        else
+            sFile = lcl_getNotebookbarFileName( eApp );
+
         OUString sNewFile = rUIFile + sFile;
         OUString sCurrentFile;
         VclPtr<NotebookBar> pNotebookBar = pSysWindow->GetNotebookBar();
@@ -369,6 +393,7 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
                 && bSkippedFirstInit.find(pViewShell) == 
bSkippedFirstInit.end())
             {
                 bSkippedFirstInit[pViewShell] = true;
+                ResetActiveToolbarModeToDefault(eApp);
                 return false;
             }
 

Reply via email to