forked from CCob/Volumiser
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUI.cs
More file actions
165 lines (125 loc) · 4.47 KB
/
UI.cs
File metadata and controls
165 lines (125 loc) · 4.47 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System.Collections;
using Terminal.Gui;
namespace Volumiser {
class UI {
Window topLevel;
ListView list;
Label preview;
Label volumeLabel;
Label itemLabel;
Label downloadLabel;
public delegate void ItemDelegate(string itemValue);
public event ItemDelegate ItemSelected;
public event ItemDelegate ItemChanged;
public string VolumeLabel {
get { return volumeLabel.Text.ToString(); }
set { volumeLabel.Text = value; }
}
public string ItemLabel {
get { return itemLabel.Text.ToString(); }
set { itemLabel.Text = value; }
}
public string DownloadLabel {
get { return downloadLabel.Text.ToString(); }
set { downloadLabel.Text = value; }
}
public string PreviewText {
get { return preview.Text.ToString(); }
set { preview.Text = value; }
}
public UI() {
Application.Init();
Colors.Base.Normal = Application.Driver.MakeAttribute(Color.Gray, Color.Black);
// Creates the top-level window to show
topLevel = new Window("Volumiser") {
X = 0,
Y = 0,
// By using Dim.Fill(), it will automatically resize without manual intervention
Width = Dim.Fill(),
Height = Dim.Fill(),
};
var middleContainer = new Window() {
X = 0,
Y = 0,
Width = Dim.Fill(),
Height = Dim.Fill() - 1
};
middleContainer.Border.BorderStyle = BorderStyle.None;
volumeLabel = new Label($"") {
X = 1,
Y = Pos.Bottom(middleContainer),
Width = Dim.Percent(20),
Height = 1
};
itemLabel = new Label($"") {
X = Pos.Right(volumeLabel),
Y = Pos.Bottom(middleContainer),
Width = Dim.Percent(40),
Height = 1
};
downloadLabel = new Label($"") {
X = Pos.Right(itemLabel),
Y = Pos.Bottom(middleContainer),
Width = Dim.Percent(40),
Height = 1
};
list = new ListView() {
X = 1,
Y = Pos.Top(topLevel),
Width = Dim.Fill(),
Height = Dim.Percent(55)
};
list.Border = new Border() {
// BorderStyle = BorderStyle.Single,
//Title = "Filesystem Structure"
};
list.OpenSelectedItem += List_OpenSelectedItem;
list.SelectedItemChanged += List_SelectedItemChanged;
preview = new Label() {
X = 1,
Y = Pos.Bottom(list) + 1,
Width = Dim.Fill() - 1,
Height = Dim.Fill() - 1
};
preview.Border = new Border() {
BorderStyle = BorderStyle.Rounded,
Title = "Preview",
};
middleContainer.Add(list, preview);
topLevel.Add(volumeLabel, itemLabel, downloadLabel, middleContainer);
Application.Top.Add(topLevel);
Application.Top.KeyPress += Top_KeyPress;
}
private void Top_KeyPress(View.KeyEventEventArgs obj) {
if(obj.KeyEvent.Key == Key.Esc)
Application.RequestStop();
}
private void List_SelectedItemChanged(ListViewItemEventArgs obj) {
ItemChanged?.Invoke((string)obj.Value);
}
public void Run() {
try{
Application.Run();
}
finally {
Application.Shutdown();
}
}
public void UpdateCurrentPathItems(IList items) {
list.SetSource(items);
}
private void List_OpenSelectedItem(ListViewItemEventArgs obj) {
ItemSelected?.Invoke((string)obj.Value);
}
public void Refresh() {
Application.Refresh();
}
public bool ShowDownloadDialog(string fileName, string size) {
var n = MessageBox.Query(" Download File", $"Do you want to download {fileName} ({size}) ", "Yes", "No");
if (n == 0)
return true;
else
return false;
}
}
}