Skip to content

Commit 97475d1

Browse files
committed
extracted IWebNavigator interface
1 parent b3a9dc5 commit 97475d1

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

Rubberduck.Core/UI/About/AboutControlViewModel.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ namespace Rubberduck.UI.About
1313
public class AboutControlViewModel
1414
{
1515
private readonly IVersionCheck _version;
16+
private readonly IWebNavigator _web;
1617

17-
public AboutControlViewModel(IVersionCheck version)
18+
public AboutControlViewModel(IVersionCheck version, IWebNavigator web)
1819
{
1920
_version = version;
21+
_web = web;
2022

2123
UriCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteUri);
2224
ViewLogCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteViewLog);
@@ -42,10 +44,7 @@ public AboutControlViewModel(IVersionCheck version)
4244

4345
public CommandBase ViewLogCommand { get; }
4446

45-
private void ExecuteUri(object parameter)
46-
{
47-
Process.Start(new ProcessStartInfo(((Uri)parameter).AbsoluteUri));
48-
}
47+
private void ExecuteUri(object parameter) => _web.Navigate(((Uri)parameter));
4948

5049
private void ExecuteViewLog(object parameter)
5150
{

Rubberduck.Core/UI/About/AboutDialog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace Rubberduck.UI.About
55
{
66
public partial class AboutDialog : Form
77
{
8-
public AboutDialog(IVersionCheck versionCheck) : this()
8+
public AboutDialog(IVersionCheck versionCheck, IWebNavigator web) : this()
99
{
10-
ViewModel = new AboutControlViewModel(versionCheck);
10+
ViewModel = new AboutControlViewModel(versionCheck, web);
1111
}
1212

1313
public AboutDialog()

Rubberduck.Core/UI/Command/AboutCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ namespace Rubberduck.UI.Command
1010
[ComVisible(false)]
1111
public class AboutCommand : CommandBase
1212
{
13-
public AboutCommand(IVersionCheck versionService)
13+
public AboutCommand(IVersionCheck versionService, IWebNavigator web)
1414
{
1515
_versionService = versionService;
16+
_web = web;
1617
}
1718

1819
private readonly IVersionCheck _versionService;
20+
private readonly IWebNavigator _web;
1921

2022
protected override void OnExecute(object parameter)
2123
{
22-
using (var window = new AboutDialog(_versionService))
24+
using (var window = new AboutDialog(_versionService, _web))
2325
{
2426
window.ShowDialog();
2527
}

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public QuickFixCommandViewModel(
8989

9090
public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelection, IComparer<IInspectionResult>, IComparer, IDisposable
9191
{
92+
private readonly IWebNavigator _web;
9293
private readonly RubberduckParserState _state;
9394
private readonly IInspector _inspector;
9495
private readonly IQuickFixProvider _quickFixProvider;
@@ -106,10 +107,12 @@ public InspectionResultsViewModel(
106107
INavigateCommand navigateCommand,
107108
ReparseCommand reparseCommand,
108109
IClipboardWriter clipboard,
110+
IWebNavigator web,
109111
IConfigurationService<Configuration> configService,
110112
ISettingsFormFactory settingsFormFactory,
111113
IUiDispatcher uiDispatcher)
112114
{
115+
_web = web;
113116
_state = state;
114117
_inspector = inspector;
115118
_quickFixProvider = quickFixProvider;
@@ -771,11 +774,13 @@ public bool CanDisableInspection
771774
}
772775
}
773776

774-
public string InspectionDetailsUrl => _selectedInspection == null
775-
? "https://rubberduckvba.com/inspections"
776-
: $"https://rubberduckvba.com/inspections/details/{_selectedInspection.AnnotationName}";
777+
private static readonly Uri _inspectionsHomeUrl = new Uri("https://rubberduckvba.com/inspections");
777778

778-
private void ExecuteOpenInspectionDetailsPageCommand(object parameter) => Process.Start(new ProcessStartInfo(InspectionDetailsUrl));
779+
public Uri InspectionDetailsUrl => _selectedInspection == null
780+
? _inspectionsHomeUrl
781+
: new Uri($"https://rubberduckvba.com/inspections/details/{_selectedInspection.AnnotationName}");
782+
783+
private void ExecuteOpenInspectionDetailsPageCommand(object parameter) => _web.Navigate(InspectionDetailsUrl);
779784

780785
private static readonly List<(string Name, hAlignment alignment)> ResultColumns = new List<(string Name, hAlignment alignment)>
781786
{

Rubberduck.Core/UI/WebNavigator.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace Rubberduck.UI
5+
{
6+
public interface IWebNavigator
7+
{
8+
/// <summary>
9+
/// Opens the specified URI in the default browser.
10+
/// </summary>
11+
void Navigate(Uri uri);
12+
}
13+
14+
public class WebNavigator : IWebNavigator
15+
{
16+
public void Navigate(Uri uri)
17+
{
18+
Process.Start(new ProcessStartInfo(uri.AbsoluteUri));
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)