include/vcl/weld.hxx                         |    1 +
 sfx2/source/control/templatedlglocalview.cxx |   10 ++++++++++
 sfx2/source/inc/helpids.h                    |    8 ++++++++
 vcl/inc/salvtables.hxx                       |    1 +
 vcl/source/app/salvtables.cxx                |    7 +++++++
 vcl/unx/gtk3/gtkinst.cxx                     |    5 +++++
 6 files changed, 32 insertions(+)

New commits:
commit 65c91bd5aa6f9b68390739a0e027d23c8a32da08
Author:     Rafael Lima <rafael.palma.l...@gmail.com>
AuthorDate: Fri Jul 21 14:47:47 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sun Jul 23 15:07:11 2023 +0200

    tdf#147911 Implement set_item_help_id for context menu items
    
    This patch adds the method set_item_help_id for weld::Menu (similarly to 
what we already have for weld::Toolbar). This way, it is possible to define 
help IDs for each entry in context menus that are created during runtime.
    
    This is necessary to fix various bug tickets that request F1 to redirect to 
the corresponding help page when a context menu item has focus. This currently 
works for context menus created from XML files, but fails for context menus 
created during runtime.
    
    Besides implementing the new method, this patch fixes bug 147911 (see 
changes in file templatedlglocalview.cxx) to showcase how set_item_help_id can 
be used.
    
    NOTE: Pressing F1 in context menus only work with "gen" and "win"... 
unfortunately it does not work in kf5 and gtk3 due to a separate bug (see bug 
156376).
    
    Change-Id: Ic9bb1bca3e646cb4d0b879d8672c5dcc9c19c4c9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154699
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 4c198b3ecc99..c03f78d6c0e1 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -2419,6 +2419,7 @@ public:
                         TriState eCheckRadioFalse)
         = 0;
 
+    virtual void set_item_help_id(const OUString& rIdent, const OUString& 
rHelpId) = 0;
     virtual void remove(const OUString& rId) = 0;
 
     virtual void clear() = 0;
diff --git a/sfx2/source/control/templatedlglocalview.cxx 
b/sfx2/source/control/templatedlglocalview.cxx
index b469ea716dc8..52a12b4ef965 100644
--- a/sfx2/source/control/templatedlglocalview.cxx
+++ b/sfx2/source/control/templatedlglocalview.cxx
@@ -19,6 +19,7 @@
 #include <vcl/svapp.hxx>
 #include <vcl/event.hxx>
 #include <sfx2/doctempl.hxx>
+#include <helpids.h>
 #include <bitmaps.hlst>
 
 
TemplateDlgLocalView::TemplateDlgLocalView(std::unique_ptr<weld::ScrolledWindow>
 xWindow,
@@ -113,6 +114,15 @@ void TemplateDlgLocalView::createContextMenu(const bool 
bIsDefault, const bool b
     mxContextMenu->append("move", SfxResId(STR_MOVE), BMP_MENU_MOVE);
     mxContextMenu->append("export", SfxResId(STR_EXPORT), BMP_MENU_EXPORT);
 
+    // Set the help IDs of all context menu entries
+    mxContextMenu->set_item_help_id("open", HID_TEMPLATEDLG_OPEN);
+    mxContextMenu->set_item_help_id("edit", HID_TEMPLATEDLG_EDIT);
+    mxContextMenu->set_item_help_id("default", HID_TEMPLATEDLG_DEFAULT);
+    mxContextMenu->set_item_help_id("rename", HID_TEMPLATEDLG_RENAME);
+    mxContextMenu->set_item_help_id("delete", HID_TEMPLATEDLG_DELETE);
+    mxContextMenu->set_item_help_id("move", HID_TEMPLATEDLG_MOVE);
+    mxContextMenu->set_item_help_id("export", HID_TEMPLATEDLG_EXPORT);
+
     if (!bIsSingleSel)
     {
         mxContextMenu->set_sensitive("open", false);
diff --git a/sfx2/source/inc/helpids.h b/sfx2/source/inc/helpids.h
index 7dbce5235779..051cc5ada8a5 100644
--- a/sfx2/source/inc/helpids.h
+++ b/sfx2/source/inc/helpids.h
@@ -40,6 +40,14 @@ inline constexpr OUStringLiteral HID_HELP_TOOLBOXITEM_PRINT 
= u"SFX2_HID_HELP_TO
 inline constexpr OUStringLiteral HID_HELP_TOOLBOXITEM_BOOKMARKS = 
u"SFX2_HID_HELP_TOOLBOXITEM_BOOKMARKS";
 inline constexpr OUStringLiteral HID_HELP_TOOLBOXITEM_SEARCHDIALOG = 
u"SFX2_HID_HELP_TOOLBOXITEM_SEARCHDIALOG";
 
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_OPEN = 
u"SFX2_HID_TEMPLATEDLG_OPEN";
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_EDIT = 
u"SFX2_HID_TEMPLATEDLG_EDIT";
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_DEFAULT = 
u"SFX2_HID_TEMPLATEDLG_DEFAULT";
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_RENAME = 
u"SFX2_HID_TEMPLATEDLG_RENAME";
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_DELETE = 
u"SFX2_HID_TEMPLATEDLG_DELETE";
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_MOVE = 
u"SFX2_HID_TEMPLATEDLG_MOVE";
+inline constexpr OUStringLiteral HID_TEMPLATEDLG_EXPORT = 
u"SFX2_HID_TEMPLATEDLG_EXPORT";
+
 inline constexpr OUStringLiteral HID_QUERY_LOAD_TEMPLATE = 
u"SFX2_HID_QUERY_LOAD_TEMPLATE";
 
 inline constexpr OUStringLiteral HID_SIDEBAR_WINDOW = 
u"SFX2_HID_SIDEBAR_WINDOW";
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 04a42c3a8929..4264de0cea6d 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -169,6 +169,7 @@ public:
                         const css::uno::Reference<css::graphic::XGraphic>& 
rImage,
                         TriState eCheckRadioFalse) override;
     virtual void insert_separator(int pos, const OUString& rId) override;
+    virtual void set_item_help_id(const OUString& rIdent, const OUString& 
rHelpId) override;
     virtual void remove(const OUString& rId) override;
     virtual OUString get_id(int pos) const override;
     virtual int n_children() const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index ff59e7f4d156..3ed96cd8ef58 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -960,6 +960,13 @@ void SalInstanceMenu::insert_separator(int pos, const 
OUString& rId)
     auto nInsertPos = pos == -1 ? MENU_APPEND : pos;
     m_xMenu->InsertSeparator(rId, nInsertPos);
 }
+
+// Defines the help id of the item in a given position
+void SalInstanceMenu::set_item_help_id(const OUString& rIdent, const OUString& 
rHelpId)
+{
+    m_xMenu->SetHelpId(m_xMenu->GetItemId(rIdent), rHelpId);
+}
+
 void SalInstanceMenu::remove(const OUString& rId)
 {
     m_xMenu->RemoveItem(m_xMenu->GetItemPos(m_xMenu->GetItemId(rId)));
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 60d6c6b12b3b..1e56851000c0 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -11665,6 +11665,11 @@ public:
         return get_n_children();
     }
 
+    virtual void set_item_help_id(const OUString& rIdent, const OUString& 
rHelpId) override
+    {
+        ::set_help_id(GTK_WIDGET(m_aMap[rIdent]), rHelpId);
+    }
+
     void remove(const OUString& rIdent) override
     {
 #if !GTK_CHECK_VERSION(4, 0, 0)

Reply via email to