commit c446ff9afb9dd9565af40515d2050481be590491 Author: ti_mo Date: Fri Jan 2 01:41:58 2026 +0100 initial push diff --git a/.idea/.idea.Photos/.idea/avalonia.xml b/.idea/.idea.Photos/.idea/avalonia.xml new file mode 100644 index 0000000..d584b1c --- /dev/null +++ b/.idea/.idea.Photos/.idea/avalonia.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Photos/.idea/discord.xml b/.idea/.idea.Photos/.idea/discord.xml new file mode 100644 index 0000000..30bab2a --- /dev/null +++ b/.idea/.idea.Photos/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.Photos/.idea/indexLayout.xml b/.idea/.idea.Photos/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.Photos/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Photos/.idea/material_theme_project_new.xml b/.idea/.idea.Photos/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..f1ce2f0 --- /dev/null +++ b/.idea/.idea.Photos/.idea/material_theme_project_new.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Photos/.idea/vcs.xml b/.idea/.idea.Photos/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.Photos/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Photos.sln b/Photos.sln new file mode 100644 index 0000000..7525fbe --- /dev/null +++ b/Photos.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Photos", "Photos\Photos.csproj", "{D87FA05B-91E4-41DD-B57A-E7ADD2656214}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D87FA05B-91E4-41DD-B57A-E7ADD2656214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D87FA05B-91E4-41DD-B57A-E7ADD2656214}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D87FA05B-91E4-41DD-B57A-E7ADD2656214}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D87FA05B-91E4-41DD-B57A-E7ADD2656214}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Photos.sln.DotSettings.user b/Photos.sln.DotSettings.user new file mode 100644 index 0000000..e1cce78 --- /dev/null +++ b/Photos.sln.DotSettings.user @@ -0,0 +1,3 @@ + + ForceIncluded + ForceIncluded \ No newline at end of file diff --git a/Photos/App.axaml b/Photos/App.axaml new file mode 100644 index 0000000..567ca0b --- /dev/null +++ b/Photos/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Photos/App.axaml.cs b/Photos/App.axaml.cs new file mode 100644 index 0000000..da47c62 --- /dev/null +++ b/Photos/App.axaml.cs @@ -0,0 +1,47 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using Photos.ViewModels; +using Photos.Views; + +namespace Photos; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + // Avoid duplicate validations from both Avalonia and the CommunityToolkit. + // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins + DisableAvaloniaDataAnnotationValidation(); + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() + { + // Get an array of plugins to remove + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/Photos/Assets/avalonia-logo.ico b/Photos/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/Photos/Assets/avalonia-logo.ico differ diff --git a/Photos/Models/Photo.cs b/Photos/Models/Photo.cs new file mode 100644 index 0000000..f4eb666 --- /dev/null +++ b/Photos/Models/Photo.cs @@ -0,0 +1,27 @@ +using System; +using System.IO; +using Avalonia.Media; +using Avalonia.Media.Imaging; +using Avalonia.Platform.Storage; + +namespace Photos.Models; + +public class Photo +{ + public string DisplayName { get; set; } + public string FullPath { get; set; } + public string DisplayPath { get; set; } + + public IImage Source { get; set; } + + public Photo(string path, string relativeTo) + { + DisplayName = System.IO.Path.GetFileName(path); + FullPath = path; + DisplayPath = path.Remove(0, relativeTo.Length + 1); + using (var stream = File.OpenRead(path)) + { + Source = new Bitmap(stream); + } + } +} \ No newline at end of file diff --git a/Photos/Photos.csproj b/Photos/Photos.csproj new file mode 100644 index 0000000..1ddaeba --- /dev/null +++ b/Photos/Photos.csproj @@ -0,0 +1,27 @@ + + + WinExe + net9.0 + enable + app.manifest + true + + + + + + + + + + + + + + None + All + + + + + diff --git a/Photos/Program.cs b/Photos/Program.cs new file mode 100644 index 0000000..ef69d04 --- /dev/null +++ b/Photos/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace Photos; + +sealed class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} \ No newline at end of file diff --git a/Photos/ViewLocator.cs b/Photos/ViewLocator.cs new file mode 100644 index 0000000..b307756 --- /dev/null +++ b/Photos/ViewLocator.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using Photos.ViewModels; + +namespace Photos; + +/// +/// Given a view model, returns the corresponding view if possible. +/// +[RequiresUnreferencedCode( + "Default implementation of ViewLocator involves reflection which may be trimmed away.", + Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")] +public class ViewLocator : IDataTemplate +{ + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} \ No newline at end of file diff --git a/Photos/ViewModels/MainWindowViewModel.cs b/Photos/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..65af5bb --- /dev/null +++ b/Photos/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.Net; +using Avalonia.Controls; +using Avalonia.Input; +using Photos.Models; +using Avalonia.Platform.Storage; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Avalonia.Threading; +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Photos.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public ObservableCollection Photos { get; private set; } = []; + + [ObservableProperty] private Photo? _selectedPhoto; + + public string LibraryPath { get; private set; } = string.Empty; + + public MainWindowViewModel() + { + + } + + void OpenDirectory() + { + + } + + private void SanitizeFiles(List files, IEnumerable extensions) + => files.RemoveAll(x => !extensions.Any(ex => x.EndsWith(ex, StringComparison.OrdinalIgnoreCase))); + + private async Task AddPhotosAsync(string path) + { + try + { + var files = await Task.Run(() => + { + var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories).ToList(); + SanitizeFiles(files, [".png", ".jpg", ".jpeg"]); + return files; + }); + + var photosToAdd = await Task.Run(() => + { + var photos = new List(); + foreach (var file in files) + { + photos.Add(new Photo(file, LibraryPath)); + } + return photos; + }); + + await Dispatcher.UIThread.InvokeAsync(() => + { + foreach (var photo in photosToAdd) Photos.Add(photo); + }); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + + public async void WindowDropHandler(DragEventArgs e) + { + var files = e.DataTransfer.TryGetFiles(); + if (files is null || files.Length == 0) return; + + var localPath = Path.GetDirectoryName(files[0].TryGetLocalPath()); + if (String.IsNullOrWhiteSpace(localPath)) return; + + LibraryPath = localPath; + Photos.Clear(); + + await AddPhotosAsync(localPath); + } + + public void PhotoClicked(PointerReleasedEventArgs e) + { + if(e.Source is not Image img) return; + SelectedPhoto = Photos.FirstOrDefault(x => x.Source == img.Source); + } + + public void SelectedPhotoClicked() + { + SelectedPhoto = null; + } +} \ No newline at end of file diff --git a/Photos/ViewModels/ViewModelBase.cs b/Photos/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..a16941f --- /dev/null +++ b/Photos/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Photos.ViewModels; + +public abstract class ViewModelBase : ObservableObject +{ +} \ No newline at end of file diff --git a/Photos/Views/MainWindow.axaml b/Photos/Views/MainWindow.axaml new file mode 100644 index 0000000..88dd08f --- /dev/null +++ b/Photos/Views/MainWindow.axaml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Photos/Views/MainWindow.axaml.cs b/Photos/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..a209342 --- /dev/null +++ b/Photos/Views/MainWindow.axaml.cs @@ -0,0 +1,20 @@ +using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Xaml.Interactions.DragAndDrop; +using Photos.ViewModels; + +namespace Photos.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + DataContext = new MainWindowViewModel(); + } + + public void DropHandler(object sender, DragEventArgs e) + { + (DataContext as MainWindowViewModel)?.WindowDropHandler(e); + } +} \ No newline at end of file diff --git a/Photos/app.manifest b/Photos/app.manifest new file mode 100644 index 0000000..9d86038 --- /dev/null +++ b/Photos/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +