-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathLauncherPage.cs
More file actions
130 lines (109 loc) · 3.1 KB
/
Copy pathLauncherPage.cs
File metadata and controls
130 lines (109 loc) · 3.1 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Threading.Tasks;
using Avalonia.Collections;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class LauncherPage : ObservableObject
{
public RepositoryNode Node
{
get => _node;
set => SetProperty(ref _node, value);
}
public object Data
{
get => _data;
set => SetProperty(ref _data, value);
}
public Models.DirtyState DirtyState
{
get => _dirtyState;
private set => SetProperty(ref _dirtyState, value);
}
public Popup Popup
{
get => _popup;
set => SetProperty(ref _popup, value);
}
public AvaloniaList<Models.Notification> Notifications
{
get;
set;
} = new AvaloniaList<Models.Notification>();
public LauncherPage()
{
_node = new RepositoryNode() { Id = Guid.NewGuid().ToString() };
_data = Welcome.Instance;
// New welcome page will clear the search filter before.
Welcome.Instance.ClearSearchFilter();
}
public LauncherPage(RepositoryNode node, Repository repo)
{
_node = node;
_data = repo;
}
public void ClearNotifications()
{
Notifications.Clear();
}
public void ChangeDirtyState(Models.DirtyState flag, bool remove)
{
var state = _dirtyState;
if (remove)
{
if (state.HasFlag(flag))
state -= flag;
}
else
{
state |= flag;
}
DirtyState = state;
}
public bool CanCreatePopup()
{
return _popup is not { InProgress: true };
}
public async Task ProcessPopupAsync()
{
if (_popup is { InProgress: false } dump)
{
if (!dump.Check())
return;
dump.InProgress = true;
try
{
var finished = await dump.Sure();
if (finished)
{
dump.Cleanup();
Popup = null;
}
}
catch (Exception e)
{
Native.OS.LogException(e);
}
dump.InProgress = false;
}
}
public void CancelPopup()
{
if (_popup == null || _popup.InProgress)
return;
_popup?.Cleanup();
Popup = null;
}
public void TerminatePopup()
{
if (_popup is not { CanTerminate: true, InProgress: true })
return;
_popup.Terminate();
}
private RepositoryNode _node = null;
private object _data = null;
private Models.DirtyState _dirtyState = Models.DirtyState.None;
private Popup _popup = null;
}
}