This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
UpTool2/UpToolEto/UpToolEto/Controls/AppList.cs

59 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Eto.Drawing;
using Eto.Forms;
using UpToolEto.Forms;
using UpToolLib.v1.Tool;
using UpToolLib.v2;
using UpToolLib.v2.TaskQueue;
namespace UpToolEto.Controls
{
public class AppList : StackLayout
{
private readonly AppExtras _extras;
private readonly Action<Guid, App> _itemClickEvent;
private readonly StackLayout _layout;
private readonly AppListSearchProvider _searchProvider;
public AppList(AppExtras extras, Action<Guid, App> itemClickEvent, bool online, TaskFactory factory, IList<AppTask> tasks)
{
_extras = extras;
_itemClickEvent = itemClickEvent;
_searchProvider = new AppListSearchProvider(online, Update);
Items.Add(_searchProvider);
_layout = new StackLayout
{
Padding = 10,
Orientation = Orientation.Vertical,
Width = 200
};
Scrollable scrollable = new()
{
Content = _layout
};
if (Main.DebugColors)
scrollable.BackgroundColor = Colors.YellowGreen;
Items.Add(new StackLayoutItem(scrollable, VerticalAlignment.Stretch, true));
Orientation = Orientation.Vertical;
if (Main.DebugColors)
BackgroundColor = Colors.Green;
Update();
}
public void Update()
{
_layout.Items.Clear();
foreach (App app in _extras.FindApps(_searchProvider.GetSearchTerms()))
if (_searchProvider.Matches(app))
_layout.Items.Add(new Button((_, _) => _itemClickEvent(app.Id, app))
{
Text = app.Name,
Image = (Icon)app.Icon,
ImagePosition = ButtonImagePosition.Left,
});
}
}
}