Skip to content

Commit

Permalink
Added elapsed time to compile window
Browse files Browse the repository at this point in the history
closes #130
  • Loading branch information
Exactol committed Sep 27, 2020
1 parent 9ded0e5 commit 969db75
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CompilePalX/Compiling/CompilingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -219,6 +220,11 @@ public static void CancelCompile()
postCompile(null);
}

public static Stopwatch GetTime()
{
return compileTimeStopwatch;
}

class MapErrors
{
public string MapName { get; set; }
Expand Down
1 change: 1 addition & 0 deletions CompilePalX/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<Label Name="UpdateLabel" Visibility="Collapsed" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10" MouseLeftButtonUp="UpdateLabel_MouseLeftButtonUp" >
<Hyperlink Name="UpdateHyperLink" NavigateUri="https://github.com/ruarai/CompilePal/releases/latest" RequestNavigate="UpdateHyperLink_OnRequestNavigate"/>
</Label>
<Label Name="TimeElapsedLabel" Visibility="Collapsed" Grid.Row="2" VerticalAlignment="Bottom" FontWeight="Bold" HorizontalAlignment="Left" Margin="10" />
</Grid>

<Window.TaskbarItemInfo>
Expand Down
23 changes: 23 additions & 0 deletions CompilePalX/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public partial class MainWindow
public static Dispatcher ActiveDispatcher;
private ObservableCollection<CompileProcess> CompileProcessesSubList = new ObservableCollection<CompileProcess>();
private bool processModeEnabled;
private DispatcherTimer elapsedTimeDispatcherTimer;
public static MainWindow Instance { get; private set; }

public MainWindow()
Expand Down Expand Up @@ -88,6 +89,12 @@ public MainWindow()

RowDragHelper.RowSwitched += RowDragHelperOnRowSwitched;

elapsedTimeDispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 1), DispatcherPriority.Background,
this.TickElapsedTimer, Dispatcher.CurrentDispatcher)
{
IsEnabled = false
};

HandleArgs();
}

Expand Down Expand Up @@ -283,6 +290,14 @@ private void CompilingManager_OnStart()

AddMapButton.IsEnabled = false;
RemoveMapButton.IsEnabled = false;

// hide update link so elapsed time can be shown
UpdateLabel.Visibility = Visibility.Collapsed;
TimeElapsedLabel.Visibility = Visibility.Visible;
// Tick elapsed timer to display the default string
TickElapsedTimer(null, null);

elapsedTimeDispatcherTimer.IsEnabled = true;
}

private void CompilingManager_OnFinish()
Expand All @@ -307,6 +322,9 @@ private void CompilingManager_OnFinish()
AddMapButton.IsEnabled = true;
RemoveMapButton.IsEnabled = true;

TimeElapsedLabel.Visibility = Visibility.Collapsed;
elapsedTimeDispatcherTimer.IsEnabled = false;

string logName = DateTime.Now.ToString("s").Replace(":", "-") + ".txt";
string textLog = new TextRange(CompileOutputTextbox.Document.ContentStart, CompileOutputTextbox.Document.ContentEnd).Text;

Expand Down Expand Up @@ -774,6 +792,11 @@ private void BugReportButton_OnClick(object sender, RoutedEventArgs e)
Process.Start(new ProcessStartInfo("https://github.com/ruarai/CompilePal/issues/"));
e.Handled = true;
}

private void TickElapsedTimer(object sender, EventArgs e)
{
TimeElapsedLabel.Content = $"Time Elapsed: {CompilingManager.GetTime().Elapsed.ToString(@"hh\:mm\:ss")}";
}
}

public static class ObservableCollectionExtension
Expand Down
2 changes: 1 addition & 1 deletion CompilePalX/version_prerelease.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
027.12
027.13

0 comments on commit 969db75

Please sign in to comment.