sw/inc/cmdid.h                      |    2 ++
 sw/inc/swabstdlg.hxx                |    2 +-
 sw/sdi/_textsh.sdi                  |    6 ++++++
 sw/sdi/swriter.sdi                  |   18 ++++++++++++++++++
 sw/source/ui/dialog/swdlgfact.cxx   |    4 ++--
 sw/source/ui/dialog/swdlgfact.hxx   |    2 +-
 sw/source/ui/misc/bookmark.cxx      |   25 ++++++++++++++++++++++---
 sw/source/uibase/inc/bookmark.hxx   |    5 +++--
 sw/source/uibase/shells/textsh1.cxx |   13 +++++++++++--
 sw/source/uibase/utlui/content.cxx  |    7 ++++++-
 10 files changed, 72 insertions(+), 12 deletions(-)

New commits:
commit 9cc6acce941ea9306f5c2aa81bb06ac28a7f7f45
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Aug 11 18:54:54 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Aug 12 11:06:00 2022 +0200

    sw: select entry in Insert->Bookmarks dialog when called from Navigator
    
    The context menu is called "Edit", so let's put dialog in edit mode.
    
    Change-Id: Ib3a2b164e4d6a0b93e3a5aac26125a20d41a60dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138155
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index f456dc2b13ea..f183108c071e 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -313,6 +313,8 @@ class SwUINumRuleItem;
 #define FN_TABLE_PASTE_ROW_BEFORE   (FN_INSERT2 + 31)  /* paste table as new 
table rows */
 #define FN_TABLE_PASTE_COL_BEFORE   (FN_INSERT2 + 32)  /* paste table as new 
table columns */
 
+#define FN_EDIT_BOOKMARK        (FN_INSERT2 + 33 )  /* Bookmark */
+
 // Region: Format
 #define FN_AUTOFORMAT_APPLY     (FN_FORMAT + 1 ) /* apply autoformat options */
 #define FN_AUTOFORMAT_AUTO      (FN_FORMAT + 2 ) /* apply autoformat during 
user input */
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 1c0762f84432..5c5f2bc2cae7 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -399,7 +399,7 @@ public:
     virtual VclPtr<SfxAbstractDialog> CreateSwAddressAbstractDlg(weld::Window* 
pParent, const SfxItemSet& rSet) = 0;
     virtual VclPtr<AbstractSwAsciiFilterDlg>  
CreateSwAsciiFilterDlg(weld::Window* pParent, SwDocShell& rDocSh,
                                                                 SvStream* 
pStream) = 0;
-    virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window 
*pParent, SwWrtShell &rSh) = 0;
+    virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window 
*pParent, SwWrtShell &rSh, OUString const* pSelected) = 0;
     virtual VclPtr<VclAbstractDialog> CreateSwContentControlDlg(weld::Window 
*pParent, SwWrtShell &rSh) = 0;
 
     virtual VclPtr<AbstractSwContentControlListItemDlg>
diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi
index a508445f8dca..f9788707eb84 100644
--- a/sw/sdi/_textsh.sdi
+++ b/sw/sdi/_textsh.sdi
@@ -140,6 +140,12 @@ interface BaseText
         StateMethod = GetState ;
         DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
     ]
+    FN_EDIT_BOOKMARK
+    [
+        ExecMethod = Execute ;
+        StateMethod = GetState ;
+        DisableFlags="SfxDisableFlags::SwOnProtectedCursor";
+    ]
     FN_SET_REMINDER
     [
         ExecMethod = Execute ;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index cd3304860374..78f1d7cd74b0 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -2554,6 +2554,24 @@ SfxVoidItem InsertBookmark FN_INSERT_BOOKMARK
     GroupId = SfxGroupId::Insert;
 ]
 
