Allow locating file that was moved/renamed

This commit is contained in:
2026-02-17 14:50:59 +09:00
parent 83f2ea88b5
commit 0d4c1b90c2
2 changed files with 56 additions and 4 deletions
+35
View File
@@ -286,6 +286,41 @@ class MainViewModel : BaseViewModel, IFontResolver
}
}
public void LocateFile(object f) => LocateFileImpl((ReportFile) f);
public async void LocateFileImpl(ReportFile reportFile)
{
var topLevel = TopLevelGrabber?.GetTopLevel();
if (topLevel is not null)
{
var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
{
Title = "Choose image or PDF file...",
AllowMultiple = false,
FileTypeFilter = [
new FilePickerFileType("All Types")
{
Patterns = GetAllowedFileExtensionPatterns(),
AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ],
MimeTypes = [ "image/*", "application/pdf", "image/heic" ]
},
FilePickerFileTypes.ImageAll,
new FilePickerFileType("HEIC Images")
{
Patterns = [ "*.heic" ],
AppleUniformTypeIdentifiers = [ "public.heic" ],
MimeTypes = [ "image/heic" ]
},
FilePickerFileTypes.Pdf,
],
});
if (files.Count > 0)
{
var file = files[0];
reportFile.FilePath = file.Path.LocalPath;
}
}
}
// https://github.com/AvaloniaUI/Avalonia/issues/10075
public void OpenFile(object f) => OpenFileImpl((ReportFile)f);
public void OpenFileImpl(ReportFile file)