diff options
author | sr55 <[email protected]> | 2020-09-05 21:46:30 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2020-09-05 21:46:30 +0100 |
commit | 50535c33e0a4734a1f15b26e87db101854e2b96f (patch) | |
tree | 62df19eb608c89e83457404e9944d84d696ed6d4 /win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs | |
parent | 1cdd6e4e7c824eac273e2bf5f752a6d02bff966e (diff) |
WinGui: Various fixes to the log window when using muilti-instance.
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index acdb33816..2ce7c6c5e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -14,7 +14,6 @@ namespace HandBrakeWPF.ViewModels using System.Diagnostics;
using System.Linq;
using System.Text;
- using System.Windows.Forms;
using Caliburn.Micro;
@@ -27,9 +26,8 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.ViewModels.Interfaces;
using Clipboard = System.Windows.Clipboard;
- using ILog = HandBrakeWPF.Services.Logging.Interfaces.ILog;
- using LogEventArgs = HandBrakeWPF.Services.Logging.EventArgs.LogEventArgs;
- using LogService = HandBrakeWPF.Services.Logging.LogService;
+ using ILog = Services.Logging.Interfaces.ILog;
+ using LogEventArgs = Services.Logging.EventArgs.LogEventArgs;
public class LogViewModel : ViewModelBase, ILogViewModel
{
@@ -48,7 +46,6 @@ namespace HandBrakeWPF.ViewModels this.errorService = errorService;
this.logInstanceManager = logInstanceManager;
this.Title = Resources.LogViewModel_Title;
- this.selectedLogFile = logInstanceManager.ApplicationAndScanLog;
}
public event EventHandler<LogEventArgs> LogMessageReceived;
@@ -74,7 +71,11 @@ namespace HandBrakeWPF.ViewModels get => this.selectedLogFile;
set
{
- if (value == this.selectedLogFile) return;
+ if (value == this.selectedLogFile)
+ {
+ return;
+ }
+
this.selectedLogFile = value;
this.NotifyOfPropertyChange(() => this.SelectedLogFile);
@@ -106,59 +107,36 @@ namespace HandBrakeWPF.ViewModels {
this.logInstanceManager.NewLogInstanceRegistered += this.LogInstanceManager_NewLogInstanceRegistered;
- if (string.IsNullOrEmpty(this.SelectedLogFile))
- {
- base.OnActivate();
- return;
- }
-
- if (this.logService == null)
- {
- this.logService = this.logInstanceManager.GetLogInstance(this.SelectedLogFile);
- }
-
this.NotifyOfPropertyChange(() => this.LogFiles);
- this.logService.MessageLogged += this.LogService_MessageLogged;
- this.logService.LogReset += LogService_LogReset;
-
- // Refresh the Log Display
- this.log.Clear();
- foreach (LogMessage logMessage in this.logService.GetLogMessages())
+ if (string.IsNullOrEmpty(this.SelectedLogFile) || !this.LogFiles.Contains(this.SelectedLogFile))
{
- this.log.AppendLine(logMessage.Content);
- this.lastReadIndex = logMessage.MessageIndex;
-
- if (this.lastReadIndex > logMessage.MessageIndex)
- {
- throw new Exception("Log Message Index Error");
- }
- }
-
- this.OnLogMessageReceived(null);
- this.NotifyOfPropertyChange(() => this.ActivityLog);
+ this.SelectedLogFile = this.LogFiles.LastOrDefault();
+ }
base.OnActivate();
}
- protected virtual void OnLogMessageReceived(LogEventArgs e)
+ protected override void OnDeactivate(bool close)
{
- var onLogMessageReceived = this.LogMessageReceived;
- if (onLogMessageReceived != null)
+ if (this.logService != null)
{
- onLogMessageReceived.Invoke(this, e);
+ this.logService.MessageLogged -= this.LogService_MessageLogged;
+ this.logService.LogReset -= this.LogService_LogReset;
}
- }
- protected override void OnDeactivate(bool close)
- {
- this.logService.MessageLogged -= this.LogService_MessageLogged;
- this.logService.LogReset -= this.LogService_LogReset;
+ this.SelectedLogFile = null;
this.logInstanceManager.NewLogInstanceRegistered -= this.LogInstanceManager_NewLogInstanceRegistered;
base.OnDeactivate(close);
}
+ protected virtual void OnLogMessageReceived(LogEventArgs e)
+ {
+ var onLogMessageReceived = this.LogMessageReceived;
+ onLogMessageReceived?.Invoke(this, e);
+ }
+
private void ChangeLogFileView()
{
if (this.logService != null)
@@ -167,11 +145,33 @@ namespace HandBrakeWPF.ViewModels this.logService.LogReset -= this.LogService_LogReset;
}
+ if (this.SelectedLogFile == null)
+ {
+ return;
+ }
+
this.logService = this.logInstanceManager.GetLogInstance(this.SelectedLogFile);
if (this.logService != null)
{
- OnActivate();
+ this.logService.MessageLogged += this.LogService_MessageLogged;
+ this.logService.LogReset += LogService_LogReset;
+
+ // Refresh the Log Display
+ this.log.Clear();
+ foreach (LogMessage logMessage in this.logService.GetLogMessages())
+ {
+ this.log.AppendLine(logMessage.Content);
+ this.lastReadIndex = logMessage.MessageIndex;
+
+ if (this.lastReadIndex > logMessage.MessageIndex)
+ {
+ throw new Exception("Log Message Index Error");
+ }
+ }
+
+ this.OnLogMessageReceived(null);
+ this.NotifyOfPropertyChange(() => this.ActivityLog);
}
}
|