sd/source/ui/dlg/navigatr.cxx | 15 +---------- sd/source/ui/dlg/sdtreelb.cxx | 36 +++++++++++++++++---------- sd/source/ui/inc/sdtreelb.hxx | 2 - sd/uiconfig/sdraw/ui/navigatorcontextmenu.ui | 4 +-- 4 files changed, 27 insertions(+), 30 deletions(-)
New commits: commit 7af4a3191d9172e4af7f6e6b3b99fc530ab2ae29 Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Thu Apr 17 00:47:38 2025 -0800 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Sun Apr 20 02:27:48 2025 +0200 tdf#139633 Draw Navigator rename pages and objects take two Recent review of the patch done to provide in-place renaming in the Writer Navigator (commit 492c94abe05e5ac213475cdd85f158b7a462f824) inspired me to review what had been done for this for the Draw Navigator. This patch revamps the original work and makes the context menu item Rename consistent with the behavior of the Writer Navigator context menu item Rename. It starts in-place editing instead of opening the Name dialog. Known issues: * Gtk3 in-place editing doesn't notify when editing is canceled by Escape. This leaves the SdPageObjsTLV editing flag true which causes the Enter key to start entry editing instead of going to the object in the document. * For the Navigator in the sidebar, sal in-place editing doesn't revert to the original text when Escape is pressed. The sidebar FocusManager handling of Escape for focus in a panel content location is the culprit. Change-Id: If51f962daf8f9f10a738fa8483fc4626a037bc6a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184321 Tested-by: Jenkins Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sd/source/ui/dlg/navigatr.cxx b/sd/source/ui/dlg/navigatr.cxx index d4f189277fd7..e9c78690c98b 100644 --- a/sd/source/ui/dlg/navigatr.cxx +++ b/sd/source/ui/dlg/navigatr.cxx @@ -271,18 +271,7 @@ void SdNavigatorWin::ExecuteContextMenuAction(std::u16string_view rSelectedPopup weld::TreeView& rTreeView = GetObjects().get_treeview(); std::unique_ptr<weld::TreeIter> xIter(rTreeView.make_iterator()); if (rTreeView.get_selected(xIter.get())) - { - // grab the shell focus so the navigator will update - if (SfxViewShell* pCurSh = SfxViewShell::Current()) - { - if (vcl::Window* pShellWnd = pCurSh->GetWindow()) - pShellWnd->GrabFocus(); - } - if (rTreeView.get_iter_depth(*xIter) > 0) - mpBindings->Execute(SID_NAME_GROUP); - else - mpBindings->Execute(SID_RENAMEPAGE); - } + rTreeView.start_editing(*xIter); } } @@ -747,7 +736,7 @@ IMPL_LINK(SdNavigatorWin, KeyInputHdl, const KeyEvent&, rKEvt, bool) if (KEY_ESCAPE == rKEvt.GetKeyCode().GetCode()) { // during drag'n'drop we just stop the drag but do not close the navigator - if (!SdPageObjsTLV::IsInDrag() && !GetObjects().IsEditingActive()) + if (!SdPageObjsTLV::IsInDrag()) { ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( mpBindings->GetDispatcher()->GetFrame()); if (pBase) diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx index aecdbe4bda5f..2db89458adca 100644 --- a/sd/source/ui/dlg/sdtreelb.cxx +++ b/sd/source/ui/dlg/sdtreelb.cxx @@ -301,8 +301,13 @@ bool SdPageObjsTLV::IsEqualToDoc( const SdDrawDocument* pInDoc ) IMPL_LINK(SdPageObjsTLV, CommandHdl, const CommandEvent&, rCEvt, bool) { - if (IsEditingActive()) - return false; + if (m_bEditing) + { + // Set the editing flag false here because gtk3 in-place editing ends but EditedEntryHdl + // doesn't get called. This isn't needed for sal in-place editing because EditedEntryHdl + // gets called when focus is lost. + m_bEditing = false; + } if (rCEvt.GetCommand() == CommandEventId::ContextMenu) { @@ -328,16 +333,17 @@ IMPL_LINK(SdPageObjsTLV, CommandHdl, const CommandEvent&, rCEvt, bool) IMPL_LINK(SdPageObjsTLV, KeyInputHdl, const KeyEvent&, rKEvt, bool) { + if (m_bEditing) + return false; + const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode(); if (m_xAccel->execute(rKeyCode)) { - m_bEditing = false; // the accelerator consumed the event return true; } if (rKeyCode.GetCode() == KEY_RETURN) { - m_bEditing = false; std::unique_ptr<weld::TreeIter> xCursor(m_xTreeView->make_iterator()); if (m_xTreeView->get_cursor(xCursor.get()) && m_xTreeView->iter_has_child(*xCursor)) { @@ -352,15 +358,16 @@ IMPL_LINK(SdPageObjsTLV, KeyInputHdl, const KeyEvent&, rKEvt, bool) return true; } bool bRet = m_aKeyPressHdl.Call(rKEvt); - // m_bEditing needs to be set after key press handler call back or x11 won't end editing on - // Esc key press. See SdNavigatorWin::KeyInputHdl. - m_bEditing = false; return bRet; } IMPL_LINK(SdPageObjsTLV, MousePressHdl, const MouseEvent&, rMEvt, bool) { - m_bEditing = false; + // Don't set m_bEditing false here. Sal in-place editing doesn't like that because the in-place + // editing mouse presses also end up here. + if (m_bEditing) + return false; + m_bSelectionHandlerNavigates = rMEvt.GetClicks() == 1; m_bNavigationGrabsFocus = rMEvt.GetClicks() != 1; return false; @@ -368,6 +375,9 @@ IMPL_LINK(SdPageObjsTLV, MousePressHdl, const MouseEvent&, rMEvt, bool) IMPL_LINK_NOARG(SdPageObjsTLV, MouseReleaseHdl, const MouseEvent&, bool) { + if (m_bEditing) + return false; + if (m_aMouseReleaseHdl.IsSet() && m_aMouseReleaseHdl.Call(MouseEvent())) return false; @@ -767,12 +777,11 @@ SdPageObjsTLV::SdPageObjsTLV(std::unique_ptr<weld::TreeView> xTreeView) m_xTreeView->set_column_editables({true}); } -IMPL_LINK(SdPageObjsTLV, EditEntryAgain, void*, p, void) +IMPL_LINK(SdPageObjsTLV, EditEntryAgain, void*, pTreeIter, void) { m_xTreeView->grab_focus(); - std::unique_ptr<weld::TreeIter> xEntry(static_cast<weld::TreeIter*>(p)); + std::unique_ptr<weld::TreeIter> xEntry(static_cast<weld::TreeIter*>(pTreeIter)); m_xTreeView->start_editing(*xEntry); - m_bEditing = true; } IMPL_LINK_NOARG(SdPageObjsTLV, EditingEntryHdl, const weld::TreeIter&, bool) @@ -790,7 +799,8 @@ IMPL_LINK(SdPageObjsTLV, EditedEntryHdl, const IterString&, rIterString, bool) return true; // If the new name is empty or not unique, start editing again. - if (rIterString.second.isEmpty() || m_pDoc->GetObj(rIterString.second)) + if (rIterString.second.isEmpty() || m_pDoc->GetObj(rIterString.second) + || m_pDoc->IsPageNameUnique(rIterString.second)) { std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(&rIterString.first)); Application::PostUserEvent(LINK(this, SdPageObjsTLV, EditEntryAgain), xEntry.release()); @@ -846,7 +856,7 @@ void SdPageObjsTLV::Select() { m_nSelectEventId = nullptr; - if (IsEditingActive()) + if (m_bEditing) return; m_bLinkableSelected = true; diff --git a/sd/source/ui/inc/sdtreelb.hxx b/sd/source/ui/inc/sdtreelb.hxx index 1b8f3683179e..e61a6d0bd127 100644 --- a/sd/source/ui/inc/sdtreelb.hxx +++ b/sd/source/ui/inc/sdtreelb.hxx @@ -173,8 +173,6 @@ public: SD_DLLPUBLIC SdPageObjsTLV(std::unique_ptr<weld::TreeView> xTreeview); SD_DLLPUBLIC ~SdPageObjsTLV(); - bool IsEditingActive() const {return m_bEditing;} - void hide() { m_xTreeView->hide(); diff --git a/sd/uiconfig/sdraw/ui/navigatorcontextmenu.ui b/sd/uiconfig/sdraw/ui/navigatorcontextmenu.ui index 746734e4e86f..787cdd02f852 100644 --- a/sd/uiconfig/sdraw/ui/navigatorcontextmenu.ui +++ b/sd/uiconfig/sdraw/ui/navigatorcontextmenu.ui @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 --> +<!-- Generated with glade 3.40.0 --> <interface domain="sd"> <requires lib="gtk+" version="3.20"/> <object class="GtkMenu" id="navmenu"> @@ -9,7 +9,7 @@ <object class="GtkMenuItem" id="rename"> <property name="visible">True</property> <property name="can-focus">False</property> - <property name="label" translatable="yes" context="navigatorcontextmenu|STR_RENAME">Rename...</property> + <property name="label" translatable="yes" context="navigatorcontextmenu|STR_RENAME">Rename</property> <property name="use-underline">True</property> </object> </child>