fix(StyleEditor): save style when adding/importing

This commit is contained in:
goat 2021-09-28 19:09:11 +02:00
parent 4630d448fc
commit f2d604c4ef
No known key found for this signature in database
GPG key ID: F18F057873895461

View file

@ -89,6 +89,8 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor
if (ImGui.Button(Loc.Localize("StyleEditorAddNew", "Add new style")))
{
this.SaveStyle();
var newStyle = StyleModel.DalamudStandard;
newStyle.Name = GetRandomName();
config.SavedStyles.Add(newStyle);
@ -152,6 +154,8 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor
if (ImGuiComponents.IconButton(FontAwesomeIcon.FileImport))
{
this.SaveStyle();
var styleJson = ImGui.GetClipboardText();
try
@ -307,14 +311,10 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor
if (ImGui.Button(Loc.Localize("SaveAndClose", "Save and Close")))
{
this.SaveStyle();
config.ChosenStyle = config.SavedStyles[this.currentSel].Name;
var newStyle = StyleModel.Get();
newStyle.Name = config.ChosenStyle;
config.SavedStyles[this.currentSel] = newStyle;
newStyle.Apply();
config.Save();
this.didSave = true;
this.IsOpen = false;
@ -342,6 +342,21 @@ namespace Dalamud.Interface.Internal.Windows.StyleEditor
}
}
private void SaveStyle()
{
if (this.currentSel == 0)
return;
var config = Service<DalamudConfiguration>.Get();
var newStyle = StyleModel.Get();
newStyle.Name = config.ChosenStyle;
config.SavedStyles[this.currentSel] = newStyle;
newStyle.Apply();
config.Save();
}
private static string GetRandomName()
{
var data = Service<DataManager>.Get();