/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// callback to modify EditBox
IMPL_LINK_NOARG(SwInsertBookmarkDlg, ModifyHdl, weld::Entry&, void)
{
ValidateBookmarks();
m_xBookmarksBox->unselect_all(); // if a string has been pasted from the clipboard then // there may be illegal characters in the box // sanitization
OUString sTmp = m_xEditBox->get_text();
OUString sMsg; const sal_Int32 nLen = sTmp.getLength(); for (sal_Int32 i = 0; i < BookmarkTable::aForbiddenChars.getLength(); i++)
{ const sal_Int32 nTmpLen = sTmp.getLength();
sTmp = sTmp.replaceAll(OUStringChar(BookmarkTable::aForbiddenChars.getStr()[i]), ""); if (sTmp.getLength() != nTmpLen)
sMsg += OUStringChar(BookmarkTable::aForbiddenChars.getStr()[i]);
} constbool bHasForbiddenChars = sTmp.getLength() != nLen;
m_xForbiddenChars->set_visible(bHasForbiddenChars); if (bHasForbiddenChars)
m_xEditBox->set_message_type(weld::EntryMessageType::Error); else
m_xEditBox->set_message_type(weld::EntryMessageType::Normal);
// allow to add new bookmark only if one name provided and it's not taken
m_xInsertBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 0 && !bHasForbiddenChars
&& !m_bAreProtected);
// allow to delete only if all bookmarks are recognized
m_xDeleteBtn->set_sensitive(nEntries > 0 && nSelectedEntries == nEntries && !m_bAreProtected);
m_xGotoBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1);
m_xEditTextBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1);
m_xRenameBtn->set_sensitive(nEntries == 1 && nSelectedEntries == 1 && !m_bAreProtected);
}
// callback to delete a text mark
IMPL_LINK_NOARG(SwInsertBookmarkDlg, DeleteHdl, weld::Button&, void)
{ if (!ValidateBookmarks()) return;
IMPL_LINK_NOARG(SwInsertBookmarkDlg, SelectionChangedHdl, weld::TreeView&, void)
{ if (!ValidateBookmarks()) return; // this event should fired only if we change selection by clicking on BookmarkTable entry if (!m_xBookmarksBox->has_focus()) return;
IMPL_LINK_NOARG(SwInsertBookmarkDlg, EditTextHdl, weld::Button&, void)
{ if (!ValidateBookmarks()) return; auto pSelected = m_xBookmarksBox->get_selected(); if (!pSelected) return;
m_xBookmarksBox->start_editing(*pSelected);
}
IMPL_LINK_NOARG(SwInsertBookmarkDlg, RenameHdl, weld::Button&, void)
{ if (!ValidateBookmarks()) return; auto xSelected = m_xBookmarksBox->get_selected(); if (!xSelected) return;
// callback to an insert button. Inserts a new text mark to the current position.
IMPL_LINK_NOARG(SwInsertBookmarkDlg, InsertHdl, weld::Button&, void)
{
OUString sBookmark = m_xEditBox->get_text();
m_rSh.SetBookmark2(vcl::KeyCode(), SwMarkName(sBookmark), m_xHideCB->get_active(),
m_xConditionED->get_text());
IMPL_LINK(SwInsertBookmarkDlg, EditedHdl, weld::TreeView::iter_string const&, rIterString, bool)
{
sw::mark::MarkBase const* const pBookmark(
weld::fromId<sw::mark::MarkBase*>(m_xBookmarksBox->get_id(rIterString.first)));
assert(pBookmark); bool bRet(false); if (pBookmark->GetMarkPos() != pBookmark->GetOtherMarkPos())
{ if (pBookmark->GetMarkPos().GetNode() != pBookmark->GetOtherMarkPos().GetNode())
{ returnfalse; // don't allow editing if it spans multiple nodes
}
m_rSh.Push();
m_rSh.GotoMark(pBookmark); // GetSelText only works for 1 paragraph, but it's checked above if (m_rSh.GetSelText() != rIterString.second)
{
bRet = m_rSh.Replace(rIterString.second, false);
}
m_rSh.Pop(SwEditShell::PopMode::DeleteCurrent);
} elseif (pBookmark->IsExpanded() && !rIterString.second.isEmpty())
{ // SwEditShell::Replace does nothing for empty selection
m_rSh.Insert(rIterString.second);
bRet = true;
} return bRet;
}
void SwInsertBookmarkDlg::GotoSelectedBookmark()
{ if (!ValidateBookmarks()) return; // if no entries selected we can't jump anywhere // shouldn't be needed as we disable GoTo button when jump is not possible auto xSelected = m_xBookmarksBox->get_selected(); if (!xSelected) return;
// disabled until "Hide" flag is not checked
m_xConditionED->set_sensitive(false);
m_xConditionFT->set_sensitive(false);
// restore dialog size
SvtViewOptions aDlgOpt(EViewType::Dialog, u"BookmarkDialog"_ustr); if (aDlgOpt.Exists())
m_xDialog->set_window_state(aDlgOpt.GetWindowState());
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();
}
}
}
const OUString& sHideCondition = pBookmark->GetHideCondition(); const SwMarkName& sName = pBookmark->GetName();
OUString sHidden
= (pBookmark->IsHidden() || !sHideCondition.isEmpty() || // tdf#150955 add "hidden" status to the imported OOXML _Toc and _Ref bookmarks // to allow separating custom bookmarks by sorting based on their Hidden status. // Note: this "hidden" means here only that these bookmarks haven't got // visible bookmark formatting aids (gray I-shape or brackets), otherwise // their anchor are still visible.
sName.toString().startsWith("_Toc") || sName.toString().startsWith("_Ref"))
? SwResId(STR_BOOKMARK_YES)
: SwResId(STR_BOOKMARK_NO);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.