cui/source/dialogs/hyperlinkinternettabpage.cxx |   56 +++++++++++++++++++++++-
 cui/source/inc/hyperlinkinternettabpage.hxx     |    4 +
 cui/uiconfig/ui/hyperlinkinternetpage.ui        |   21 ++++++++-
 3 files changed, 79 insertions(+), 2 deletions(-)

New commits:
commit ff0d6aec23bbb669364a28d9d1bccaa0f58ee04b
Author:     siddhisalunkhe1998 <[email protected]>
AuthorDate: Thu Feb 19 07:46:53 2026 +0000
Commit:     Heiko Tietze <[email protected]>
CommitDate: Tue Feb 24 10:21:32 2026 +0100

    tdf#170592  Add "Remove query string" checkbox to Hyperlink dialog
    
    Adds a checkbox on the Internet tab page.
    
    It strips the entire query string part (from ?...) of URL
    except the fragment part ( # )
    https://en.wikipedia.org/wiki/URL#Syntax
    
    Change-Id: I372ae0d1192864071294b35e6277e6513a65450f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199687
    Reviewed-by: Heiko Tietze <[email protected]>
    Tested-by: Jenkins

diff --git a/cui/source/dialogs/hyperlinkinternettabpage.cxx 
b/cui/source/dialogs/hyperlinkinternettabpage.cxx
index 8d1e2f458c40..d9dbc1a8bd51 100644
--- a/cui/source/dialogs/hyperlinkinternettabpage.cxx
+++ b/cui/source/dialogs/hyperlinkinternettabpage.cxx
@@ -14,6 +14,11 @@
 #include <sot/exchange.hxx>
 #include <hlmarkwn_def.hxx>
 
+namespace
+{
+bool bRemoveQueryString = false;
+}
+
 OUString HyperlinkInternetTP::CreateAbsoluteURL() const
 {
     // erase leading and trailing whitespaces
@@ -33,6 +38,7 @@ HyperlinkInternetTP::HyperlinkInternetTP(weld::Container* 
pParent,
     : HyperlinkTabPageBase(pParent, pController, 
u"cui/ui/hyperlinkinternetpage.ui"_ustr,
                            u"HyperlinkInternetPage"_ustr, pSet)
     , 
m_xCbbTarget(std::make_unique<SvxHyperURLBox>(m_xBuilder->weld_combo_box(u"target"_ustr)))
+    , 
m_xCbRemoveQueryString(m_xBuilder->weld_check_button(u"removequerystring"_ustr))
 {
     m_xCbbTarget->SetSmartProtocol(GetSmartProtocolFromButtons());
 
@@ -41,6 +47,8 @@ HyperlinkInternetTP::HyperlinkInternetTP(weld::Container* 
pParent,
     // set handlers
     m_xCbbTarget->connect_focus_out(LINK(this, HyperlinkInternetTP, 
LostFocusTargetHdl_Impl));
     m_xCbbTarget->connect_changed(LINK(this, HyperlinkInternetTP, 
ModifiedTargetHdl_Impl));
+    m_xCbRemoveQueryString->connect_toggled(
+        LINK(this, HyperlinkInternetTP, ClickRemoveQueryStringHdl_Impl));
     maTimer.SetInvokeHandler(LINK(this, HyperlinkInternetTP, TimeoutHdl_Impl));
 }
 
@@ -51,6 +59,23 @@ std::unique_ptr<SfxTabPage> 
HyperlinkInternetTP::Create(weld::Container* pParent
     return std::make_unique<HyperlinkInternetTP>(pParent, pController, pSet);
 }
 
+void HyperlinkInternetTP::RemoveQueryString()
+{
+    OUString aStrURL(m_xCbbTarget->get_active_text());
+    sal_Int32 nQueryPos = aStrURL.indexOf('?');
+    if (nQueryPos != -1)
+    {
+        // Preserve #fragment if present
+        OUString aFragment;
+        sal_Int32 nFragPos = aStrURL.indexOf('#', nQueryPos);
+        if (nFragPos != -1)
+            aFragment = aStrURL.copy(nFragPos);
+
+        aStrURL = OUString::Concat(aStrURL.subView(0, nQueryPos)) + aFragment;
+        m_xCbbTarget->set_entry_text(aStrURL);
+    }
+}
+
 void HyperlinkInternetTP::FillDlgFields(const OUString& rStrURL)
 {
     // tdf#146576 - propose clipboard content when inserting a hyperlink
@@ -97,6 +122,13 @@ void HyperlinkInternetTP::FillDlgFields(const OUString& 
rStrURL)
         m_xCbbTarget->set_entry_text(rStrURL);
 
     SetScheme(aStrScheme);
+
+    OUString aFinalURL(m_xCbbTarget->get_active_text());
+    bool bHasQuery = aFinalURL.indexOf('?') != -1;
+    m_xCbRemoveQueryString->set_active(bRemoveQueryString);
+
+    if (bRemoveQueryString && bHasQuery)
+        RemoveQueryString();
 }
 
 void HyperlinkInternetTP::GetCurrentItemData(OUString& rStrURL, OUString& 
aStrName,
@@ -107,7 +139,11 @@ void HyperlinkInternetTP::GetCurrentItemData(OUString& 
rStrURL, OUString& aStrNa
     GetDataFromCommonFields(aStrName, aStrIntName, aStrFrame, eMode);
 }
 
-void HyperlinkInternetTP::ClearPageSpecificControls() { 
m_xCbbTarget->set_entry_text(OUString()); }
+void HyperlinkInternetTP::ClearPageSpecificControls()
+{
+    m_xCbbTarget->set_entry_text(OUString());
+    m_xCbRemoveQueryString->set_active(bRemoveQueryString);
+}
 
 IMPL_LINK_NOARG(HyperlinkInternetTP, ModifiedTargetHdl_Impl, weld::ComboBox&, 
void)
 {
@@ -115,6 +151,14 @@ IMPL_LINK_NOARG(HyperlinkInternetTP, 
ModifiedTargetHdl_Impl, weld::ComboBox&, vo
     if (!aScheme.isEmpty())
         SetScheme(aScheme);
 
+    OUString aStrURL(m_xCbbTarget->get_active_text());
+    bool bHasQuery = aStrURL.indexOf('?') != -1;
+
+    if (m_xCbRemoveQueryString->get_active() && bHasQuery)
+    {
+        RemoveQueryString();
+    }
+
     // start timer
     maTimer.SetTimeout(2500);
     maTimer.Start();
@@ -122,6 +166,16 @@ IMPL_LINK_NOARG(HyperlinkInternetTP, 
ModifiedTargetHdl_Impl, weld::ComboBox&, vo
 
 IMPL_LINK_NOARG(HyperlinkInternetTP, TimeoutHdl_Impl, Timer*, void) { 
RefreshMarkWindow(); }
 
+IMPL_LINK_NOARG(HyperlinkInternetTP, ClickRemoveQueryStringHdl_Impl, 
weld::Toggleable&, void)
+{
+    bRemoveQueryString = m_xCbRemoveQueryString->get_active();
+
+    if (bRemoveQueryString)
+    {
+        RemoveQueryString();
+    }
+}
+
 void HyperlinkInternetTP::SetScheme(std::u16string_view rScheme)
 {
     // update target
diff --git a/cui/source/inc/hyperlinkinternettabpage.hxx 
b/cui/source/inc/hyperlinkinternettabpage.hxx
index 94cb3944ec54..f2f0338468a8 100644
--- a/cui/source/inc/hyperlinkinternettabpage.hxx
+++ b/cui/source/inc/hyperlinkinternettabpage.hxx
@@ -17,13 +17,17 @@ class HyperlinkInternetTP final : public 
HyperlinkTabPageBase
 {
 private:
     std::unique_ptr<SvxHyperURLBox> m_xCbbTarget;
+    std::unique_ptr<weld::CheckButton> m_xCbRemoveQueryString;
 
     DECL_LINK(ModifiedTargetHdl_Impl, weld::ComboBox&, void);
     DECL_LINK(LostFocusTargetHdl_Impl, weld::Widget&, void);
     DECL_LINK(TimeoutHdl_Impl, Timer*, void);
+    DECL_LINK(ClickRemoveQueryStringHdl_Impl, weld::Toggleable&, void);
 
     OUString CreateAbsoluteURL() const;
 
+    void RemoveQueryString();
+
     void SetScheme(std::u16string_view rScheme);
     void RemoveImproperProtocol(std::u16string_view aProperScheme);
     static INetProtocol GetSmartProtocolFromButtons();
diff --git a/cui/uiconfig/ui/hyperlinkinternetpage.ui 
b/cui/uiconfig/ui/hyperlinkinternetpage.ui
index 33d49943dd24..c4fc71796faf 100644
--- a/cui/uiconfig/ui/hyperlinkinternetpage.ui
+++ b/cui/uiconfig/ui/hyperlinkinternetpage.ui
@@ -16,7 +16,7 @@
         <property name="label-xalign">0</property>
         <property name="shadow-type">none</property>
         <child>
-          <!-- n-columns=2 n-rows=2 -->
+          <!-- n-columns=2 n-rows=3 -->
           <object class="GtkGrid" id="grid1">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
@@ -95,6 +95,25 @@
                 <property name="top-attach">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkCheckButton" id="removequerystring">
+                <property name="label" translatable="yes" 
context="hyperlinkinternetpage|removequerystring">Remove _query 
string</property>
+                <property name="visible">True</property>
+                <property name="can-focus">True</property>
+                <property name="receives-default">False</property>
+                <property name="use-underline">True</property>
+                <property name="draw-indicator">True</property>
+                <child internal-child="accessible">
+                  <object class="AtkObject" id="removequerystring-atkobject">
+                    <property name="AtkObject::accessible-description" 
translatable="yes" 
context="hyperlinkinternetpage|extended_tip|removequerystring">Remove query 
string (everything after ?) from the URL.</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="left-attach">1</property>
+                <property name="top-attach">2</property>
+              </packing>
+            </child>
           </object>
         </child>
         <child type="label">

Reply via email to