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

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
10 changes: 10 additions & 0 deletions src/Camelot.Services.Abstractions/IAppearanceSettingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Camelot.Services.Abstractions.Models;

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;
}
}
1 change: 0 additions & 1 deletion src/Camelot.Services.Environment/Models/DriveInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DriveType = System.IO.DriveType;
using IoDriveInfo = System.IO.DriveInfo;

namespace Camelot.Services.Environment.Models;

Expand Down
51 changes: 51 additions & 0 deletions src/Camelot.Services/AppearanceSettingsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Camelot.DataAccess.UnitOfWork;
using Camelot.Services.Abstractions;
using Camelot.Services.Abstractions.Models;

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);
_cachedSettingsValue = dbModel ?? _default;
}

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 @@ -3,7 +3,6 @@
using Camelot.ViewModels.Services.Interfaces.Enums;
using Camelot.ViewModels.Services.Interfaces.Models;
using Camelot.ViewModels.Windows.WinApi;
using SystemBitmap = System.Drawing.Bitmap;
using AvaloniaBitmap = Avalonia.Media.Imaging.Bitmap;

namespace Camelot.ViewModels.Windows.ShellIcons;
Expand Down Expand Up @@ -84,7 +83,7 @@
var icon = IconExtractor.ExtractIcon(path);
// TODO: check if lossy and/or try other options, see url below. (iksi4prs).
// https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imageconverter.canconvertfrom?view=dotnet-plat-ext-7.0
var systemBitmap = icon.ToBitmap();

Check warning on line 86 in src/Camelot.ViewModels.Windows/ShellIcons/WindowsShellIconsService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'Icon.ToBitmap()' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 86 in src/Camelot.ViewModels.Windows/ShellIcons/WindowsShellIconsService.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'Icon.ToBitmap()' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 86 in src/Camelot.ViewModels.Windows/ShellIcons/WindowsShellIconsService.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

This call site is reachable on all platforms. 'Icon.ToBitmap()' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 86 in src/Camelot.ViewModels.Windows/ShellIcons/WindowsShellIconsService.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

This call site is reachable on all platforms. 'Icon.ToBitmap()' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
var avaloniaBitmap = SystemImageToAvaloniaBitmapConverter.Convert(systemBitmap);
result = new ImageModel(avaloniaBitmap);
}
Expand Down
1 change: 0 additions & 1 deletion src/Camelot.ViewModels.Windows/WinApi/ShellIcon.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Camelot.Services.Windows.WinApi;
using System.Diagnostics;

namespace Camelot.ViewModels.Windows.WinApi;

Expand Down
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();
ShowKeyboardShortcuts = _initialShowKeyboardShortcuts = model.ShowKeyboardShortcuts;
}

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.

Loading
Loading