Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HelpViewModel #121

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/RepoM.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:converters="clr-namespace:RepoM.App.Converters"
xmlns:controls="clr-namespace:RepoM.App.Controls"
xmlns:app="clr-namespace:RepoM.App"
xmlns:viewModels="clr-namespace:RepoM.App.ViewModels"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="12"
Expand All @@ -22,7 +23,8 @@
fw:AcrylicWindow.TintColor="#101010"
fw:AcrylicWindow.FallbackColor="#303030"
fw:AcrylicWindow.TintOpacity="0.7"
fw:AcrylicWindow.Enabled="True">
fw:AcrylicWindow.Enabled="True"
d:DataContext="{d:DesignInstance viewModels:MainWindowViewModel}">
<Window.Resources>
<converters:UtcToHumanizedLocalDateTimeConverter x:Key="UtcToHumanizedLocalDateTimeConverter" />
</Window.Resources>
Expand Down Expand Up @@ -385,14 +387,14 @@
</DockPanel>
</Grid>
<ScrollViewer>
<StackPanel>
<TextBlock Name="txtHelpCaption"
TextWrapping="Wrap"
TextElement.FontWeight="Bold"
TextElement.FontSize="12" />
<TextBlock Name="txtHelp"
TextWrapping="Wrap"
TextElement.FontSize="12" />
<StackPanel DataContext="{Binding Help}">
<TextBlock TextWrapping="Wrap"
TextElement.FontWeight="Bold"
TextElement.FontSize="12"
Text="{Binding Header}"/>
<TextBlock TextWrapping="Wrap"
TextElement.FontSize="12"
Text="{Binding Description}" />
<Button Command="{x:Static materialDesign:Transitioner.MovePreviousCommand}"
Content="{DynamicResource GotIt}"></Button>
</StackPanel>
Expand Down
26 changes: 7 additions & 19 deletions src/RepoM.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ public MainWindow(
var filterViewModel = new FiltersViewModel(_repositoryFilteringManager, threadDispatcher);
var pluginsViewModel = new PluginCollectionViewModel(moduleManager);

DataContext = new MainWindowViewModel(appSettingsService, orderingsViewModel, queryParsersViewModel, filterViewModel, pluginsViewModel);
DataContext = new MainWindowViewModel(
appSettingsService,
orderingsViewModel,
queryParsersViewModel,
filterViewModel,
pluginsViewModel,
new HelpViewModel(_translationService));
SettingsMenu.DataContext = DataContext; // this is out of the visual tree

_monitor = repositoryMonitor as DefaultRepositoryMonitor;
Expand All @@ -108,10 +114,6 @@ public MainWindow(
repositoryFilteringManager.SelectedQueryParserChanged += (_, _) => view.Refresh();
repositoryFilteringManager.SelectedFilterChanged += (_, _) => view.Refresh();

AssemblyName? appName = Assembly.GetEntryAssembly()?.GetName();
txtHelpCaption.Text = appName?.Name + " " + appName?.Version?.ToString(2);
txtHelp.Text = GetHelp();

PlaceFormByTaskBarLocation();
}

Expand Down Expand Up @@ -861,19 +863,5 @@ private void TxtFilter_Finish(object sender, EventArgs e)
item?.Focus();
}

private string GetHelp()
{
return _translationService.Translate(
"Help Detail",
StatusCharacterMap.IDENTICAL_SIGN,
StatusCharacterMap.STASH_SIGN,
StatusCharacterMap.IDENTICAL_SIGN,
StatusCharacterMap.ARROW_UP_SIGN,
StatusCharacterMap.ARROW_DOWN_SIGN,
StatusCharacterMap.NO_UPSTREAM_SIGN,
StatusCharacterMap.STASH_SIGN
);
}

public bool IsShown => Visibility == Visibility.Visible && IsActive;
}
41 changes: 41 additions & 0 deletions src/RepoM.App/ViewModels/HelpViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace RepoM.App.ViewModels;

using System;
using System.Reflection;
using JetBrains.Annotations;
using RepoM.Api.Common;
using RepoM.Api.Git;

