1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Fixed all cases of the profile selection going empty I could find

This commit is contained in:
SpoinkyNL 2017-05-22 14:28:52 +02:00
parent d737716e12
commit 7791b64a0f
3 changed files with 17 additions and 23 deletions

View File

@ -177,21 +177,13 @@ namespace Artemis.Models
return newProfile; return newProfile;
} }
public async Task<bool> DeleteProfile(ProfileModel selectedProfile, ModuleModel moduleModel) public async Task<bool> ConfirmDeleteProfile(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)
return false;
var defaultProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, moduleModel, "Default"); return confirm.Value;
var deleteProfile = selectedProfile;
moduleModel.ChangeProfile(defaultProfile);
ProfileProvider.DeleteProfile(deleteProfile);
return true;
} }
public async Task<ProfileModel> ImportProfile(ModuleModel moduleModel) public async Task<ProfileModel> ImportProfile(ModuleModel moduleModel)

View File

@ -1,12 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows;
using Artemis.DAL; using Artemis.DAL;
using Artemis.Events; using Artemis.Events;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Models; using Artemis.Models;
using Artemis.Profiles; using Artemis.Profiles;
using Artemis.Profiles.Layers.Interfaces;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ninject; using Ninject;
@ -96,7 +94,7 @@ namespace Artemis.Modules.Abstract
public void ChangeProfile(ProfileModel profileModel) public void ChangeProfile(ProfileModel profileModel)
{ {
if (!IsInitialized) if (!IsInitialized || Equals(ProfileModel, profileModel))
return; return;
ProfileModel?.Deactivate(_luaManager); ProfileModel?.Deactivate(_luaManager);
@ -133,7 +131,7 @@ namespace Artemis.Modules.Abstract
ChangeToLastProfile(); ChangeToLastProfile();
} }
private void ChangeToLastProfile() public void ChangeToLastProfile()
{ {
var profileName = !string.IsNullOrEmpty(Settings?.LastProfile) ? Settings.LastProfile : "Default"; var profileName = !string.IsNullOrEmpty(Settings?.LastProfile) ? Settings.LastProfile : "Default";

View File

@ -406,8 +406,6 @@ namespace Artemis.ViewModels
ProfileNames.Clear(); ProfileNames.Clear();
if (_moduleModel != null && _deviceManager.ActiveKeyboard != null) if (_moduleModel != null && _deviceManager.ActiveKeyboard != null)
ProfileNames.AddRange(ProfileProvider.GetProfileNames(_deviceManager.ActiveKeyboard, _moduleModel)); ProfileNames.AddRange(ProfileProvider.GetProfileNames(_deviceManager.ActiveKeyboard, _moduleModel));
NotifyOfPropertyChange(() => SelectedProfile);
}); });
} }
@ -444,7 +442,7 @@ namespace Artemis.ViewModels
return; return;
LoadProfiles(); LoadProfiles();
_moduleModel.ChangeProfile(profile); SelectedProfileName = profile.Name;
} }
public async void RenameProfile() public async void RenameProfile()
@ -456,7 +454,8 @@ namespace Artemis.ViewModels
await ProfileEditorModel.RenameProfile(SelectedProfile); await ProfileEditorModel.RenameProfile(SelectedProfile);
LoadProfiles(); LoadProfiles();
_moduleModel.ChangeProfile(renameProfile); SelectedProfileName = "Default";
SelectedProfileName = renameProfile.Name;
} }
public async void DuplicateProfile() public async void DuplicateProfile()
@ -469,7 +468,7 @@ namespace Artemis.ViewModels
return; return;
LoadProfiles(); LoadProfiles();
_moduleModel.ChangeProfile(newProfle); SelectedProfileName = newProfle.Name;
} }
public async void DeleteProfile() public async void DeleteProfile()
@ -477,12 +476,17 @@ namespace Artemis.ViewModels
if (SelectedProfile == null) if (SelectedProfile == null)
return; return;
var confirmed = await ProfileEditorModel.DeleteProfile(SelectedProfile, _moduleModel); var confirmed = await ProfileEditorModel.ConfirmDeleteProfile(SelectedProfile, _moduleModel);
if (!confirmed) if (!confirmed)
return; return;
var deleteProfile = SelectedProfile;
_moduleModel.ChangeProfile(null);
ProfileProvider.DeleteProfile(deleteProfile);
LoadProfiles(); LoadProfiles();
ProfileEditorModel.ChangeProfileByName(_moduleModel, null); SelectedProfileName = "Default";
} }
public async void ImportProfile() public async void ImportProfile()
@ -499,7 +503,7 @@ namespace Artemis.ViewModels
return; return;
LoadProfiles(); LoadProfiles();
_moduleModel.ChangeProfile(importProfile); SelectedProfileName = importProfile.Name;
} }
public void ExportProfile() public void ExportProfile()