mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 17:53:32 +00:00
Profile editor tweaks and fixes
Select profile after duplicate/add Select default profile after delete
This commit is contained in:
parent
afb6315ec6
commit
bc2508e4ac
@ -153,50 +153,54 @@ namespace Artemis.Models
|
|||||||
ProfileProvider.RenameProfile(profileModel, profileModel.Name);
|
ProfileProvider.RenameProfile(profileModel, profileModel.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DuplicateProfile(ProfileModel selectedProfile)
|
public async Task<ProfileModel> DuplicateProfile(ProfileModel selectedProfile)
|
||||||
{
|
{
|
||||||
var newProfile = GeneralHelpers.Clone(selectedProfile);
|
var newProfile = GeneralHelpers.Clone(selectedProfile);
|
||||||
var name = await GetValidProfileName("Rename profile", "Please enter a unique new profile name");
|
var name = await GetValidProfileName("Duplicate profile", "Please enter a unique new profile name");
|
||||||
// User cancelled
|
// User cancelled
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return;
|
return null;
|
||||||
var doRename = await MakeProfileUnique(newProfile, name, newProfile.Name);
|
var doRename = await MakeProfileUnique(newProfile, name, newProfile.Name);
|
||||||
if (!doRename)
|
if (!doRename)
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
// Make sure it's not default, in case of copying a default profile
|
// Make sure it's not default, in case of copying a default profile
|
||||||
newProfile.IsDefault = false;
|
newProfile.IsDefault = false;
|
||||||
ProfileProvider.AddOrUpdate(newProfile);
|
ProfileProvider.AddOrUpdate(newProfile);
|
||||||
|
|
||||||
|
return newProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteProfile(ProfileModel selectedProfile, ModuleModel moduleModel)
|
public async Task<bool> DeleteProfile(ProfileModel selectedProfile, ModuleModel moduleModel)
|
||||||
{
|
{
|
||||||
var confirm = await _dialogService.ShowQuestionMessageBox("Delete profile",
|
var confirm = await _dialogService.ShowQuestionMessageBox("Delete profile",
|
||||||
$"Are you sure you want to delete the profile named: {selectedProfile.Name}?\n\n" +
|
$"Are you sure you want to delete the profile named: {selectedProfile.Name}?\n\n" +
|
||||||
"This cannot be undone.");
|
"This cannot be undone.");
|
||||||
if (!confirm.Value)
|
if (!confirm.Value)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
var defaultProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, moduleModel, "Default");
|
var defaultProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, moduleModel, "Default");
|
||||||
var deleteProfile = selectedProfile;
|
var deleteProfile = selectedProfile;
|
||||||
|
|
||||||
moduleModel.ChangeProfile(defaultProfile);
|
moduleModel.ChangeProfile(defaultProfile);
|
||||||
ProfileProvider.DeleteProfile(deleteProfile);
|
ProfileProvider.DeleteProfile(deleteProfile);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ImportProfile(ModuleModel moduleModel)
|
public async Task<ProfileModel> ImportProfile(ModuleModel moduleModel)
|
||||||
{
|
{
|
||||||
var dialog = new OpenFileDialog {Filter = "Artemis profile (*.json)|*.json"};
|
var dialog = new OpenFileDialog {Filter = "Artemis profile (*.json)|*.json"};
|
||||||
var result = dialog.ShowDialog();
|
var result = dialog.ShowDialog();
|
||||||
if (result != DialogResult.OK)
|
if (result != DialogResult.OK)
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
var profileModel = ProfileProvider.LoadProfileIfValid(dialog.FileName);
|
var profileModel = ProfileProvider.LoadProfileIfValid(dialog.FileName);
|
||||||
if (profileModel == null)
|
if (profileModel == null)
|
||||||
{
|
{
|
||||||
_dialogService.ShowErrorMessageBox("Oh noes, the profile you provided is invalid. " +
|
_dialogService.ShowErrorMessageBox("Oh noes, the profile you provided is invalid. " +
|
||||||
"If this keeps happening, please make an issue on GitHub and provide the profile.");
|
"If this keeps happening, please make an issue on GitHub and provide the profile.");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the game
|
// Verify the game
|
||||||
@ -204,7 +208,7 @@ namespace Artemis.Models
|
|||||||
{
|
{
|
||||||
_dialogService.ShowErrorMessageBox(
|
_dialogService.ShowErrorMessageBox(
|
||||||
$"Oh oops! This profile is ment for {profileModel.GameName}, not {moduleModel.Name} :c");
|
$"Oh oops! This profile is ment for {profileModel.GameName}, not {moduleModel.Name} :c");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the keyboard
|
// Verify the keyboard
|
||||||
@ -216,7 +220,7 @@ namespace Artemis.Models
|
|||||||
"You can still import it but you'll probably have to do some adjusting\n\n" +
|
"You can still import it but you'll probably have to do some adjusting\n\n" +
|
||||||
"Continue?");
|
"Continue?");
|
||||||
if (!adjustKeyboard.Value)
|
if (!adjustKeyboard.Value)
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
// Resize layers that are on the full keyboard width
|
// Resize layers that are on the full keyboard width
|
||||||
profileModel.ResizeLayers(deviceManager.ActiveKeyboard);
|
profileModel.ResizeLayers(deviceManager.ActiveKeyboard);
|
||||||
@ -232,13 +236,22 @@ namespace Artemis.Models
|
|||||||
var name = await GetValidProfileName("Rename profile", "Please enter a unique new profile name");
|
var name = await GetValidProfileName("Rename profile", "Please enter a unique new profile name");
|
||||||
// User cancelled
|
// User cancelled
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return;
|
return null;
|
||||||
var doRename = await MakeProfileUnique(profileModel, name, profileModel.Name);
|
var doRename = await MakeProfileUnique(profileModel, name, profileModel.Name);
|
||||||
if (!doRename)
|
if (!doRename)
|
||||||
return;
|
return null;
|
||||||
|
|
||||||
profileModel.IsDefault = false;
|
profileModel.IsDefault = false;
|
||||||
ProfileProvider.AddOrUpdate(profileModel);
|
ProfileProvider.AddOrUpdate(profileModel);
|
||||||
|
return profileModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeProfileByName(ModuleModel moduleModel, string profileName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(profileName))
|
||||||
|
profileName = "Default";
|
||||||
|
|
||||||
|
moduleModel.ChangeProfile(ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, moduleModel, profileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> GetValidProfileName(string title, string text)
|
private async Task<string> GetValidProfileName(string title, string text)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
using Artemis.Events;
|
using Artemis.DAL;
|
||||||
|
using Artemis.Events;
|
||||||
using Artemis.Managers;
|
using Artemis.Managers;
|
||||||
using Artemis.Services;
|
using Artemis.Services;
|
||||||
using Artemis.Settings;
|
using Artemis.Settings;
|
||||||
using Artemis.ViewModels;
|
using Artemis.ViewModels;
|
||||||
using Artemis.ViewModels.Profiles;
|
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
@ -13,23 +13,33 @@ namespace Artemis.Modules.Abstract
|
|||||||
{
|
{
|
||||||
public abstract class ModuleViewModel : Screen
|
public abstract class ModuleViewModel : Screen
|
||||||
{
|
{
|
||||||
private readonly ModuleManager _moduleManager;
|
|
||||||
private readonly MainManager _mainManager;
|
private readonly MainManager _mainManager;
|
||||||
private readonly IKernel _kernel;
|
private readonly ModuleManager _moduleManager;
|
||||||
|
private readonly GeneralSettings _generalSettings;
|
||||||
private ModuleSettings _settings;
|
private ModuleSettings _settings;
|
||||||
private GeneralSettings _generalSettings;
|
|
||||||
|
|
||||||
public ModuleViewModel(MainManager mainManager, ModuleModel moduleModel, IKernel kernel)
|
public ModuleViewModel(MainManager mainManager, ModuleModel moduleModel, IKernel kernel)
|
||||||
{
|
{
|
||||||
_mainManager = mainManager;
|
_mainManager = mainManager;
|
||||||
_kernel = kernel;
|
|
||||||
_moduleManager = mainManager.ModuleManager;
|
_moduleManager = mainManager.ModuleManager;
|
||||||
_generalSettings = DAL.SettingsProvider.Load<GeneralSettings>();
|
_generalSettings = SettingsProvider.Load<GeneralSettings>();
|
||||||
ModuleModel = moduleModel;
|
ModuleModel = moduleModel;
|
||||||
Settings = moduleModel.Settings;
|
Settings = moduleModel.Settings;
|
||||||
|
|
||||||
_mainManager.EnabledChanged += MainManagerOnEnabledChanged;
|
_mainManager.EnabledChanged += MainManagerOnEnabledChanged;
|
||||||
_moduleManager.EffectChanged += ModuleManagerOnModuleChanged;
|
_moduleManager.EffectChanged += ModuleManagerOnModuleChanged;
|
||||||
|
|
||||||
|
// ReSharper disable once VirtualMemberCallInConstructor
|
||||||
|
if (!UsesProfileEditor)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IParameter[] args =
|
||||||
|
{
|
||||||
|
new ConstructorArgument("mainManager", _mainManager),
|
||||||
|
new ConstructorArgument("moduleModel", ModuleModel),
|
||||||
|
new ConstructorArgument("lastProfile", Settings.LastProfile)
|
||||||
|
};
|
||||||
|
ProfileEditor = kernel.Get<ProfileEditorViewModel>(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileEditorViewModel ProfileEditor { get; set; }
|
public ProfileEditorViewModel ProfileEditor { get; set; }
|
||||||
@ -142,24 +152,13 @@ namespace Artemis.Modules.Abstract
|
|||||||
protected override void OnActivate()
|
protected override void OnActivate()
|
||||||
{
|
{
|
||||||
base.OnActivate();
|
base.OnActivate();
|
||||||
|
ProfileEditor?.OnActivate();
|
||||||
if (!UsesProfileEditor)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IParameter[] args =
|
|
||||||
{
|
|
||||||
new ConstructorArgument("mainManager", _mainManager),
|
|
||||||
new ConstructorArgument("moduleModel", ModuleModel),
|
|
||||||
new ConstructorArgument("lastProfile", Settings.LastProfile)
|
|
||||||
};
|
|
||||||
ProfileEditor = _kernel.Get<ProfileEditorViewModel>(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDeactivate(bool close)
|
protected override void OnDeactivate(bool close)
|
||||||
{
|
{
|
||||||
base.OnDeactivate(close);
|
base.OnDeactivate(close);
|
||||||
ProfileEditor?.Dispose();
|
ProfileEditor?.OnDeactivate(close);
|
||||||
ProfileEditor = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ using Screen = Caliburn.Micro.Screen;
|
|||||||
|
|
||||||
namespace Artemis.ViewModels
|
namespace Artemis.ViewModels
|
||||||
{
|
{
|
||||||
public sealed class ProfileEditorViewModel : Screen, IDropTarget, IDisposable
|
public sealed class ProfileEditorViewModel : Screen, IDropTarget
|
||||||
{
|
{
|
||||||
private readonly DeviceManager _deviceManager;
|
private readonly DeviceManager _deviceManager;
|
||||||
private readonly MetroDialogService _dialogService;
|
private readonly MetroDialogService _dialogService;
|
||||||
@ -68,16 +68,22 @@ namespace Artemis.ViewModels
|
|||||||
PropertyChanged += EditorStateHandler;
|
PropertyChanged += EditorStateHandler;
|
||||||
_deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
|
_deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged;
|
||||||
_moduleModel.ProfileChanged += ModuleModelOnProfileChanged;
|
_moduleModel.ProfileChanged += ModuleModelOnProfileChanged;
|
||||||
_loopManager.RenderCompleted += LoopManagerOnRenderCompleted;
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public new void OnActivate()
|
||||||
{
|
{
|
||||||
|
base.OnActivate();
|
||||||
|
|
||||||
|
_loopManager.RenderCompleted += LoopManagerOnRenderCompleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public new void OnDeactivate(bool close)
|
||||||
|
{
|
||||||
|
base.OnDeactivate(close);
|
||||||
|
|
||||||
SaveSelectedProfile();
|
SaveSelectedProfile();
|
||||||
ProfileEditorModel.Dispose();
|
|
||||||
_loopManager.RenderCompleted -= LoopManagerOnRenderCompleted;
|
_loopManager.RenderCompleted -= LoopManagerOnRenderCompleted;
|
||||||
_deviceManager.OnKeyboardChanged -= DeviceManagerOnOnKeyboardChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region LUA
|
#region LUA
|
||||||
@ -154,11 +160,10 @@ namespace Artemis.ViewModels
|
|||||||
get { return SelectedProfile?.Name; }
|
get { return SelectedProfile?.Name; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value == SelectedProfile?.Name)
|
SaveSelectedProfile();
|
||||||
return;
|
|
||||||
|
|
||||||
_moduleModel.ChangeProfile(ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, _moduleModel, value));
|
|
||||||
NotifyOfPropertyChange(() => SelectedProfileName);
|
NotifyOfPropertyChange(() => SelectedProfileName);
|
||||||
|
if (value != null)
|
||||||
|
ProfileEditorModel.ChangeProfileByName(_moduleModel, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +213,15 @@ namespace Artemis.ViewModels
|
|||||||
UpdateLayerList(SelectedLayer);
|
UpdateLayerList(SelectedLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void EditLayer(LayerModel layerModel)
|
||||||
|
{
|
||||||
|
if (layerModel == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ProfileEditorModel.EditLayer(layerModel, _moduleModel.DataModel);
|
||||||
|
UpdateLayerList(layerModel);
|
||||||
|
}
|
||||||
|
|
||||||
public LayerModel AddLayer()
|
public LayerModel AddLayer()
|
||||||
{
|
{
|
||||||
if (SelectedProfile == null)
|
if (SelectedProfile == null)
|
||||||
@ -355,6 +369,7 @@ namespace Artemis.ViewModels
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
|
_moduleModel.ChangeProfile(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void RenameProfile()
|
public async void RenameProfile()
|
||||||
@ -362,8 +377,11 @@ namespace Artemis.ViewModels
|
|||||||
if (SelectedProfile == null)
|
if (SelectedProfile == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var renameProfile = SelectedProfile;
|
||||||
await ProfileEditorModel.RenameProfile(SelectedProfile);
|
await ProfileEditorModel.RenameProfile(SelectedProfile);
|
||||||
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
|
_moduleModel.ChangeProfile(renameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void DuplicateProfile()
|
public async void DuplicateProfile()
|
||||||
@ -371,8 +389,12 @@ namespace Artemis.ViewModels
|
|||||||
if (SelectedProfile == null)
|
if (SelectedProfile == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await ProfileEditorModel.DuplicateProfile(SelectedProfile);
|
var newProfle = await ProfileEditorModel.DuplicateProfile(SelectedProfile);
|
||||||
|
if (newProfle == null)
|
||||||
|
return;
|
||||||
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
|
_moduleModel.ChangeProfile(newProfle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void DeleteProfile()
|
public async void DeleteProfile()
|
||||||
@ -380,8 +402,12 @@ namespace Artemis.ViewModels
|
|||||||
if (SelectedProfile == null)
|
if (SelectedProfile == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await ProfileEditorModel.DeleteProfile(SelectedProfile, _moduleModel);
|
var confirmed = await ProfileEditorModel.DeleteProfile(SelectedProfile, _moduleModel);
|
||||||
|
if (!confirmed)
|
||||||
|
return;
|
||||||
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
|
ProfileEditorModel.ChangeProfileByName(_moduleModel, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void ImportProfile()
|
public async void ImportProfile()
|
||||||
@ -393,8 +419,12 @@ namespace Artemis.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ProfileEditorModel.ImportProfile(_moduleModel);
|
var importProfile = await ProfileEditorModel.ImportProfile(_moduleModel);
|
||||||
|
if (importProfile == null)
|
||||||
|
return;
|
||||||
|
|
||||||
LoadProfiles();
|
LoadProfiles();
|
||||||
|
_moduleModel.ChangeProfile(importProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExportProfile()
|
public void ExportProfile()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user