mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-27 02:33:38 +00:00
118 lines
4.7 KiB
C#
118 lines
4.7 KiB
C#
using AIStudio.Settings;
|
|
|
|
using Lua;
|
|
|
|
namespace AIStudio.Dialogs.Settings;
|
|
|
|
public partial class SettingsDialogProfiles : SettingsDialogBase
|
|
{
|
|
private Task AddProfile() => this.AddProfile(null);
|
|
|
|
private async Task ImportProfile()
|
|
{
|
|
if (!this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("PROFILES"))
|
|
return;
|
|
var table = await ConfigurationSnippetImportDialog.ShowAsync(this.DialogService, "PROFILES", T("Import Profile"));
|
|
if (table is not null && this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("PROFILES"))
|
|
await this.AddProfile(table);
|
|
}
|
|
|
|
private async Task AddProfile(LuaTable? importedConfiguration)
|
|
{
|
|
if (importedConfiguration is not null && !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("PROFILES"))
|
|
return;
|
|
|
|
var dialogParameters = new DialogParameters<ProfileDialog>
|
|
{
|
|
{ x => x.IsEditing, false },
|
|
};
|
|
if (importedConfiguration is not null)
|
|
dialogParameters.Add(x => x.ImportedConfiguration, importedConfiguration);
|
|
|
|
var dialogReference = await this.DialogService.ShowAsync<ProfileDialog>(T("Add Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
var dialogResult = await dialogReference.Result;
|
|
if (dialogResult is null || dialogResult.Canceled ||
|
|
(importedConfiguration is not null && !this.SettingsManager.ConfigurationData.App.CanImportConfigurationSnippet("PROFILES")))
|
|
return;
|
|
|
|
var addedProfile = (Profile)dialogResult.Data!;
|
|
addedProfile = addedProfile with { Num = this.SettingsManager.ConfigurationData.NextProfileNum++ };
|
|
|
|
this.SettingsManager.ConfigurationData.Profiles.Add(addedProfile);
|
|
|
|
await this.SettingsManager.StoreSettings();
|
|
await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
|
|
}
|
|
|
|
private async Task EditProfile(Profile profile)
|
|
{
|
|
var dialogParameters = new DialogParameters<ProfileDialog>
|
|
{
|
|
{ x => x.DataNum, profile.Num },
|
|
{ x => x.DataId, profile.Id },
|
|
{ x => x.DataName, profile.Name },
|
|
{ x => x.DataNeedToKnow, profile.NeedToKnow },
|
|
{ x => x.DataActions, profile.Actions },
|
|
{ x => x.IsEditing, true },
|
|
};
|
|
|
|
var dialogReference = await this.DialogService.ShowAsync<ProfileDialog>(T("Edit Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
var dialogResult = await dialogReference.Result;
|
|
if (dialogResult is null || dialogResult.Canceled)
|
|
return;
|
|
|
|
var editedProfile = (Profile)dialogResult.Data!;
|
|
this.SettingsManager.ConfigurationData.Profiles[this.SettingsManager.ConfigurationData.Profiles.IndexOf(profile)] = editedProfile;
|
|
|
|
await this.SettingsManager.StoreSettings();
|
|
await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
|
|
}
|
|
|
|
private async Task ViewProfile(Profile profile)
|
|
{
|
|
var dialogParameters = new DialogParameters<ProfileDialog>
|
|
{
|
|
{ x => x.DataNum, profile.Num },
|
|
{ x => x.DataId, profile.Id },
|
|
{ x => x.DataName, profile.Name },
|
|
{ x => x.DataNeedToKnow, profile.NeedToKnow },
|
|
{ x => x.DataActions, profile.Actions },
|
|
{ x => x.IsEditing, true },
|
|
{ x => x.IsReadOnly, true },
|
|
};
|
|
|
|
await this.DialogService.ShowAsync<ProfileDialog>(T("View Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
}
|
|
|
|
private async Task ExportProfile(Profile profile)
|
|
{
|
|
if (!this.SettingsManager.ConfigurationData.App.ShowAdminSettings)
|
|
return;
|
|
|
|
if (profile == Profile.NO_PROFILE || profile.IsEnterpriseConfiguration)
|
|
return;
|
|
|
|
var luaCode = profile.ExportAsConfigurationSection();
|
|
if (!string.IsNullOrWhiteSpace(luaCode))
|
|
await this.RustService.CopyText2Clipboard(luaCode);
|
|
}
|
|
|
|
private async Task DeleteProfile(Profile profile)
|
|
{
|
|
var dialogParameters = new DialogParameters<ConfirmDialog>
|
|
{
|
|
{ x => x.Message, string.Format(T("Are you sure you want to delete the profile '{0}'?"), profile.Name) },
|
|
};
|
|
|
|
var dialogReference = await this.DialogService.ShowAsync<ConfirmDialog>(T("Delete Profile"), dialogParameters, DialogOptions.FULLSCREEN);
|
|
var dialogResult = await dialogReference.Result;
|
|
if (dialogResult is null || dialogResult.Canceled)
|
|
return;
|
|
|
|
this.SettingsManager.ConfigurationData.Profiles.Remove(profile);
|
|
await this.SettingsManager.StoreSettings();
|
|
|
|
await this.MessageBus.SendMessage<bool>(this, Event.CONFIGURATION_CHANGED);
|
|
}
|
|
}
|