officecfg/registry/schema/org/openoffice/Office/Common.xcs |    6 +
 sw/inc/strings.hrc                                         |    5 +
 sw/qa/extras/layout/layout.cxx                             |   18 ++++
 sw/qa/extras/layout/layout3.cxx                            |   48 +++++++++++++
 sw/qa/extras/layout/layout4.cxx                            |   18 ++++
 sw/source/uibase/uiview/view0.cxx                          |   27 ++++++-
 6 files changed, 119 insertions(+), 3 deletions(-)

New commits:
commit 4e461bb4e33eaabe54dcd6bb3a7f5b2dbce707be
Author:     marus087 <[email protected]>
AuthorDate: Mon May 12 15:39:54 2025 +0300
Commit:     Heiko Tietze <[email protected]>
CommitDate: Wed May 14 10:50:56 2025 +0200

    tdf#159444 Warn when View -> Field Names is activated
    
    Change-Id: I0a839ab93ac50e701329d3203ae8e2e655ee748c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185213
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <[email protected]>

diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 4de5cfadd07a..663d70a909b6 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -5426,6 +5426,12 @@
         </info>
         <value>true</value>
       </prop>
+      <prop oor:name="QueryShowFieldName" oor:type="xs:boolean" 
oor:nillable="false">
+        <info>
+          <desc>Determines whether to show the field name when entering the 
field mode.</desc>
+        </info>
+        <value>true</value>
+      </prop>
       <prop oor:name="QueryDeleteAllComments" oor:type="xs:boolean" 
oor:nillable="false">
         <info>
           <desc>Determines whether to confirm delete all comments or all by 
user.</desc>
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index 9c6b5b9d4d3e..6e1ac4888cce 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -1558,6 +1558,11 @@
 #define STR_QUERY_INSMODE_TEXT NC_("STR_QUERY_INSMODE_TEXT", "The overwrite 
mode allows to type over text. It is indicated by a block cursor and at the 
statusbar. Press Insert again to switch back.")
 #define STR_QUERY_INSMODE_QUESTION NC_("STR_QUERY_INSMODE_QUESTION", "Do you 
want to continue?")
 
+// To translators: title, text, question for confirmation whether to activate 
Field Names
+#define STR_QUERY_FIELDNAME_TITLE NC_("STR_QUERY_FIELDNAME_TITLE", "You 
activated Field Names")
+#define STR_QUERY_FIELDNAME_TEXT NC_("STR_QUERY_FIELDNAME_TEXT", "This will 
show the names of fields not as they appear in the final document but with 
their internal identifiers.")
+#define STR_QUERY_FIELDNAME_QUESTION NC_("STR_QUERY_FIELDNAME_QUESTION", "Do 
you want to activate Field Names?")
+
 // To translators: title and question for confirmation whether to delete all 
comments / all comments by author; text intentionally empty
 #define STR_QUERY_DELALLCOMMENTS_TITLE NC_("STR_QUERY_DELALLCOMMENTS_TITLE", 
"Confirm delete")
 #define STR_QUERY_DELALLCOMMENTS_QUESTION 
NC_("STR_QUERY_DELALLCOMMENTS_QUESTION", "Are you sure you want to delete all 
comments?")
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 2fee67640dd4..781830a1ef06 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -27,6 +27,8 @@
 #include <unoframe.hxx>
 #include <fldmgr.hxx>
 
+#include <officecfg/Office/Common.hxx>
+
 /// Test to assert layout / rendering result of Writer.
 class SwLayoutWriter : public SwModelTestBase
 {
@@ -761,6 +763,16 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInBody)
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testFlyHiddenParagraph)
 {
+    // disable Field Names warning dialog
+    const bool bAsk = 
officecfg::Office::Common::Misc::QueryShowFieldName::get();
+    std::shared_ptr<comphelper::ConfigurationChanges> xChanges;
+    if (bAsk)
+    {
+        xChanges = comphelper::ConfigurationChanges::create();
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(false, 
xChanges);
+        xChanges->commit();
+    }
+
     createSwDoc("fly_hidden_paragraph.fodt");
 
     // first, disable both so para gets hidden
@@ -807,6 +819,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testFlyHiddenParagraph)
     // so just hardcode it...
     dispatchCommand(mxComponent, ".uno:Fieldnames", args);
     Scheduler::ProcessEventsToIdle();
+
+    if (bAsk)
+    {
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
+        xChanges->commit();
+    }
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testFieldHideSection)
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 260b340a8d25..15034a6fb8b3 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -40,6 +40,8 @@
 #include <drawdoc.hxx>
 #include <svx/svdpage.hxx>
 
+#include <officecfg/Office/Common.hxx>
+
 namespace
 {
 /// Test to assert layout / rendering result of Writer.
@@ -1505,6 +1507,16 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testKeepWithNextPlusFlyFollowTextFlow)
         assertXPath(pXmlDoc, "/root/page", 1);
     }
 
+    // disable Field Names warning dialog
+    const bool bAsk = 
officecfg::Office::Common::Misc::QueryShowFieldName::get();
+    std::shared_ptr<comphelper::ConfigurationChanges> xChanges;
+    if (bAsk)
+    {
+        xChanges = comphelper::ConfigurationChanges::create();
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(false, 
xChanges);
+        xChanges->commit();
+    }
+
     dispatchCommand(mxComponent, u".uno:Fieldnames"_ustr, {});
 
     {
@@ -1535,6 +1547,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testKeepWithNextPlusFlyFollowTextFlow)
         assertXPath(pXmlDoc, "/root/page[1]/body/txt[3]/infos/bounds", 
"height", u"276");
         assertXPath(pXmlDoc, "/root/page", 1);
     }
