sw/inc/strings.hrc                   |    5 +
 sw/source/ui/index/swuiidxmrk.cxx    |   94 ++++++++++++++++++++++++++++++-----
 sw/source/uibase/inc/swuiidxmrk.hxx  |    8 ++
 sw/uiconfig/swriter/ui/indexentry.ui |   11 +---
 4 files changed, 100 insertions(+), 18 deletions(-)

New commits:
commit ec7389d5975bb584b1d7a0e13ba412b4d8920f99
Author:     Alexandru Babacea <[email protected]>
AuthorDate: Thu May 15 23:40:43 2025 +0300
Commit:     Heiko Tietze <[email protected]>
CommitDate: Wed May 28 14:31:22 2025 +0200

    tdf#156055 Edit Index Entry dialog saving changes
    
    Modified the Close button functionality so that a warning
    message is displayed if there are unsaved changes.
    
    Removed Apply button.
    
    Added a Reset button that restores the current index entry
    if it was modified.
    
    Change-Id: I20d0d07794a27abda7830ba4b34ba412e755369f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185373
    Tested-by: Jenkins
    Reviewed-by: Heiko Tietze <[email protected]>

diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index d6797a26a0b1..edbc744db6a0 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -1568,6 +1568,11 @@
 #define STR_QUERY_DELALLCOMMENTS_QUESTION 
