33#include <osl/diagnose.h>
51#include <bitmaps.hlst>
60#define GLOBAL_UPDATE_TIMEOUT 2000
66class SwGlobalFrameListener_Impl :
public SfxListener
70 explicit SwGlobalFrameListener_Impl(
SfxViewFrame& rFrame)
78 bool IsValid()
const {
return m_bValid;}
85 if( rHint.
GetId() == SfxHintId::Dying)
91enum GLOBAL_CONTEXT_IDX
94 IDX_STR_EDIT_CONTENT = 1,
95 IDX_STR_EDIT_INSERT = 2,
99 IDX_STR_INSERT_TEXT = 6,
101 IDX_STR_UPDATE_SEL = 8,
102 IDX_STR_UPDATE_INDEX = 9,
103 IDX_STR_UPDATE_LINK = 10,
104 IDX_STR_UPDATE_ALL = 11,
105 IDX_STR_BROKEN_LINK = 12,
106 IDX_STR_EDIT_LINK = 13
130 : m_xTreeView(
std::move(xTreeView))
131 , m_aDropTargetHelper(*this)
133 , m_aUpdateTimer(
"SwGlobalTree m_aUpdateTimer")
134 , m_pActiveShell(nullptr)
164 : DropTargetHelper(rTreeView.get_widget().get_drop_target())
165 , m_rTreeView(rTreeView)
174 std::unique_ptr<weld::TreeIter> xDropEntry(rWidget.
make_iterator());
186 weld::fromId<const SwGlblDocContent*>(rWidget.
get_id(*xDropEntry)) :
188 if(
aData.HasFormat( SotClipboardFormatId::FILE_LIST ))
192 int nAbsContPos = xDropEntry ?
199 aData.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList );
200 for (
size_t n = aFileList.
Count();
n--; )
210 pSh->GetGlobalDocContent(aTempContents);
213 if(nEntryCount < aTempContents.
size())
217 pCnt = aTempContents[ nAbsContPos ].get();
223 else if( !(sFileName =
249 if (IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE) ||
250 IsDropFormatSupported( SotClipboardFormatId::STRING) ||
251 IsDropFormatSupported( SotClipboardFormatId::FILE_LIST) ||
252 IsDropFormatSupported( SotClipboardFormatId::SOLK) ||
253 IsDropFormatSupported( SotClipboardFormatId::NETSCAPE_BOOKMARK )||
254 IsDropFormatSupported( SotClipboardFormatId::FILECONTENT) ||
255 IsDropFormatSupported( SotClipboardFormatId::FILEGRPDESCRIPTOR) ||
256 IsDropFormatSupported( SotClipboardFormatId::UNIFORMRESOURCELOCATOR) ||
257 IsDropFormatSupported( SotClipboardFormatId::FILENAME))
267 if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
271 if (m_pActiveShell && !m_pActiveShell->GetView().GetDocShell()->IsReadOnly())
273 std::unique_ptr<weld::Builder> xBuilder(
Application::CreateBuilder(m_xTreeView.get(),
"modules/swriter/ui/mastercontextmenu.ui"));
274 std::unique_ptr<weld::Menu> xPopup = xBuilder->weld_menu(
"navmenu");
293 OUString sCommand = xPopup->popup_at_rect(m_xTreeView.get(),
tools::Rectangle(rCEvt.GetMousePosPixel(),
Size(1,1)));
294 if (!sCommand.isEmpty())
295 ExecuteContextMenuAction(sCommand);
305 if (rCommand ==
u"insert")
312 else if (rCommand ==
u"update")
320 std::unique_ptr<weld::TreeIter> xEntry(
m_xTreeView->make_iterator());
321 bool bEntry =
m_xTreeView->get_selected(xEntry.get());
323 int nSelCount =
m_xTreeView->count_selected_rows();
325 std::unique_ptr<weld::TreeIter> xPrevEntry;
326 bool bPrevEntry =
false;
329 xPrevEntry =
m_xTreeView->make_iterator(xEntry.get());
330 bPrevEntry =
m_xTreeView->iter_previous(*xPrevEntry);
334 if(nSelCount == 1 || !nEntryCount)
345 else if(!nEntryCount)
360 const SwGlblDocContent* pCont = weld::fromId<const SwGlblDocContent*>(m_xTreeView->get_id(rIter));
366 sEntry = m_aContextStrings[IDX_STR_BROKEN_LINK] + sEntry;
379 int nSelCount =
m_xTreeView->count_selected_rows();
381 int nAbsPos = nSel != -1 ? nSel : 0;
385 pNavi->
m_xGlobalToolBox->set_item_sensitive(
"edit", nSelCount == 1 && !bReadonly);
386 pNavi->
m_xGlobalToolBox->set_item_sensitive(
"insert", nSelCount <= 1 && !bReadonly);
389 nSelCount == 1 && nAbsPos && !bReadonly);
391 nSelCount == 1 && nAbsPos < m_xTreeView->n_children() - 1 && !bReadonly);
399 int nDest = pDropEntry ?
m_xTreeView->get_iter_index_in_parent(*pDropEntry)
416 bool bHandled =
false;
424 GetParentWindow()->ToggleTree();
438 std::unique_ptr<weld::TreeIter> xEntry =
m_xTreeView->make_iterator();
439 bool bEntry =
m_xTreeView->get_iter_first(*xEntry);
440 for (
size_t i = 0;
i <
nCount && bEntry;
i++)
450 assert(bEntry ||
i ==
nCount - 1);
455 int nOldSelEntry =
m_xTreeView->get_selected_index();
458 if (nOldSelEntry != -1)
461 nSelPos = nOldSelEntry;
483 aImage = RID_BMP_NAVI_INDEX;
490 aImage = RID_BMP_DROP_REGION;
496 if (!aImage.isEmpty())
502 if (sEntry == sEntryName)
518 Sequence< OUString > aFileNames;
525 else if ( !pFileName->isEmpty() )
527 aFileNames.realloc(1);
531 aFileNames.getArray()[0]
539 sal_uInt16 nSlot = 0;
573 bool bUpdateHard =
false;
580 std::optional<SwGlblDocContent> oContCopy;
584 sal_uInt16 nSlot = 0;
585 if (rSelectedPopupEntry ==
u"updatesel")
606 else if (rSelectedPopupEntry ==
u"updateindex")
611 else if (rSelectedPopupEntry ==
u"updatelinks" || rSelectedPopupEntry ==
u"updateall")
614 if (rSelectedPopupEntry ==
u"updateall")
619 else if (rSelectedPopupEntry ==
u"editcontent")
621 OSL_ENSURE(pCont,
"edit without entry ? " );
627 else if (rSelectedPopupEntry ==
u"editlink")
629 OSL_ENSURE(pCont,
"edit without entry ? " );
638 else if (rSelectedPopupEntry ==
u"deleteentry")
643 std::vector<int> aRows =
m_xTreeView->get_selected_rows();
644 std::sort(aRows.begin(), aRows.end());
646 std::unique_ptr<SwGlblDocContents> pTempContents;
648 for (
auto iter = aRows.rbegin(); iter != aRows.rend(); ++iter)
656 pTempContents.reset();
660 else if (rSelectedPopupEntry ==
u"insertindex")
669 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
679 if(
RET_OK == pDlg->Execute())
682 pDlg->GetCurrentTOXType());
691 else if (rSelectedPopupEntry ==
u"insertfile")
697 else if (rSelectedPopupEntry ==
u"insertnewfile")
700 SwGlobalFrameListener_Impl aFrameListener(rGlobFrame);
704 SwDocShell::Factory().GetFilterContainer()->
GetName());
708 SfxCallMode::SYNCHRON, { &aFactory }));
717 SID_SAVEASDOC, SfxCallMode::SYNCHRON ));
723 if(aFrameListener.IsValid() && !sNewFile.isEmpty())
734 pCont = nEntry != -1 ? weld::fromId<SwGlblDocContent*>(
m_xTreeView->get_id(nEntry)) :
nullptr;
756 else if (rSelectedPopupEntry ==
u"inserttext")
767 else if (rSelectedPopupEntry ==
u"update")
780 SwView* pView = GetParentWindow()->GetCreateView();
798 if (pActiveShellCurrSection)
800 const SwSection* pSection = pActiveShellCurrSection;
858 int nSource = nEntry;
860 if (rCmd ==
u"movedown")
863 bMove = nEntryCount > nSource + 1;
866 else if (rCmd ==
u"moveup")
868 bMove = 0 != nSource;
906 aTempContents.
size() != nChildren)
913 for(
size_t i = 0;
i < aTempContents.
size() && !bCopy;
i++)
958 while( !bFound && pCurr )
978 ExecuteList(SID_OPENDOC, SfxCallMode::ASYNCHRON,
979 { &
aURL, &aReadOnly, &aReferer, &aTargetFrameName });
985 int nEntry = m_xTreeView->get_cursor_index();
986 SwGlblDocContent* pCont = weld::fromId<SwGlblDocContent*>(m_xTreeView->get_id(nEntry));
992 m_pActiveShell->GetView().GetEditWin().GrabFocus();
1012 sal_Int32 nFiles = _rFiles.getLength();
1018 bool bMove = _pContent ==
nullptr;
1019 const OUString* pFileNames = _rFiles.getConstArray();
1032 nAnchorContent = nContent;
1038 for ( sal_Int32 nFile = 0; nFile < nFiles; ++nFile )
1043 OSL_ENSURE(aTempContents.
size() > (nAnchorContent + nFile),
"invalid anchor content -> last insertion failed");
1044 if ( aTempContents.
size() > (nAnchorContent + nFile) )
1045 pAnchorContent = aTempContents[nAnchorContent + nFile].get();
1047 pAnchorContent = aTempContents.
back().get();
1048 OUString sFileName(pFileNames[nFile]);
1054 OUString sTempSectionName(sSectionName);
1055 sal_uInt16 nAddNumber = 0;
1058 while ( nCount < nSectCount )
1066 sTempSectionName = sSectionName +
":" + OUString::number( nAddNumber );
1073 sSectionName = sTempSectionName;
1076 aSectionData.SetProtectFlag(
true);
1077 aSectionData.SetHidden(
false);
1079 aSectionData.SetLinkFileName(sFileName);
1081 aSectionData.SetLinkFilePassword( OUString() );
1103 if ( aMedList.empty() )
1106 Sequence< OUString >aFileNames( aMedList.size() );
1107 OUString* pFileNames = aFileNames.getArray();
1109 for (
const std::unique_ptr<SfxMedium>& pMed : aMedList)
1115 + pMed->GetFilter()->GetFilterName()
1117 pFileNames[
nPos++] = sFileName;
1119 InsertRegion( &*m_oDocContent, aFileNames );
1120 m_oDocContent.reset();
1137 if (rHint.
GetId() == SfxHintId::SwNavigatorUpdateTracking)
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
OUString GetFile(size_t nIndex) const
bool Detect(bool bExtendedInfo=false)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool SetSmartURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const OUString & GetEventName() const
SfxFrame * GetFrame() const
SAL_WARN_UNUSED_RESULT SfxViewFrame * GetCurrentViewFrame() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
bool IsListening(SfxBroadcaster &rBroadcaster) const
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
const INetURLObject & GetURLObject() const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
SfxMedium * GetMedium() const
OUString GetTitle(sal_uInt16 nMaxLen=0) const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
SfxItemPool & GetPool() const
const css::uno::Reference< css::frame::XController2 > & GetController() const
SfxDispatcher * GetDispatcher()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
virtual SfxObjectShell * GetObjectShell() override
SfxViewFrame & GetViewFrame() const
virtual VclPtr< AbstractMultiTOXTabDialog > CreateMultiTOXTabDialog(weld::Widget *pParent, const SfxItemSet &rSet, SwWrtShell &rShell, SwTOXBase *pCurTOX, bool bGlobal)=0
static SwAbstractDialogFactory * Create()
bool GotoPrevTOXBase(const OUString *=nullptr)
jump to previous index
void EndAction(const bool bIdleEnd=false)
void GotoGlobalDocContent(const SwGlblDocContent &rPos)
size_t GetSectionFormatCount() const
void DeleteGlobalDocContent(const SwGlblDocContents &rArr, size_t nPos)
const SwSection * GetCurrSection() const
void InsertGlobalDocContent(const SwGlblDocContent &rPos, SwSectionData &rNew)
bool MoveGlobalDocContent(const SwGlblDocContents &rArr, size_t nFromPos, size_t nToPos, size_t nNewPos)
const SwSectionFormat & GetSectionFormat(size_t nFormat) const
sfx2::LinkManager & GetLinkManager()
void GetGlobalDocContent(SwGlblDocContents &rArr) const
const SwSection * GetSection() const
GlobalDocContentType GetType() const
Query contents.
const SwTOXBase * GetTOX() const
SwNodeOffset GetDocPos() const
SwGlobalTreeDropTarget(SwGlobalTree &rTreeView)
SwGlobalTree & m_rTreeView
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
std::unique_ptr< weld::TreeView > m_xTreeView
std::optional< SwGlblDocContent > m_oDocContent
std::unique_ptr< SwGlblDocContents > m_pSwGlblDocContents
void EditContent(const SwGlblDocContent *pCont)
SwNavigationPI * GetParentWindow()
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
void ExecuteContextMenuAction(std::u16string_view rSelectedPopupEntry)
SwNavigationPI * m_pDialog
static const SfxObjectShell * s_pShowShell
MenuEnableFlags GetEnableFlags() const
void ExecCommand(std::u16string_view rCmd)
OUString m_aContextStrings[GLOBAL_CONTEXT_COUNT]
void InsertRegion(const SwGlblDocContent *_pContent, const css::uno::Sequence< OUString > &_rFiles)
void MoveSelectionTo(const weld::TreeIter *pDropTarget)
void Display(bool bOnlyUpdateUserData=false)
const SwWrtShell * GetActiveWrtShell() const
weld::TreeView & get_widget()
void GotoContent(const SwGlblDocContent *)
SwGlobalTree(std::unique_ptr< weld::TreeView > xTreeView, SwNavigationPI *pDialog)
void TbxMenuHdl(std::u16string_view rCommand, weld::Menu &rMenu)
static void SetShowShell(const SfxObjectShell *pSet)
std::unique_ptr< sfx2::DocumentInserter > m_pDocInserter
void OpenDoc(const SwGlblDocContent *)
SwWrtShell * m_pActiveShell
SwView * GetCreateView() const
static OUString CreateDropFileName(const TransferableDataHelper &rData)
std::unique_ptr< weld::Toolbar > m_xGlobalToolBox
virtual weld::Window * GetFrameWeld() const override
OUString const & GetLinkFileName() const
SwSection * GetParent() const
const OUString & GetSectionName() const
bool IsConnectFlag() const
const OUString & GetTOXName() const
const OUString & GetTitle() const
Built on top of SwWrtShell, provides functionality to insert, update or perform other actions on vari...
bool UpdateOrInsertTOX(const SwTOXDescription &rDesc, SwTOXBase **ppBase, const SfxItemSet *pSet)
SwWrtShell & GetWrtShell() const
SwWrtShell * GetWrtShellPtr() const
SwDocShell * GetDocShell()
Used by the UI to modify the document model.
bool GotoNextTOXBase(const OUString *pName=nullptr)
void SplitNode(bool bAutoFormat=false)
void UpdateTableOf(const SwTOXBase &rTOX, const SfxItemSet *pSet=nullptr)
bool Up(bool bSelect, sal_uInt16 nCount=1, bool bBasicCall=false)
const SwView & GetView() const
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
const Value & back() const
void UpdateAllLinks(bool bAskUpdate, bool bUpdateGrfLinks, weld::Window *pParentWin)
sal_uInt16 GetCode() const
sal_uInt16 GetModifier() const
virtual std::unique_ptr< TreeIter > make_iterator(const TreeIter *pOrig=nullptr) const=0
virtual int get_iter_index_in_parent(const TreeIter &rIter) const=0
virtual int n_children() const=0
virtual TreeView * get_drag_source() const=0
virtual bool get_dest_row_at_pos(const Point &rPos, weld::TreeIter *pResult, bool bDnDMode, bool bAutoScroll=true)=0
virtual OUString get_id(int pos) const=0
#define FN_PARAM_TOX_TYPE
#define FN_INSERT_MULTI_TOX
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
virtual OUString GetName() const override
::std::vector< std::unique_ptr< SfxMedium > > SfxMediumList
IMPL_LINK_NOARG(SwGlobalTree, SelectHdl, weld::TreeView &, void)
IMPL_LINK(SwGlobalTree, CommandHdl, const CommandEvent &, rCEvt, bool)
#define GLOBAL_UPDATE_TIMEOUT
IMPL_STATIC_LINK_NOARG(SwGlobalTree, ShowFrameHdl, void *, void)
const TranslateId GLOBAL_CONTEXT_ARY[]
constexpr OUStringLiteral HID_NAVIGATOR_GLOB_TREELIST
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatCol > RES_COL(115)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(97)
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_MOD2
#define LINK(Instance, Class, Member)
constexpr OUStringLiteral aData
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
const sal_Unicode cTokenSeparator
OUString toId(const void *pValue)
const css::datatransfer::dnd::DropTargetDropEvent maDropEvent
#define GLOBAL_CONTEXT_COUNT
OUString SwResId(TranslateId aId)