-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Offload project loading, add loading bar modal (#31)
- Loading branch information
1 parent
176f457
commit 6897f4a
Showing
6 changed files
with
175 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace SerialLoops.Lib.Util | ||
{ | ||
public interface IProgressTracker | ||
{ | ||
public int Loaded { get; set; } | ||
public int Total { get; set; } | ||
public string CurrentlyLoading { get; set; } | ||
|
||
public void Focus(string item, int count) | ||
{ | ||
Total += count; | ||
CurrentlyLoading = item; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Eto.Drawing; | ||
using Eto.Forms; | ||
using SerialLoops.Controls; | ||
using SerialLoops.Lib.Util; | ||
using SerialLoops.Utility; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SerialLoops | ||
{ | ||
public class LoadingDialog : Dialog | ||
{ | ||
|
||
private readonly Action _loadingTask; | ||
private readonly LoopyProgressTracker _tracker; | ||
private readonly Action _onComplete; | ||
|
||
public LoadingDialog(Action loadingTask, Action onComplete, LoopyProgressTracker tracker) | ||
{ | ||
_loadingTask = loadingTask; | ||
_tracker = tracker; | ||
_onComplete = onComplete; | ||
|
||
Title = "Loading"; | ||
ShowInTaskbar = false; | ||
Closeable = false; | ||
Resizable = false; | ||
MinimumSize = new Size(300, 100); | ||
Content = tracker; | ||
|
||
ShowModal(); | ||
} | ||
|
||
protected async override void OnShown(EventArgs e) | ||
{ | ||
base.OnShown(e); | ||
await Task.Run(() => | ||
{ | ||
_loadingTask(); | ||
Application.Instance.Invoke(() => | ||
{ | ||
_onComplete(); | ||
}); | ||
}); | ||
Close(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Eto.Forms; | ||
using SerialLoops.Lib.Util; | ||
using System; | ||
|
||
namespace SerialLoops.Utility | ||
{ | ||
public class LoopyProgressTracker : StackLayout, IProgressTracker | ||
{ | ||
|
||
private readonly ProgressBar _loadingProgress; | ||
private readonly Label _loadingItem; | ||
|
||
public LoopyProgressTracker() | ||
{ | ||
_loadingProgress = new() { Width = 390 }; | ||
_loadingItem = new(); | ||
|
||
Padding = 10; | ||
Spacing = 10; | ||
HorizontalContentAlignment = HorizontalAlignment.Center; | ||
Items.Add(_loadingItem); | ||
Items.Add(_loadingProgress); | ||
} | ||
|
||
|
||
private int _current; | ||
public int Loaded { | ||
get => _current; | ||
set | ||
{ | ||
_current = value; | ||
Application.Instance.Invoke(() => _loadingProgress.Value = _current); | ||
} | ||
} | ||
|
||
private int _total; | ||
public int Total | ||
{ | ||
get => _total; | ||
set | ||
{ | ||
_total = value; | ||
Application.Instance.Invoke(() => _loadingProgress.MaxValue = _total); | ||
} | ||
} | ||
|
||
private string _currentlyLoading; | ||
public string CurrentlyLoading { | ||
get => _currentlyLoading; | ||
set | ||
{ | ||
_currentlyLoading = $"Loading {value}..."; | ||
Application.Instance.Invoke(() => _loadingItem.Text = _currentlyLoading); | ||
} | ||
} | ||
|
||
} | ||
} |