NC_("STR_QUERY_DELALLCOMMENTS_QUESTION", "Are you sure you want to delete all 
comments?")
 #define STR_QUERY_DELALLCOMMENTSAUTHOR_QUESTION 
NC_("STR_QUERY_DELALLCOMMENTS_QUESTION", "Are you sure you want to delete all 
comments by %AUTHOR?")
 
+// To translators: title, text, question for confirmation whether to switch 
overwrite mode on
+#define STR_QUERY_CLOSE_TITLE NC_("STR_QUERY_CLOSE_TITLE", "Confirm changes")
+#define STR_QUERY_CLOSE_TEXT NC_("STR_QUERY_CLOSE_TEXT", "The current index 
entry was modified.")
+#define STR_QUERY_CLOSE_QUESTION NC_("STR_QUERY_CLOSE_QUESTION", "Do you want 
to save changes?")
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/index/swuiidxmrk.cxx 
b/sw/source/ui/index/swuiidxmrk.cxx
index f75736fcb7bf..5c6e7456c80d 100644
--- a/sw/source/ui/index/swuiidxmrk.cxx
+++ b/sw/source/ui/index/swuiidxmrk.cxx
@@ -58,6 +58,9 @@
 #include <doc.hxx>
 #include <docsh.hxx>
 
+#include <strings.hrc>
+#include <vcl/abstdlg.hxx>
+
 #define POS_CONTENT 0
 #define POS_INDEX   1
 
@@ -134,6 +137,7 @@ 
SwIndexMarkPane::SwIndexMarkPane(std::shared_ptr<weld::Dialog> xDialog, weld::Bu
     , m_bDel(false)
     , m_bNewMark(bNewDlg)
     , m_bSelected(false)
+    , m_bModified(false)
     , m_bPhoneticED0_ChangedByUser(false)
     , m_bPhoneticED1_ChangedByUser(false)
     , m_bPhoneticED2_ChangedByUser(false)
@@ -161,8 +165,9 @@ 
SwIndexMarkPane::SwIndexMarkPane(std::shared_ptr<weld::Dialog> xDialog, weld::Bu
     , m_xApplyToAllCB(rBuilder.weld_check_button(u"applytoallcb"_ustr))
     , 
m_xSearchCaseSensitiveCB(rBuilder.weld_check_button(u"searchcasesensitivecb"_ustr))
     , 
m_xSearchCaseWordOnlyCB(rBuilder.weld_check_button(u"searchcasewordonlycb"_ustr))
-    , m_xOKBT(bNewDlg ? rBuilder.weld_button(u"insert"_ustr) : 
rBuilder.weld_button(u"ok"_ustr))
+    , m_xOKBT(rBuilder.weld_button(u"insert"_ustr))
     , m_xCloseBT(rBuilder.weld_button(u"close"_ustr))
+    , m_xResetBT(rBuilder.weld_button(u"reset"_ustr))
     , m_xDelBT(rBuilder.weld_button(u"delete"_ustr))
     , m_xPrevSameBT(rBuilder.weld_button(u"first"_ustr))
     , m_xNextSameBT(rBuilder.weld_button(u"last"_ustr))
@@ -210,6 +215,7 @@ 
SwIndexMarkPane::SwIndexMarkPane(std::shared_ptr<weld::Dialog> xDialog, weld::Bu
     m_xKey1DCB->connect_changed(LINK(this,SwIndexMarkPane,      
KeyDCBModifyHdl));
     m_xKey2DCB->connect_changed(LINK(this,SwIndexMarkPane,     
KeyDCBModifyHdl));
     m_xCloseBT->connect_clicked(LINK(this,SwIndexMarkPane,      CloseHdl));
+    m_xResetBT->connect_clicked(LINK(this,SwIndexMarkPane,      ResetHdl));
     m_xEntryED->connect_changed(LINK(this,SwIndexMarkPane,     ModifyEditHdl));
     m_xNewBT->connect_clicked(LINK(this, SwIndexMarkPane,       
NewUserIdxHdl));
     m_xApplyToAllCB->connect_toggled(LINK(this, SwIndexMarkPane, 
SearchTypeHdl));
@@ -218,11 +224,22 @@ 
SwIndexMarkPane::SwIndexMarkPane(std::shared_ptr<weld::Dialog> xDialog, weld::Bu
     m_xPhoneticED2->connect_changed(LINK(this,SwIndexMarkPane, 
PhoneticEDModifyHdl));
     m_xSyncED->connect_clicked(LINK(this, SwIndexMarkPane, SyncSelectionHdl));
 
+    m_xSearchCaseWordOnlyCB->connect_toggled(LINK(this, SwIndexMarkPane, 
GenericToggleModifiedHdl));
+    m_xSearchCaseSensitiveCB->connect_toggled(LINK(this, SwIndexMarkPane, 
GenericToggleModifiedHdl));
+    m_xMainEntryCB->connect_toggled(LINK(this, SwIndexMarkPane, 
GenericToggleModifiedHdl));
+    m_xLevelNF->connect_changed(LINK(this, SwIndexMarkPane, 
GenericEntryModifiedHdl));
+
     if (m_bNewMark)
+    {
         m_xDelBT->hide();
+        m_xOKBT->show();
+    }
     else
+    {
         m_xNewBT->hide();
-    m_xOKBT->show();
+        m_xResetBT->show();
+        m_xResetBT->set_sensitive(m_bModified);
+    }
     m_xOKBT->connect_clicked(LINK(this, SwIndexMarkPane, InsertHdl));
 
     m_xEntryED->grab_focus();
@@ -492,6 +509,8 @@ void SwIndexMarkPane::InsertUpdate()
 
     nKey1Pos = m_xKey1DCB->find_text(m_xKey1DCB->get_active_text());
     nKey2Pos = m_xKey2DCB->find_text(m_xKey2DCB->get_active_text());
+
+    SetModified(false);
 }
 
 // insert mark
@@ -672,21 +691,26 @@ IMPL_LINK_NOARG(SwIndexMarkPane, NewUserIdxHdl, 
weld::Button&, void)
 
 IMPL_LINK( SwIndexMarkPane, SearchTypeHdl, weld::Toggleable&, rBox, void)
 {
+    SetModified(true);
     const bool bEnable = rBox.get_active() && rBox.get_sensitive();
     m_xSearchCaseWordOnlyCB->set_sensitive(bEnable);
     m_xSearchCaseSensitiveCB->set_sensitive(bEnable);
 }
 
-IMPL_LINK(SwIndexMarkPane, InsertHdl, weld::Button&, rButton, void)
+IMPL_LINK_NOARG(SwIndexMarkPane, InsertHdl, weld::Button&, void)
 {
     Apply();
-    //close the dialog if only one entry is available
-    if(!m_bNewMark && !m_xPrevBT->get_visible() && !m_xNextBT->get_visible())
-        CloseHdl(rButton);
 }
 
 IMPL_LINK_NOARG(SwIndexMarkPane, CloseHdl, weld::Button&, void)
 {
+    if (!m_bDel && m_bModified &&
+        (!m_bNewMark ||
+         (!m_pSh->HasReadonlySel() &&
+         (!m_xEntryED->get_text().isEmpty() || m_pSh->GetCursorCnt(false)))
+        ) && ShowWarning4Modifications() == RET_YES)
+            Apply();
+
     if (m_bNewMark)
     {
         if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
@@ -696,22 +720,49 @@ IMPL_LINK_NOARG(SwIndexMarkPane, CloseHdl, weld::Button&, 
void)
         }
     }
     else
-    {
         m_xDialog->response(RET_CLOSE);
-    }
+}
+
+IMPL_LINK_NOARG(SwIndexMarkPane, ResetHdl, weld::Button&, void)
+{
+    UpdateDialog();
+}
+
+IMPL_LINK_NOARG(SwIndexMarkPane, GenericEntryModifiedHdl, weld::Entry&, void)
+{
+    SetModified(true);
+}
+
+IMPL_LINK_NOARG(SwIndexMarkPane, GenericToggleModifiedHdl, weld::Toggleable&, 
void)
+{
+    SetModified(true);
 }
 
 // select index type only when inserting
 IMPL_LINK(SwIndexMarkPane, ModifyListBoxHdl, weld::ComboBox&, rBox, void)
 {
+    SetModified(true);
     ModifyHdl(rBox);
 }
 
 IMPL_LINK(SwIndexMarkPane, ModifyEditHdl, weld::Entry&, rEdit, void)
 {
+    SetModified(true);
     ModifyHdl(rEdit);
 }
 
+short SwIndexMarkPane::ShowWarning4Modifications()
+{
+    short nresult = RET_NO;
+    VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
+    auto pDlg = pFact->CreateQueryDialog(
+        m_xDialog.get(), SwResId(STR_QUERY_CLOSE_TITLE),
+        SwResId(STR_QUERY_CLOSE_TEXT), SwResId(STR_QUERY_CLOSE_QUESTION), 
false);
+    nresult = pDlg->Execute();
+
+    return nresult;
+}
+
 void SwIndexMarkPane::ModifyHdl(const weld::Widget& rBox)
 {
     if (m_xTypeDCB.get() == &rBox)
@@ -788,28 +839,32 @@ void SwIndexMarkPane::ModifyHdl(const weld::Widget& rBox)
 
 IMPL_LINK_NOARG(SwIndexMarkPane, NextHdl, weld::Button&, void)
 {
-    InsertUpdate();
+    if (m_bModified && ShowWarning4Modifications() == RET_YES)
+        InsertUpdate();
     m_pTOXMgr->NextTOXMark();
     UpdateDialog();
 }
 
 IMPL_LINK_NOARG(SwIndexMarkPane, NextSameHdl, weld::Button&, void)
 {
-    InsertUpdate();
+    if (m_bModified && ShowWarning4Modifications() == RET_YES)
+        InsertUpdate();
     m_pTOXMgr->NextTOXMark(true);
     UpdateDialog();
 }
 
 IMPL_LINK_NOARG(SwIndexMarkPane, PrevHdl, weld::Button&, void)
 {
-    InsertUpdate();
+    if (m_bModified && ShowWarning4Modifications() == RET_YES)
+        InsertUpdate();
     m_pTOXMgr->PrevTOXMark();
     UpdateDialog();
 }
 
 IMPL_LINK_NOARG(SwIndexMarkPane, PrevSameHdl, weld::Button&, void)
 {
-    InsertUpdate();
+    if (m_bModified && ShowWarning4Modifications() == RET_YES)
+        InsertUpdate();
     m_pTOXMgr->PrevTOXMark(true);
     UpdateDialog();
 }
@@ -824,7 +879,9 @@ IMPL_LINK_NOARG(SwIndexMarkPane, DelHdl, weld::Button&, 
void)
         UpdateDialog();
     else
     {
+        m_bDel = true;
         CloseHdl(*m_xCloseBT);
+        m_bDel = false;
         if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
             pViewFrm->GetBindings().Invalidate(FN_EDIT_IDX_ENTRY_DLG);
     }
@@ -933,11 +990,14 @@ void SwIndexMarkPane::UpdateDialog()
     m_pSh->SwapPam();
 
     m_pSh->EndCursorMove();
+
+    SetModified(false);
 }
 
 // Remind whether the edit boxes for Phonetic reading are changed manually
 IMPL_LINK(SwIndexMarkPane, PhoneticEDModifyHdl, weld::Entry&, rEdit, void)
 {
+    SetModified(true);
     if (m_xPhoneticED0.get() == &rEdit)
     {
         m_bPhoneticED0_ChangedByUser = !rEdit.get_text().isEmpty();
@@ -955,6 +1015,7 @@ IMPL_LINK(SwIndexMarkPane, PhoneticEDModifyHdl, 
weld::Entry&, rEdit, void)
 // Enable Disable of the 2nd key
 IMPL_LINK( SwIndexMarkPane, KeyDCBModifyHdl, weld::ComboBox&, rBox, void )
 {
+    SetModified(true);
     if (m_xKey1DCB.get() == &rBox)
     {
         bool bEnable = !rBox.get_active_text().isEmpty();
@@ -1007,6 +1068,15 @@ IMPL_LINK( SwIndexMarkPane, KeyDCBModifyHdl, 
weld::ComboBox&, rBox, void )
     m_xPhoneticED2->set_sensitive(bKey2HasText && m_bIsPhoneticReadingEnabled);
 }
 
+void SwIndexMarkPane::SetModified(bool bModified)
+{
+    if (m_bModified == bModified)
+        return;
+
+    m_bModified = bModified;
+    m_xResetBT->set_sensitive(bModified);
+}
+
 SwIndexMarkPane::~SwIndexMarkPane()
 {
 }
diff --git a/sw/source/uibase/inc/swuiidxmrk.hxx 
b/sw/source/uibase/inc/swuiidxmrk.hxx
index 9f90ce36f398..fc2191c2bbbe 100644
--- a/sw/source/uibase/inc/swuiidxmrk.hxx
+++ b/sw/source/uibase/inc/swuiidxmrk.hxx
@@ -43,6 +43,7 @@ class SwIndexMarkPane
     bool            m_bDel;
     bool const      m_bNewMark;
     bool            m_bSelected;
+    bool            m_bModified;
 
     bool            m_bPhoneticED0_ChangedByUser;
     bool            m_bPhoneticED1_ChangedByUser;
@@ -79,6 +80,7 @@ class SwIndexMarkPane
     std::unique_ptr<weld::CheckButton> m_xSearchCaseWordOnlyCB;
     std::unique_ptr<weld::Button> m_xOKBT;
     std::unique_ptr<weld::Button> m_xCloseBT;
+    std::unique_ptr<weld::Button> m_xResetBT;
     std::unique_ptr<weld::Button> m_xDelBT;
     std::unique_ptr<weld::Button> m_xPrevSameBT;
     std::unique_ptr<weld::Button> m_xNextSameBT;
@@ -93,6 +95,9 @@ class SwIndexMarkPane
 
     DECL_LINK(InsertHdl, weld::Button&, void);
     DECL_LINK(CloseHdl, weld::Button&, void);
+    DECL_LINK(ResetHdl, weld::Button&, void);
+    DECL_LINK(GenericEntryModifiedHdl, weld::Entry&, void);
+    DECL_LINK(GenericToggleModifiedHdl, weld::Toggleable&, void);
     DECL_LINK(SyncSelectionHdl, weld::Button&, void);
     DECL_LINK(DelHdl, weld::Button&, void);
     DECL_LINK( NextHdl, weld::Button&, void );
@@ -119,6 +124,9 @@ class SwIndexMarkPane
     void            InsertUpdate();
 
     void            Activate();
+    void            SetModified(bool bModified);
+
+    short           ShowWarning4Modifications();
 
 public:
 
diff --git a/sw/uiconfig/swriter/ui/indexentry.ui 
b/sw/uiconfig/swriter/ui/indexentry.ui
index 916e2a3b865a..81cf45dfeb90 100644
--- a/sw/uiconfig/swriter/ui/indexentry.ui
+++ b/sw/uiconfig/swriter/ui/indexentry.ui
@@ -89,8 +89,8 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="insert">
-                <property name="label" translatable="yes" 
context="indexentry|insert">Insert</property>
+              <object class="GtkButton" id="reset">
+                <property name="label" translatable="yes" 
context="indexentry">Reset</property>
                 <property name="can-focus">True</property>
                 <property name="can-default">True</property>
                 <property name="has-default">True</property>
@@ -104,14 +104,13 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="ok">
-                <property name="label" translatable="yes" 
context="stock">_Apply</property>
+              <object class="GtkButton" id="insert">
+                <property name="label" translatable="yes" 
context="indexentry|insert">Insert</property>
                 <property name="can-focus">True</property>
                 <property name="can-default">True</property>
                 <property name="has-default">True</property>
                 <property name="receives-default">True</property>
                 <property name="no-show-all">True</property>
-                <property name="use-underline">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -726,7 +725,7 @@
       <action-widget response="-7">close</action-widget>
       <action-widget response="101">delete</action-widget>
       <action-widget response="102">insert</action-widget>
-      <action-widget response="-5">ok</action-widget>
+      <action-widget response="103">reset</action-widget>
       <action-widget response="-11">help</action-widget>
     </action-widgets>
     <child internal-child="accessible">

Reply via email to