mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Fixed separators and replaced obsolete filepicker calls
This commit is contained in:
1 parent
81a7b0d089
commit
a173f3cc61
12 files changed
+83
-81
No files matched your search
@@ -1,4 +1,7 @@
|
||||
using Avalonia.Controls;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Artemis.UI.Shared.Services.Builders;
|
||||
|
||||
@@ -7,11 +10,12 @@ namespace Artemis.UI.Shared.Services.Builders;
|
||||
/// </summary>
|
||||
public class FileDialogFilterBuilder
|
||||
{
|
||||
private readonly FileDialogFilter _filter;
|
||||
private string _name;
|
||||
private readonly List<string> _extensions = new();
|
||||
|
||||
internal FileDialogFilterBuilder()
|
||||
{
|
||||
_filter = new FileDialogFilter();
|
||||
_name = "Unknown";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -19,7 +23,7 @@ public class FileDialogFilterBuilder
|
||||
/// </summary>
|
||||
public FileDialogFilterBuilder WithName(string name)
|
||||
{
|
||||
_filter.Name = name;
|
||||
_name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -28,12 +32,16 @@ public class FileDialogFilterBuilder
|
||||
/// </summary>
|
||||
public FileDialogFilterBuilder WithExtension(string extension)
|
||||
{
|
||||
_filter.Extensions.Add(extension);
|
||||
if (!_extensions.Contains(extension))
|
||||
_extensions.Add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
internal FileDialogFilter Build()
|
||||
internal FilePickerFileType Build()
|
||||
{
|
||||
return _filter;
|
||||
return new FilePickerFileType(_name)
|
||||
{
|
||||
Patterns = _extensions.Select(e => "*." + e).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Artemis.UI.Shared.Services.Builders;
|
||||
|
||||
@@ -10,8 +12,9 @@ namespace Artemis.UI.Shared.Services.Builders;
|
||||
/// </summary>
|
||||
public class OpenFileDialogBuilder
|
||||
{
|
||||
private readonly OpenFileDialog _openFileDialog;
|
||||
private readonly Window _parent;
|
||||
private readonly FilePickerOpenOptions _options;
|
||||
private List<FilePickerFileType>? _fileTypeFilters;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenFileDialogBuilder" /> class.
|
||||
@@ -20,7 +23,7 @@ public class OpenFileDialogBuilder
|
||||
internal OpenFileDialogBuilder(Window parent)
|
||||
{
|
||||
_parent = parent;
|
||||
_openFileDialog = new OpenFileDialog();
|
||||
_options = new FilePickerOpenOptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,7 +31,7 @@ public class OpenFileDialogBuilder
|
||||
/// </summary>
|
||||
public OpenFileDialogBuilder WithAllowMultiple()
|
||||
{
|
||||
_openFileDialog.AllowMultiple = true;
|
||||
_options.AllowMultiple = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -37,7 +40,7 @@ public class OpenFileDialogBuilder
|
||||
/// </summary>
|
||||
public OpenFileDialogBuilder WithTitle(string? title)
|
||||
{
|
||||
_openFileDialog.Title = title;
|
||||
_options.Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -46,16 +49,7 @@ public class OpenFileDialogBuilder
|
||||
/// </summary>
|
||||
public OpenFileDialogBuilder WithDirectory(string? directory)
|
||||
{
|
||||
_openFileDialog.Directory = directory;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the initial file name of the dialog
|
||||
/// </summary>
|
||||
public OpenFileDialogBuilder WithInitialFileName(string? initialFileName)
|
||||
{
|
||||
_openFileDialog.InitialFileName = initialFileName;
|
||||
_options.SuggestedStartLocation = directory != null ? _parent.StorageProvider.TryGetFolderFromPathAsync(directory).GetAwaiter().GetResult() : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -67,8 +61,9 @@ public class OpenFileDialogBuilder
|
||||
FileDialogFilterBuilder builder = new();
|
||||
configure(builder);
|
||||
|
||||
_openFileDialog.Filters ??= new List<FileDialogFilter>();
|
||||
_openFileDialog.Filters.Add(builder.Build());
|
||||
_fileTypeFilters ??= new List<FilePickerFileType>();
|
||||
_fileTypeFilters.Add(builder.Build());
|
||||
_options.FileTypeFilter = _fileTypeFilters;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -82,6 +77,7 @@ public class OpenFileDialogBuilder
|
||||
/// </returns>
|
||||
public async Task<string[]?> ShowAsync()
|
||||
{
|
||||
return await _openFileDialog.ShowAsync(_parent);
|
||||
IReadOnlyList<IStorageFile> files = await _parent.StorageProvider.OpenFilePickerAsync(_options);
|
||||
return files.Select(f => f.Path.AbsolutePath).ToArray();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Artemis.UI.Shared.Services.Builders;
|
||||
|
||||
@@ -8,8 +11,8 @@ namespace Artemis.UI.Shared.Services.Builders;
|
||||
/// </summary>
|
||||
public class OpenFolderDialogBuilder
|
||||
{
|
||||
private readonly OpenFolderDialog _openFolderDialog;
|
||||
private readonly Window _parent;
|
||||
private readonly FolderPickerOpenOptions _options;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="OpenFolderDialogBuilder" /> class.
|
||||
@@ -18,16 +21,15 @@ public class OpenFolderDialogBuilder
|
||||
internal OpenFolderDialogBuilder(Window parent)
|
||||
{
|
||||
_parent = parent;
|
||||
_openFolderDialog = new OpenFolderDialog();
|
||||
_options = new FolderPickerOpenOptions {AllowMultiple = false};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set the title of the dialog
|
||||
/// </summary>
|
||||
public OpenFolderDialogBuilder WithTitle(string? title)
|
||||
{
|
||||
_openFolderDialog.Title = title;
|
||||
_options.Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -36,7 +38,7 @@ public class OpenFolderDialogBuilder
|
||||
/// </summary>
|
||||
public OpenFolderDialogBuilder WithDirectory(string? directory)
|
||||
{
|
||||
_openFolderDialog.Directory = directory;
|
||||
_options.SuggestedStartLocation = directory != null ? _parent.StorageProvider.TryGetFolderFromPathAsync(directory).GetAwaiter().GetResult() : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -49,6 +51,7 @@ public class OpenFolderDialogBuilder
|
||||
/// </returns>
|
||||
public async Task<string?> ShowAsync()
|
||||
{
|
||||
return await _openFolderDialog.ShowAsync(_parent);
|
||||
IReadOnlyList<IStorageFolder> folder = await _parent.StorageProvider.OpenFolderPickerAsync(_options);
|
||||
return folder.FirstOrDefault()?.Path.AbsolutePath;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace Artemis.UI.Shared.Services.Builders;
|
||||
|
||||
@@ -11,8 +12,9 @@ namespace Artemis.UI.Shared.Services.Builders;
|
||||
public class SaveFileDialogBuilder
|
||||
{
|
||||
private readonly Window _parent;
|
||||
private readonly SaveFileDialog _saveFileDialog;
|
||||
|
||||
private readonly FilePickerSaveOptions _options;
|
||||
private List<FilePickerFileType>? _fileTypeFilters;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="SaveFileDialogBuilder" /> class.
|
||||
/// </summary>
|
||||
@@ -20,7 +22,7 @@ public class SaveFileDialogBuilder
|
||||
internal SaveFileDialogBuilder(Window parent)
|
||||
{
|
||||
_parent = parent;
|
||||
_saveFileDialog = new SaveFileDialog();
|
||||
_options = new FilePickerSaveOptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,7 +30,7 @@ public class SaveFileDialogBuilder
|
||||
/// </summary>
|
||||
public SaveFileDialogBuilder WithTitle(string? title)
|
||||
{
|
||||
_saveFileDialog.Title = title;
|
||||
_options.Title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ public class SaveFileDialogBuilder
|
||||
/// </summary>
|
||||
public SaveFileDialogBuilder WithDirectory(string? directory)
|
||||
{
|
||||
_saveFileDialog.Directory = directory;
|
||||
_options.SuggestedStartLocation = directory != null ? _parent.StorageProvider.TryGetFolderFromPathAsync(directory).GetAwaiter().GetResult() : null;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -46,16 +48,7 @@ public class SaveFileDialogBuilder
|
||||
/// </summary>
|
||||
public SaveFileDialogBuilder WithInitialFileName(string? initialFileName)
|
||||
{
|
||||
_saveFileDialog.InitialFileName = initialFileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the default extension of the dialog
|
||||
/// </summary>
|
||||
public SaveFileDialogBuilder WithDefaultExtension(string? defaultExtension)
|
||||
{
|
||||
_saveFileDialog.DefaultExtension = defaultExtension;
|
||||
_options.SuggestedFileName = initialFileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -67,8 +60,9 @@ public class SaveFileDialogBuilder
|
||||
FileDialogFilterBuilder builder = new();
|
||||
configure(builder);
|
||||
|
||||
_saveFileDialog.Filters ??= new List<FileDialogFilter>();
|
||||
_saveFileDialog.Filters.Add(builder.Build());
|
||||
_fileTypeFilters ??= new List<FilePickerFileType>();
|
||||
_fileTypeFilters.Add(builder.Build());
|
||||
_options.FileTypeChoices = _fileTypeFilters;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -82,6 +76,7 @@ public class SaveFileDialogBuilder
|
||||
/// </returns>
|
||||
public async Task<string?> ShowAsync()
|
||||
{
|
||||
return await _saveFileDialog.ShowAsync(_parent);
|
||||
IStorageFile? path = await _parent.StorageProvider.SaveFilePickerAsync(_options);
|
||||
return path?.Path.AbsolutePath;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<Border Classes="card" Margin="20">
|
||||
<StackPanel>
|
||||
<TextBlock>I'm in a panel yo!</TextBlock>
|
||||
<Separator Classes="card-separator" />
|
||||
<Border Classes="card-separator" />
|
||||
<TextBlock>I'm in a panel yo!</TextBlock>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
@@ -44,7 +44,7 @@
|
||||
<Setter Property="CornerRadius" Value="{DynamicResource CardCornerRadius}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Separator.card-separator">
|
||||
<Style Selector="Border.card-separator">
|
||||
<Setter Property="Background" Value="{DynamicResource ButtonBorderBrush}" />
|
||||
<Setter Property="Margin" Value="-12 15" />
|
||||
<Setter Property="Height" Value="1" />
|
||||
|
||||
Reference in new issue
Block a user