1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-19 08:30:25 +02:00

Fixed Bookmark selection after delete + refactoring

This commit is contained in:
Simon Lübeß 2022-08-13 19:24:17 +02:00
parent 6884b9fc21
commit fefffd4f64
2 changed files with 249 additions and 179 deletions

View file

@ -53,6 +53,8 @@ namespace IDE
public String mNotes ~ delete _; public String mNotes ~ delete _;
public bool mIsDisabled; public bool mIsDisabled;
public BookmarkFolder mFolder; public BookmarkFolder mFolder;
internal int IndexInFolder => mFolder.mBookmarkList.IndexOf(this);
} }
public class BookmarkFolder public class BookmarkFolder
@ -60,15 +62,7 @@ namespace IDE
/// The title of the bookmark-folder that will be visible in the bookmark-panel /// The title of the bookmark-folder that will be visible in the bookmark-panel
public String mTitle ~ delete _; public String mTitle ~ delete _;
public List<Bookmark> mBookmarkList = new List<Bookmark>() ~ public List<Bookmark> mBookmarkList = new List<Bookmark>() ~ delete _;
{
for (var bookmark in mBookmarkList)
bookmark.Kill();
gApp.mDebugger.mBreakpointsChangedDelegate();
delete _;
};
/// Gets or Sets whether every bookmark in this folder is disabled or not. /// Gets or Sets whether every bookmark in this folder is disabled or not.
public bool IsDisabled public bool IsDisabled
@ -86,7 +80,7 @@ namespace IDE
for (var bookmark in mBookmarkList) for (var bookmark in mBookmarkList)
bookmark.mIsDisabled = value; bookmark.mIsDisabled = value;
gApp.mBookmarkManager.mBookmarksChangedDelegate(); gApp.mBookmarkManager.BookmarksChanged();
} }
} }
@ -100,22 +94,28 @@ namespace IDE
mBookmarkList.Add(bookmark); mBookmarkList.Add(bookmark);
bookmark.mFolder = this; bookmark.mFolder = this;
} }
internal int Index => gApp.mBookmarkManager.mBookmarkFolders.IndexOf(this);
} }
using internal Bookmark;
using internal BookmarkFolder;
public class BookmarkManager public class BookmarkManager
{ {
public BookmarkFolder mRootFolder = new .(); public BookmarkFolder mRootFolder = new .();
public List<BookmarkFolder> mBookmarkFolders = new .() {mRootFolder} ~ DeleteContainerAndItems!(_); public List<BookmarkFolder> mBookmarkFolders = new .() {mRootFolder} ~ DeleteContainerAndItems!(_);
public Event<Action> mBookmarksChangedDelegate ~ _.Dispose(); /// Occurs when a bookmark/folder is added, removed or moved.
public Event<Action> BookmarksChanged ~ _.Dispose();
public delegate void MovedToBookmarkEventHandler(Bookmark bookmark);
// Occurs when the user jumped to a bookmark.
public Event<MovedToBookmarkEventHandler> MovedToBookmark ~ _.Dispose();
private int mBookmarkCount; private int mBookmarkCount;
/// Index of the folder that was navigated to last
public int32 mFolderIdx;
/// Index of the bookmark (inside of its folder) that was navigated to last
public int32 mBookmarkIdx;
/// Number of bookmarks created, used to generate the names. /// Number of bookmarks created, used to generate the names.
private int32 _createdBookmarks; private int32 _createdBookmarks;
/// Number of folders created, used to generate the names. /// Number of folders created, used to generate the names.
@ -140,11 +140,20 @@ namespace IDE
{ {
folder.IsDisabled = value; folder.IsDisabled = value;
} }
mBookmarksChangedDelegate(); BookmarksChanged();
} }
} }
/// Gets the currently selected bookmark or null, if no bookmark is selected.
public Bookmark CurrentBookmark
{
get;
private set;
}
public BookmarkFolder CurrentFolder => CurrentBookmark?.mFolder;
/** /**
* Creates a new bookmark folder * Creates a new bookmark folder
* @param title The title of the bookmark * @param title The title of the bookmark
@ -152,8 +161,6 @@ namespace IDE
*/ */
public BookmarkFolder CreateFolder(String title = null) public BookmarkFolder CreateFolder(String title = null)
{ {
mBookmarkIdx = -1;
BookmarkFolder folder = new .(); BookmarkFolder folder = new .();
if (title == null) if (title == null)
@ -161,9 +168,9 @@ namespace IDE
else else
folder.mTitle = new String(title); folder.mTitle = new String(title);
mBookmarkFolders.Add(folder); mBookmarkFolders.Add(folder);
mBookmarksChangedDelegate(); BookmarksChanged();
return folder; return folder;
} }
@ -171,23 +178,53 @@ namespace IDE
/// Deletes the given bookmark folder and all bookmarks inside it. /// Deletes the given bookmark folder and all bookmarks inside it.
public void DeleteFolder(BookmarkFolder folder) public void DeleteFolder(BookmarkFolder folder)
{ {
int folderIdx = mBookmarkFolders.IndexOf(folder); if (folder == CurrentFolder)
{
// the current bookmark will be deleted, so we have to find another one
int folderIdx = mBookmarkFolders.IndexOf(folder);
int newFolderIdx = folderIdx;
BookmarkFolder newFolder = null;
repeat
{
newFolderIdx--;
if (newFolderIdx < 0)
{
newFolderIdx = mBookmarkFolders.Count - 1;
}
if (mBookmarkFolders[newFolderIdx].mBookmarkList.Count != 0)
{
newFolder = mBookmarkFolders[newFolderIdx];
break;
}
}
// Break when we reach start
while ((folderIdx != newFolderIdx));
if (newFolder != null)
{
Debug.Assert(newFolder.mBookmarkList.Count != 0);
CurrentBookmark = newFolder.mBookmarkList[0];
}
}
while (!folder.mBookmarkList.IsEmpty)
{
gApp.mBookmarkManager.DeleteBookmark(folder.mBookmarkList.Back);
}
mBookmarkFolders.Remove(folder); mBookmarkFolders.Remove(folder);
delete folder; delete folder;
// Select the previous folder if (gApp.mDebugger.mBreakpointsChangedDelegate.HasListeners)
if (mFolderIdx == folderIdx) gApp.mDebugger.mBreakpointsChangedDelegate();
folderIdx--;
if (mFolderIdx >= mBookmarkFolders.Count)
mFolderIdx = (int32)mBookmarkFolders.Count - 1;
// Select last bookmark inside the newly selected folder BookmarksChanged();
if (mBookmarkIdx >= mBookmarkFolders[mFolderIdx].mBookmarkList.Count)
mBookmarkIdx = (int32)mBookmarkFolders[mFolderIdx].mBookmarkList.Count - 1;
mBookmarksChangedDelegate();
} }
public Bookmark CreateBookmark(String fileName, int wantLineNum, int wantColumn, bool isDisabled = false, String title = null, BookmarkFolder folder = null) public Bookmark CreateBookmark(String fileName, int wantLineNum, int wantColumn, bool isDisabled = false, String title = null, BookmarkFolder folder = null)
@ -196,10 +233,6 @@ namespace IDE
folder = folder ?? mRootFolder; folder = folder ?? mRootFolder;
mFolderIdx = (int32)mBookmarkFolders.IndexOf(folder);
mBookmarkIdx = (int32)folder.mBookmarkList.Count;
Bookmark bookmark = new Bookmark(); Bookmark bookmark = new Bookmark();
bookmark.mFileName = new String(fileName); bookmark.mFileName = new String(fileName);
bookmark.mLineNum = (int32)wantLineNum; bookmark.mLineNum = (int32)wantLineNum;
@ -213,45 +246,59 @@ namespace IDE
bookmark.mIsDisabled = isDisabled; bookmark.mIsDisabled = isDisabled;
folder.[Friend]AddBookmark(bookmark); folder.[Friend]AddBookmark(bookmark);
gApp.mDebugger.mBreakpointsChangedDelegate();
mBookmarksChangedDelegate(); if (gApp.mDebugger.mBreakpointsChangedDelegate.HasListeners)
gApp.mDebugger.mBreakpointsChangedDelegate();
CurrentBookmark = bookmark;
BookmarksChanged();
mBookmarkCount++; mBookmarkCount++;
return bookmark; return bookmark;
} }
/** Moves the bookmark to the specified folder. public void DeleteBookmark(Bookmark bookmark)
* @param bookmark The bookmark to move. {
* @param folder The folder to which the bookmark will be moved. bool deletedCurrentBookmark = false;
* @param insertBefore If null the bookmark will be added at the end of the folder. Otherwise it will be inserted before the specified bookmark. Bookmark newCurrentBookmark = null;
*/
public void MoveBookmarkToFolder(Bookmark bookmark, BookmarkFolder folder, Bookmark insertBefore = null) if (bookmark == CurrentBookmark)
{
if (bookmark.mFolder != null)
{ {
bookmark.mFolder.mBookmarkList.Remove(bookmark); deletedCurrentBookmark = true;
// try to select a bookmark from the current folder
newCurrentBookmark = FindPrevBookmark(true);
if (newCurrentBookmark == null || newCurrentBookmark == CurrentBookmark)
{
// Current folder is empty, select from previous folder
newCurrentBookmark = FindPrevBookmark(false);
if (newCurrentBookmark == CurrentBookmark)
{
// We have to make sure, that we don't select the current bookmark
newCurrentBookmark = null;
}
}
} }
if (insertBefore == null) BookmarkFolder folder = bookmark.mFolder;
folder.mBookmarkList.Add(bookmark);
else
{
Debug.Assert(folder == insertBefore.mFolder, "Insert before must be in folder.");
int index = folder.mBookmarkList.IndexOf(insertBefore); folder.mBookmarkList.Remove(bookmark);
folder.mBookmarkList.Insert(index, bookmark); bookmark.Kill();
}
bookmark.mFolder = folder; if (deletedCurrentBookmark)
CurrentBookmark = newCurrentBookmark;
FixupIndices();
mBookmarksChangedDelegate(); if (gApp.mDebugger.mBreakpointsChangedDelegate.HasListeners)
} gApp.mDebugger.mBreakpointsChangedDelegate();
BookmarksChanged();
mBookmarkCount--;
}
enum Placement enum Placement
{ {
@ -259,6 +306,42 @@ namespace IDE
After After
} }
/** Moves the bookmark to the specified folder.
* @param bookmark The bookmark to move.
* @param folder The folder to which the bookmark will be moved.
* @param insertBefore If null the bookmark will be added at the end of the folder. Otherwise it will be inserted before the specified bookmark.
*/
public void MoveBookmarkToFolder(Bookmark bookmark, BookmarkFolder targetFolder, Placement place = .Before, Bookmark targetBookmark = null)
{
if (bookmark.mFolder != null)
{
bookmark.mFolder.mBookmarkList.Remove(bookmark);
}
if (targetBookmark == null)
targetFolder.mBookmarkList.Add(bookmark);
else
{
Debug.Assert(targetFolder == targetBookmark.mFolder, "Insert before must be in folder.");
int index = targetFolder.mBookmarkList.IndexOf(targetBookmark);
if (place == .After)
index++;
targetFolder.mBookmarkList.Insert(index, bookmark);
}
bookmark.mFolder = targetFolder;
BookmarksChanged();
}
/** Moves the given folder in front of or behind the given target-folder.
* @param folder The folder to move.
* @param place Specifies whether folder will be placed in front of or behind target.
* @param target The folder relative to which folder will be placed.
*/
public void MoveFolder(BookmarkFolder folder, Placement place = .After, BookmarkFolder target = null) public void MoveFolder(BookmarkFolder folder, Placement place = .After, BookmarkFolder target = null)
{ {
if (folder == target) if (folder == target)
@ -280,41 +363,11 @@ namespace IDE
mBookmarkFolders.Insert(index, folder); mBookmarkFolders.Insert(index, folder);
} }
FixupIndices();
mBookmarksChangedDelegate(); BookmarksChanged();
} }
/// Make sure that the bookmark and folder indices are valid. /// Deletes all bookmarks and bookmark-folders.
private void FixupIndices()
{
if (mBookmarkIdx <= 0 || mBookmarkIdx >= mBookmarkFolders[mFolderIdx].mBookmarkList.Count)
{
mBookmarkIdx = 0;
// Don't have an empty folder selected
if (mBookmarkFolders[mFolderIdx].mBookmarkList.Count == 0)
mFolderIdx = 0;
}
}
public void DeleteBookmark(Bookmark bookmark)
{
BookmarkFolder folder = bookmark.mFolder;
folder.mBookmarkList.Remove(bookmark);
FixupIndices();
gApp.mDebugger.mBreakpointsChangedDelegate();
bookmark.Kill();
mBookmarksChangedDelegate();
mBookmarkCount--;
}
public void Clear() public void Clear()
{ {
for (var folder in mBookmarkFolders) for (var folder in mBookmarkFolders)
@ -327,108 +380,134 @@ namespace IDE
mRootFolder = new BookmarkFolder(); mRootFolder = new BookmarkFolder();
mBookmarkFolders.Add(mRootFolder); mBookmarkFolders.Add(mRootFolder);
mFolderIdx = 0;
mBookmarkIdx = 0;
gApp.mDebugger.mBreakpointsChangedDelegate();
mBookmarksChangedDelegate(); if (gApp.mDebugger.mBreakpointsChangedDelegate.HasListeners)
gApp.mDebugger.mBreakpointsChangedDelegate();
mBookmarkCount = 0;
BookmarksChanged();
} }
public void PrevBookmark(bool currentFolderOnly = false) /** Finds and returns the previous bookmark relative to CurrentBookmark.
{ * @param currentFolderOnly If set to true, only the current folder will be searched. Otherwise all folders will be searched.
* @returns The previous bookmark. If CurrentBookmark is the only bookmark, CurrentBookmark will be returned. Null, if there are no bookmarks.
*/
private Bookmark FindPrevBookmark(bool currentFolderOnly)
{
if (mBookmarkCount == 0) if (mBookmarkCount == 0)
return; return null;
int32 currentFolderIdx = mFolderIdx; int currentFolderIdx = CurrentFolder.Index;
int32 currentBookmarkIdx = mBookmarkIdx; int currentBookmarkIdx = CurrentBookmark.IndexInFolder;
Bookmark prevBookmark = null; Bookmark prevBookmark = null;
int newFolderIndex = currentFolderIdx;
int newBmIndex = currentBookmarkIdx;
repeat repeat
{ {
mBookmarkIdx--; newBmIndex--;
if (mBookmarkIdx < 0) if (newBmIndex < 0)
{ {
if (!currentFolderOnly) if (!currentFolderOnly)
{ {
mFolderIdx--; newFolderIndex--;
if (mFolderIdx < 0) if (newFolderIndex < 0)
{ {
// wrap to last folder // wrap to last folder
mFolderIdx = (int32)mBookmarkFolders.Count - 1; newFolderIndex = (int32)mBookmarkFolders.Count - 1;
} }
} }
// Select last bookmark in current folder // Select last bookmark in current folder
mBookmarkIdx = (int32)mBookmarkFolders[mFolderIdx].mBookmarkList.Count - 1; newBmIndex = (int32)mBookmarkFolders[newFolderIndex].mBookmarkList.Count - 1;
} }
if (mBookmarkIdx >= 0) if (newBmIndex >= 0)
prevBookmark = mBookmarkFolders[mFolderIdx].mBookmarkList[mBookmarkIdx]; prevBookmark = mBookmarkFolders[newFolderIndex].mBookmarkList[newBmIndex];
else else
prevBookmark = null; prevBookmark = null;
} }
// skip disabled bookmarks, stop when we reach starting point // skip disabled bookmarks, stop when we reach starting point
while ((prevBookmark == null || prevBookmark.mIsDisabled) && ((currentFolderIdx != mFolderIdx) || (currentBookmarkIdx != mBookmarkIdx) && mBookmarkIdx != -1)); while ((prevBookmark == null || prevBookmark.mIsDisabled) && ((currentFolderIdx != newFolderIndex) || (currentBookmarkIdx != newBmIndex) && newBmIndex != -1));
return prevBookmark;
}
/** Jumps to the previous bookmark.
* @param currentFolderOnly If true, only the current folder will be searched. Otherwise all folders will be searched.
*/
public void PrevBookmark(bool currentFolderOnly = false)
{
Bookmark prevBookmark = FindPrevBookmark(currentFolderOnly);
// If prevBookmark is disabled no bookmark is enabled. // If prevBookmark is disabled no bookmark is enabled.
if (prevBookmark != null && !prevBookmark.mIsDisabled) if (prevBookmark != null && !prevBookmark.mIsDisabled)
GotoBookmark(prevBookmark); GotoBookmark(prevBookmark);
} }
/* Jumps to the next bookmark.
* @param currentFolderOnly If true, only the current folder will be searched. Otherwise all folders will be searched.
*/
public void NextBookmark(bool currentFolderOnly = false) public void NextBookmark(bool currentFolderOnly = false)
{ {
if (mBookmarkCount == 0) if (mBookmarkCount == 0)
return; return;
int32 currentFolderIdx = mFolderIdx; int currentFolderIdx = CurrentFolder.Index;
int32 currentBookmarkIdx = mBookmarkIdx; int currentBookmarkIdx = CurrentBookmark.IndexInFolder;
Bookmark nextBookmark = null; Bookmark nextBookmark = null;
int newFolderIndex = currentFolderIdx;
int newBmIndex = currentBookmarkIdx;
repeat repeat
{ {
mBookmarkIdx++; newBmIndex++;
if (mBookmarkIdx >= mBookmarkFolders[mFolderIdx].mBookmarkList.Count) if (newBmIndex >= mBookmarkFolders[newFolderIndex].mBookmarkList.Count)
{ {
if (!currentFolderOnly) if (!currentFolderOnly)
{ {
mFolderIdx++; newFolderIndex++;
if (mFolderIdx >= mBookmarkFolders.Count) if (newFolderIndex >= mBookmarkFolders.Count)
{ {
// wrap to first folder // wrap to first folder
mFolderIdx = 0; newFolderIndex = 0;
} }
} }
// Select first bookmark in current folder (or -1 if there is no bookmark) // Select first bookmark in current folder (or -1 if there is no bookmark)
mBookmarkIdx = mBookmarkFolders[mFolderIdx].mBookmarkList.IsEmpty ? -1 : 0; newBmIndex = mBookmarkFolders[newFolderIndex].mBookmarkList.IsEmpty ? -1 : 0;
} }
if (mBookmarkIdx >= 0) if (newBmIndex >= 0)
nextBookmark = mBookmarkFolders[mFolderIdx].mBookmarkList[mBookmarkIdx]; nextBookmark = mBookmarkFolders[newFolderIndex].mBookmarkList[newBmIndex];
else else
nextBookmark = null; nextBookmark = null;
} }
// skip disabled bookmarks, stop when we reach starting point // skip disabled bookmarks, stop when we reach starting point
while ((nextBookmark == null || nextBookmark.mIsDisabled) && ((currentFolderIdx != mFolderIdx) || (currentBookmarkIdx != mBookmarkIdx) && mBookmarkIdx != -1)); while ((nextBookmark == null || nextBookmark.mIsDisabled) && ((currentFolderIdx != newFolderIndex) || (currentBookmarkIdx != newBmIndex) && newBmIndex != -1));
// If nextBookmark is disabled no bookmark is enabled. // If nextBookmark is disabled no bookmark is enabled.
if (nextBookmark != null && !nextBookmark.mIsDisabled) if (nextBookmark != null && !nextBookmark.mIsDisabled)
GotoBookmark(nextBookmark); GotoBookmark(nextBookmark);
} }
/// Moves the cursor to the given bookmark.
public void GotoBookmark(Bookmark bookmark) public void GotoBookmark(Bookmark bookmark)
{ {
mFolderIdx = (int32)mBookmarkFolders.IndexOf(bookmark.mFolder); CurrentBookmark = bookmark;
mBookmarkIdx = (int32)bookmark.mFolder.mBookmarkList.IndexOf(bookmark);
gApp.ShowSourceFileLocation(bookmark.mFileName, -1, -1, bookmark.mLineNum, bookmark.mColumn, LocatorType.Smart); gApp.ShowSourceFileLocation(bookmark.mFileName, -1, -1, bookmark.mLineNum, bookmark.mColumn, LocatorType.Smart);
MovedToBookmark(bookmark);
} }
} }
} }

