-
Notifications
You must be signed in to change notification settings - Fork 21
/
FormNewRepoScan.cs
101 lines (91 loc) · 3.31 KB
/
FormNewRepoScan.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace GitForce
{
/// <summary>
/// Scan for new repositories
/// </summary>
public partial class FormNewRepoScan : Form
{
public FormNewRepoScan()
{
InitializeComponent();
ClassWinGeometry.Restore(this);
checkBoxDeepScan.Checked = Properties.Settings.Default.RepoDeepScan;
}
private void FormNewRepoScanFormClosing(object sender, FormClosingEventArgs e)
{
ClassWinGeometry.Save(this);
}
/// <summary>
/// Return a list of selected directories
/// </summary>
public List<string> GetList()
{
return listRepos.Items.Cast<object>().
Where((t, i) => listRepos.GetItemCheckState(i) == CheckState.Checked).
Select(t => t.ToString()).ToList();
}
/// <summary>
/// Browse for a initial directory to scan from
/// </summary>
private void BtBrowseClick(object sender, EventArgs e)
{
if (folderDlg.ShowDialog() == DialogResult.OK)
{
textRoot.Text = folderDlg.SelectedPath;
}
}
/// <summary>
/// Start scanning
/// </summary>
private void BtScanClick(object sender, EventArgs e)
{
FormNewRepoScanProgress formScanProgress = new FormNewRepoScanProgress(textRoot.Text, checkBoxDeepScan.Checked);
if (formScanProgress.ShowDialog() == DialogResult.OK)
{
// Add only unique values to the list, so we can run the scan on multiple
// directories and add all scanned paths, even if they have common folders
foreach (var path in formScanProgress.Gits.ToArray().
Where(path => !listRepos.Items.Contains(path)))
listRepos.Items.Add(path);
btSelectAll.Enabled = btSelectNone.Enabled = listRepos.Items.Count > 0;
BtSelectAllClick(null, null);
}
}
/// <summary>
/// Select all directories
/// </summary>
private void BtSelectAllClick(object sender, EventArgs e)
{
for (int i = 0; i < listRepos.Items.Count; i++)
listRepos.SetItemChecked(i, true);
}
/// <summary>
/// Select no directory from the list
/// </summary>
private void BtSelectNoneClick(object sender, EventArgs e)
{
for (int i = 0; i < listRepos.Items.Count; i++)
listRepos.SetItemChecked(i, false);
}
/// <summary>
/// On text in the root directory changed, verify the directory and enable Scan button
/// </summary>
private void TextRootTextChanged(object sender, EventArgs e)
{
btScan.Enabled = Path.IsPathRooted(textRoot.Text) && Directory.Exists(textRoot.Text);
}
/// <summary>
/// Item in the list of paths is being checked, adjust button enables.
/// </summary>
private void ListReposItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked)
btAdd.Enabled = true;
}
}
}