officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu |    8 ++
 sw/inc/cmdid.h                                                      |    1 
 sw/qa/uibase/shells/shells.cxx                                      |   29 
++++++++++
 sw/sdi/_textsh.sdi                                                  |    6 ++
 sw/sdi/swriter.sdi                                                  |   18 
++++++
 sw/source/uibase/shells/textfld.cxx                                 |   20 
++++++
 sw/uiconfig/swriter/menubar/menubar.xml                             |    1 
 sw/uiconfig/swriter/popupmenu/table.xml                             |    1 
 sw/uiconfig/swriter/popupmenu/text.xml                              |    1 
 9 files changed, 85 insertions(+)

New commits:
commit 627a601d1fcea0b3198654756d351b0b81600b49
Author:     TokieSan <elto...@aucegypt.edu>
AuthorDate: Sat Apr 15 19:05:12 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon May 15 08:56:46 2023 +0200

    tdf#148979 Added option to update selected field
    
    Added Uno command UpdateSelectedField, FN_UPDATE_SEL_FIELD
    to support updating a single selected field
    
    Change-Id: Ia1a2387e137f8a672a24056b13234d4275a77ca4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150450
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git 
a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu 
b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
index 8e9715c24acd..617901255c4b 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu
@@ -1636,6 +1636,14 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:UpdateSelectedField" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Update Selected Field</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:LinkDialog" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">E~xternal Links...</value>
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 5459c63b8ff1..d330f36966bd 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -78,6 +78,7 @@ class SwUINumRuleItem;
 #define FN_EDIT_LINK_DLG        (FN_EDIT + 9 )    /* Edit link dialog */
 
 #define FN_NUMBER_BULLETS       (FN_EDIT + 21)    /* Bullets */
+#define FN_UPDATE_SEL_FIELD     (FN_EDIT + 22 )   /* Update selected field */
 #define FN_EDIT_IDX_ENTRY_DLG   (FN_EDIT + 23)    /* Edit Index-Entry */
 #define FN_UPDATE_FIELDS        (FN_EDIT + 26)    /* Update fields */
 #define FN_EXECUTE_MACROFIELD   (FN_EDIT + 27)    /* Execute macrofield */
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 8c251cb09f87..c962f4a5d65e 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -28,6 +28,7 @@
 #include <comphelper/string.hxx>
 #include <comphelper/propertysequence.hxx>
 #include <comphelper/sequence.hxx>
+#include <osl/thread.hxx>
 
 #include <IDocumentContentOperations.hxx>
 #include <cmdid.h>
@@ -1049,6 +1050,34 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testInsertTextFormFieldEndnote)
     CPPUNIT_ASSERT_EQUAL(OUString("result"), aActual);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateSelectedField)
+{
+    // Given an empty doc:
+    createSwDoc();
+    SwDoc* pDoc = getSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
+
+    // Insert a time field and select it:
+    dispatchCommand(mxComponent, ".uno:InsertTimeField", {});
+
+    pCursor->SetMark();
+    pCursor->Move(fnMoveBackward);
+
+    OUString aTimeFieldBefore, aTimeFieldAfter;
+    pWrtShell->GetSelectedText(aTimeFieldBefore);
+
+    // Wait for one second:
+    osl::Thread::wait(std::chrono::seconds(1));
+
+    // Update the field at cursor:
+    dispatchCommand(mxComponent, ".uno:UpdateSelectedField", {});
+    pWrtShell->GetSelectedText(aTimeFieldAfter);
+
+    // Check that the selected field has changed:
+    CPPUNIT_ASSERT(aTimeFieldAfter != aTimeFieldBefore);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index 45f6eb7c9bdb..086a7622b137 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -1010,6 +1010,12 @@ interface BaseText
         StateMethod = StateField ;
         DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
     ]
