-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from strem-app/spike/try-photino-native-dialogs
Spike/try photino native dialogs
- Loading branch information
Showing
13 changed files
with
93 additions
and
38 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
19 changes: 0 additions & 19 deletions
19
src/Strem.Platforms.Windows/Services/Browsers/FileBrowser.cs
This file was deleted.
Oops, something went wrong.
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
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
21 changes: 21 additions & 0 deletions
21
src/Strem.UnitTests/App/Services/BlazorNativeFileBrowserTests.cs
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,21 @@ | ||
using Strem.Services.Dialogs; | ||
|
||
namespace Strem.UnitTests.App.Services; | ||
|
||
public class BlazorNativeFileBrowserTests | ||
{ | ||
[Fact] | ||
public void should_correctly_convert_filter_string_to_filter_tuple() | ||
{ | ||
var filterString = "Excel Files (*.xls, *.xlsx)|*.xls;*.xlsx|CSV Files (*.csv)|*.csv"; | ||
var transformedFilters = BlazorNativeFileBrowser.FilterToBlazorFilter(filterString); | ||
Assert.Equal(2, transformedFilters.Length); | ||
Assert.Equal("Excel Files (*.xls, *.xlsx)", transformedFilters[0].Name); | ||
Assert.Equal(2, transformedFilters[0].Extensions.Length); | ||
Assert.Contains("*.xls", transformedFilters[0].Extensions); | ||
Assert.Contains("*.xlsx", transformedFilters[0].Extensions); | ||
Assert.Equal("CSV Files (*.csv)", transformedFilters[1].Name); | ||
Assert.Equal(1, transformedFilters[1].Extensions.Length); | ||
Assert.Contains("*.csv", transformedFilters[1].Extensions); | ||
} | ||
} |
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
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,56 @@ | ||
using System.Text.RegularExpressions; | ||
using Photino.Blazor; | ||
using Strem.Core.Services.Browsers.File; | ||
|
||
namespace Strem.Services.Dialogs; | ||
|
||
public class BlazorNativeFileBrowser : IFileBrowser | ||
{ | ||
public static Regex FilterPattern { get; } = new Regex(@"(.*?\|[\;\.\-\*\w]*)\|?"); | ||
|
||
public PhotinoBlazorApp App { get; } | ||
|
||
public BlazorNativeFileBrowser(PhotinoBlazorApp app) | ||
{ | ||
App = app; | ||
} | ||
|
||
// EXAMPLE "Excel Files (*.xls, *.xlsx)|*.xls;*.xlsx|CSV Files (*.csv)|*.csv" | ||
public static (string Name, string[] Extensions)[] FilterToBlazorFilter(string filter) | ||
{ | ||
if (string.IsNullOrEmpty(filter)) | ||
{ return Array.Empty<(string Name, string[] Extensions)>(); } | ||
|
||
if (!filter.Contains('|')) | ||
{ return [(filter, new[] { filter })]; } | ||
|
||
var filterList = new List<(string Name, string[] Extensions)>(); | ||
var lineFilters = FilterPattern.Matches(filter).Select(x => x.Value); | ||
foreach (var lineFilter in lineFilters) | ||
{ | ||
if (!lineFilter.Contains('|')) | ||
{ filterList.Add((lineFilter, new[] { lineFilter })); } | ||
else | ||
{ | ||
var filerSections = lineFilter.Split("|"); | ||
filterList.Add((filerSections[0], filerSections[1].Split(";"))); | ||
} | ||
} | ||
|
||
return filterList.ToArray(); | ||
} | ||
|
||
public string BrowseToOpenFile(string startingDirectory = null, string filterList = null) | ||
{ | ||
var filters = FilterToBlazorFilter(filterList); | ||
var result = App.MainWindow.ShowOpenFile(defaultPath: startingDirectory, filters: filters, multiSelect: false); | ||
return result.Length == 0 ? string.Empty : result[0]; | ||
} | ||
|
||
public string BrowseToSaveFile(string startingDirectory = null, string filterList = null) | ||
{ | ||
var filters = FilterToBlazorFilter(filterList); | ||
var result = App.MainWindow.ShowSaveFile(defaultPath: startingDirectory, filters: filters); | ||
return string.IsNullOrEmpty(result) ? string.Empty : result; | ||
} | ||
} |
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