include/sfx2/templatedlg.hxx                 |    2 --
 include/sfx2/templatedlglocalview.hxx        |    1 +
 sfx2/source/control/templatedlglocalview.cxx |    2 ++
 sfx2/source/doc/templatedlg.cxx              |   24 +++++++++---------------
 4 files changed, 12 insertions(+), 17 deletions(-)

New commits:
commit ff6043a3db629085f3f62423ebd6c8a97cdffc06
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Jan 13 22:40:09 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Jan 14 09:24:11 2026 +0100

    template dlg: Drop double bookkeeping of view mode
    
    Instead of having an `mViewMode` member to keep
    track of the current TemplateViewMode in both,
    SfxTemplateManagerDlg and its TemplateDlgLocalView,
    only maintain it in the TemplateDlgLocalView, and
    add a public getter to get the current view mode
    from there in TemplateDlgLocalView when needed.
    
    Change-Id: I9167874df309bb93d2dcc12dddb53b85e92da8d3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197228
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx
index f4bf100209b9..a1e0bcc799b4 100644
--- a/include/sfx2/templatedlg.hxx
+++ b/include/sfx2/templatedlg.hxx
@@ -134,7 +134,6 @@ protected:
     std::unique_ptr<weld::CustomWeld> mxLocalViewWeld;
     std::unique_ptr<weld::Toggleable> mxListViewButton;
     std::unique_ptr<weld::Toggleable> mxThumbnailViewButton;
-    TemplateViewMode mViewMode;
     bool bMakeSelItemVisible;
 };
 
diff --git a/include/sfx2/templatedlglocalview.hxx 
b/include/sfx2/templatedlglocalview.hxx
index 2d035c2cfec3..fbba7c166ddd 100644
--- a/include/sfx2/templatedlglocalview.hxx
+++ b/include/sfx2/templatedlglocalview.hxx
@@ -19,6 +19,7 @@ public:
                          std::unique_ptr<weld::TreeView> xTreeView);
 
     void setTemplateViewMode(TemplateViewMode eMode);
+    TemplateViewMode getTemplateViewMode() const;
 
     virtual void showAllTemplates() override;
 