View file

@ -137,7 +137,8 @@ namespace IDE.ui
AddWidget(mBookmarksListView); AddWidget(mBookmarksListView);
gApp.mBookmarkManager.mBookmarksChangedDelegate.Add(new => BookmarksChanged); gApp.mBookmarkManager.BookmarksChanged.Add(new => BookmarksChanged);
gApp.mBookmarkManager.MovedToBookmark.Add(new => MovedToBookmark);
} }
private void BookmarksLV_OnKeyDown(KeyDownEvent event) private void BookmarksLV_OnKeyDown(KeyDownEvent event)
@ -220,21 +221,11 @@ namespace IDE.ui
{ {
if (theEvent.mDragKind == .After) if (theEvent.mDragKind == .After)
{ {
int index = targetBookmark.mFolder.mBookmarkList.IndexOf(targetBookmark); gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, targetBookmark.mFolder, .After, targetBookmark);
index++;
Bookmark prevBookmark = null;
if (index < targetBookmark.mFolder.mBookmarkList.Count)
{
prevBookmark = targetBookmark.mFolder.mBookmarkList[index];
}
gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, targetBookmark.mFolder, prevBookmark);
} }
else if (theEvent.mDragKind == .Before) else if (theEvent.mDragKind == .Before)
{ {
gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, targetBookmark.mFolder, targetBookmark); gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, targetBookmark.mFolder, .Before, targetBookmark);
} }
} }
else if (var targetFolder = target.RefObject as BookmarkFolder) else if (var targetFolder = target.RefObject as BookmarkFolder)
@ -313,27 +304,10 @@ namespace IDE.ui
Menu menu = new Menu(); Menu menu = new Menu();
Menu anItem; Menu anItem;
anItem = menu.AddItem("Delete"); anItem = menu.AddItem("Delete");
anItem.mOnMenuItemSelected.Add(new (item) => anItem.mOnMenuItemSelected.Add(new (item) => { DeleteSelectedItems(); });
{
listView.GetRoot().WithSelectedItems(scope (item) =>
{
if (var bookmarkItem = item as BookmarksListViewItem)
{
if (var bookmark = bookmarkItem.RefObject as Bookmark)
gApp.mBookmarkManager.DeleteBookmark(bookmark);
else if (var folder = bookmarkItem.RefObject as BookmarkFolder)
gApp.mBookmarkManager.DeleteFolder(folder);
}
});
});
anItem = menu.AddItem("Rename"); anItem = menu.AddItem("Rename");
anItem.mOnMenuItemSelected.Add(new (item) => anItem.mOnMenuItemSelected.Add(new (item) => { TryRenameItem(); });
{
var selectedItem = mBookmarksListView.GetRoot().FindFirstSelectedItem();
if (selectedItem != null)
RenameItem(selectedItem);
});
menu.AddItem(); menu.AddItem();
@ -394,16 +368,37 @@ namespace IDE.ui
mBookmarksDirty = true; mBookmarksDirty = true;
} }
private void MovedToBookmark(Bookmark bookmark)
{
var root = (BookmarksListViewItem)mBookmarksListView.GetRoot();
root.WithItems(scope (item) =>
{
var bmItem = (BookmarksListViewItem)item;
if (bmItem.RefObject == bookmark)
{
bmItem.mIsBold = true;
ListViewItem parent = item.mParentItem;
parent.Open(true);
}
else
{
bmItem.mIsBold = false;
}
});
}
public override void Update() public override void Update()
{ {
if (mBookmarksDirty) if (mBookmarksDirty)
UpdateBookmarks(); UpdateBookmarks();
ShowTooltip(mBtnCreateBookmarkFolder, "Create a new folder."); ShowTooltip(mBtnCreateBookmarkFolder, "Create a new folder.");
ShowTooltip(mBtnPrevBookmark, "Move the cursor to previous bookmark."); ShowTooltip(mBtnPrevBookmark, "Move the cursor to the previous bookmark.");
ShowTooltip(mBtnNextBookmark, "Move the cursor to next bookmark."); ShowTooltip(mBtnNextBookmark, "Move the cursor to the next bookmark.");
ShowTooltip(mBtnPrevBookmarkInFolder, "Move the cursor to previous bookmark in the current folder."); ShowTooltip(mBtnPrevBookmarkInFolder, "Move the cursor to the previous bookmark in the current folder.");
ShowTooltip(mBtnNextBookmarkInFolder, "Move the cursor to next bookmark in the current folder."); ShowTooltip(mBtnNextBookmarkInFolder, "Move the cursor to the next bookmark in the current folder.");
base.Update(); base.Update();
} }
@ -432,23 +427,18 @@ namespace IDE.ui
var openFolders = scope List<BookmarkFolder>(); var openFolders = scope List<BookmarkFolder>();
if (root.mChildItems != null) root.WithItems(scope (item) =>
{
// Find all open Folders so that we can open them again after rebuilding the list view
for (var child in root.mChildItems)
{ {
if (!child.IsOpen) if (item.IsOpen && (var bookmarkFolder = ((BookmarksListViewItem)item).RefObject as BookmarkFolder))
continue;
if (var bookmarkFolder = ((BookmarksListViewItem)child).RefObject as BookmarkFolder)
{ {
openFolders.Add(bookmarkFolder); openFolders.Add(bookmarkFolder);
} }
} });
}
root.Clear(); root.Clear();
Bookmark currentBookmark = gApp.mBookmarkManager.CurrentBookmark;
for (BookmarkFolder folder in gApp.mBookmarkManager.mBookmarkFolders) for (BookmarkFolder folder in gApp.mBookmarkManager.mBookmarkFolders)
{ {
bool isRoot = (folder == IDEApp.sApp.mBookmarkManager.mRootFolder); bool isRoot = (folder == IDEApp.sApp.mBookmarkManager.mRootFolder);
@ -466,7 +456,8 @@ namespace IDE.ui
for (Bookmark bookmark in folder.mBookmarkList) for (Bookmark bookmark in folder.mBookmarkList)
{ {
AddBookmarkToListView(FolderItem, bookmark); BookmarksListViewItem bmItem = AddBookmarkToListView(FolderItem, bookmark);
bmItem.mIsBold = (bookmark == currentBookmark);
} }
if (!isRoot) if (!isRoot)