summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-07-31 14:51:48 +0100
committerCaolán McNamara <caolanm@redhat.com>2013-07-31 23:28:29 +0100
commitd7d7b51c23a921803929f716a6554d869b1150a3 (patch)
tree35b3d70f09d982e5aa0cd6b90c362122083e19e2
parente78f75bc2da9d97be80e2bf240fa9ef38497ae4e (diff)
restore last selection of target-in-document dialog
Change-Id: Ib6eb3d9089b71888de76e338015519845d9f6b9d
-rw-r--r--cui/source/dialogs/hlmarkwn.cxx120
-rw-r--r--cui/source/inc/hlmarkwn.hxx3
2 files changed, 111 insertions, 12 deletions
diff --git a/cui/source/dialogs/hlmarkwn.cxx b/cui/source/dialogs/hlmarkwn.cxx
index c07b37587a7c..bd7a50e43eed 100644
--- a/cui/source/dialogs/hlmarkwn.cxx
+++ b/cui/source/dialogs/hlmarkwn.cxx
@@ -19,7 +19,8 @@
-#include <vcl/wrkwin.hxx>
#include <dialmgr.hxx>
#include <sfx2/docfile.hxx>
+#include <unotools/viewoptions.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
+#include <vcl/wrkwin.hxx>
@@ -27,2 +28,3 @@
#include <comphelper/processfactory.hxx>
+#include <comphelper/sequence.hxx>
#include <com/sun/star/awt/XBitmap.hpp>
@@ -140,3 +142,2 @@ SvxHlinkDlgMarkWnd::SvxHlinkDlgMarkWnd( SvxHyperlinkTabPageBase *pParent )
maLbTree.SetAccessibleName(String(CUI_RES(STR_MARK_TREE)));
-
}
@@ -202,2 +203,64 @@ sal_Bool SvxHlinkDlgMarkWnd::ConnectToDialog( sal_Bool bDoit )
+namespace
+{
+ void SelectPath(SvTreeListEntry *pEntry, SvxHlmarkTreeLBox &rLbTree,
+ std::deque<OUString> &rLastSelectedPath)
+ {
+ OUString sTitle(rLastSelectedPath.front());
+ rLastSelectedPath.pop_front();
+ if (sTitle.isEmpty())
+ return;
+ while (pEntry)
+ {
+ if (sTitle == rLbTree.GetEntryText(pEntry))
+ {
+ rLbTree.Select(pEntry);
+ rLbTree.MakeVisible(pEntry);
+ if (!rLastSelectedPath.empty())
+ {
+ rLbTree.Expand(pEntry);
+ SelectPath(rLbTree.FirstChild(pEntry), rLbTree, rLastSelectedPath);
+ }
+ break;
+ }
+ pEntry = rLbTree.NextSibling(pEntry);
+ }
+ }
+}
+
+#define TG_SETTING_MANAGER "TargetInDocument"
+#define TG_SETTING_LASTMARK "LastSelectedMark"
+#define TG_SETTING_LASTPATH "LastSelectedPath"
+
+void SvxHlinkDlgMarkWnd::RestoreLastSelection()
+{
+ bool bSelectedEntry = false;
+
+ OUString sLastSelectedMark;
+ std::deque<OUString> aLastSelectedPath;
+ SvtViewOptions aViewSettings( E_DIALOG, TG_SETTING_MANAGER );
+ if (aViewSettings.Exists())
+ {
+ //Maybe we might want to have some sort of mru list and keep a mapping
+ //per document, rather than the current reuse of "the last thing
+ //selected, regardless of the document"
+ aViewSettings.GetUserItem(TG_SETTING_LASTMARK) >>= sLastSelectedMark;
+ uno::Sequence<OUString> aTmp;
+ aViewSettings.GetUserItem(TG_SETTING_LASTPATH) >>= aTmp;
+ aLastSelectedPath = comphelper::sequenceToContainer< std::deque<OUString> >(aTmp);
+ }
+ //fallback to previous entry selected the last
+ //time we executed this dialog. First see if
+ //the exact mark exists and re-use that
+ if (!sLastSelectedMark.isEmpty())
+ bSelectedEntry = SelectEntry(sLastSelectedMark);
+ //Otherwise just select the closest path available
+ //now to what was available at dialog close time
+ if (!bSelectedEntry && !aLastSelectedPath.empty())
+ {
+ std::deque<OUString> aTmpSelectedPath(aLastSelectedPath);
+ SelectPath(maLbTree.First(), maLbTree, aTmpSelectedPath);
+ }
+}
+
/*************************************************************************
@@ -224,2 +287,4 @@ void SvxHlinkDlgMarkWnd::RefreshTree ( String aStrURL )
+ bool bSelectedEntry = false;
+
if ( nPos != STRING_NOTFOUND )
@@ -227,5 +292,8 @@ void SvxHlinkDlgMarkWnd::RefreshTree ( String aStrURL )
String aStrMark = aStrURL.Copy ( nPos+1 );
- SelectEntry ( aStrMark );
+ bSelectedEntry = SelectEntry(aStrMark);
}
+ if (!bSelectedEntry)
+ RestoreLastSelection();
+
LeaveWait();
@@ -427,3 +495,3 @@ void SvxHlinkDlgMarkWnd::ClearTree()
|*
-|* Find Entry for Strng
+|* Find Entry for String
|*
@@ -454,10 +522,10 @@ SvTreeListEntry* SvxHlinkDlgMarkWnd::FindEntry ( String aStrName )
-void SvxHlinkDlgMarkWnd::SelectEntry ( String aStrMark )
+bool SvxHlinkDlgMarkWnd::SelectEntry(String aStrMark)
{
SvTreeListEntry* pEntry = FindEntry ( aStrMark );
- if ( pEntry )
- {
- maLbTree.Select ( pEntry );
- maLbTree.MakeVisible ( pEntry );
- }
+ if (!pEntry)
+ return false;
+ maLbTree.Select ( pEntry );
+ maLbTree.MakeVisible ( pEntry );
+ return true;
}
@@ -496,2 +564,33 @@ IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl)
{
+ SvTreeListEntry* pEntry = maLbTree.GetCurEntry();
+ if ( pEntry )
+ {
+ TargetData* pUserData = (TargetData *) pEntry->GetUserData();
+ OUString sLastSelectedMark = pUserData->aUStrLinkname;
+
+ std::deque<OUString> aLastSelectedPath;
+ if (pEntry)
+ {
+ //If the bottommost entry is expanded but nothing
+ //underneath it is selected leave a dummy entry
+ if (maLbTree.IsExpanded(pEntry))
+ aLastSelectedPath.push_front(OUString());
+ while (pEntry)
+ {
+ aLastSelectedPath.push_front(maLbTree.GetEntryText(pEntry));
+ pEntry = maLbTree.GetParent(pEntry);
+ }
+ }
+
+ uno::Sequence< beans::NamedValue > aSettings(2);
+ aSettings[0].Name = TG_SETTING_LASTMARK;
+ aSettings[0].Value <<= sLastSelectedMark;
+ aSettings[1].Name = TG_SETTING_LASTPATH;
+ aSettings[1].Value <<= comphelper::containerToSequence<OUString>(aLastSelectedPath);
+
+ // write
+ SvtViewOptions aViewSettings( E_DIALOG, TG_SETTING_MANAGER );
+ aViewSettings.SetUserData( aSettings );
+ }
+
Close();
@@ -501,3 +600,2 @@ IMPL_LINK_NOARG(SvxHlinkDlgMarkWnd, ClickCloseHdl_Impl)
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/inc/hlmarkwn.hxx b/cui/source/inc/hlmarkwn.hxx
index ec170d3f6550..18629a3ca35a 100644
--- a/cui/source/inc/hlmarkwn.hxx
+++ b/cui/source/inc/hlmarkwn.hxx
@@ -74,2 +74,3 @@ protected:
sal_Bool RefreshFromDoc( OUString aURL );
+ void RestoreLastSelection();
@@ -90,3 +91,3 @@ public:
void RefreshTree ( String aStrURL );
- void SelectEntry ( String aStrMark );
+ bool SelectEntry(String aStrMark);