Skip to content

Commit 63597f3

Browse files
committed
Initialize commands in constructor
To keep all string properties together, I also moved AboutCopyright above the commands.
1 parent 055eaa7 commit 63597f3

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

Rubberduck.Core/UI/About/AboutControlViewModel.cs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class AboutControlViewModel
1717
public AboutControlViewModel(IVersionCheck version)
1818
{
1919
_version = version;
20+
21+
UriCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUri);
22+
ViewLogCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteViewLog);
2023
}
2124

2225
public string Version => string.Format(Resources.RubberduckUI.Rubberduck_AboutBuild, _version.CurrentVersion);
@@ -32,46 +35,28 @@ public AboutControlViewModel(IVersionCheck version)
3235
public string HostExecutable => string.Format(AboutUI.AboutWindow_HostExecutable,
3336
Path.GetFileName(Application.ExecutablePath).ToUpper()); // .ToUpper() used to convert ExceL.EXE -> EXCEL.EXE
3437

35-
private CommandBase _uriCommand;
36-
public CommandBase UriCommand
38+
public string AboutCopyright =>
39+
string.Format(AboutUI.AboutWindow_Copyright, DateTime.Now.Year);
40+
41+
public CommandBase UriCommand { get; }
42+
43+
public CommandBase ViewLogCommand { get; }
44+
45+
private void ExecuteUri(object parameter)
3746
{
38-
get
39-
{
40-
if (_uriCommand != null)
41-
{
42-
return _uriCommand;
43-
}
44-
return _uriCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), uri =>
45-
{
46-
Process.Start(new ProcessStartInfo(((Uri)uri).AbsoluteUri));
47-
});
48-
}
47+
Process.Start(new ProcessStartInfo(((Uri)parameter).AbsoluteUri));
4948
}
5049

51-
private CommandBase _viewLogCommand;
52-
public CommandBase ViewLogCommand
50+
private void ExecuteViewLog(object parameter)
5351
{
54-
get
55-
{
56-
if (_viewLogCommand != null)
57-
{
58-
return _viewLogCommand;
59-
}
60-
return _viewLogCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ =>
61-
{
62-
var fileTarget = (FileTarget) LogManager.Configuration.FindTargetByName("file");
52+
var fileTarget = (FileTarget) LogManager.Configuration.FindTargetByName("file");
6353

64-
var logEventInfo = new LogEventInfo { TimeStamp = DateTime.Now };
65-
var fileName = fileTarget.FileName.Render(logEventInfo);
54+
var logEventInfo = new LogEventInfo { TimeStamp = DateTime.Now };
55+
var fileName = fileTarget.FileName.Render(logEventInfo);
6656

67-
// The /select argument will only work if the path has backslashes
68-
fileName = fileName.Replace("/", "\\");
69-
Process.Start(new ProcessStartInfo("explorer.exe", $"/select, \"{fileName}\""));
70-
});
71-
}
57+
// The /select argument will only work if the path has backslashes
58+
fileName = fileName.Replace("/", "\\");
59+
Process.Start(new ProcessStartInfo("explorer.exe", $"/select, \"{fileName}\""));
7260
}
73-
74-
public string AboutCopyright =>
75-
string.Format(AboutUI.AboutWindow_Copyright, DateTime.Now.Year);
7661
}
7762
}

0 commit comments

Comments
 (0)