+    FN_UPDATE_SEL_FIELD
+    [
+        ExecMethod = ExecField ;
+        StateMethod = StateField ;
+        DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
+    ]
     FN_GLOSSARY_DLG // status()
     [
         ExecMethod = ExecGlossary ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 15d098cc996c..b765d861e34a 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -1246,6 +1246,24 @@ SfxVoidItem FieldDialog FN_EDIT_FIELD
     GroupId = SfxGroupId::Edit;
 ]
 
+SfxVoidItem UpdateSelectedField FN_UPDATE_SEL_FIELD
+()
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Edit;
+]
+
 SfxBoolItem Fieldnames FN_VIEW_FIELDNAME
 
 [
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index d3b3d6853dff..4d9c50a44324 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -153,6 +153,16 @@ void SwTextShell::ExecField(SfxRequest &rReq)
             }
             break;
         }
+        case FN_UPDATE_SEL_FIELD:
+        {
+            SwField *pField = rSh.GetCurField();
+
+            if (pField)
+            {
+               rSh.UpdateOneField(*pField);
+            }
+            break;
+        }
         case FN_EXECUTE_MACROFIELD:
         {
             SwField* pField = rSh.GetCurField();
@@ -1453,6 +1463,16 @@ void SwTextShell::StateField( SfxItemSet &rSet )
             }
             break;
 
+        case FN_UPDATE_SEL_FIELD:
+            {
+                pField = rSh.GetCurField();
+
+                if (!pField)
+                    rSet.DisableItem( nWhich );
+            }
+
+            break;
+
         case FN_EXECUTE_MACROFIELD:
             {
                 if(!bGetField)
diff --git a/sw/uiconfig/swriter/menubar/menubar.xml 
b/sw/uiconfig/swriter/menubar/menubar.xml
index a85022ccdd5e..20a0593ac499 100644
--- a/sw/uiconfig/swriter/menubar/menubar.xml
+++ b/sw/uiconfig/swriter/menubar/menubar.xml
@@ -777,6 +777,7 @@
           <menu:menuitem menu:id=".uno:UpdateAll"/>
           <menu:menuseparator/>
           <menu:menuitem menu:id=".uno:Repaginate"/>
+          <menu:menuitem menu:id=".uno:UpdateSelectedField"/>
           <menu:menuitem menu:id=".uno:UpdateFields"/>
           <menu:menuitem menu:id=".uno:UpdateAllIndexes"/>
           <menu:menuitem menu:id=".uno:UpdateCurIndex"/>
diff --git a/sw/uiconfig/swriter/popupmenu/table.xml 
b/sw/uiconfig/swriter/popupmenu/table.xml
index 30449122097a..d8a3254b0b61 100644
--- a/sw/uiconfig/swriter/popupmenu/table.xml
+++ b/sw/uiconfig/swriter/popupmenu/table.xml
@@ -126,6 +126,7 @@
   <menu:menuseparator/>
   <menu:menuitem menu:id=".uno:InsertFormula"/>
   <menu:menuitem menu:id=".uno:InsertAnnotation"/>
+  <menu:menuitem menu:id=".uno:UpdateSelectedField"/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:AcceptTrackedChange"/>
   <menu:menuitem menu:id=".uno:RejectTrackedChange"/>
diff --git a/sw/uiconfig/swriter/popupmenu/text.xml 
b/sw/uiconfig/swriter/popupmenu/text.xml
index 47d0ac89039d..8a01aa97ca6d 100644
--- a/sw/uiconfig/swriter/popupmenu/text.xml
+++ b/sw/uiconfig/swriter/popupmenu/text.xml
@@ -22,6 +22,7 @@
   <menu:menuitem menu:id=".uno:EditCurIndex"/>
   <menu:menuitem menu:id=".uno:RemoveTableOf"/>
   <menu:menuseparator/>
+  <menu:menuitem menu:id=".uno:UpdateSelectedField"/>
   <menu:menuitem menu:id=".uno:FieldDialog"/>
   <menu:menuitem menu:id=".uno:EditFootnote"/>
   <menu:menuitem menu:id=".uno:IndexEntryDialog"/>

Reply via email to