Skip to content

Commit

Permalink
Mac: Fixed performance bug with NSOutlineView for Library Browser in …
Browse files Browse the repository at this point in the history
…MainWindow. Now using the ItemDidExpand notification to replace the dummy node with actual content next instead of ItemExpandable. This makes the browser MUCH faster with loads of content!

Related to issue #381.
  • Loading branch information
ycastonguay committed Aug 18, 2013
1 parent 0ec1875 commit 5a57ac9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
15 changes: 0 additions & 15 deletions MPfm/MPfm.Mac/Classes/Delegates/LibraryBrowserDataSource.cs
Expand Up @@ -68,22 +68,7 @@ public override NSObject GetChild(NSOutlineView outlineView, int childIndex, NSO

public override bool ItemExpandable(NSOutlineView outlineView, NSObject item)
{
// Cast item and return subitem count
LibraryBrowserItem libraryBrowserItem = (LibraryBrowserItem)item;

// Check for dummy nodes
if (libraryBrowserItem.SubItems.Count > 0 && libraryBrowserItem.SubItems [0].Entity.Type == LibraryBrowserEntityType.Dummy)
{
// Extract more data
//IEnumerable<LibraryBrowserEntity> entities = libraryBrowserPresenter.TreeNodeExpandable(libraryBrowserItem.Entity);
IEnumerable<LibraryBrowserEntity> entities = OnTreeNodeExpandable.Invoke(libraryBrowserItem.Entity);

// Clear subitems (dummy node) and fill with actual nodes
libraryBrowserItem.SubItems.Clear();
foreach (LibraryBrowserEntity entity in entities)
libraryBrowserItem.SubItems.Add(new LibraryBrowserItem(entity));
}

return (libraryBrowserItem.SubItems.Count > 0) ? true : false;
}

Expand Down
26 changes: 22 additions & 4 deletions MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs
Expand Up @@ -110,11 +110,8 @@ public MainWindowController(Action<IBaseView> onViewReady) : base ("MainWindow",
public override void WindowDidLoad()
{
base.WindowDidLoad();
}

public override void AwakeFromNib()
{
Tracing.Log("MainWindowController.AwakeFromNib -- Initializing user interface...");
Tracing.Log("MainWindowController.WindowDidLoad -- Initializing user interface...");
//this.Window.Title = "Sessions " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + " ALPHA";

splitMain.Delegate = new MainSplitViewDelegate();
Expand Down Expand Up @@ -151,6 +148,8 @@ public override void AwakeFromNib()
scrollViewAlbumCovers.SetSynchronizedScrollView(scrollViewSongBrowser);
scrollViewSongBrowser.SetSynchronizedScrollView(scrollViewAlbumCovers);

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSOutlineViewItemDidExpandNotification"), ItemDidExpand, outlineLibraryBrowser);

OnViewReady.Invoke(this);
}

Expand Down Expand Up @@ -531,6 +530,25 @@ private void LoadImages()
partial void actionRemoveMarker(NSObject sender)
{
}

[Export ("outlineViewItemDidExpand")]
public void ItemDidExpand(NSNotification notification)
{
// Check for dummy nodes
var item = (LibraryBrowserItem)notification.UserInfo["NSObject"];
if (item.SubItems.Count > 0 && item.SubItems[0].Entity.Type == LibraryBrowserEntityType.Dummy)
{
IEnumerable<LibraryBrowserEntity> entities = OnTreeNodeExpandable(item.Entity);
//Console.WriteLine("MainWindowController - ItemDidExpand - dummy node - entities.Count: {0}", entities.Count());

// Clear subitems (dummy node) and fill with actual nodes
item.SubItems.Clear();
foreach (LibraryBrowserEntity entity in entities)
item.SubItems.Add(new LibraryBrowserItem(entity));

outlineLibraryBrowser.ReloadData();
}
}

protected void HandleLibraryBrowserDoubleClick(object sender, EventArgs e)
{
Expand Down

0 comments on commit 5a57ac9

Please sign in to comment.