forked from tiagosimoes/ReactViewWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabView.cs
77 lines (59 loc) · 2.96 KB
/
TabView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Styling;
using Avalonia.Threading;
using ReactViewControl;
using WebViewControl;
namespace Sample.Avalonia {
internal class TabView : ContentControl, IStyleable {
Type IStyleable.StyleKey => typeof(ContentControl);
private MainView mainView;
private TaskListViewModule taskListView;
private int taskCounter;
private readonly List<Task> taskList = new List<Task>() {
new Task() { id = 0, text = "Learn react.js", isCompleted = true, user = "User1" },
new Task() { id = 1, text = "Explore the ReactView framework", user = "User2" }
};
public TabView(int id) {
taskCounter = taskList.Count;
mainView = new MainView();
mainView.TitleMessage = "Tasks List (" + id + ")";
mainView.BackgroundKind = BackgroundKind.Image;
mainView.AddTaskButtonClicked += OnMainViewAddTaskButtonClicked;
mainView.GetTasksCount += () => taskList.Count;
mainView.TaskListShown += () => taskListView.Load();
mainView.WithPlugin<ViewPlugin>().NotifyViewLoaded += viewName => AppendLog(viewName + " loaded");
taskListView = (TaskListViewModule)mainView.ListView;
taskListView.GetTasks += () => taskList.ToArray();
// this is an example of dynamic resources support
taskListView.CustomResourceRequested += OnTaskListViewCustomResourceRequested;
taskListView.WithPlugin<ViewPlugin>().NotifyViewLoaded += (viewName) => AppendLog(viewName + " loaded (child)");
taskListView.Load();
Content = mainView;
}
private void OnMainViewAddTaskButtonClicked(TaskCreationDetails taskDetails) {
taskList.Add(new Task() {
id = taskCounter++,
text = taskDetails.text,
user = "User1"
});
mainView.Refresh(); // refresh task counter
taskListView.Refresh(); // refresh task list
AppendLog("Added task: " + taskDetails.text);
}
public void ToggleHideCompletedTasks() => taskListView.ToggleHideCompletedTasks();
public void ShowDevTools() => mainView.ShowDeveloperTools();
public void ToggleIsEnabled() => mainView.IsEnabled = !mainView.IsEnabled;
public ReactViewControl.EditCommands EditCommands => mainView.EditCommands;
private void AppendLog(string log) {
Dispatcher.UIThread.Post(() => {
var status = this.FindControl<TextBox>("status");
status.Text = DateTime.Now + ": " + log + Environment.NewLine + status.Text;
});
}
private Resource OnTaskListViewCustomResourceRequested(string resourceKey, params string[] options) {
return new Resource(ResourcesManager.GetResource(GetType().Assembly, new[] { "Users", resourceKey + ".png" }));
}
}
}