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

appearance - show keyboard hints #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions src/Camelot.Services.Abstractions/IAppearanceSettingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Camelot.Services.Abstractions.Models;
using Camelot.Services.Abstractions.Models.Enums;

namespace Camelot.Services.Abstractions;

public interface IAppearanceSettingsService
{
AppearanceSettingsModel GetAppearanceSettings();

void SaveAppearanceSettings(AppearanceSettingsModel appearanceSettingsModel);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Camelot.Services.Abstractions.Models;

public class AppearanceSettingsModel
{
public bool ShowKeyboardShortcuts { get; }

public AppearanceSettingsModel(bool showKeyboardShortcuts)
{
ShowKeyboardShortcuts = showKeyboardShortcuts;
}
}
55 changes: 55 additions & 0 deletions src/Camelot.Services/AppearanceSettingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Camelot.DataAccess.UnitOfWork;
using Camelot.Services.Abstractions;
using Camelot.Services.Abstractions.Models;
using Camelot.Services.Abstractions.Models.Enums;

namespace Camelot.Services;

public class AppearanceSettingsService : IAppearanceSettingsService
{
private const string SettingsId = "AppearanceSettings";
private readonly AppearanceSettingsModel _default;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private AppearanceSettingsModel _cachedSettingsValue;
public AppearanceSettingsService(IUnitOfWorkFactory unitOfWorkFactory)
{
_unitOfWorkFactory = unitOfWorkFactory;
_default = new AppearanceSettingsModel(false);
GetAppearanceSettings();
}

public AppearanceSettingsModel GetAppearanceSettings()
{
if (_cachedSettingsValue == null)
{
using var uow = _unitOfWorkFactory.Create();
var repository = uow.GetRepository<AppearanceSettingsModel>();
var dbModel = repository.GetById(SettingsId);
if (dbModel != null)
_cachedSettingsValue = dbModel;
else
_cachedSettingsValue = _default;
}
else
{
// we set value of _cachedValue in 'save',
// so no need to read from the repository every time.
}
return _cachedSettingsValue;
}


public void SaveAppearanceSettings(AppearanceSettingsModel appearanceSettingsModel)
{
if (appearanceSettingsModel == null)
throw new ArgumentNullException(nameof(appearanceSettingsModel));

using var uow = _unitOfWorkFactory.Create();
var repository = uow.GetRepository<AppearanceSettingsModel>();
repository.Upsert(SettingsId, appearanceSettingsModel);
_cachedSettingsValue = appearanceSettingsModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SettingsDialogViewModel : DialogViewModelBase
public ISettingsViewModel GeneralSettingsViewModel { get; set; }
public ISettingsViewModel IconsSettingsViewModel { get; set; }

public ISettingsViewModel AppearanceSettingsViewModel { get; set; }
public int SelectedIndex
{
get => _selectedIndex;
Expand All @@ -31,16 +32,21 @@ public int SelectedIndex

public SettingsDialogViewModel(
ISettingsViewModel generalSettingsViewModel,
ISettingsViewModel appearanceSettingsViewModel,
ISettingsViewModel terminalSettingsViewModel,
ISettingsViewModel iconsSettingsViewModel)
{
TerminalSettingsViewModel = terminalSettingsViewModel;
GeneralSettingsViewModel = generalSettingsViewModel;
IconsSettingsViewModel = iconsSettingsViewModel;

AppearanceSettingsViewModel = appearanceSettingsViewModel;
// Items in next array should be in same order as 'tabs' in xaml,
// Otherwise, Activate will called for wrong model.
// TODO: need to make it more dynamic, and not rely on order in view.
_settingsViewModels = new[]
{
generalSettingsViewModel,
appearanceSettingsViewModel,
terminalSettingsViewModel,
iconsSettingsViewModel
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TopOperationsViewModel : ViewModelBase, ITopOperationsViewModel
private readonly IArchiveService _archiveService;
private readonly INodesSelectionService _nodesSelectionService;
private readonly ISystemDialogService _systemDialogService;
private readonly IAppearanceSettingsService _appearanceSettingsService;

public ICommand PackCommand { get; }

Expand All @@ -31,6 +32,14 @@ public class TopOperationsViewModel : ViewModelBase, ITopOperationsViewModel

public ICommand OpenTerminalCommand { get; }

public bool KeyboardShortcutIsVisible
{
get
{
return _appearanceSettingsService.GetAppearanceSettings().ShowKeyboardShortcuts;
}
}

public TopOperationsViewModel(
ITerminalService terminalService,
IDirectoryService directoryService,
Expand All @@ -39,7 +48,8 @@ public TopOperationsViewModel(
IPathService pathService,
IArchiveService archiveService,
INodesSelectionService nodesSelectionService,
ISystemDialogService systemDialogService)
ISystemDialogService systemDialogService,
IAppearanceSettingsService appearanceSettingsService)
{
_terminalService = terminalService;
_directoryService = directoryService;
Expand All @@ -49,6 +59,7 @@ public TopOperationsViewModel(
_archiveService = archiveService;
_nodesSelectionService = nodesSelectionService;
_systemDialogService = systemDialogService;
_appearanceSettingsService = appearanceSettingsService;

PackCommand = ReactiveCommand.CreateFromTask(PackAsync);
ExtractCommand = ReactiveCommand.Create(ExtractAsync);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Camelot.Services.Abstractions;
using Camelot.Services.Abstractions.Models;
using Camelot.ViewModels.Interfaces.Settings;
using ReactiveUI.Fody.Helpers;

namespace Camelot.ViewModels.Implementations.Settings;

public class AppearanceSettingsViewModel : ViewModelBase, ISettingsViewModel
{
private readonly IAppearanceSettingsService _appearanceSettingService;
private bool _initialShowKeyboardShortcuts;

private bool _isActivated;

[Reactive]
public bool ShowKeyboardShortcuts { get; set; }


public bool IsChanged => _initialShowKeyboardShortcuts != ShowKeyboardShortcuts;

public AppearanceSettingsViewModel(
IAppearanceSettingsService appearanceSettingService)
{
_appearanceSettingService = appearanceSettingService;
}

public void Activate()
{
if (_isActivated)
{
return;
}

_isActivated = true;

var model = _appearanceSettingService.GetAppearanceSettings();
_initialShowKeyboardShortcuts = model.ShowKeyboardShortcuts;
ShowKeyboardShortcuts = _initialShowKeyboardShortcuts;
}

public void SaveChanges()
{
var model = new AppearanceSettingsModel(ShowKeyboardShortcuts);
_appearanceSettingService.SaveAppearanceSettings(model);
}
}
4 changes: 4 additions & 0 deletions src/Camelot/DependencyInjection/ServicesBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ private static void RegisterCommonServices(IMutableDependencyResolver services,
resolver.GetRequiredService<IUnitOfWorkFactory>(),
resolver.GetRequiredService<IPlatformService>()
));

services.RegisterLazySingleton<IAppearanceSettingsService>(() => new AppearanceSettingsService(
resolver.GetRequiredService<IUnitOfWorkFactory>()
));
}

private static void RegisterPlatformSpecificServices(IMutableDependencyResolver services, IReadonlyDependencyResolver resolver)
Expand Down
8 changes: 7 additions & 1 deletion src/Camelot/DependencyInjection/ViewModelsBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,17 @@ private static void RegisterCommonViewModels(IMutableDependencyResolver services
));
services.Register(() => new SettingsDialogViewModel(
resolver.GetRequiredService<GeneralSettingsViewModel>(),
resolver.GetRequiredService<AppearanceSettingsViewModel>(),
resolver.GetRequiredService<TerminalSettingsViewModel>(),
resolver.GetRequiredService<IconsSettingsViewModel>()
));
services.Register(() => new IconsSettingsViewModel(
resolver.GetRequiredService<IIconsSettingsService>()
));
services.Register(() => new AppearanceSettingsViewModel(
resolver.GetRequiredService<IAppearanceSettingsService>()
));

services.RegisterLazySingleton(() => new FilePropertiesBehavior(
resolver.GetRequiredService<IDialogService>()
));
Expand Down Expand Up @@ -312,7 +317,8 @@ private static void RegisterCommonViewModels(IMutableDependencyResolver services
resolver.GetRequiredService<IPathService>(),
resolver.GetRequiredService<IArchiveService>(),
resolver.GetRequiredService<INodesSelectionService>(),
resolver.GetRequiredService<ISystemDialogService>()
resolver.GetRequiredService<ISystemDialogService>(),
resolver.GetRequiredService<IAppearanceSettingsService>()
));
services.RegisterLazySingleton<IOperationStateViewModelFactory>(() => new OperationStateViewModelFactory(
resolver.GetRequiredService<IPathService>()
Expand Down
10 changes: 10 additions & 0 deletions src/Camelot/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Camelot/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,10 @@
<data name="SupportedOnWindowsOnly" xml:space="preserve">
<value>* Supported on Windows only</value>
</data>
<data name="Appearance" xml:space="preserve">
<value>Appearance</value>
</data>
<data name="ShowKeyboardShortcuts" xml:space="preserve">
<value>Show keyboard shortcuts</value>
</data>
</root>
8 changes: 8 additions & 0 deletions src/Camelot/Styles/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<Setter Property="Opacity" Value="0.5" />
<Setter Property="Margin" Value="5,5,0,0" />
</Style>

<Style Selector="TextBlock.topOperationHotkeyTextBlock">
<Setter Property="FontFamily" Value="SansSerif" />
<Setter Property="Foreground" Value="{DynamicResource OperationButtonHotkeyBrush}" />
<Setter Property="FontSize" Value="16" />
<Setter Property="Opacity" Value="0.5" />
<Setter Property="Margin" Value="5,0,0,0" />
</Style>

<Style Selector="Border.tabBorder">
<Setter Property="CornerRadius" Value="4,4,0,0" />
Expand Down
38 changes: 38 additions & 0 deletions src/Camelot/Views/Dialogs/Settings/AppearanceSettingsView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:p="clr-namespace:Camelot.Properties"
xmlns:settings="clr-namespace:Camelot.ViewModels.Implementations.Settings;assembly=Camelot.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Camelot.Views.Dialogs.Settings.AppearanceSettingsView"
x:DataType="settings:AppearanceSettingsViewModel"
x:CompileBindings="True">

<Design.DataContext>
<settings:AppearanceSettingsViewModel />
</Design.DataContext>
<Grid RowDefinitions="Auto,Auto,Auto"
ColumnDefinitions="Auto"
Margin="10">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Classes="settingsTabTextBlock" Margin="5,8,10,0"
Text="{x:Static p:Resources.ChangesRequireRestart}" />

<StackPanel Name="Quick Search"
Grid.Row="1"
Grid.Column="0"
Margin="5,8,10,0"
Orientation="Horizontal"
Spacing="5">
<CheckBox
IsChecked="{Binding ShowKeyboardShortcuts}">
</CheckBox>
<TextBlock
Classes="settingsTabTextBlock"
Text="{x:Static p:Resources.ShowKeyboardShortcuts}" />
</StackPanel>
</Grid>
</UserControl>
13 changes: 13 additions & 0 deletions src/Camelot/Views/Dialogs/Settings/AppearanceSettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace Camelot.Views.Dialogs.Settings;
public class AppearanceSettingsView : UserControl
{
public AppearanceSettingsView()
{
InitializeComponent();
}

private void InitializeComponent() => AvaloniaXamlLoader.Load(this);
}
Loading
Loading