+SfxVoidItem EditBookmark FN_EDIT_BOOKMARK
+(SfxStringItem Bookmark FN_EDIT_BOOKMARK)
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = FALSE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Asynchron;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Insert;
+]
+
 SfxVoidItem SetReminder FN_SET_REMINDER
 
 [
diff --git a/sw/source/ui/dialog/swdlgfact.cxx 
b/sw/source/ui/dialog/swdlgfact.cxx
index 8aaa5566a79e..1aa438f01af6 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -831,9 +831,9 @@ VclPtr<AbstractSwAsciiFilterDlg> 
SwAbstractDialogFactory_Impl::CreateSwAsciiFilt
 }
 
 VclPtr<VclAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwInsertBookmarkDlg(weld::Window *pParent,
-                                                                               
   SwWrtShell &rSh)
+        SwWrtShell &rSh, OUString const*const pSelected)
 {
-    return 
VclPtr<AbstractGenericDialog_Impl>::Create(std::make_shared<SwInsertBookmarkDlg>(pParent,
 rSh));
+    return 
VclPtr<AbstractGenericDialog_Impl>::Create(std::make_shared<SwInsertBookmarkDlg>(pParent,
 rSh, pSelected));
 }
 
 VclPtr<VclAbstractDialog> 
SwAbstractDialogFactory_Impl::CreateSwContentControlDlg(weld::Window* pParent,
diff --git a/sw/source/ui/dialog/swdlgfact.hxx 
b/sw/source/ui/dialog/swdlgfact.hxx
index 24b2017967ca..c127566ea10a 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -676,7 +676,7 @@ public:
     virtual VclPtr<SfxAbstractDialog> CreateSwAddressAbstractDlg(weld::Window* 
pParent, const SfxItemSet& rSet) override;
     virtual VclPtr<AbstractSwAsciiFilterDlg>  
CreateSwAsciiFilterDlg(weld::Window* pParent, SwDocShell& rDocSh,
                                                                 SvStream* 
pStream) override;
-    virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window 
*pParent, SwWrtShell &rSh) override;
+    virtual VclPtr<VclAbstractDialog> CreateSwInsertBookmarkDlg(weld::Window 
*pParent, SwWrtShell &rSh, OUString const* pSelected) override;
     virtual VclPtr<VclAbstractDialog> CreateSwContentControlDlg(weld::Window 
*pParent, SwWrtShell &rSh) override;
 
     VclPtr<AbstractSwContentControlListItemDlg>
diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx
index 6f45170d5d0b..4309517f4a21 100644
--- a/sw/source/ui/misc/bookmark.cxx
+++ b/sw/source/ui/misc/bookmark.cxx
@@ -151,6 +151,11 @@ IMPL_LINK_NOARG(SwInsertBookmarkDlg, SelectionChangedHdl, 
weld::TreeView&, void)
     if (!m_xBookmarksBox->has_focus())
         return;
 
+    SelectionChanged();
+}
+
+void SwInsertBookmarkDlg::SelectionChanged()
+{
     OUStringBuffer sEditBoxText;
     int nSelectedRows = 0;
     m_xBookmarksBox->selected_foreach(
@@ -355,7 +360,8 @@ void SwInsertBookmarkDlg::PopulateTable()
     m_nLastBookmarksCount = pMarkAccess->getBookmarksCount();
 }
 
-SwInsertBookmarkDlg::SwInsertBookmarkDlg(weld::Window* pParent, SwWrtShell& rS)
+SwInsertBookmarkDlg::SwInsertBookmarkDlg(weld::Window* pParent, SwWrtShell& rS,
+                                         OUString const* const pSelected)
     : SfxDialogController(pParent, "modules/swriter/ui/insertbookmark.ui", 
"InsertBookmarkDialog")
     , rSh(rS)
     , m_nLastBookmarksCount(0)
@@ -419,6 +425,18 @@ SwInsertBookmarkDlg::SwInsertBookmarkDlg(weld::Window* 
pParent, SwWrtShell& rS)
     SvtViewOptions aDlgOpt(EViewType::Dialog, "BookmarkDialog");
     if (aDlgOpt.Exists())
         m_xDialog->set_window_state(aDlgOpt.GetWindowState().toUtf8());
+
+    if (pSelected)
+    {
+        if (m_xBookmarksBox->SelectByName(*pSelected))
+        {
+            SelectionChanged();
+            // which is better, focus on a button or focus on the table row?
+            // as long as editing doesn't work via the TreeView with VCL
+            // widgets, better on button.
+            m_xEditTextBtn->grab_focus();
+        }
+    }
 }
 
 SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