+
+    if (bAsk)
+    {
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
+        xChanges->commit();
+    }
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf122607)
@@ -2431,6 +2449,15 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testHiddenParagraphFollowFrame)
         dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
     });
 
+    // disable Field Names warning dialog
+    const bool bAsk = 
officecfg::Office::Common::Misc::QueryShowFieldName::get();
+    std::shared_ptr<comphelper::ConfigurationChanges> xChanges;
+    if (bAsk)
+    {
+        xChanges = comphelper::ConfigurationChanges::create();
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(false, 
xChanges);
+        xChanges->commit();
+    }
     uno::Sequence<beans::PropertyValue> argsSH(
         comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
     dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
@@ -2446,6 +2473,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testHiddenParagraphFollowFrame)
         assertXPath(pXmlDoc, "/root/page[2]/body/txt", 2);
     }
 
+    if (bAsk)
+    {
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
+        xChanges->commit();
+    }
+
     dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", {});
 
     {
@@ -2477,6 +2510,15 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testHiddenParagraphFlys)
         dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
     });
 
+    // disable Field Names warning dialog
+    const bool bAsk = 
officecfg::Office::Common::Misc::QueryShowFieldName::get();
+    std::shared_ptr<comphelper::ConfigurationChanges> xChanges;
+    if (bAsk)
+    {
+        xChanges = comphelper::ConfigurationChanges::create();
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(false, 
xChanges);
+        xChanges->commit();
+    }
     uno::Sequence<beans::PropertyValue> argsSH(
         comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
     dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
@@ -2490,6 +2532,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testHiddenParagraphFlys)
         assertXPath(pXmlDoc, 
"/root/page/body/txt[3]/anchored/fly/infos/bounds", "height", u"724");
     }
 
+    if (bAsk)
+    {
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
+        xChanges->commit();
+    }
+
     dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", {});
 
     {
diff --git a/sw/qa/extras/layout/layout4.cxx b/sw/qa/extras/layout/layout4.cxx
index 8e5a12735c2d..a0556b1dce94 100644
--- a/sw/qa/extras/layout/layout4.cxx
+++ b/sw/qa/extras/layout/layout4.cxx
@@ -30,6 +30,8 @@
 #include <dcontact.hxx>
 #include <frameformats.hxx>
 
+#include <officecfg/Office/Common.hxx>
+
 namespace
 {
 /// Test to assert layout / rendering result of Writer.
@@ -46,6 +48,16 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, 
testHiddenSectionPageDescs)
 {
     createSwDoc("hidden-sections-with-pagestyles.odt");
 
+    // disable Field Names warning dialog
+    const bool bAsk = 
officecfg::Office::Common::Misc::QueryShowFieldName::get();
+    std::shared_ptr<comphelper::ConfigurationChanges> xChanges;
+    if (bAsk)
+    {
+        xChanges = comphelper::ConfigurationChanges::create();
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(false, 
xChanges);
+        xChanges->commit();
+    }
+
     // hide these just so that the height of the section is what is expected;
     // otherwise height depends on which tests run previously
     uno::Sequence<beans::PropertyValue> argsSH(
@@ -75,6 +87,12 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, 
testHiddenSectionPageDescs)
         assertXPath(pXmlDoc, "/root/page[2]", "formatName", u"Folgeseite");
     }
 
+    if (bAsk)
+    {
+        officecfg::Office::Common::Misc::QueryShowFieldName::set(true, 
xChanges);
+        xChanges->commit();
+    }
+
     // toggle one section hidden and other visible
     executeMacro(
         
u"vnd.sun.star.script:Standard.Module1.Main?language=Basic&location=document"_ustr);
diff --git a/sw/source/uibase/uiview/view0.cxx 
b/sw/source/uibase/uiview/view0.cxx
index 420f90bee2eb..f931a7387da1 100644
--- a/sw/source/uibase/uiview/view0.cxx
+++ b/sw/source/uibase/uiview/view0.cxx
@@ -73,6 +73,8 @@
 
 #include <sfx2/sidebar/SidebarController.hxx>
 
+#include <strings.hrc>
+
 using namespace ::com::sun::star;
 
 SFX_IMPL_NAMED_VIEWFACTORY(SwView, "Default")
@@ -558,12 +560,31 @@ void SwView::ExecViewOptions(SfxRequest &rReq)
         pOpt->SetViewAnyRuler( bFlag );
         break;
     case FN_VIEW_FIELDNAME:
+    {
         if( STATE_TOGGLE == eState )
             bFlag = !pOpt->IsFieldName() ;
-
-        pOpt->SetFieldName( bFlag );
+        const bool bDoAsk = 
officecfg::Office::Common::Misc::QueryShowFieldName::get();
+        short nresult = RET_YES;
+        if (bFlag && bDoAsk)
+        {
+            VclAbstractDialogFactory* pFact = 
VclAbstractDialogFactory::Create();
+            auto pDlg = pFact->CreateQueryDialog(
+                GetWrtShell().GetView().GetFrameWeld(), 
SwResId(STR_QUERY_FIELDNAME_TITLE),
+                SwResId(STR_QUERY_FIELDNAME_TEXT), 
SwResId(STR_QUERY_FIELDNAME_QUESTION), true);
+            nresult = pDlg->Execute();
+            if (pDlg->ShowAgain() == false)
+            {
+                std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
+                    comphelper::ConfigurationChanges::create());
+                
officecfg::Office::Common::Misc::QueryShowFieldName::set(false, xChanges);
+                xChanges->commit();
+            }
+            pDlg->disposeOnce();
+        }
+        if (nresult == RET_YES)
+            pOpt->SetFieldName(bFlag);
         break;
-
+    }
     case FN_VIEW_MARKS:
         if( STATE_TOGGLE == eState )
             bFlag = !lcl_IsViewMarks(*pOpt) ;

Reply via email to