forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncherPage.cs
More file actions
149 lines (127 loc) · 3.68 KB
/
Copy pathLauncherPage.cs
File metadata and controls
149 lines (127 loc) · 3.68 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using Avalonia.Collections;
using Avalonia.Media;
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 IBrush DirtyBrush
{
get => _dirtyBrush;
private set => SetProperty(ref _dirtyBrush, 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 CopyPath()
{
if (_node.IsRepository)
App.CopyText(_node.Id);
}
public void ChangeDirtyState(Models.DirtyState flag, bool remove)
{
if (remove)
{
if (_dirtyState.HasFlag(flag))
_dirtyState -= flag;
}
else
{
_dirtyState |= flag;
}
if (_dirtyState.HasFlag(Models.DirtyState.HasLocalChanges))
DirtyBrush = Brushes.Gray;
else if (_dirtyState.HasFlag(Models.DirtyState.HasPendingPullOrPush))
DirtyBrush = Brushes.RoyalBlue;
else
DirtyBrush = null;
}
public bool CanCreatePopup()
{
return _popup is not { InProgress: true };
}
public void StartPopup(Popup popup)
{
Popup = popup;
if (popup.CanStartDirectly())
ProcessPopup();
}
public async void ProcessPopup()
{
if (_popup is { InProgress: false } dump)
{
if (!dump.Check())
return;
dump.InProgress = true;
var task = dump.Sure();
var finished = false;
if (task != null)
{
try
{
finished = await task;
}
catch (Exception e)
{
App.LogException(e);
}
dump.InProgress = false;
if (finished)
Popup = null;
}
else
{
dump.InProgress = false;
Popup = null;
}
}
}
public void CancelPopup()
{
if (_popup == null)
return;
if (_popup.InProgress)
return;
Popup = null;
}
private RepositoryNode _node = null;
private object _data = null;
private IBrush _dirtyBrush = null;
private Models.DirtyState _dirtyState = Models.DirtyState.None;
private Popup _popup = null;
}
}