public class HelpViewModel
{
public HelpViewModel(ITranslationService translationService)
{
ArgumentNullException.ThrowIfNull(translationService);
Header = GetHeader();
Description = GetHelp(translationService);
}

public string Header { [UsedImplicitly] get; }

public string Description { [UsedImplicitly] get; }

private static string GetHeader()
{
AssemblyName? appName = Assembly.GetEntryAssembly()?.GetName();
return appName?.Name + ' ' + appName?.Version?.ToString(2).Trim();
}

private static string GetHelp(ITranslationService translationService)
{
return translationService.Translate(
"Help Detail",
StatusCharacterMap.IDENTICAL_SIGN,
StatusCharacterMap.STASH_SIGN,
StatusCharacterMap.IDENTICAL_SIGN,
StatusCharacterMap.ARROW_UP_SIGN,
StatusCharacterMap.ARROW_DOWN_SIGN,
StatusCharacterMap.NO_UPSTREAM_SIGN,
StatusCharacterMap.STASH_SIGN
);
}
}
6 changes: 5 additions & 1 deletion src/RepoM.App/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public MainWindowViewModel(
OrderingsViewModel orderingsViewModel,
QueryParsersViewModel queryParsersViewModel,
FiltersViewModel filtersViewModel,
PluginCollectionViewModel pluginsViewModel)
PluginCollectionViewModel pluginsViewModel,
HelpViewModel helpViewModel)
{
_appSettingsService = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService));
Orderings = orderingsViewModel ?? throw new ArgumentNullException(nameof(orderingsViewModel));
QueryParsers = queryParsersViewModel ?? throw new ArgumentNullException(nameof(queryParsersViewModel));
Filters = filtersViewModel ?? throw new ArgumentNullException(nameof(filtersViewModel));
Plugins = pluginsViewModel ?? throw new ArgumentNullException(nameof(pluginsViewModel));
Help = helpViewModel ?? throw new ArgumentNullException(nameof(helpViewModel));
}

private AutoFetchMode AutoFetchMode
Expand All @@ -48,6 +50,8 @@ private AutoFetchMode AutoFetchMode

public PluginCollectionViewModel Plugins { [UsedImplicitly] get; }

public HelpViewModel Help { [UsedImplicitly] get; }

public bool AutoFetchOff
{
get => AutoFetchMode == AutoFetchMode.Off;
Expand Down
4 changes: 2 additions & 2 deletions tests/RepoM.ActionMenu.Core.Tests/Plugin/PluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public PluginTests()
new()
{
Host = "h1",
DatabaseNames = new [] {"x1", "x2", },
DatabaseNames = ["x1", "x2",],
Key = "k1",
},
new()
{
Host = "h2",
DatabaseNames = new [] {"x21", "x22", },
DatabaseNames = ["x21", "x22",],
Key = "k2",
},
};
Expand Down
16 changes: 10 additions & 6 deletions tests/RepoM.App.Tests/ViewModels/MainWindowViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MainWindowViewModelTests
private readonly QueryParsersViewModel _queryParsersViewModel;
private readonly FiltersViewModel _filtersViewModel;
private readonly PluginCollectionViewModel _pluginsViewModel;
private readonly HelpViewModel _helpViewModel;

public MainWindowViewModelTests()
{
Expand All @@ -30,6 +31,7 @@ public MainWindowViewModelTests()
_queryParsersViewModel = new QueryParsersViewModel(repositoryFilterManager, threadDispatcher);
_filtersViewModel = new FiltersViewModel(repositoryFilterManager, threadDispatcher);
_pluginsViewModel = new PluginCollectionViewModel(moduleManager);
_helpViewModel = new HelpViewModel(A.Fake<ITranslationService>());
}

[Fact]
Expand All @@ -38,18 +40,20 @@ public void Ctor_ShouldThrown_WhenArgumentIsNull()
// arrange

// act
Action act1 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, null!);
Action act2 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, null!, _pluginsViewModel);
Action act3 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, null!, _filtersViewModel, _pluginsViewModel);
Action act4 = () => _ = new MainWindowViewModel(_appSettingsService, null!, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel);
Action act5 = () => _ = new MainWindowViewModel(null!, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel);
Action act1 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, null!, _helpViewModel);
Action act2 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, null!, _pluginsViewModel, _helpViewModel);
Action act3 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, null!, _filtersViewModel, _pluginsViewModel, _helpViewModel);
Action act4 = () => _ = new MainWindowViewModel(_appSettingsService, null!, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel, _helpViewModel);
Action act5 = () => _ = new MainWindowViewModel(null!, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel, _helpViewModel);
Action act6 = () => _ = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel, null!);

// assert
act1.Should().ThrowExactly<ArgumentNullException>();
act2.Should().ThrowExactly<ArgumentNullException>();
act3.Should().ThrowExactly<ArgumentNullException>();
act4.Should().ThrowExactly<ArgumentNullException>();
act5.Should().ThrowExactly<ArgumentNullException>();
act6.Should().ThrowExactly<ArgumentNullException>();
}

[Fact]
Expand All @@ -58,7 +62,7 @@ public void Ctor_ShouldInitializeProperties()
// arrange

// act
var sut = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel);
var sut = new MainWindowViewModel(_appSettingsService, _orderingsViewModel, _queryParsersViewModel, _filtersViewModel, _pluginsViewModel, _helpViewModel);

// assert
sut.QueryParsers.Should().BeSameAs(_queryParsersViewModel);
Expand Down
Loading