diff --git a/sfx2/source/control/templatedlglocalview.cxx 
b/sfx2/source/control/templatedlglocalview.cxx
index 17e4dcb6de66..1bd21f0a0a10 100644
--- a/sfx2/source/control/templatedlglocalview.cxx
+++ b/sfx2/source/control/templatedlglocalview.cxx
@@ -240,6 +240,8 @@ void TemplateDlgLocalView::insertItems(const 
std::vector<TemplateItemProperties>
 
 void TemplateDlgLocalView::setTemplateViewMode(TemplateViewMode eMode) { 
mViewMode = eMode; }
 
+TemplateViewMode TemplateDlgLocalView::getTemplateViewMode() const { return 
mViewMode; }
+
 void TemplateDlgLocalView::Show()
 {
     if (mViewMode == TemplateViewMode::ListView)
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index a673a0ff24f5..221d5615e6d3 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -167,7 +167,6 @@ SfxTemplateManagerDlg::SfxTemplateManagerDlg(weld::Window 
*pParent)
     , mxLocalViewWeld(new weld::CustomWeld(*m_xBuilder, u"template_view"_ustr, 
maLocalView))
     , mxListViewButton(m_xBuilder->weld_toggle_button(u"list_view_btn"_ustr))
     , 
mxThumbnailViewButton(m_xBuilder->weld_toggle_button(u"thumbnail_view_btn"_ustr))
-    , mViewMode(TemplateViewMode::ThumbnailView)
 {
     // Create popup menus
     mxActionBar->append_item(MNI_ACTION_NEW_FOLDER, 
SfxResId(STR_CATEGORY_NEW), BMP_ACTION_NEW_CATEGORY);
@@ -287,7 +286,7 @@ void SfxTemplateManagerDlg::setDocumentModel(const 
uno::Reference<frame::XModel>
 
 void SfxTemplateManagerDlg::setTemplateViewMode(TemplateViewMode eViewMode)
 {
-    if (mViewMode == eViewMode)
+    if (maLocalView.getTemplateViewMode() == eViewMode)
         return;
 
     if (eViewMode == TemplateViewMode::ThumbnailView)
@@ -304,7 +303,6 @@ void 
SfxTemplateManagerDlg::setTemplateViewMode(TemplateViewMode eViewMode)
         maLocalView.ListView::grab_focus();
     }
 
-    mViewMode = eViewMode;
     maLocalView.setTemplateViewMode(eViewMode);
     maLocalView.Show();
 }
@@ -460,7 +458,7 @@ void SfxTemplateManagerDlg::writeSettings ()
     {
         { TM_SETTING_LASTFOLDER, css::uno::Any(aLastFolder) },
         { TM_SETTING_LASTAPPLICATION,     
css::uno::Any(sal_uInt16(mxCBApp->get_active())) },
-        { TM_SETTING_VIEWMODE, 
css::uno::Any(static_cast<sal_Int16>(mViewMode)) }
+        { TM_SETTING_VIEWMODE, 
css::uno::Any(static_cast<sal_Int16>(maLocalView.getTemplateViewMode())) }
     };
 
     // write
commit ad90881c9652825776bb062ed16b3792a0606f7e
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Jan 13 22:34:44 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Jan 14 09:24:05 2026 +0100

    sfx2: Simplify/Deduplicate SfxTemplateManagerDlg::setTemplateViewMode
    
    Return early if the view mode hasn't changed.
    Share some code that is the same for both view modes.
    
    Also switch the second `if` checking for the view
    mode to an `else` and add an assert that the
    only other valid view mode, TemplateViewMode::ListView,
    is actually used.
    
    Change-Id: I07c17086da51bc7385da9910f6d38e19b993b3d2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197227
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 92d57a08716d..a673a0ff24f5 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -287,24 +287,26 @@ void SfxTemplateManagerDlg::setDocumentModel(const 
uno::Reference<frame::XModel>
 
 void SfxTemplateManagerDlg::setTemplateViewMode(TemplateViewMode eViewMode)
 {
-    if (eViewMode == TemplateViewMode::ThumbnailView && mViewMode != 
TemplateViewMode::ThumbnailView)
+    if (mViewMode == eViewMode)
+        return;
+
+    if (eViewMode == TemplateViewMode::ThumbnailView)
     {
         mxThumbnailViewButton->set_active(true);
         mxListViewButton->set_active(false);
         maLocalView.ThumbnailView::GrabFocus();
-        mViewMode = eViewMode;
-        maLocalView.setTemplateViewMode(eViewMode);
-        maLocalView.Show();
     }
-    if (eViewMode == TemplateViewMode::ListView && mViewMode != 
TemplateViewMode::ListView)
+    else
     {
+        assert(eViewMode == TemplateViewMode::ListView);
         mxListViewButton->set_active(true);
         mxThumbnailViewButton->set_active(false);
         maLocalView.ListView::grab_focus();
-        mViewMode = eViewMode;
-        maLocalView.setTemplateViewMode(eViewMode);
-        maLocalView.Show();
     }
+
+    mViewMode = eViewMode;
+    maLocalView.setTemplateViewMode(eViewMode);
+    maLocalView.Show();
 }
 
 FILTER_APPLICATION SfxTemplateManagerDlg::getCurrentApplicationFilter() const
commit 89b187d683f3768a6f8f16a684061f6197991c5a
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Jan 13 22:25:32 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Jan 14 09:23:58 2026 +0100

    sfx2: Drop SfxTemplateManagerDlg::getTemplateViewMode
    
    No need for a public getter, as this is only used
    internally. Access the member directly instead.
    
    Change-Id: I8f0b0bd3785721e95c98a8216425883bce41bf6c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197226
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/include/sfx2/templatedlg.hxx b/include/sfx2/templatedlg.hxx
index f5e46a01440b..f4bf100209b9 100644
--- a/include/sfx2/templatedlg.hxx
+++ b/include/sfx2/templatedlg.hxx
@@ -49,7 +49,6 @@ public:
 
     SAL_DLLPRIVATE void setDocumentModel(const 
css::uno::Reference<css::frame::XModel>& rModel);
     SAL_DLLPRIVATE void setTemplateViewMode(TemplateViewMode eViewMode);
-    SAL_DLLPRIVATE TemplateViewMode getTemplateViewMode() const;
 
 protected:
     SAL_DLLPRIVATE void getApplicationSpecificSettings();
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index cb4df13b4a66..92d57a08716d 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -307,12 +307,6 @@ void 
SfxTemplateManagerDlg::setTemplateViewMode(TemplateViewMode eViewMode)
     }
 }
 
-TemplateViewMode SfxTemplateManagerDlg::getTemplateViewMode() const
-{
-    return mViewMode;
-}
-
-
 FILTER_APPLICATION SfxTemplateManagerDlg::getCurrentApplicationFilter() const
 {
     const sal_Int16 nCurAppId = mxCBApp->get_active();
@@ -464,7 +458,7 @@ void SfxTemplateManagerDlg::writeSettings ()
     {
         { TM_SETTING_LASTFOLDER, css::uno::Any(aLastFolder) },
         { TM_SETTING_LASTAPPLICATION,     
css::uno::Any(sal_uInt16(mxCBApp->get_active())) },
-        { TM_SETTING_VIEWMODE, 
css::uno::Any(static_cast<sal_Int16>(getTemplateViewMode()))}
+        { TM_SETTING_VIEWMODE, 
css::uno::Any(static_cast<sal_Int16>(mViewMode)) }
     };
 
     // write

Reply via email to