diff options
author | sr55 <[email protected]> | 2018-05-24 21:24:48 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-05-24 21:24:48 +0100 |
commit | fe78dde1e5ab55ae1596ca0b6903a441dec6c9b3 (patch) | |
tree | b2f7064f16df896f88d4bdfd7a8b0b09b748d0f2 /win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs | |
parent | 1b4d3a46f3643b73997973dca05f8558c0acafce (diff) |
WinGui: Open and Save File dialogs on the main window, now have their own "MRU" initial directory target. #1353
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs b/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs index d2f381e55..54da681dc 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs @@ -9,8 +9,12 @@ namespace HandBrakeWPF.ViewModels
{
+ using System;
+ using System.IO;
+
using Caliburn.Micro;
+ using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.ViewModels.Interfaces;
/// <summary>
@@ -18,30 +22,19 @@ namespace HandBrakeWPF.ViewModels /// </summary>
public class ViewModelBase : Screen, IViewModelBase
{
- #region Constants and Fields
+ private readonly IUserSettingService userSettingService;
- /// <summary>
- /// Backing Field to prevent the Load method being called more than once.
- /// </summary>
private bool hasLoaded;
-
- /// <summary>
- /// The title.
- /// </summary>
private string title;
- #endregion
-
- #region Constructors and Destructors
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ViewModelBase"/> class.
- /// </summary>
public ViewModelBase()
{
}
- #endregion
+ public ViewModelBase(IUserSettingService userSettingService)
+ {
+ this.userSettingService = userSettingService;
+ }
#region Properties
@@ -58,7 +51,7 @@ namespace HandBrakeWPF.ViewModels set
{
this.title = value;
- this.NotifyOfPropertyChange("Title");
+ this.NotifyOfPropertyChange();
}
}
@@ -88,6 +81,38 @@ namespace HandBrakeWPF.ViewModels // Implement in the ViewModel to perform viewmodel specific code.
}
+ public string GetMru(string key)
+ {
+ if (this.userSettingService == null)
+ {
+ throw new NotImplementedException("You must use the constructor with UserSettingService to use this function.");
+ }
+
+ string filePath = this.userSettingService.GetUserSetting<string>("mru" + key);
+ if (!string.IsNullOrEmpty(filePath) && Directory.Exists(filePath))
+ {
+ return filePath;
+ }
+
+ return null;
+ }
+
+ public void SetMru(string key, string value)
+ {
+ if (this.userSettingService == null)
+ {
+ throw new NotImplementedException("You must use the constructor with UserSettingService to use this function.");
+ }
+
+ if (string.IsNullOrEmpty(value) || !Directory.Exists(value))
+ {
+ this.userSettingService.SetUserSetting("mru" + key, string.Empty);
+ return;
+ }
+
+ this.userSettingService.SetUserSetting("mru" + key, value);
+ }
+
#endregion
}
}
\ No newline at end of file |