diff --git a/FoliCon/Modules/utils/DialogUtils.cs b/FoliCon/Modules/utils/DialogUtils.cs index 4a48da2..2e21b2f 100644 --- a/FoliCon/Modules/utils/DialogUtils.cs +++ b/FoliCon/Modules/utils/DialogUtils.cs @@ -53,8 +53,11 @@ public static VistaFolderBrowserDialog NewFolderBrowserDialog(string description }; return folderBrowser; } - - public static VistaOpenFileDialog NewOpenFileDialog(string description, string filter= "All files (*.*)|*.*") + public static VistaOpenFileDialog NewOpenFileDialog(string description) + { + return NewOpenFileDialog(description, "All files (*.*)|*.*"); + } + public static VistaOpenFileDialog NewOpenFileDialog(string description, string filter) { Logger.Debug("Creating New Open File Dialog"); var openFileDialog = new VistaOpenFileDialog diff --git a/FoliCon/Modules/utils/UiUtils.cs b/FoliCon/Modules/utils/UiUtils.cs index a657894..a9ad215 100644 --- a/FoliCon/Modules/utils/UiUtils.cs +++ b/FoliCon/Modules/utils/UiUtils.cs @@ -19,4 +19,9 @@ public static void SetColumnWidth(ListView listView) column.Width = double.NaN; } } + + public static Visibility BooleanToVisibility(bool value) + { + return value ? Visibility.Visible : Visibility.Hidden; + } } \ No newline at end of file diff --git a/FoliCon/ViewModels/PreviewerViewModel.cs b/FoliCon/ViewModels/PreviewerViewModel.cs index de14744..8b1f9cc 100644 --- a/FoliCon/ViewModels/PreviewerViewModel.cs +++ b/FoliCon/ViewModels/PreviewerViewModel.cs @@ -1,18 +1,15 @@ -using Microsoft.Win32; -using Prism.Commands; -using Prism.Mvvm; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Media; -using FoliCon.Modules.utils; +using FoliCon.Modules.utils; +using NLog; namespace FoliCon.ViewModels { public class PreviewerViewModel : BindableBase, IDialogAware { + private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger(); + public PreviewerViewModel() { + Logger.Debug("PosterIconConfigViewModel created"); PosterIconInstance = new FoliCon.Models.Data.PosterIcon { Rating = Rating @@ -59,7 +56,7 @@ public bool RatingVisibility set { SetProperty(ref _ratingVisibility, value); - PosterIconInstance.RatingVisibility = BooleanToVisibility(value).ToString(); + PosterIconInstance.RatingVisibility = UiUtils.BooleanToVisibility(value).ToString(); } } @@ -69,46 +66,63 @@ public bool OverlayVisibility set { SetProperty(ref _overlayVisibility, value); - PosterIconInstance.MockupVisibility = BooleanToVisibility(value).ToString(); + PosterIconInstance.MockupVisibility = UiUtils.BooleanToVisibility(value).ToString(); } } - public event Action RequestClose; public DelegateCommand SelectImageCommand { get; set; } private void SelectImage() { - var fileDialog = DialogUtils.NewOpenFileDialog("Select Image", "Image files (*.png, *.jpg, *.gif, *.bmp, *.ico)|*.png;*.jpg;*.gif;*.bmp;*.ico"); + Logger.Debug("Opening image selection dialog"); + var fileDialog = DialogUtils.NewOpenFileDialog(LangProvider.GetLang("ChooseAnImage"), "Image files (*.png, *.jpg, *.gif, *.bmp, *.ico)|*.png;*.jpg;*.gif;*.bmp;*.ico"); var selected = fileDialog.ShowDialog(); - if (selected != null && (bool)!selected) return; + if (selected != null && (bool)!selected) + { + Logger.Warn("No image selected"); + return; + } + var thisMemoryStream = new MemoryStream(File.ReadAllBytes(fileDialog.FileName)); var rt= new FoliCon.Models.Data.PosterIcon { FolderJpg = (ImageSource)new ImageSourceConverter().ConvertFrom(thisMemoryStream) }; PosterIconInstance = rt; + Logger.Info("Image selected: {FileName}", fileDialog.FileName); } - - public bool CanCloseDialog() + + + #region DialogMethods + public event Action RequestClose; + protected virtual void CloseDialog(string parameter) { - return true; - } + Logger.Info("CloseDialog called with parameter {Parameter}", parameter); + var result = parameter?.ToLower(CultureInfo.InvariantCulture) switch + { + "true" => ButtonResult.OK, + "false" => ButtonResult.Cancel, + _ => ButtonResult.None + }; - public void OnDialogClosed() - { - + RaiseRequestClose(new DialogResult(result)); } - public void OnDialogOpened(IDialogParameters parameters) + public virtual void RaiseRequestClose(IDialogResult dialogResult) => + RequestClose?.Invoke(dialogResult); + + public virtual bool CanCloseDialog() => true; + + public virtual void OnDialogClosed() { - } - - public Visibility BooleanToVisibility(bool value) + + public virtual void OnDialogOpened(IDialogParameters parameters) { - return value ? Visibility.Visible : Visibility.Hidden; } + + #endregion DialogMethods } }