Skip to content

Commit

Permalink
save when items are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Nov 20, 2023
1 parent 4b404b0 commit d4a345b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private async void TranslateFile(object sender, EventArgs e)

if (success)
{
root = ApplyTranslations(root, data, inputPath, outputFile);
root = ApplyTranslations(root, data, inputPath, outputFile, out var deleted);

var hintCount = 0;
if (hintOverrideBox.Checked && translator.Hints.HasElements)
Expand All @@ -332,7 +332,7 @@ private async void TranslateFile(object sender, EventArgs e)
Log($"Merged {hintCount} hints{NL}", Color.Green);
}

if (data.Count > 0 || hintCount > 0)
if (data.Count > 0 || hintCount > 0 || deleted > 0)
{
root.Save(outputFile);
Log($"Saved {outputFile}{NL}", Color.Blue);
Expand Down Expand Up @@ -415,7 +415,8 @@ private void Log(string message, Color? color = null)


private XElement ApplyTranslations(
XElement root, List<XElement> data, string inputPath, string outputFile)
XElement root, List<XElement> data, string inputPath, string outputFile,
out int deletedCount)
{
// add or update changes...

Expand Down Expand Up @@ -473,6 +474,7 @@ private XElement ApplyTranslations(
Log($"Deleted {d.Attribute("name").Value}{NL}", Color.DarkRed);
});

deletedCount = deleted.Count;
deleted.Remove();

if (sortBox.Checked)
Expand Down

0 comments on commit d4a345b

Please sign in to comment.