summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrakeWPF/Constants.cs3
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs22
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/ViewModelBase.cs59
3 files changed, 65 insertions, 19 deletions
diff --git a/win/CS/HandBrakeWPF/Constants.cs b/win/CS/HandBrakeWPF/Constants.cs
index 37d0f923b..cf322e85c 100644
--- a/win/CS/HandBrakeWPF/Constants.cs
+++ b/win/CS/HandBrakeWPF/Constants.cs
@@ -83,5 +83,8 @@ namespace HandBrakeWPF
/// Preset Micro Version
/// </summary>
public const string PresetVersionMicro = "0";
+
+ public const string FileScanMru = "FileScanMru";
+ public const string FileSaveMru = "FileSaveMru";
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
index a081d28d5..4af305d47 100644
--- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
@@ -169,6 +169,7 @@ namespace HandBrakeWPF.ViewModels
IFiltersViewModel filtersViewModel, IAudioViewModel audioViewModel, ISubtitlesViewModel subtitlesViewModel,
IX264ViewModel advancedViewModel, IChaptersViewModel chaptersViewModel, IStaticPreviewViewModel staticPreviewViewModel,
IQueueViewModel queueViewModel, IMetaDataViewModel metaDataViewModel, INotifyIconService notifyIconService)
+ : base(userSettingService)
{
this.scanService = scanService;
this.presetService = presetService;
@@ -1656,10 +1657,19 @@ namespace HandBrakeWPF.ViewModels
public void FileScan()
{
OpenFileDialog dialog = new OpenFileDialog { Filter = "All files (*.*)|*.*" };
+
+ string mruDir = this.GetMru(Constants.FileScanMru);
+ if (!string.IsNullOrEmpty(mruDir))
+ {
+ dialog.InitialDirectory = mruDir;
+ }
+
bool? dialogResult = dialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
+ this.SetMru(Constants.FileScanMru, Path.GetDirectoryName(dialog.FileName));
+
this.StartScan(dialog.FileName, this.TitleSpecificScan);
}
}
@@ -1850,7 +1860,7 @@ namespace HandBrakeWPF.ViewModels
// StartScan is not synchronous, so for now we don't support adding both srt and video file at the same time.
string[] subtitleFiles = fileNames.Where(f => Path.GetExtension(f)?.ToLower() == ".srt").ToArray();
- if (this.SelectedTab != 5 && subtitleFiles.Any())
+ if (subtitleFiles.Any())
{
this.SwitchTab(5);
this.SubtitleViewModel.Import(subtitleFiles);
@@ -1888,6 +1898,13 @@ namespace HandBrakeWPF.ViewModels
? (extension == ".mp4" || extension == ".m4v" ? 1 : 2)
: (this.CurrentTask.OutputFormat == OutputFormat.Mkv ? 2 : 0);
+ string mruDir = this.GetMru(Constants.FileSaveMru);
+ if (!string.IsNullOrEmpty(mruDir))
+ {
+ saveFileDialog.InitialDirectory = mruDir;
+ }
+
+ // If we have a current directory, override the MRU.
if (this.CurrentTask != null && !string.IsNullOrEmpty(this.CurrentTask.Destination))
{
if (Directory.Exists(Path.GetDirectoryName(this.CurrentTask.Destination)))
@@ -1901,6 +1918,8 @@ namespace HandBrakeWPF.ViewModels
bool? result = saveFileDialog.ShowDialog();
if (result.HasValue && result.Value)
{
+ this.SetMru(Constants.FileSaveMru, Path.GetDirectoryName(saveFileDialog.FileName));
+
if (saveFileDialog.FileName == this.ScannedSource.ScanPath)
{
this.errorService.ShowMessageBox(Resources.Main_SourceDestinationMatchError, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
@@ -2769,7 +2788,6 @@ namespace HandBrakeWPF.ViewModels
this.NotifyOfPropertyChange(() => this.ShowAdvancedTab);
}
}
-
#endregion
}
} \ No newline at end of file
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