Migration to MVVM
This commit is contained in:
parent
0c1bb50dce
commit
1db874ce77
6 changed files with 946 additions and 575 deletions
|
|
@ -4,6 +4,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing.Text;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -15,25 +16,55 @@ namespace ImageCatalog_2
|
|||
public class DataModel : ViewModelBase
|
||||
{
|
||||
public ICommand TestCommand { get; }
|
||||
|
||||
public ICommand AsyncTestCommand { get; }
|
||||
public ICommand AsyncCancelOperationCommand { get; }
|
||||
|
||||
public ICommand ProcessImagesCommand { get; }
|
||||
public ICommand SelectSourceFolderCommand { get; }
|
||||
public ICommand SelectDestinationFolderCommand { get; }
|
||||
public ICommand SelectLogoFileCommand { get; }
|
||||
public ICommand SaveSettingsCommand { get; }
|
||||
public ICommand LoadSettingsCommand { get; }
|
||||
public ICommand SelectColorCommand { get; }
|
||||
|
||||
private readonly ITestService _service;
|
||||
private readonly ILogger<DataModel> _logger;
|
||||
private readonly ISettingsService _settingsService;
|
||||
|
||||
public DataModel(ITestService testService, ILogger<DataModel> logger)
|
||||
// ComboBox collections
|
||||
public List<string> AvailableFonts { get; }
|
||||
public List<string> VerticalPositions { get; } = new() { "Alto", "Centro", "Basso" };
|
||||
public List<string> HorizontalAlignments { get; } = new() { "Sinistra", "Centro", "Destra" };
|
||||
|
||||
public DataModel(ITestService testService, ISettingsService settingsService, ILogger<DataModel> logger)
|
||||
{
|
||||
_service = testService;
|
||||
_logger = logger;
|
||||
_settingsService = settingsService;
|
||||
|
||||
TestCommand = new RelayCommand(Test);
|
||||
AsyncTestCommand = new AsyncCommand(TestAsync);
|
||||
AsyncCancelOperationCommand = new AsyncCommand(CancelOperation);
|
||||
|
||||
ProcessImagesCommand = new AsyncCommand(ProcessImages);
|
||||
|
||||
SelectSourceFolderCommand = new RelayCommand(SelectSourceFolder);
|
||||
SelectDestinationFolderCommand = new RelayCommand(SelectDestinationFolder);
|
||||
SelectLogoFileCommand = new RelayCommand(SelectLogoFile);
|
||||
SaveSettingsCommand = new RelayCommand(SaveSettings);
|
||||
LoadSettingsCommand = new RelayCommand(LoadSettings);
|
||||
SelectColorCommand = new RelayCommand(SelectColor);
|
||||
|
||||
// Load available fonts
|
||||
AvailableFonts = LoadAvailableFonts();
|
||||
}
|
||||
|
||||
private List<string> LoadAvailableFonts()
|
||||
{
|
||||
var fonts = new List<string>();
|
||||
using (var installedFonts = new InstalledFontCollection())
|
||||
{
|
||||
fonts.AddRange(installedFonts.Families.Select(f => f.Name));
|
||||
}
|
||||
return fonts;
|
||||
}
|
||||
|
||||
private CancellationTokenSource? _mainToken;
|
||||
|
|
@ -158,6 +189,546 @@ namespace ImageCatalog_2
|
|||
}
|
||||
}
|
||||
|
||||
// Thumbnail settings
|
||||
private string _thumbnailPrefix = "tn_";
|
||||
public string ThumbnailPrefix
|
||||
{
|
||||
get => _thumbnailPrefix;
|
||||
set
|
||||
{
|
||||
_thumbnailPrefix = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _thumbnailHeight = 350;
|
||||
public int ThumbnailHeight
|
||||
{
|
||||
get => _thumbnailHeight;
|
||||
set
|
||||
{
|
||||
_thumbnailHeight = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _thumbnailWidth = 350;
|
||||
public int ThumbnailWidth
|
||||
{
|
||||
get => _thumbnailWidth;
|
||||
set
|
||||
{
|
||||
_thumbnailWidth = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Big photo settings
|
||||
private int _photoBigHeight = 2240;
|
||||
public int PhotoBigHeight
|
||||
{
|
||||
get => _photoBigHeight;
|
||||
set
|
||||
{
|
||||
_photoBigHeight = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _photoBigWidth = 2240;
|
||||
public int PhotoBigWidth
|
||||
{
|
||||
get => _photoBigWidth;
|
||||
set
|
||||
{
|
||||
_photoBigWidth = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Font settings
|
||||
private int _fontSize = 20;
|
||||
public int FontSize
|
||||
{
|
||||
get => _fontSize;
|
||||
set
|
||||
{
|
||||
_fontSize = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _fontSizeThumbnail = 50;
|
||||
public int FontSizeThumbnail
|
||||
{
|
||||
get => _fontSizeThumbnail;
|
||||
set
|
||||
{
|
||||
_fontSizeThumbnail = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _fontName = "Arial";
|
||||
public string FontName
|
||||
{
|
||||
get => _fontName;
|
||||
set
|
||||
{
|
||||
_fontName = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _fontBold = false;
|
||||
public bool FontBold
|
||||
{
|
||||
get => _fontBold;
|
||||
set
|
||||
{
|
||||
_fontBold = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Text settings
|
||||
private int _textTransparency = 0;
|
||||
public int TextTransparency
|
||||
{
|
||||
get => _textTransparency;
|
||||
set
|
||||
{
|
||||
_textTransparency = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _textMargin = 8;
|
||||
public int TextMargin
|
||||
{
|
||||
get => _textMargin;
|
||||
set
|
||||
{
|
||||
_textMargin = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _textColorRGB = "Yellow";
|
||||
public string TextColorRGB
|
||||
{
|
||||
get => _textColorRGB;
|
||||
set
|
||||
{
|
||||
_textColorRGB = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Logo/Watermark settings
|
||||
private string _logoFile = "";
|
||||
public string LogoFile
|
||||
{
|
||||
get => _logoFile;
|
||||
set
|
||||
{
|
||||
_logoFile = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _logoHeight = 430;
|
||||
public int LogoHeight
|
||||
{
|
||||
get => _logoHeight;
|
||||
set
|
||||
{
|
||||
_logoHeight = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _logoWidth = 430;
|
||||
public int LogoWidth
|
||||
{
|
||||
get => _logoWidth;
|
||||
set
|
||||
{
|
||||
_logoWidth = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _logoMargin = 290;
|
||||
public int LogoMargin
|
||||
{
|
||||
get => _logoMargin;
|
||||
set
|
||||
{
|
||||
_logoMargin = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _logoTransparency = 100;
|
||||
public int LogoTransparency
|
||||
{
|
||||
get => _logoTransparency;
|
||||
set
|
||||
{
|
||||
_logoTransparency = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Folder division settings
|
||||
private int _filesPerFolder = 99;
|
||||
public int FilesPerFolder
|
||||
{
|
||||
get => _filesPerFolder;
|
||||
set
|
||||
{
|
||||
_filesPerFolder = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _folderSuffix = "";
|
||||
public string FolderSuffix
|
||||
{
|
||||
get => _folderSuffix;
|
||||
set
|
||||
{
|
||||
_folderSuffix = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _counterDigits = 2;
|
||||
public int CounterDigits
|
||||
{
|
||||
get => _counterDigits;
|
||||
set
|
||||
{
|
||||
_counterDigits = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical text settings
|
||||
private int _verticalTextSize = 20;
|
||||
public int VerticalTextSize
|
||||
{
|
||||
get => _verticalTextSize;
|
||||
set
|
||||
{
|
||||
_verticalTextSize = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _verticalTextMargin = 6;
|
||||
public int VerticalTextMargin
|
||||
{
|
||||
get => _verticalTextMargin;
|
||||
set
|
||||
{
|
||||
_verticalTextMargin = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// JPEG compression settings
|
||||
private int _jpegQuality = 85;
|
||||
public int JpegQuality
|
||||
{
|
||||
get => _jpegQuality;
|
||||
set
|
||||
{
|
||||
_jpegQuality = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private int _jpegQualityThumbnail = 30;
|
||||
public int JpegQualityThumbnail
|
||||
{
|
||||
get => _jpegQualityThumbnail;
|
||||
set
|
||||
{
|
||||
_jpegQualityThumbnail = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// CheckBox settings
|
||||
private bool _createThumbnails = true;
|
||||
public bool CreateThumbnails
|
||||
{
|
||||
get => _createThumbnails;
|
||||
set
|
||||
{
|
||||
_createThumbnails = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _automaticRotation;
|
||||
public bool AutomaticRotation
|
||||
{
|
||||
get => _automaticRotation;
|
||||
set
|
||||
{
|
||||
_automaticRotation = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _forceJpeg;
|
||||
public bool ForceJpeg
|
||||
{
|
||||
get => _forceJpeg;
|
||||
set
|
||||
{
|
||||
_forceJpeg = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _updateSubdirectories;
|
||||
public bool UpdateSubdirectories
|
||||
{
|
||||
get => _updateSubdirectories;
|
||||
set
|
||||
{
|
||||
_updateSubdirectories = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _createSubfolders;
|
||||
public bool CreateSubfolders
|
||||
{
|
||||
get => _createSubfolders;
|
||||
set
|
||||
{
|
||||
_createSubfolders = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _addTime;
|
||||
public bool AddTime
|
||||
{
|
||||
get => _addTime;
|
||||
set
|
||||
{
|
||||
_addTime = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _addRaceTime;
|
||||
public bool AddRaceTime
|
||||
{
|
||||
get => _addRaceTime;
|
||||
set
|
||||
{
|
||||
_addRaceTime = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _addLogo;
|
||||
public bool AddLogo
|
||||
{
|
||||
get => _addLogo;
|
||||
set
|
||||
{
|
||||
_addLogo = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _keepOriginalDimensions;
|
||||
public bool KeepOriginalDimensions
|
||||
{
|
||||
get => _keepOriginalDimensions;
|
||||
set
|
||||
{
|
||||
_keepOriginalDimensions = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showDate;
|
||||
public bool ShowDate
|
||||
{
|
||||
get => _showDate;
|
||||
set
|
||||
{
|
||||
_showDate = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showPhotoNumber;
|
||||
public bool ShowPhotoNumber
|
||||
{
|
||||
get => _showPhotoNumber;
|
||||
set
|
||||
{
|
||||
_showPhotoNumber = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _shutdownSystem;
|
||||
public bool ShutdownSystem
|
||||
{
|
||||
get => _shutdownSystem;
|
||||
set
|
||||
{
|
||||
_shutdownSystem = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// ComboBox position/alignment settings
|
||||
private string _verticalPosition = "Basso";
|
||||
public string VerticalPosition
|
||||
{
|
||||
get => _verticalPosition;
|
||||
set
|
||||
{
|
||||
_verticalPosition = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _horizontalAlignment = "Centro";
|
||||
public string HorizontalAlignment
|
||||
{
|
||||
get => _horizontalAlignment;
|
||||
set
|
||||
{
|
||||
_horizontalAlignment = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _logoHorizontalPosition = "Destra";
|
||||
public string LogoHorizontalPosition
|
||||
{
|
||||
get => _logoHorizontalPosition;
|
||||
set
|
||||
{
|
||||
_logoHorizontalPosition = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _logoVerticalPosition = "Basso";
|
||||
public string LogoVerticalPosition
|
||||
{
|
||||
get => _logoVerticalPosition;
|
||||
set
|
||||
{
|
||||
_logoVerticalPosition = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// RadioButton settings
|
||||
private bool _useProgressiveNumbering = true;
|
||||
public bool UseProgressiveNumbering
|
||||
{
|
||||
get => _useProgressiveNumbering;
|
||||
set
|
||||
{
|
||||
_useProgressiveNumbering = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _useFileNumbering;
|
||||
public bool UseFileNumbering
|
||||
{
|
||||
get => _useFileNumbering;
|
||||
set
|
||||
{
|
||||
_useFileNumbering = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _useParallelProcessing = true;
|
||||
public bool UseParallelProcessing
|
||||
{
|
||||
get => _useParallelProcessing;
|
||||
set
|
||||
{
|
||||
_useParallelProcessing = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _useSequentialProcessing;
|
||||
public bool UseSequentialProcessing
|
||||
{
|
||||
get => _useSequentialProcessing;
|
||||
set
|
||||
{
|
||||
_useSequentialProcessing = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
// Additional settings that were missing
|
||||
private bool _addTimeToThumbnails;
|
||||
public bool AddTimeToThumbnails
|
||||
{
|
||||
get => _addTimeToThumbnails;
|
||||
set
|
||||
{
|
||||
_addTimeToThumbnails = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showFileNameOnThumbnails;
|
||||
public bool ShowFileNameOnThumbnails
|
||||
{
|
||||
get => _showFileNameOnThumbnails;
|
||||
set
|
||||
{
|
||||
_showFileNameOnThumbnails = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime _raceStartDate = DateTime.Now;
|
||||
public DateTime RaceStartDate
|
||||
{
|
||||
get => _raceStartDate;
|
||||
set
|
||||
{
|
||||
_raceStartDate = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string _timeLabel = "";
|
||||
public string TimeLabel
|
||||
{
|
||||
get => _timeLabel;
|
||||
set
|
||||
{
|
||||
_timeLabel = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void Test(object parameter)
|
||||
{
|
||||
Debug.WriteLine("Yep");
|
||||
|
|
@ -187,5 +758,54 @@ namespace ImageCatalog_2
|
|||
_logger.LogInformation("Ignora questo errore");
|
||||
}
|
||||
}
|
||||
|
||||
// Note: These commands will trigger events that the View will handle to show dialogs
|
||||
// since dialogs require UI context
|
||||
public event EventHandler SelectSourceFolderRequested;
|
||||
public event EventHandler SelectDestinationFolderRequested;
|
||||
public event EventHandler SelectLogoFileRequested;
|
||||
public event EventHandler<string> SaveSettingsRequested;
|
||||
public event EventHandler<string> LoadSettingsRequested;
|
||||
public event EventHandler SelectColorRequested;
|
||||
|
||||
private void SelectSourceFolder(object parameter)
|
||||
{
|
||||
SelectSourceFolderRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void SelectDestinationFolder(object parameter)
|
||||
{
|
||||
SelectDestinationFolderRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void SelectLogoFile(object parameter)
|
||||
{
|
||||
SelectLogoFileRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void SaveSettings(object parameter)
|
||||
{
|
||||
SaveSettingsRequested?.Invoke(this, null);
|
||||
}
|
||||
|
||||
private void LoadSettings(object parameter)
|
||||
{
|
||||
LoadSettingsRequested?.Invoke(this, null);
|
||||
}
|
||||
|
||||
private void SelectColor(object parameter)
|
||||
{
|
||||
SelectColorRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public async Task SaveSettingsToFileAsync(string filePath)
|
||||
{
|
||||
await _settingsService.SaveSettingsAsync(filePath, this);
|
||||
}
|
||||
|
||||
public async Task LoadSettingsFromFileAsync(string filePath)
|
||||
{
|
||||
await _settingsService.LoadSettingsAsync(filePath, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue