1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Bookmark folders, Drag & Drop

This commit is contained in:
Simon Lübeß 2022-06-09 12:25:48 +02:00
parent b3787313be
commit bd048e2fe6
5 changed files with 670 additions and 188 deletions

View file

@ -52,38 +52,153 @@ namespace IDE
public String mTitle ~ delete _; public String mTitle ~ delete _;
public String mNotes ~ delete _; public String mNotes ~ delete _;
public bool mIsDisabled; public bool mIsDisabled;
public BookmarkFolder mFolder;
} }
public class BookmarkFolder
{
/// The title of the bookmark-folder that will be visible in the bookmark-panel
public String mTitle ~ delete _;
public List<Bookmark> mBookmarkList = new List<Bookmark>() ~
{
for (var bookmark in mBookmarkList)
bookmark.Kill();
gApp.mDebugger.mBreakpointsChangedDelegate();
delete _;
};
/// Gets or Sets whether every bookmark in this folder is disabled or not.
public bool IsDisabled
{
get
{
for (var bookmark in mBookmarkList)
if (!bookmark.mIsDisabled)
return false;
return true;
}
set
{
for (var bookmark in mBookmarkList)
bookmark.mIsDisabled = value;
gApp.mBookmarksPanel.mBookmarksDirty = true;
}
}
/// Adds the given bookmark to this folder. If needed, removes it from its old folder.
public void AddBookmark(Bookmark bookmark)
{
if (bookmark.mFolder != null)
{
bookmark.mFolder.mBookmarkList.Remove(bookmark);
}
mBookmarkList.Add(bookmark);
bookmark.mFolder = this;
//gApp.mBookmarksPanel.mBookmarksDirty = true;
}
}
public class BookmarkManager public class BookmarkManager
{ {
public List<Bookmark> mBookmarkList = new List<Bookmark>() ~ public BookmarkFolder mRootFolder = new .();
{ public List<BookmarkFolder> mBookmarkFolders = new .() {mRootFolder} ~ DeleteContainerAndItems!(_);
for (var bookmark in mBookmarkList)
bookmark.Kill(); private int mBookmarkCount;
delete _;
}; /// 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; public int32 mBookmarkIdx;
/// Number of bookmarks created, used to generate the names.
private int32 _createdBookmarks; private int32 _createdBookmarks;
/// Number of folders created, used to generate the names.
private int32 _createdFolders;
/// Gets or sets whether all bookmarks are disabled or not.
public bool AllBookmarksDisabled public bool AllBookmarksDisabled
{ {
get get
{ {
for (Bookmark b in mBookmarkList) for (var folder in mBookmarkFolders)
{ {
if (!b.mIsDisabled) if (!folder.IsDisabled)
return false; return false;
} }
return true; return true;
} }
set
{
for (var folder in mBookmarkFolders)
{
folder.IsDisabled = value;
}
gApp.mBookmarksPanel.mBookmarksDirty = true;
}
} }
public Bookmark CreateBookmark(String fileName, int wantLineNum, int wantColumn, bool isDisabled = false, String title = null) /**
* Creates a new bookmark folder
* @param title The title of the bookmark
* @returns the newly created BookmarkFolder
*/
public BookmarkFolder CreateFolder(String title = null)
{ {
mBookmarkIdx = (int32)mBookmarkList.Count; mBookmarkIdx = -1;
_createdBookmarks++;
BookmarkFolder folder = new .();
if (title == null)
folder.mTitle = new $"Folder {_createdFolders++}";
else
folder.mTitle = new String(title);
mBookmarkFolders.Add(folder);
gApp.mBookmarksPanel.mBookmarksDirty = true;
return folder;
}
/// Deletes the given bookmark folder and all bookmarks inside it.
public void DeleteFolder(BookmarkFolder folder)
{
int folderIdx = mBookmarkFolders.IndexOf(folder);
mBookmarkFolders.Remove(folder);
delete folder;
// Select the previous folder
if (mFolderIdx == folderIdx)
folderIdx--;
if (mFolderIdx >= mBookmarkFolders.Count)
mFolderIdx = (int32)mBookmarkFolders.Count - 1;
// Select last bookmark inside the newly selected folder
if (mBookmarkIdx >= mBookmarkFolders[mFolderIdx].mBookmarkList.Count)
mBookmarkIdx = (int32)mBookmarkFolders[mFolderIdx].mBookmarkList.Count - 1;
gApp.mBookmarksPanel.mBookmarksDirty = true;
}
public Bookmark CreateBookmark(String fileName, int wantLineNum, int wantColumn, bool isDisabled = false, String title = null, BookmarkFolder folder = null)
{
var folder;
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);
@ -97,91 +212,222 @@ namespace IDE
bookmark.mIsDisabled = isDisabled; bookmark.mIsDisabled = isDisabled;
mBookmarkList.Add(bookmark); folder.AddBookmark(bookmark);
gApp.mDebugger.mBreakpointsChangedDelegate(); gApp.mDebugger.mBreakpointsChangedDelegate();
//gApp.mBookmarksPanel.UpdateBookmarks();
gApp.mBookmarksPanel.mBookmarksDirty = true; gApp.mBookmarksPanel.mBookmarksDirty = true;
mBookmarkCount++;
return bookmark; return bookmark;
} }
/** 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 folder, Bookmark insertBefore = null)
{
if (bookmark.mFolder != null)
{
bookmark.mFolder.mBookmarkList.Remove(bookmark);
}
if (insertBefore == null)
folder.mBookmarkList.Add(bookmark);
else
{
Debug.Assert(folder == insertBefore.mFolder, "Insert before must be in folder.");
int index = folder.mBookmarkList.IndexOf(insertBefore);
folder.mBookmarkList.Insert(index, bookmark);
}
bookmark.mFolder = folder;
FixupIndices();
gApp.mBookmarksPanel.mBookmarksDirty = true;
}
enum Placement
{
Before,
After
}
public void MoveFolder(BookmarkFolder folder, Placement place = .After, BookmarkFolder target = null)
{
if (folder == target)
return;
if (mBookmarkFolders.Contains(folder))
mBookmarkFolders.Remove(folder);
if (target == null)
{
mBookmarkFolders.Add(folder);
}
else
{
int index = mBookmarkFolders.IndexOf(target);
if (place == .After)
index++;
mBookmarkFolders.Insert(index, folder);
}
FixupIndices();
gApp.mBookmarksPanel.mBookmarksDirty = true;
}
/// Make sure that the bookmark and folder indices are valid.
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) public void DeleteBookmark(Bookmark bookmark)
{ {
int idx = mBookmarkList.IndexOf(bookmark); BookmarkFolder folder = bookmark.mFolder;
mBookmarkList.RemoveAt(idx);
if (mBookmarkIdx == idx) folder.mBookmarkList.Remove(bookmark);
mBookmarkIdx--;
if (mBookmarkIdx >= mBookmarkList.Count) FixupIndices();
mBookmarkIdx = (int32)mBookmarkList.Count - 1;
gApp.mDebugger.mBreakpointsChangedDelegate(); gApp.mDebugger.mBreakpointsChangedDelegate();
bookmark.Kill(); bookmark.Kill();
//gApp.mBookmarksPanel.UpdateBookmarks();
gApp.mBookmarksPanel.mBookmarksDirty = true; gApp.mBookmarksPanel.mBookmarksDirty = true;
mBookmarkCount--;
} }
public void Clear() public void Clear()
{ {
for (var bookmark in mBookmarkList) for (var folder in mBookmarkFolders)
bookmark.Kill(); {
mBookmarkList.Clear(); for (var bookmark in folder.mBookmarkList)
bookmark.Kill();
folder.mBookmarkList.Clear();
}
ClearAndDeleteItems!(mBookmarkFolders);
mRootFolder = new BookmarkFolder();
mBookmarkFolders.Add(mRootFolder);
mFolderIdx = 0;
mBookmarkIdx = 0; mBookmarkIdx = 0;
gApp.mDebugger.mBreakpointsChangedDelegate(); gApp.mDebugger.mBreakpointsChangedDelegate();
//gApp.mBookmarksPanel.UpdateBookmarks();
gApp.mBookmarksPanel.mBookmarksDirty = true; gApp.mBookmarksPanel.mBookmarksDirty = true;
} }
public void PrevBookmark() public void PrevBookmark(bool currentFolderOnly = false)
{ {
if (mBookmarkList.Count == 0) if (mBookmarkCount == 0)
return; return;
int32 currentIdx = mBookmarkIdx; int32 currentFolderIdx = mFolderIdx;
int32 currentBookmarkIdx = mBookmarkIdx;
Bookmark prevBookmark; Bookmark nextBookmark = null;
repeat repeat
{ {
mBookmarkIdx++; mBookmarkIdx++;
if (mBookmarkIdx >= mBookmarkList.Count)
mBookmarkIdx = 0;
prevBookmark = mBookmarkList[mBookmarkIdx]; if (mBookmarkIdx >= mBookmarkFolders[mFolderIdx].mBookmarkList.Count)
{
if (!currentFolderOnly)
{
mFolderIdx++;
if (mFolderIdx >= mBookmarkFolders.Count)
{
// wrap to first folder
mFolderIdx = 0;
}
}
// Select first bookmark in current folder (or -1 if there is no bookmark)
mBookmarkIdx = mBookmarkFolders[mFolderIdx].mBookmarkList.IsEmpty ? -1 : 0;
}
if (mBookmarkIdx >= 0)
nextBookmark = mBookmarkFolders[mFolderIdx].mBookmarkList[mBookmarkIdx];
else
nextBookmark = null;
} }
// skip disabled bookmarks, stop when we reach starting point // skip disabled bookmarks, stop when we reach starting point
while (prevBookmark.mIsDisabled && (currentIdx != mBookmarkIdx)); while ((nextBookmark == null || nextBookmark.mIsDisabled) && ((currentFolderIdx != mFolderIdx) || (currentBookmarkIdx != mBookmarkIdx) && mBookmarkIdx != -1));
GotoBookmark(prevBookmark); // If nextBookmark is disabled no bookmark is enabled.
if (nextBookmark != null && !nextBookmark.mIsDisabled)
GotoBookmark(nextBookmark);
} }
public void NextBookmark() public void NextBookmark(bool currentFolderOnly = false)
{ {
if (mBookmarkList.Count == 0) if (mBookmarkCount == 0)
return; return;
int32 currentIdx = mBookmarkIdx; int32 currentFolderIdx = mFolderIdx;
int32 currentBookmarkIdx = mBookmarkIdx;
Bookmark nextBookmark; Bookmark nextBookmark = null;
repeat repeat
{ {
mBookmarkIdx--; mBookmarkIdx--;
if (mBookmarkIdx < 0)
mBookmarkIdx = (int32)mBookmarkList.Count - 1;
nextBookmark = mBookmarkList[mBookmarkIdx]; if (mBookmarkIdx < 0)
{
if (!currentFolderOnly)
{
mFolderIdx--;
if (mFolderIdx < 0)
{
// wrap to last folder
mFolderIdx = (int32)mBookmarkFolders.Count - 1;
}
}
// Select last bookmark in current folder
mBookmarkIdx = (int32)mBookmarkFolders[mFolderIdx].mBookmarkList.Count - 1;
}
if (mBookmarkIdx >= 0)
nextBookmark = mBookmarkFolders[mFolderIdx].mBookmarkList[mBookmarkIdx];
else
nextBookmark = null;
} }
// skip disabled bookmarks, stop when we reach starting point // skip disabled bookmarks, stop when we reach starting point
while (nextBookmark.mIsDisabled && (currentIdx != mBookmarkIdx)); while ((nextBookmark == null || nextBookmark.mIsDisabled) && ((currentFolderIdx != mFolderIdx) || (currentBookmarkIdx != mBookmarkIdx) && mBookmarkIdx != -1));
GotoBookmark(nextBookmark); // If nextBookmark is disabled no bookmark is enabled.
if (nextBookmark != null && !nextBookmark.mIsDisabled)
GotoBookmark(nextBookmark);
} }
public void GotoBookmark(Bookmark bookmark) public void GotoBookmark(Bookmark bookmark)
{ {
mFolderIdx = (int32)mBookmarkFolders.IndexOf(bookmark.mFolder);
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);
} }
} }

View file

@ -196,6 +196,8 @@ namespace IDE
Add("Autocomplete", new => gApp.Cmd_ShowAutoComplete, .None); Add("Autocomplete", new => gApp.Cmd_ShowAutoComplete, .None);
Add("Bookmark Next", new => gApp.Cmd_NextBookmark, .Editor); Add("Bookmark Next", new => gApp.Cmd_NextBookmark, .Editor);
Add("Bookmark Prev", new => gApp.Cmd_PrevBookmark, .Editor); Add("Bookmark Prev", new => gApp.Cmd_PrevBookmark, .Editor);
Add("Bookmark Next in Folder", new => gApp.Cmd_NextBookmarkInFolder, .Editor);
Add("Bookmark Prev in Folder", new => gApp.Cmd_PrevBookmarkInFolder, .Editor);
Add("Bookmark Toggle", new => gApp.Cmd_ToggleBookmark, .Editor); Add("Bookmark Toggle", new => gApp.Cmd_ToggleBookmark, .Editor);
Add("Bookmark Clear", new => gApp.Cmd_ClearBookmarks, .Editor); Add("Bookmark Clear", new => gApp.Cmd_ClearBookmarks, .Editor);
Add("Break All", new => gApp.[Friend]Cmd_Break); Add("Break All", new => gApp.[Friend]Cmd_Break);

View file

@ -1897,25 +1897,36 @@ namespace IDE
} }
} }
using (sd.CreateArray("Bookmarks")) using (sd.CreateArray("BookmarkFolders"))
{ {
for (var bookmark in mBookmarkManager.mBookmarkList) for (var folder in mBookmarkManager.mBookmarkFolders)
{ {
if (bookmark.mFileName != null) using (sd.CreateObject())
{ {
using (sd.CreateObject()) sd.Add("Title", folder.mTitle);
{
String relPath = scope .(); using (sd.CreateArray("Bookmarks"))
mWorkspace.GetWorkspaceRelativePath(bookmark.mFileName, relPath); {
sd.Add("File", relPath); for (var bookmark in folder.mBookmarkList)
sd.Add("Line", bookmark.mLineNum); {
sd.Add("Column", bookmark.mColumn); if (bookmark.mFileName != null)
sd.Add("Title", bookmark.mTitle); {
if (bookmark.mIsDisabled) using (sd.CreateObject())
sd.Add("Disabled", true); {
} String relPath = scope .();
} mWorkspace.GetWorkspaceRelativePath(bookmark.mFileName, relPath);
} sd.Add("File", relPath);
sd.Add("Line", bookmark.mLineNum);
sd.Add("Column", bookmark.mColumn);
sd.Add("Title", bookmark.mTitle);
if (bookmark.mIsDisabled)
sd.Add("Disabled", true);
}
}
}
}
}
}
} }
using (sd.CreateObject("DebuggerDisplayTypes")) using (sd.CreateObject("DebuggerDisplayTypes"))
@ -3309,21 +3320,32 @@ namespace IDE
} }
} }
for (var _bookmark in data.Enumerate("Bookmarks")) for (var _bookmarkFolder in data.Enumerate("BookmarkFolders"))
{ {
String relPath = scope String();
data.GetString("File", relPath);
IDEUtils.FixFilePath(relPath);
String absPath = scope String();
mWorkspace.GetWorkspaceAbsPath(relPath, absPath);
int32 lineNum = data.GetInt("Line");
int32 column = data.GetInt("Column");
String title = scope String(); String title = scope String();
data.GetString("Title", title); data.GetString("Title", title);
bool isDisabled = data.GetBool("Disabled", false); BookmarkFolder folder = null;
mBookmarkManager.CreateBookmark(absPath, lineNum, column, isDisabled, title); if (!String.IsNullOrWhiteSpace(title))
folder = mBookmarkManager.CreateFolder(title);
for (var _bookmark in data.Enumerate("Bookmarks"))
{
String relPath = scope String();
data.GetString("File", relPath);
IDEUtils.FixFilePath(relPath);
String absPath = scope String();
mWorkspace.GetWorkspaceAbsPath(relPath, absPath);
int32 lineNum = data.GetInt("Line");
int32 column = data.GetInt("Column");
String bookmarkTitle = scope String();
data.GetString("Title", bookmarkTitle);
bool isDisabled = data.GetBool("Disabled", false);
mBookmarkManager.CreateBookmark(absPath, lineNum, column, isDisabled, bookmarkTitle, folder);
}
} }
for (var referenceId in data.Enumerate("DebuggerDisplayTypes")) for (var referenceId in data.Enumerate("DebuggerDisplayTypes"))
@ -3952,13 +3974,25 @@ namespace IDE
[IDECommand] [IDECommand]
public void Cmd_PrevBookmark() public void Cmd_PrevBookmark()
{ {
mBookmarkManager.PrevBookmark(); mBookmarkManager.PrevBookmark(false);
}
[IDECommand]
public void Cmd_PrevBookmarkInFolder()
{
mBookmarkManager.PrevBookmark(true);
} }
[IDECommand] [IDECommand]
public void Cmd_NextBookmark() public void Cmd_NextBookmark()
{ {
mBookmarkManager.NextBookmark(); mBookmarkManager.NextBookmark(false);
}
[IDECommand]
public void Cmd_NextBookmarkInFolder()
{
mBookmarkManager.NextBookmark(true);
} }
[IDECommand] [IDECommand]

View file

@ -5,34 +5,78 @@ using System;
using System.Collections; using System.Collections;
using Beefy.theme; using Beefy.theme;
using Beefy.events; using Beefy.events;
using System.Diagnostics;
namespace IDE.ui namespace IDE.ui
{ {
public class BookmarksListView : IDEListView
{
protected override ListViewItem CreateListViewItem()
{
return new BookmarksListViewItem();
}
protected override void SetScaleData()
{
base.SetScaleData();
mIconX = GS!(200);
mOpenButtonX = GS!(0);
mLabelX = GS!(0);
//mChildIndent = GS!(16);
mHiliteOffset = GS!(-2);
}
}
public class BookmarksListViewItem : IDEListViewItem
{
public Object RefObject;
public String BookmarkLine ~ delete _;
public float mLabelOffsetFolder = GS!(16);
public float mLabelOffsetBookmark = GS!(0);
public override void RehupScale(float oldScale, float newScale)
{
base.RehupScale(oldScale, newScale);
mLabelOffsetFolder = GS!(16);
mLabelOffsetBookmark = GS!(0);
}
protected override float GetLabelOffset()
{
if (RefObject is BookmarkFolder)
{
return mLabelOffsetFolder;
}
return mLabelOffsetBookmark;
}
public void Goto()
{
if (Bookmark bookmark = RefObject as Bookmark)
{
gApp.mBookmarkManager.GotoBookmark(bookmark);
}
}
}
class BookmarksPanel : Panel class BookmarksPanel : Panel
{ {
public class BookmarksListView : IDEListView public DarkButton mCreateBookmarkFolder;
{
protected override ListViewItem CreateListViewItem()
{
return new BookmarksListViewItem();
}
}
public class BookmarksListViewItem : IDEListViewItem
{
public Bookmark Bookmark;
public String BookmarkLine ~ delete _;
public void Goto()
{
gApp.mBookmarkManager.GotoBookmark(Bookmark);
}
}
public BookmarksListView mBookmarksLV; public BookmarksListView mBookmarksLV;
public this() public this()
{ {
mCreateBookmarkFolder = new DarkButton();
mCreateBookmarkFolder.Label = "New Folder";
mCreateBookmarkFolder.mOnMouseClick.Add(new (args) =>
{
gApp.mBookmarkManager.CreateFolder();
});
AddWidget(mCreateBookmarkFolder);
mBookmarksLV = new .(); mBookmarksLV = new .();
mBookmarksLV.mOnEditDone.Add(new => HandleEditDone); mBookmarksLV.mOnEditDone.Add(new => HandleEditDone);
@ -44,6 +88,9 @@ namespace IDE.ui
mBookmarksLV.AddColumn(400, "File"); mBookmarksLV.AddColumn(400, "File");
mBookmarksLV.AddColumn(120, "Line"); mBookmarksLV.AddColumn(120, "Line");
mBookmarksLV.mOnDragEnd.Add(new => BookmarksLV_OnDragEnd);
mBookmarksLV.mOnDragUpdate.Add(new => BookmarksLV_OnDragUpdate);
mBookmarksLV.mOnItemMouseDown.Add(new (item, x, y, btnNum, btnCount) => mBookmarksLV.mOnItemMouseDown.Add(new (item, x, y, btnNum, btnCount) =>
{ {
if ((btnNum == 0) && (btnCount == 2)) if ((btnNum == 0) && (btnCount == 2))
@ -58,55 +105,160 @@ namespace IDE.ui
mBookmarksLV.mOnKeyDown.Add(new => BookmarksLV_OnKeyDown); mBookmarksLV.mOnKeyDown.Add(new => BookmarksLV_OnKeyDown);
AddWidget(mBookmarksLV); AddWidget(mBookmarksLV);
} }
private void BookmarksLV_OnKeyDown(KeyDownEvent event) private void BookmarksLV_OnKeyDown(KeyDownEvent event)
{ {
if (event.mKeyCode == KeyCode.Delete) if (event.mKeyCode == KeyCode.Delete)
{ {
DeleteSelectedItem(); DeleteSelectedItems();
} }
ListViewKeyDown_ShowMenu(event); ListViewKeyDown_ShowMenu(event);
} }
public override void RehupScale(float oldScale, float newScale)
{
mBookmarksLV.mOpenButtonX = GS!(4);
base.RehupScale(oldScale, newScale);
}
private void BookmarksLV_OnDragUpdate(DragEvent evt)
{
var dragKind = evt.mDragKind;
evt.mDragKind = .None;
var dragSource = evt.mSender as BookmarksListViewItem;
var dragTarget = evt.mDragTarget as BookmarksListViewItem;
// Folders can only be dragged onto other folders
if (dragSource.RefObject is BookmarkFolder && (!dragTarget.RefObject is BookmarkFolder))
return;
if (dragSource == null)
return;
if (dragTarget == null)
return;
evt.mDragKind = .After;
if ((dragTarget.mLabel == "") && (dragKind == .After))
dragKind = .Before;
if (dragKind == .None)
return;
evt.mDragKind = dragKind;
}
private void BookmarksLV_OnDragEnd(DragEvent theEvent)
{
if (theEvent.mDragKind == .None)
return;
if (theEvent.mDragTarget is BookmarksListViewItem)
{
var source = (BookmarksListViewItem)theEvent.mSender;
var target = (BookmarksListViewItem)theEvent.mDragTarget;
if (source.mListView == target.mListView)
{
if (source == target)
return;
List<BookmarksListViewItem> selectedItems = scope .();
mBookmarksLV.GetRoot().WithSelectedItems(scope [&] (selectedItem) =>
{
selectedItems.Add((BookmarksListViewItem)selectedItem);
});
for (BookmarksListViewItem item in selectedItems)
{
if (var sourceBookmark = item.RefObject as Bookmark)
{
if (var targetBookmark = target.RefObject as Bookmark)
{
if (theEvent.mDragKind == .After)
{
int index = targetBookmark.mFolder.mBookmarkList.IndexOf(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)
{
gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, targetBookmark.mFolder, targetBookmark);
}
}
else if (var targetFolder = target.RefObject as BookmarkFolder)
{
if (theEvent.mDragKind == .Before)
{
// Drop before folder -> Drop to root
gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, gApp.mBookmarkManager.mRootFolder);
}
else if (theEvent.mDragKind == .After || theEvent.mDragKind == .Inside)
{
gApp.mBookmarkManager.MoveBookmarkToFolder(sourceBookmark, targetFolder);
}
}
}
else if (var sourceFolder = item.RefObject as BookmarkFolder)
{
if (var targetFolder = target.RefObject as BookmarkFolder)
{
if (theEvent.mDragKind == .Before)
{
gApp.mBookmarkManager.MoveFolder(sourceFolder, .Before, targetFolder);
}
else if (theEvent.mDragKind == .After)
{
gApp.mBookmarkManager.MoveFolder(sourceFolder, .After, targetFolder);
}
}
}
}
}
}
}
/// Tries to rename the currently selected bookmark /// Tries to rename the currently selected bookmark
public void TryRenameItem() public void TryRenameItem()
{ {
ListViewItem selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem(); ListViewItem selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem();
RenameItem(selectedItem); RenameItem(selectedItem);
} }
public void DeleteSelectedItem() private void HandleEditDone(EditWidget editWidget, bool cancelled)
{ {
ListViewItem selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem(); String newValue = scope String();
if (var bookmarkItem = selectedItem as BookmarksListViewItem) editWidget.GetText(newValue);
{ newValue.Trim();
gApp.mBookmarkManager.DeleteBookmark(bookmarkItem.Bookmark);
}
}
private void HandleEditDone(EditWidget editWidget, bool cancelled)
{
String newValue = scope String();
editWidget.GetText(newValue);
newValue.Trim();
ListViewItem listViewItem = mBookmarksLV.mEditingItem; ListViewItem listViewItem = mBookmarksLV.mEditingItem;
if (var item = listViewItem as BookmarksListViewItem) if (var item = listViewItem as BookmarksListViewItem)
{ {
item.Bookmark.mTitle.Clear(); if (var bookmark = item.RefObject as Bookmark)
item.Bookmark.mTitle.Append(newValue); {
listViewItem.Label = item.Bookmark.mTitle; bookmark.mTitle.Clear();
bookmark.mTitle.Append(newValue);
listViewItem.Label = bookmark.mTitle;
}
else if (var folder = item.RefObject as BookmarkFolder)
{
folder.mTitle.Clear();
folder.mTitle.Append(newValue);
listViewItem.Label = folder.mTitle;
}
} }
}
public ~this()
{
} }
protected override void ShowRightClickMenu(Widget relWidget, float x, float y) protected override void ShowRightClickMenu(Widget relWidget, float x, float y)
@ -118,7 +270,7 @@ namespace IDE.ui
if (listView.GetRoot().FindFirstSelectedItem() != null) if (listView.GetRoot().FindFirstSelectedItem() != null)
{ {
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) =>
{ {
@ -126,19 +278,21 @@ namespace IDE.ui
{ {
if (var bookmarkItem = item as BookmarksListViewItem) if (var bookmarkItem = item as BookmarksListViewItem)
{ {
gApp.mBookmarkManager.DeleteBookmark(bookmarkItem.Bookmark); 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) =>
{ {
var selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem(); var selectedItem = mBookmarksLV.GetRoot().FindFirstSelectedItem();
if (selectedItem != null) if (selectedItem != null)
RenameItem(selectedItem); RenameItem(selectedItem);
}); });
menu.AddItem(); menu.AddItem();
@ -146,25 +300,17 @@ namespace IDE.ui
{ {
anItem = menu.AddItem("Enable all Bookmarks"); anItem = menu.AddItem("Enable all Bookmarks");
anItem.mOnMenuItemSelected.Add(new (item) => anItem.mOnMenuItemSelected.Add(new (item) =>
{ {
for (Bookmark b in gApp.mBookmarkManager.mBookmarkList) gApp.mBookmarkManager.AllBookmarksDisabled = false;
{ });
b.mIsDisabled = false;
}
mBookmarksDirty = true;
});
} }
else else
{ {
anItem = menu.AddItem("Disable all Bookmarks"); anItem = menu.AddItem("Disable all Bookmarks");
anItem.mOnMenuItemSelected.Add(new (item) => anItem.mOnMenuItemSelected.Add(new (item) =>
{ {
for (Bookmark b in gApp.mBookmarkManager.mBookmarkList) gApp.mBookmarkManager.AllBookmarksDisabled = true;
{ });
b.mIsDisabled = true;
}
mBookmarksDirty = true;
});
} }
MenuWidget menuWidget = ThemeFactory.mDefault.CreateMenuWidget(menu); MenuWidget menuWidget = ThemeFactory.mDefault.CreateMenuWidget(menu);
@ -177,27 +323,32 @@ namespace IDE.ui
mBookmarksLV.EditListViewItem(listViewItem); mBookmarksLV.EditListViewItem(listViewItem);
} }
void RenameItem(ListViewItem listViewItem) void RenameItem(ListViewItem listViewItem)
{ {
EditListViewItem(listViewItem); if (listViewItem != null)
} EditListViewItem(listViewItem);
}
public override void Serialize(StructuredData data) public override void Serialize(StructuredData data)
{ {
base.Serialize(data); base.Serialize(data);
data.Add("Type", "BookmarksPanel"); data.Add("Type", "BookmarksPanel");
} }
public override void Resize(float x, float y, float width, float height) public override void Resize(float x, float y, float width, float height)
{ {
base.Resize(x, y, width, height); base.Resize(x, y, width, height);
mBookmarksLV.Resize(0, 0, width, height);
float buttonWidth = GS!(140);
float buttonHeight = GS!(22);
mCreateBookmarkFolder.Resize(0, 0, buttonWidth, buttonHeight);
mBookmarksLV.Resize(0, buttonHeight, width, Math.Max(mHeight - buttonHeight, 0));
} }
public void Clear() public void Clear()
{ {
} }
public bool mBookmarksDirty; public bool mBookmarksDirty;
@ -217,40 +368,81 @@ namespace IDE.ui
root.Clear(); root.Clear();
for (Bookmark bookmark in gApp.mBookmarkManager.mBookmarkList) for (BookmarkFolder folder in gApp.mBookmarkManager.mBookmarkFolders)
{ {
BookmarksListViewItem listViewItem = (.)root.CreateChildItem(); bool isRoot = (folder == IDEApp.sApp.mBookmarkManager.mRootFolder);
SetupListViewItem(listViewItem, bookmark);
BookmarksListViewItem FolderItem = null;
if (!isRoot)
{
FolderItem = (BookmarksListViewItem)root.CreateChildItem();
SetupListViewItemFolder(FolderItem, folder);
}
else
{
FolderItem = (BookmarksListViewItem)root;
}
for (Bookmark bookmark in folder.mBookmarkList)
{
var listViewItem = (BookmarksListViewItem)(FolderItem.CreateChildItem());
SetupListViewItem(listViewItem, bookmark);
}
} }
mBookmarksDirty = false; mBookmarksDirty = false;
} }
private void SetupListViewItemFolder(BookmarksListViewItem listViewItem, BookmarkFolder folder)
{
listViewItem.AllowDragging = true;
listViewItem.RefObject = folder;
var subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(0);
DarkCheckBox cb = new DarkCheckBox();
cb.Checked = !folder.IsDisabled;
cb.Resize(GS!(-16), 0, GS!(22), GS!(22));
cb.mOnValueChanged.Add(new () =>
{
folder.IsDisabled = !cb.Checked;
});
subViewItem.AddWidget(cb);
subViewItem.Label = folder.mTitle;
subViewItem.Resize(GS!(22), 0, 0, 0);
}
private void SetupListViewItem(BookmarksListViewItem listViewItem, Bookmark bookmark) private void SetupListViewItem(BookmarksListViewItem listViewItem, Bookmark bookmark)
{ {
listViewItem.Bookmark = bookmark; listViewItem.AllowDragging = true;
listViewItem.RefObject = bookmark;
var subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(0); var subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(0);
DarkCheckBox cb = new DarkCheckBox(); DarkCheckBox cb = new DarkCheckBox();
cb.Checked = !bookmark.mIsDisabled; cb.Checked = !bookmark.mIsDisabled;
cb.Resize(GS!(-16), 0, GS!(22), GS!(22)); cb.Resize(GS!(-16), 0, GS!(22), GS!(22));
cb.mOnValueChanged.Add(new () => { cb.mOnValueChanged.Add(new () =>
bookmark.mIsDisabled = !cb.Checked; {
}); bookmark.mIsDisabled = !cb.Checked;
});
subViewItem.AddWidget(cb); subViewItem.AddWidget(cb);
subViewItem.Label = bookmark.mTitle; subViewItem.Label = bookmark.mTitle;
subViewItem.Resize(GS!(22), 0, 0, 0); subViewItem.Resize(GS!(22), 0, 0, 0);
subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(1); subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(1);
subViewItem.Label = bookmark.mFileName; subViewItem.Label = bookmark.mFileName;
// Internally lines are 0-based -> add one for display // Internally lines are 0-based -> add one for display
listViewItem.BookmarkLine = new $"{bookmark.mLineNum + 1}"; listViewItem.BookmarkLine = new $"{bookmark.mLineNum + 1}";
subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(2); subViewItem = (DarkListViewItem)listViewItem.GetOrCreateSubItem(2);
subViewItem.Label = listViewItem.BookmarkLine; subViewItem.Label = listViewItem.BookmarkLine;
} }
public override void KeyDown(KeyCode keyCode, bool isRepeat) public override void KeyDown(KeyCode keyCode, bool isRepeat)
@ -265,17 +457,19 @@ namespace IDE.ui
var root = mBookmarksLV.GetRoot(); var root = mBookmarksLV.GetRoot();
List<ListViewItem> selectedItems = scope List<ListViewItem>(); List<ListViewItem> selectedItems = scope List<ListViewItem>();
root.WithSelectedItems(scope (listViewItem) => root.WithSelectedItems(scope (listViewItem) =>
{ {
selectedItems.Add(listViewItem); selectedItems.Add(listViewItem);
}); });
// Go through in reverse, to process children before their parents // Go through in reverse, to process children before their parents
for (int itemIdx = selectedItems.Count - 1; itemIdx >= 0; itemIdx--) for (int itemIdx = selectedItems.Count - 1; itemIdx >= 0; itemIdx--)
{ {
BookmarksListViewItem item = (.)selectedItems[itemIdx]; BookmarksListViewItem item = (.)selectedItems[itemIdx];
if (item.Bookmark != null) if (var bookmark = item.RefObject as Bookmark)
gApp.mBookmarkManager.DeleteBookmark(item.Bookmark); gApp.mBookmarkManager.DeleteBookmark(bookmark);
else if (var folder = item.RefObject as BookmarkFolder)
gApp.mBookmarkManager.DeleteFolder(folder);
} }
} }
} }

View file

@ -3172,15 +3172,18 @@ namespace IDE.ui
if (mFilePath == null) if (mFilePath == null)
return mTrackedTextElementViewList; return mTrackedTextElementViewList;
for (var bookmark in IDEApp.sApp.mBookmarkManager.mBookmarkList) for (var folder in IDEApp.sApp.mBookmarkManager.mBookmarkFolders)
{ {
if (Path.Equals(bookmark.mFileName, findFileName)) for (var bookmark in folder.mBookmarkList)
{ {
var bookmarkView = new TrackedTextElementView(bookmark); if (Path.Equals(bookmark.mFileName, findFileName))
UpdateTrackedElementView(bookmarkView); {
mTrackedTextElementViewList.Add(bookmarkView); var bookmarkView = new TrackedTextElementView(bookmark);
} UpdateTrackedElementView(bookmarkView);
} mTrackedTextElementViewList.Add(bookmarkView);
}
}
}
for (var breakpoint in debugManager.mBreakpointList) for (var breakpoint in debugManager.mBreakpointList)
{ {
@ -4393,11 +4396,14 @@ namespace IDE.ui
bool hadBookmark = false; bool hadBookmark = false;
WithTrackedElementsAtCursor<Bookmark>(IDEApp.sApp.mBookmarkManager.mBookmarkList, scope [&] (bookmark) => for (var folder in IDEApp.sApp.mBookmarkManager.mBookmarkFolders)
{ {
bookmarkManager.DeleteBookmark(bookmark); WithTrackedElementsAtCursor<Bookmark>(folder.mBookmarkList, scope [&] (bookmark) =>
hadBookmark = true; {
}); bookmarkManager.DeleteBookmark(bookmark);
hadBookmark = true;
});
}
if (!hadBookmark) if (!hadBookmark)
{ {