20#include <rtl/ustrbuf.hxx>
26#include <com/sun/star/frame/XModel.hpp>
27#include <com/sun/star/text/XBookmarksSupplier.hpp>
28#include <officecfg/Office/Common.hxx>
35#include <bookmark.hxx>
49 m_xBookmarksBox->unselect_all();
53 OUString sTmp = m_xEditBox->get_text();
55 const sal_Int32 nLen = sTmp.getLength();
58 const sal_Int32 nTmpLen = sTmp.getLength();
60 if (sTmp.getLength() != nTmpLen)
63 const bool bHasForbiddenChars = sTmp.getLength() != nLen;
64 m_xForbiddenChars->set_visible(bHasForbiddenChars);
65 if (bHasForbiddenChars)
70 sal_Int32 nSelectedEntries = 0;
71 sal_Int32 nEntries = 0;
72 sal_Int32 nTokenIndex = 0;
73 while (!sTmp.isEmpty() && nTokenIndex >= 0)
76 if (m_xBookmarksBox->GetBookmarkByName(aToken))
78 m_xBookmarksBox->SelectByName(aToken);
85 m_xInsertBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 0 && !bHasForbiddenChars
89 m_xDeleteBtn->set_sensitive(nEntries > 0 && nSelectedEntries == nEntries && !m_bAreProtected);
90 m_xGotoBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1);
91 m_xEditTextBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1);
92 m_xRenameBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1 && !m_bAreProtected);
98 if (!ValidateBookmarks())
101 int nSelectedRows(0);
103 m_xBookmarksBox->selected_foreach([
this, &nSelectedRows](
weld::TreeIter& rEntry) {
106 = weld::fromId<sw::mark::IMark*>(m_xBookmarksBox->get_id(rEntry));
107 OUString sRemoved = pBookmark->
GetName();
110 SfxRequest aReq(m_rSh.GetView().GetViewFrame(), FN_DELETE_BOOKMARK);
113 m_aTableBookmarks.erase(std::remove(m_aTableBookmarks.begin(), m_aTableBookmarks.end(),
114 std::make_pair(pBookmark, sRemoved)),
115 m_aTableBookmarks.end());
126 m_xBookmarksBox->remove_selection();
130 m_xDeleteBtn->set_sensitive(
false);
131 m_xGotoBtn->set_sensitive(
false);
132 m_xEditTextBtn->set_sensitive(
false);
133 m_xRenameBtn->set_sensitive(
false);
134 m_xInsertBtn->set_sensitive(
false);
142 GotoSelectedBookmark();
148 if (!ValidateBookmarks())
151 if (!m_xBookmarksBox->has_focus())
159 OUStringBuffer sEditBoxText;
160 int nSelectedRows = 0;
165 const OUString& sEntryName = pBookmark->
GetName();
166 if (!sEditBoxText.isEmpty())
167 sEditBoxText.append(
";");
168 sEditBoxText.append(sEntryName);
175 m_xGotoBtn->set_sensitive(nSelectedRows == 1);
179 m_xEditBox->set_text(sEditBoxText.makeStringAndClear());
193 if (!ValidateBookmarks())
195 auto pSelected = m_xBookmarksBox->get_selected();
199 m_xBookmarksBox->start_editing(*pSelected);
204 if (!ValidateBookmarks())
206 auto xSelected = m_xBookmarksBox->get_selected();
211 = weld::fromId<sw::mark::IMark*>(m_xBookmarksBox->get_id(*xSelected));
212 uno::Reference<frame::XModel>
xModel = m_rSh.GetView().GetDocShell()->GetBaseModel();
213 uno::Reference<text::XBookmarksSupplier> xBkms(
xModel, uno::UNO_QUERY);
214 uno::Reference<container::XNameAccess> xNameAccess = xBkms->getBookmarks();
216 uno::Reference<uno::XInterface> xTmp;
218 uno::Reference<container::XNamed> xNamed(xTmp, uno::UNO_QUERY);
228 m_xDeleteBtn->set_sensitive(
false);
229 m_xGotoBtn->set_sensitive(
false);
230 m_xEditTextBtn->set_sensitive(
false);
231 m_xRenameBtn->set_sensitive(
false);
232 m_xInsertBtn->set_sensitive(
false);
239 OUString sBookmark = m_xEditBox->get_text();
240 m_rSh.SetBookmark2(
vcl::KeyCode(), sBookmark, m_xHideCB->get_active(),
241 m_xConditionED->get_text());
248 bool bHide = rBox.get_active();
249 m_xConditionED->set_sensitive(bHide);
250 m_xConditionFT->set_sensitive(bHide);
256 weld::fromId<sw::mark::IMark*>(m_xBookmarksBox->get_id(rIter)));
260 && !m_xBookmarksBox->get_text(rIter).endsWith(
u"…");
266 weld::fromId<sw::mark::IMark*>(m_xBookmarksBox->get_id(rIterString.first)));
276 m_rSh.GotoMark(pBookmark);
278 if (m_rSh.GetSelText() != rIterString.second)
280 bRet = m_rSh.Replace(rIterString.second,
false);
284 else if (pBookmark->
IsExpanded() && !rIterString.second.isEmpty())
286 m_rSh.Insert(rIterString.second);
326 std::vector<std::pair<sw::mark::IMark*, OUString>>::const_iterator aListIter
336 if (aListIter->first != *ppBookmark || aListIter->second != (*ppBookmark)->GetName())
364 OUString
const*
const pSelected)
365 :
SfxDialogController(pParent,
"modules/swriter/ui/insertbookmark.ui",
"InsertBookmarkDialog")
367 , m_nLastBookmarksCount(0)
369 , m_xEditBox(m_xBuilder->weld_entry(
"name"))
370 , m_xInsertBtn(m_xBuilder->weld_button(
"insert"))
371 , m_xDeleteBtn(m_xBuilder->weld_button(
"delete"))
372 , m_xGotoBtn(m_xBuilder->weld_button(
"goto"))
373 , m_xEditTextBtn(m_xBuilder->weld_button(
"edittext"))
374 , m_xRenameBtn(m_xBuilder->weld_button(
"rename"))
375 , m_xHideCB(m_xBuilder->weld_check_button(
"hide"))
376 , m_xConditionFT(m_xBuilder->weld_label(
"condlabel"))
377 , m_xConditionED(new
ConditionEdit(m_xBuilder->weld_entry(
"withcond")))
378 , m_xBookmarksBox(new
BookmarkTable(m_xBuilder->weld_tree_view(
"bookmarks")))
379 , m_xForbiddenChars(m_xBuilder->weld_label(
"lbForbiddenChars"))
400 m_xBookmarksBox->set_column_editables({
false,
false,
true,
false,
false });
454 m_xBookmarksBox->make_sorted();
458 bool bSortAtoZ = m_xBookmarksBox->get_sort_order();
461 if (nColumn == m_xBookmarksBox->get_sort_column())
463 bSortAtoZ = !bSortAtoZ;
464 m_xBookmarksBox->set_sort_order(bSortAtoZ);
468 int nOldSortColumn = m_xBookmarksBox->get_sort_column();
469 if (nOldSortColumn != -1)
470 m_xBookmarksBox->set_sort_indicator(
TRISTATE_INDET, nOldSortColumn);
471 m_xBookmarksBox->set_sort_column(nColumn);
485 m_xControl->set_column_fixed_widths({ 40, 110, 150, 160 });
486 m_xControl->set_selection_mode(SelectionMode::Multiple);
491 std::unique_ptr<weld::TreeIter> xIter(
m_xControl->make_iterator());
502 OUString sBookmarkNodeText;
503 static const sal_Int32 nMaxTextLen = 50;
512 if (nMaxTextLen < sBookmarkNodeText.getLength())
514 sBookmarkNodeText = sBookmarkNodeText.subView(0, nMaxTextLen);
516 sBookmarkNodeText +=
u"…";
522 = (pBookmark->
IsHidden() || !sHideCondition.isEmpty() ||
528 sName.startsWith(
"_Toc") ||
sName.startsWith(
"_Ref"))
536 m_xControl->set_text(nRow, sBookmarkNodeText, 2);
538 m_xControl->set_text(nRow, sHideCondition, 4);
543 std::unique_ptr<weld::TreeIter> xRet;
562 return weld::fromId<sw::mark::IMark*>(
m_xControl->get_id(*xEntry));
576 OUString sDefaultBookmarkName =
SwResId(STR_BOOKMARK_DEF_NAME);
577 sal_Int32 nHighestBookmarkId = 0;
586 nHighestBookmarkId = std::max<sal_Int32>(nHighestBookmarkId, nCurrBookmarkId);
589 return sDefaultBookmarkName +
" " + OUString::number(nHighestBookmarkId + 1);
constexpr OUStringLiteral sHidden
Reference< XExecutableDialog > m_xDialog
void InsertBookmark(SwWrtShell &rSh, sw::mark::IMark *pMark)
OUString GetNameProposal() const
static constexpr OUStringLiteral aForbiddenChars
void select(const weld::TreeIter &rIter)
bool SelectByName(const OUString &sName)
static const char s_cSeparator
std::unique_ptr< weld::TreeIter > GetRowByBookmarkName(const OUString &sName)
BookmarkTable(std::unique_ptr< weld::TreeView > xControl)
sw::mark::IMark * GetBookmarkByName(const OUString &sName)
std::unique_ptr< weld::TreeIter > get_selected() const
std::unique_ptr< weld::TreeView > m_xControl
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
virtual const_iterator_t getBookmarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
virtual std::unique_ptr< ILazyDeleter > deleteMark(const IDocumentMarkAccess::const_iterator_t &ppMark, bool isMoveNodes)=0
Deletes a mark.
static SW_DLLPUBLIC MarkType GetType(const ::sw::mark::IMark &rMark)
Returns the MarkType used to create the mark.
virtual const_iterator_t getBookmarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of IBookmarks.
virtual sal_Int32 getBookmarksCount() const =0
returns the number of IBookmarks.
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
void AppendItem(const SfxPoolItem &)
void Done(bool bRemove=false)
void SetWindowState(const OUString &sState)
OUString GetWindowState() const
virtual VclPtr< AbstractSwRenameXNamedDlg > CreateSwRenameXNamedDlg(weld::Widget *pParent, css::uno::Reference< css::container::XNamed > &xNamed, css::uno::Reference< css::container::XNameAccess > &xNameAccess)=0
void Push()
store a copy of the current cursor on the cursor stack
void GetSelectedText(OUString &rBuf, ParaBreakType nHndlParaBreak=ParaBreakType::ToBlank)
Query text within selection.
std::unique_ptr< weld::Button > m_xEditTextBtn
sal_Int32 m_nLastBookmarksCount
void GotoSelectedBookmark()
std::unique_ptr< weld::Label > m_xForbiddenChars
std::vector< std::pair< sw::mark::IMark *, OUString > > m_aTableBookmarks
bool HaveBookmarksChanged()
std::unique_ptr< weld::Button > m_xRenameBtn
std::unique_ptr< weld::Button > m_xDeleteBtn
virtual ~SwInsertBookmarkDlg() override
std::unique_ptr< ConditionEdit > m_xConditionED
SwInsertBookmarkDlg(weld::Window *pParent, SwWrtShell &rSh, OUString const *pSelected)
bool ValidateBookmarks()
Check if displayed bookmarks are up-to date, if not update them.
std::unique_ptr< weld::CheckButton > m_xHideCB
std::unique_ptr< weld::Button > m_xGotoBtn
std::unique_ptr< weld::Entry > m_xEditBox
std::unique_ptr< BookmarkTable > m_xBookmarksBox
std::unique_ptr< weld::Button > m_xInsertBtn
std::unique_ptr< weld::Label > m_xConditionFT
PaM is Point and Mark: a selection of the document model.
sal_uInt16 GetPageNum(bool bAtPoint=true, const Point *pLayPos=nullptr)
Get number of page which contains cursor.
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document setting interface.
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Used by the UI to modify the document model.
void GotoMark(const ::sw::mark::IMark *const pMark)
bool Pop(SwCursorShell::PopMode, ::std::optional< SwCallLink > &roLink)
virtual const OUString & GetHideCondition() const =0
virtual bool IsHidden() const =0
virtual const SwPosition & GetOtherMarkPos() const =0
virtual bool IsExpanded() const =0
virtual const SwPosition & GetMarkStart() const =0
virtual const OUString & GetName() const =0
virtual const SwPosition & GetMarkPos() const =0
std::pair< const TreeIter &, OUString > iter_string
#define LINK(Instance, Class, Member)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SwAbstractDialogFactory & GetFactory()
OUString toId(const void *pValue)
Reference< XModel > xModel
OUString SwResId(TranslateId aId)
IMPL_LINK_NOARG(SwInsertBookmarkDlg, ModifyHdl, weld::Entry &, void)
IMPL_LINK(SwInsertBookmarkDlg, ChangeHideHdl, weld::Toggleable &, rBox, void)