Skip to content

Commit 1c3e90d

Browse files
committed
Created code file selection and fixed title issues
Created the file dialog that lets us select which files to read lines from. Also fixed issues with the title overflowing from being too long.
1 parent 9bfb44e commit 1c3e90d

3 files changed

Lines changed: 64 additions & 5 deletions

File tree

app/Project Tracker/Project Tracker/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
<Label x:Name="tasksCompletedLabel" Content="Tasks completed: 0" HorizontalAlignment="Left" Margin="20,125,0,0" VerticalAlignment="Top" FontSize="24"/>
325325
<Label x:Name="statisticsDurationLabel" Content="Duration: coming soon..." HorizontalAlignment="Left" Margin="20,195,0,0" VerticalAlignment="Top" FontSize="24"/>
326326
<Label x:Name="linesOfCodeLabel" Content="Lines of code: 0" HorizontalAlignment="Left" Margin="20,265,0,0" VerticalAlignment="Top" FontSize="24"/>
327-
<Button x:Name="setCodeCountingButton" Content="Set up code counting" HorizontalAlignment="Left" Margin="20,312,0,0" VerticalAlignment="Top" Width="202" Height="52" FontSize="18" Cursor="Hand"/>
327+
<Button x:Name="setCodeCountingButton" Content="Set up code counting" HorizontalAlignment="Left" Margin="20,312,0,0" VerticalAlignment="Top" Width="202" Height="52" FontSize="18" Cursor="Hand" PreviewMouseDown="setCodeCountingButton_PreviewMouseDown"/>
328328

329329
</Grid>
330330

app/Project Tracker/Project Tracker/MainWindow.xaml.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,12 @@ private void KeyPress(object sender, KeyEventArgs e) {
725725
changeTitleBorder.Visibility = Visibility.Hidden;
726726
displayingTitle.Visibility = Visibility.Visible;
727727

728-
displayingTitle.Content = title;
728+
if (title.Length > 25) {
729+
displayingTitle.Content = title.Substring(0, 22) + "...";
730+
}
731+
else {
732+
displayingTitle.Content = title;
733+
}
729734

730735
Save(filesRead[selectedIndex - 1]);
731736
LoadFiles();
@@ -1286,7 +1291,14 @@ private void OverallSettingsBorderMouseDown(object sender, MouseButtonEventArgs
12861291
private void ProjectStatisticsMouseDown(object sender, MouseButtonEventArgs e) {
12871292
statisticsGrid.Visibility = Visibility.Visible;
12881293

1289-
displayingTitle.Content = title += " Statistics";
1294+
if (title.Length > 14) {
1295+
displayingTitle.Content = title.Substring(0, 14) + "... Statistics";
1296+
}
1297+
else {
1298+
displayingTitle.Content = title + " Statistics";
1299+
}
1300+
1301+
12901302
displayingImage.Source = (ImageSource)TryFindResource("graphDrawingImage");
12911303

12921304
addItemBorder.Visibility = Visibility.Hidden;
@@ -1513,6 +1525,7 @@ private void SetProjectValues(string projectTitle, string[] projectTasks,
15131525
taskIdentifier.Add(identifier);
15141526
}
15151527

1528+
linesOfCodeFiles.Clear();
15161529
foreach (string file in projectLinesOfCodeFiles) {
15171530
linesOfCodeFiles.Add(file);
15181531
}
@@ -1608,7 +1621,13 @@ private void SetSelectedProject() {
16081621
projectInfo.Percent);
16091622

16101623
// Set values
1611-
displayingTitle.Content = projectInfo.Title;
1624+
if (projectInfo.Title.Length > 25) {
1625+
displayingTitle.Content = projectInfo.Title.Substring(0, 22) + "...";
1626+
}
1627+
else {
1628+
displayingTitle.Content = projectInfo.Title;
1629+
}
1630+
16121631

16131632
if (projectInfo.Icon == "rustIcon") {
16141633
// Our default rust icon is white so we need to use the
@@ -2394,5 +2413,17 @@ private void FeatureItemPressed(object sender, MouseButtonEventArgs e) {
23942413
private void folderImage_PreviewMouseDown(object sender, MouseButtonEventArgs e) {
23952414

23962415
}
2416+
2417+
private void setCodeCountingButton_PreviewMouseDown(object sender, MouseButtonEventArgs e) {
2418+
linesOfCodeFiles.Clear();
2419+
2420+
foreach (string file in Statistics.GetFiles()) {
2421+
linesOfCodeFiles.Add(file);
2422+
}
2423+
2424+
Save(filesRead[selectedIndex - 1]);
2425+
2426+
linesOfCodeLabel.Content = "Lines of code: " + Statistics.CountLines(linesOfCodeFiles.ToArray());
2427+
}
23972428
}
23982429
}

app/Project Tracker/Project Tracker/Statistics.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.Win32;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -7,6 +8,14 @@
78

89
namespace Project_Tracker {
910
class Statistics {
11+
// WARNING: READONLY VARIABLES. IF YOU CHANGE THESE, CHANGE IN ALL OTHER FILES.
12+
private static readonly string INITIAL_FILE_DIALOG_DIRECTORY = Environment.SpecialFolder.MyDocuments.ToString();
13+
14+
/// <summary>
15+
/// Counts the lines for each provided file.
16+
/// </summary>
17+
/// <param name="files">The array of files to count.</param>
18+
/// <returns>Returns the number of total lines.</returns>
1019
public static int CountLines(string[] files) {
1120
int linesOfCode = 0;
1221

@@ -17,10 +26,29 @@ public static int CountLines(string[] files) {
1726
return linesOfCode;
1827
}
1928

29+
/// <summary>
30+
/// Creates the current date in mm/dd/yyyy form.
31+
/// </summary>
32+
/// <returns>Returns the date.</returns>
2033
public static string CreationDate() {
2134
DateTime today = DateTime.Now;
2235

2336
return today.ToString("MM/dd/yyyy");
2437
}
38+
39+
/// <summary>
40+
/// Opens a file dialog and gets an array of the selected files.
41+
/// </summary>
42+
/// <returns>Returns the array of selected files.</returns>
43+
public static string[] GetFiles() {
44+
OpenFileDialog fileDialog = new OpenFileDialog();
45+
fileDialog.InitialDirectory = INITIAL_FILE_DIALOG_DIRECTORY;
46+
fileDialog.Title = "Select Code Files to Count";
47+
fileDialog.Multiselect = true;
48+
49+
fileDialog.ShowDialog();
50+
51+
return fileDialog.FileNames;
52+
}
2553
}
2654
}

0 commit comments

Comments
 (0)