-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Added PositronFilePicker
- Loading branch information
Showing
14 changed files
with
1,831 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Positron.Controls; | ||
|
||
public class CloseButton: Button | ||
{ | ||
public CloseButton() | ||
{ | ||
this.Text = "x"; | ||
this.BackgroundColor = Color.Parse("Red"); | ||
} | ||
} | ||
|
||
public sealed class ProgressPanel : Grid, IDisposable | ||
{ | ||
|
||
public readonly CancellationToken CancelToken; | ||
private readonly CancellationTokenSource cancellationTokenSource; | ||
|
||
private Grid? parentGrid; | ||
private readonly ProgressBar progress; | ||
|
||
public double Progress { get => progress.Progress; set => progress.Progress = value; } | ||
|
||
public static ProgressPanel Create(string title) | ||
{ | ||
return new ProgressPanel(title); | ||
} | ||
|
||
public ProgressPanel(string title) | ||
{ | ||
cancellationTokenSource = new CancellationTokenSource(); | ||
CancelToken = cancellationTokenSource.Token; | ||
var grid = (Application.Current.MainPage as ContentPage)?.Content as Grid; | ||
grid?.Children?.Add(this); | ||
this.HorizontalOptions = LayoutOptions.Fill; | ||
this.VerticalOptions = LayoutOptions.Fill; | ||
this.parentGrid = grid; | ||
|
||
this.progress = new ProgressBar(); | ||
this.progress.HorizontalOptions = LayoutOptions.Fill; | ||
this.progress.VerticalOptions = LayoutOptions.Center; | ||
this.progress.MinimumWidthRequest = 100; | ||
|
||
this.ColumnDefinitions.Add(new ColumnDefinition | ||
{ | ||
Width = new GridLength(1, GridUnitType.Star) | ||
}); | ||
this.ColumnDefinitions.Add(new ColumnDefinition | ||
{ | ||
Width = 5 | ||
}); | ||
this.ColumnDefinitions.Add(new ColumnDefinition | ||
{ | ||
Width = GridLength.Auto | ||
}); | ||
this.ColumnDefinitions.Add(new ColumnDefinition | ||
{ | ||
Width = GridLength.Auto | ||
}); | ||
this.ColumnDefinitions.Add(new ColumnDefinition | ||
{ | ||
Width = 5 | ||
}); | ||
this.ColumnDefinitions.Add(new ColumnDefinition | ||
{ | ||
Width = new GridLength(1, GridUnitType.Star) | ||
}); | ||
|
||
this.RowDefinitions.Add(new RowDefinition | ||
{ | ||
Height = GridLength.Star | ||
}); | ||
this.RowDefinitions.Add(new RowDefinition | ||
{ | ||
Height = 5 | ||
}); | ||
this.RowDefinitions.Add(new RowDefinition | ||
{ | ||
Height = GridLength.Auto | ||
}); | ||
this.RowDefinitions.Add(new RowDefinition | ||
{ | ||
Height = GridLength.Auto | ||
}); | ||
this.RowDefinitions.Add(new RowDefinition | ||
{ | ||
Height = 5 | ||
}); | ||
this.RowDefinitions.Add(new RowDefinition | ||
{ | ||
Height = GridLength.Star | ||
}); | ||
|
||
this.Children.Add(new Frame | ||
{ | ||
BackgroundColor = Color.Parse("White"), | ||
HasShadow = true, | ||
}.SetGrid(column: 1, columnSpan: 4, row: 1, rowSpan: 4)); | ||
|
||
this.Children.Add(new Label | ||
{ | ||
Text = title, | ||
}.SetGrid(column: 2, row: 2)); | ||
|
||
this.Children.Add(progress.SetGrid(column: 2, row: 3, columnSpan: 2)); | ||
this.Children.Add(new CloseButton | ||
{ | ||
Padding = 0, | ||
Command = new Command(() => Cancel()), | ||
}.SetGrid(row: 2, column: 3)); | ||
} | ||
|
||
public void Cancel() | ||
{ | ||
HybridRunner.RunAsync(async () => | ||
Check failure on line 120 in Positron/Controls/ProgressPanel.cs
|
||
{ | ||
if (await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Cancel?", "Are you sure you want to cancel?", "Yes", "No")) | ||
{ | ||
cancellationTokenSource.Cancel(); | ||
this.Dispose(); | ||
parentGrid = null; | ||
} | ||
}); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (parentGrid == null) | ||
{ | ||
return; | ||
} | ||
MainThread.BeginInvokeOnMainThread(() => parentGrid?.Children?.Remove(this)); | ||
} | ||
} |
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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Positron; | ||
public static class GridExtensions | ||
{ | ||
|
||
public static T SetGrid<T>( | ||
this T @this, | ||
int? column = null, | ||
int? row = null, | ||
int? columnSpan = null, | ||
int? rowSpan = null) | ||
where T : Element | ||
{ | ||
if (column != null) | ||
{ | ||
Grid.SetColumn(@this, column.Value); | ||
} | ||
if (row != null) | ||
{ | ||
Grid.SetRow(@this, row.Value); | ||
} | ||
if (columnSpan != null) | ||
{ | ||
Grid.SetColumnSpan(@this, columnSpan.Value); | ||
} | ||
if (rowSpan != null) | ||
{ | ||
Grid.SetRowSpan(@this, rowSpan.Value); | ||
} | ||
return @this; | ||
} | ||
|
||
} |
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 System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Positron; | ||
public static partial class StringExtensions | ||
{ | ||
|
||
public static string Left(this string @this, int maxLength) | ||
{ | ||
if (@this.Length <= maxLength) | ||
{ | ||
return @this; | ||
} | ||
return @this.Substring(0, maxLength); | ||
} | ||
public static string SafeFileName(this string @this, string padLeft = "", int maxLength = 60) | ||
{ | ||
var name = System.IO.Path.GetFileNameWithoutExtension(@this).Left(maxLength) + padLeft; | ||
var ext = System.IO.Path.GetExtension(@this); | ||
var sb = new StringBuilder(maxLength + ext.Length); | ||
for (int i = 0; i < name.Length; i++) | ||
{ | ||
char ch = name[i]; | ||
ch = char.IsLetterOrDigit(ch) || ch == '.' || ch == '-' ? ch : '-'; | ||
sb.Append(ch); | ||
} | ||
sb.Append(ext); | ||
return sb.ToString(); | ||
} | ||
|
||
//public static ReadOnlySpan<char> Left(this ReadOnlySpan<char> @this, int maxLength) | ||
//{ | ||
// if (@this.Length <= maxLength) | ||
// { | ||
// return @this; | ||
// } | ||
// return @this.Slice(0, maxLength); | ||
//} | ||
|
||
//public static string SafeFileName(this ReadOnlySpan<char> @this, int maxLength = 80) | ||
//{ | ||
// var name = System.IO.Path.GetFileNameWithoutExtension(@this).Left(maxLength); | ||
// var ext = System.IO.Path.GetExtension(@this); | ||
// Span<char> newName = stackalloc char[80 + ext.Length]; | ||
// for (int i = 0; i < name.Length; i++) | ||
// { | ||
// char ch = name[i]; | ||
// ch = char.IsLetterOrDigit(ch) || ch == '.' || ch == '-' ? ch : '-'; | ||
// newName[i] = ch; | ||
// } | ||
// ext.CopyTo(newName.Slice(name.Length)); | ||
// return new string(newName., name.Length + ext.Length); | ||
//} | ||
|
||
} |
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
Oops, something went wrong.