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;
}
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",
$"Are you sure you want to delete the profile named: {selectedProfile.Name}?\n\n" +
"This cannot be undone.");
if (!confirm.Value)
return false;
var defaultProfile = ProfileProvider.GetProfile(_deviceManager.ActiveKeyboard, moduleModel, "Default");
var deleteProfile = selectedProfile;
moduleModel.ChangeProfile(defaultProfile);
ProfileProvider.DeleteProfile(deleteProfile);
return true;
return confirm.Value;
}
public async Task<ProfileModel> ImportProfile(ModuleModel moduleModel)

View File

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

View File

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