Skip to content

Commit

Permalink
Merge pull request #5548 from retailcoder/weblink
Browse files Browse the repository at this point in the history
Introduces a link to the website's inspection details page for the selected inspection result, at the bottom of the bottom panel in the inspection results toolwindow.
  • Loading branch information
retailcoder committed Jul 28, 2020
2 parents 60055fc + 97475d1 commit 79cea90
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
9 changes: 4 additions & 5 deletions Rubberduck.Core/UI/About/AboutControlViewModel.cs
Expand Up @@ -13,10 +13,12 @@ namespace Rubberduck.UI.About
public class AboutControlViewModel
{
private readonly IVersionCheck _version;
private readonly IWebNavigator _web;

public AboutControlViewModel(IVersionCheck version)
public AboutControlViewModel(IVersionCheck version, IWebNavigator web)
{
_version = version;
_web = web;

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

public CommandBase ViewLogCommand { get; }

private void ExecuteUri(object parameter)
{
Process.Start(new ProcessStartInfo(((Uri)parameter).AbsoluteUri));
}
private void ExecuteUri(object parameter) => _web.Navigate(((Uri)parameter));

private void ExecuteViewLog(object parameter)
{
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Core/UI/About/AboutDialog.cs
Expand Up @@ -5,9 +5,9 @@ namespace Rubberduck.UI.About
{
public partial class AboutDialog : Form
{
public AboutDialog(IVersionCheck versionCheck) : this()
public AboutDialog(IVersionCheck versionCheck, IWebNavigator web) : this()
{
ViewModel = new AboutControlViewModel(versionCheck);
ViewModel = new AboutControlViewModel(versionCheck, web);
}

public AboutDialog()
Expand Down
6 changes: 4 additions & 2 deletions Rubberduck.Core/UI/Command/AboutCommand.cs
Expand Up @@ -10,16 +10,18 @@ namespace Rubberduck.UI.Command
[ComVisible(false)]
public class AboutCommand : CommandBase
{
public AboutCommand(IVersionCheck versionService)
public AboutCommand(IVersionCheck versionService, IWebNavigator web)
{
_versionService = versionService;
_web = web;
}

private readonly IVersionCheck _versionService;
private readonly IWebNavigator _web;

protected override void OnExecute(object parameter)
{
using (var window = new AboutDialog(_versionService))
using (var window = new AboutDialog(_versionService, _web))
{
window.ShowDialog();
}
Expand Down
5 changes: 5 additions & 0 deletions Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml
Expand Up @@ -278,6 +278,11 @@
Visibility="{Binding CanDisableInspection, Converter={StaticResource BoolToVisibility}}"
Command="{Binding DisableInspectionCommand}"
Content="{Resx ResxName=Rubberduck.Resources.Inspections.InspectionsUI, Key=DisableThisInspection}" />

<controls:LinkButton Margin="4"
Command="{Binding OpenInspectionDetailsPageCommand}"
Content="{Binding InspectionDetailsUrl}" />

</StackPanel>
</ScrollViewer>
</Border>
Expand Down
19 changes: 17 additions & 2 deletions Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs
Expand Up @@ -89,6 +89,7 @@ public class QuickFixCommandViewModel : ViewModelBase

public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelection, IComparer<IInspectionResult>, IComparer, IDisposable
{
private readonly IWebNavigator _web;
private readonly RubberduckParserState _state;
private readonly IInspector _inspector;
private readonly IQuickFixProvider _quickFixProvider;
Expand All @@ -106,10 +107,12 @@ public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelecti
INavigateCommand navigateCommand,
ReparseCommand reparseCommand,
IClipboardWriter clipboard,
IWebNavigator web,
IConfigurationService<Configuration> configService,
ISettingsFormFactory settingsFormFactory,
IUiDispatcher uiDispatcher)
{
_web = web;
_state = state;
_inspector = inspector;
_quickFixProvider = quickFixProvider;
Expand Down Expand Up @@ -144,6 +147,8 @@ public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelecti
OpenInspectionSettings = new DelegateCommand(LogManager.GetCurrentClassLogger(), OpenSettings);
CollapseAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseAll);
ExpandAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandAll);

OpenInspectionDetailsPageCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteOpenInspectionDetailsPageCommand);

QuickFixCommands = new List<(ICommand command, string key, Func<IQuickFix, bool> visibility)>
{
Expand Down Expand Up @@ -195,6 +200,8 @@ public INavigateSource SelectedItem
get => _selectedItem;
set
{
SelectedInspection = null;
CanQuickFix = false;
if (value == _selectedItem)
{
return;
Expand All @@ -203,8 +210,6 @@ public INavigateSource SelectedItem
_selectedItem = value;
OnPropertyChanged();
OnPropertyChanged(nameof(QuickFixes));
SelectedInspection = null;
CanQuickFix = false;

if (_selectedItem is IInspectionResult inspectionResult)
{
Expand All @@ -225,6 +230,7 @@ public IInspection SelectedInspection
{
_selectedInspection = value;
OnPropertyChanged();
OnPropertyChanged(nameof(InspectionDetailsUrl));
}
}

Expand Down Expand Up @@ -354,6 +360,7 @@ private bool InspectionFilter(IInspectionResult result)
public CommandBase OpenInspectionSettings { get; }
public CommandBase CollapseAllCommand { get; }
public CommandBase ExpandAllCommand { get; }
public CommandBase OpenInspectionDetailsPageCommand { get; }

private void ExecuteCollapseAll(object parameter)
{
Expand Down Expand Up @@ -767,6 +774,14 @@ public bool CanDisableInspection
}
}

private static readonly Uri _inspectionsHomeUrl = new Uri("https://rubberduckvba.com/inspections");

public Uri InspectionDetailsUrl => _selectedInspection == null
? _inspectionsHomeUrl
: new Uri($"https://rubberduckvba.com/inspections/details/{_selectedInspection.AnnotationName}");

private void ExecuteOpenInspectionDetailsPageCommand(object parameter) => _web.Navigate(InspectionDetailsUrl);

private static readonly List<(string Name, hAlignment alignment)> ResultColumns = new List<(string Name, hAlignment alignment)>
{
(Resources.Inspections.InspectionsUI.ExportColumnHeader_Type, hAlignment.Left),
Expand Down
21 changes: 21 additions & 0 deletions Rubberduck.Core/UI/WebNavigator.cs
@@ -0,0 +1,21 @@
using System;
using System.Diagnostics;

namespace Rubberduck.UI
{
public interface IWebNavigator
{
/// <summary>
/// Opens the specified URI in the default browser.
/// </summary>
void Navigate(Uri uri);
}

public class WebNavigator : IWebNavigator
{
public void Navigate(Uri uri)
{
Process.Start(new ProcessStartInfo(uri.AbsoluteUri));
}
}
}

0 comments on commit 79cea90

Please sign in to comment.