-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormMain.cs
More file actions
179 lines (153 loc) · 6.31 KB
/
FormMain.cs
File metadata and controls
179 lines (153 loc) · 6.31 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System.Diagnostics;
using System.Globalization;
namespace Manager
{
public partial class FormMain : Form
{
private Project _selectedProject;
public FormMain()
{
InitializeComponent();
CenterToScreen();
}
public void FormMain_Load(object sender, EventArgs e)
{
PopulateProfilesDropdown();
}
private void PopulateProfilesDropdown()
{
var index = 0;
foreach(var profile in ProfileHandler.Instance.Profiles)
{
var newIndex = dropdownProfile.Items.Add(profile);
if(profile.ProfileName == SettingsHandler.Instance.Settings.LastUsedProfile)
{
SettingsHandler.Instance.Settings.LastUsedProfile = profile.ProfileName;
index = newIndex;
}
}
dropdownProfile.SelectedIndex = index;
PopulateProjectList(dropdownProfile.SelectedItem.ToString()!);
}
private void PopulateProjectList(string profileName)
{
listboxProjects.Items.Clear();
var projList = ProfileHandler.Instance.Profiles.Where(x => x.ProfileName == profileName).First().ProjectList;
if (projList.Any())
{
listboxProjects.Items.AddRange(projList.ToArray());
}
else
{
listboxProjects.Items.Add("No Projects Found");
}
listboxProjects.SelectedIndex = 0;
}
private void ListboxProjects_SelectedIndexChanged(object sender, EventArgs e)
{
if (listboxProjects.SelectedItem.ToString() == "No Projects Found") { return; }
_selectedProject = ProfileHandler.Instance.GetProjectByName(SettingsHandler.Instance.Settings.LastUsedProfile, listboxProjects.SelectedItem.ToString());
PopulateProjectDetails(_selectedProject);
}
private void DropdownProfile_SelectedIndexChanged(object sender, EventArgs e)
{
SettingsHandler.Instance.Settings.LastUsedProfile = dropdownProfile.SelectedItem.ToString();
PopulateProjectList(SettingsHandler.Instance.Settings.LastUsedProfile);
}
private void PopulateProjectDetails(Project p)
{
lblProjectName.Text = p.Name;
btnNotes.Tag = p.Name;
btnOpen.Tag = p.RootDirectory;
LoadGitHistory(p.RootDirectory, p.GitLogHistory);
}
private void LoadGitHistory(string dir, int gitHistory)
{
// Current git branch
var branch = GitHandler.GetGitResponse("branch", dir);
foreach(var line in branch)
{
if (line[0] == '*')
{
lblGitBranchName.Text = line.Substring(2);
break;
}
}
// Git history
var command = $"log --oneline -{gitHistory}";
var commits = GitHandler.GetGitResponse(command, dir);
txtGitHistory.Text = "";
foreach(var line in commits)
{
txtGitHistory.Text += line + Environment.NewLine;
}
// Last commit timestamp
var timestampString = GitHandler.GetGitResponse("log -1 --format=%cd", dir);
lblLastCommitValue.Text = "";
if (timestampString.Any())
{
var dateTime = DateTimeOffset.ParseExact(timestampString[0], "ddd MMM d HH:mm:ss yyyy K", CultureInfo.InvariantCulture, DateTimeStyles.None);
lblLastCommitValue.Text = SettingsHandler.Instance.Settings.FormatTimeStamp(dateTime.DateTime);
}
else
{
lblLastCommitValue.Text = "UNKNOWN";
}
}
#region ToolStrip Menu Items
private void AddToolStripMenuItem_Click(object sender, EventArgs e)
{
var formAddNewProject = new FormAddProject();
var result = formAddNewProject.ShowDialog();
if(result == DialogResult.OK)
{
var profile = ProfileHandler.Instance.Profiles.Where(x => x.ProfileName == SettingsHandler.Instance.Settings.LastUsedProfile).First();
ProfileHandler.Instance.CreateProject(profile, formAddNewProject.Project);
PopulateProjectList(profile.ProfileName);
}
}
private void ManageToolStripMenuItem_Click(object sender, EventArgs e)
{
var formManageProjects = new FormManageProjects(SettingsHandler.Instance.Settings.LastUsedProfile);
var results = formManageProjects.ShowDialog();
if(results == DialogResult.OK)
{
PopulateProjectList(SettingsHandler.Instance.Settings.LastUsedProfile);
}
}
private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
var formSettings = new FormSettings();
if(formSettings.ShowDialog() == DialogResult.OK)
{
SettingsHandler.Instance.UpdateSettings(formSettings.UpdatedSettings);
// Update the DateTime displays if the settings changed
PopulateProjectDetails(_selectedProject);
}
}
#endregion
#region Buttons
private void BtnNotes_Click(object sender, EventArgs e)
{
var profile = ProfileHandler.Instance.Profiles.Where(x => x.ProfileName == SettingsHandler.Instance.Settings.LastUsedProfile).First();
var project = profile.ProjectList.Where(x => x.Name == btnNotes.Tag.ToString()).First();
ProfileHandler.Instance.VerifyNotesPathExists(profile, project);
var processInfo = new ProcessStartInfo()
{
Arguments = $"\"{project.NotesPath}\"",
FileName = SettingsHandler.Instance.Settings.PreferredTextEditorPath
};
Process.Start(processInfo);
}
private void BtnOpen_Click(object sender, EventArgs e)
{
var processInfo = new ProcessStartInfo()
{
Arguments = btnOpen.Tag.ToString(),
FileName = "explorer.exe"
};
Process.Start(processInfo);
}
#endregion
}
}