@@ -535,12 +553,13 @@ sw::mark::IMark* BookmarkTable::GetBookmarkByName(const 
OUString& sName)
     return weld::fromId<sw::mark::IMark*>(m_xControl->get_id(*xEntry));
 }
 
-void BookmarkTable::SelectByName(const OUString& sName)
+bool BookmarkTable::SelectByName(const OUString& sName)
 {
     auto xEntry = GetRowByBookmarkName(sName);
     if (!xEntry)
-        return;
+        return false;
     select(*xEntry);
+    return true;
 }
 
 OUString BookmarkTable::GetNameProposal() const
diff --git a/sw/source/uibase/inc/bookmark.hxx 
b/sw/source/uibase/inc/bookmark.hxx
index 36f83f3a86e9..4c1a9a2e79b9 100644
--- a/sw/source/uibase/inc/bookmark.hxx
+++ b/sw/source/uibase/inc/bookmark.hxx
@@ -33,7 +33,7 @@ class BookmarkTable
 public:
     BookmarkTable(std::unique_ptr<weld::TreeView> xControl);
     void                InsertBookmark(SwWrtShell & rSh, sw::mark::IMark* 
pMark);
-    void                SelectByName(const OUString& sName);
+    bool                SelectByName(const OUString& sName);
     sw::mark::IMark*    GetBookmarkByName(const OUString& sName);
     OUString            GetNameProposal() const;
 
@@ -107,9 +107,10 @@ class SwInsertBookmarkDlg final : public 
SfxDialogController
     bool ValidateBookmarks();
     bool HaveBookmarksChanged();
     void GotoSelectedBookmark();
+    void SelectionChanged();
 
 public:
-    SwInsertBookmarkDlg(weld::Window* pParent, SwWrtShell& rSh);
+    SwInsertBookmarkDlg(weld::Window* pParent, SwWrtShell& rSh, OUString 
const* pSelected);
     virtual ~SwInsertBookmarkDlg() override;
 };
 
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index e723e6221262..d5aff9eaa278 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -689,11 +689,20 @@ void SwTextShell::Execute(SfxRequest &rReq)
             {
                 OUString sName = static_cast<const 
SfxStringItem*>(pItem)->GetValue();
                 rWrtSh.SetBookmark( vcl::KeyCode(), sName );
+                break;
+            }
+            [[fallthrough]];
+        }
+        case FN_EDIT_BOOKMARK:
+        {
+            ::std::optional<OUString> oName;
+            if (pItem)
+            {
+                oName.emplace(static_cast<const 
SfxStringItem*>(pItem)->GetValue());
             }
-            else
             {
                 SwAbstractDialogFactory* pFact = 
SwAbstractDialogFactory::Create();
-                ScopedVclPtr<VclAbstractDialog> 
pDlg(pFact->CreateSwInsertBookmarkDlg(GetView().GetFrameWeld(), rWrtSh));
+                ScopedVclPtr<VclAbstractDialog> 
pDlg(pFact->CreateSwInsertBookmarkDlg(GetView().GetFrameWeld(), rWrtSh, oName ? 
&*oName : nullptr));
                 VclAbstractDialog::AsyncContext aContext;
                 aContext.maEndDialogFn = [](sal_Int32){};
                 pDlg->StartExecuteAsync(aContext);
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index b3285972ca2b..172156b65a21 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -4924,7 +4924,12 @@ void SwContentTree::EditEntry(const weld::TreeIter& 
rEntry, EditEntryMode nMode)
                 xNameAccess = xBkms->getBookmarks();
             }
             else
-                nSlot = FN_INSERT_BOOKMARK;
+            {
+                SfxStringItem const name(FN_EDIT_BOOKMARK, pCnt->GetName());
+                SfxPoolItem const* args[2] = { &name, nullptr };
+                m_pActiveShell->GetView().GetViewFrame()->
+                    GetDispatcher()->Execute(FN_EDIT_BOOKMARK, 
SfxCallMode::SYNCHRON, args);
+            }
         break;
 
         case ContentTypeId::REGION    :

Reply via email to