-
Notifications
You must be signed in to change notification settings - Fork 1
/
VideoChooserDialog.cs
63 lines (53 loc) · 1.9 KB
/
VideoChooserDialog.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace openu_video_fetcher
{
public partial class VideoChooserDialog : Form
{
private List<OpenuVideoData> playlist;
public VideoChooserDialog(List<OpenuVideoData> playlist)
{
this.playlist = playlist;
InitializeComponent();
}
public ListBox.SelectedIndexCollection ChosenToDownload { get { return downloadPicker.SelectedIndices; } }
class ViewVideoData
{
public OpenuVideoData Origin { get; set; }
public bool ShouldDownload { get; set; }
public string Title { get { return Origin.Title; } }
public override string ToString()
{
return Title;
}
}
private void VideoChooserDialog_Load(object sender, EventArgs e)
{
foreach (var video in playlist)
{
downloadPicker.Items.Add(new ViewVideoData { Origin = video, ShouldDownload = false }, false);
}
downloadPicker.ItemCheck += DownloadPicker_ItemCheck;
}
private void DownloadPicker_ItemCheck(object sender, ItemCheckEventArgs e)
{
((ViewVideoData)downloadPicker.Items[e.Index]).ShouldDownload = e.NewValue == CheckState.Checked;
}
private void VideoChooserDialog_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (var _item in downloadPicker.Items)
{
var item = (ViewVideoData)_item;
// Remove unselected items from list
if (!item.ShouldDownload)
playlist.Remove(item.Origin);
}
}
}
}