Implemented copy function for text element's keys
This commit is contained in:
parent
bbc10de9ff
commit
8314e7157b
@ -58,23 +58,11 @@ public class GodotCSV : IGenerator
|
|||||||
foreach (var section in sections.OrderBy(n => n.DataKey))
|
foreach (var section in sections.OrderBy(n => n.DataKey))
|
||||||
foreach (var textElement in section.TextElements.OrderBy(n => n.Code))
|
foreach (var textElement in section.TextElements.OrderBy(n => n.Code))
|
||||||
{
|
{
|
||||||
//
|
// Get the key for this text element:
|
||||||
// Build the path to the text element:
|
var key = await TextElementProcessor.GetKey(textElement.Id);
|
||||||
//
|
|
||||||
var textElementPath = new List<string>(section.Depth + 2)
|
|
||||||
{
|
|
||||||
textElement.Code
|
|
||||||
};
|
|
||||||
|
|
||||||
var parent = section;
|
|
||||||
while (parent is not null)
|
|
||||||
{
|
|
||||||
textElementPath.Add(parent.DataKey);
|
|
||||||
parent = parent.Parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the path to the text element as key:
|
// Write the path to the text element as key:
|
||||||
await writer.WriteAsync($"{string.Join(".", textElementPath.ReverseIt())}{delimiter}");
|
await writer.WriteAsync($"{key}{delimiter}");
|
||||||
|
|
||||||
// Load all translations:
|
// Load all translations:
|
||||||
var translations = textElement.Translations.DistinctBy(n => n.Culture).ToDictionary(translation => translation.Culture, translation => translation.Text);
|
var translations = textElement.Translations.DistinctBy(n => n.Culture).ToDictionary(translation => translation.Culture, translation => translation.Text);
|
||||||
|
@ -128,4 +128,36 @@ public static class TextElementProcessor
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<string> GetKey(int id)
|
||||||
|
{
|
||||||
|
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
var textElement = await db.TextElements.FirstAsync(n => n.Id == id);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Build the path to the text element:
|
||||||
|
//
|
||||||
|
var textElementPath = new List<string>(textElement.Section.Depth + 2)
|
||||||
|
{
|
||||||
|
textElement.Code
|
||||||
|
};
|
||||||
|
|
||||||
|
var parent = textElement.Section;
|
||||||
|
while (parent is not null)
|
||||||
|
{
|
||||||
|
// Load the parent's parent section:
|
||||||
|
await db.Entry(parent).Reference(n => n.Parent).LoadAsync();
|
||||||
|
|
||||||
|
// Add the parent's key to the path:
|
||||||
|
textElementPath.Add(parent.DataKey);
|
||||||
|
|
||||||
|
// Go to parent's parent:
|
||||||
|
parent = parent.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
textElementPath.Add("I18N");
|
||||||
|
|
||||||
|
// Write the path to the text element as key:
|
||||||
|
return $"{string.Join(".", textElementPath.ReverseIt())}";
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
public static class Version
|
public static class Version
|
||||||
{
|
{
|
||||||
public static string Text => $"v0.9.5 (2023-02-15), .NET {Environment.Version}";
|
public static string Text => $"v0.9.6 (2023-02-15), .NET {Environment.Version}";
|
||||||
}
|
}
|
@ -86,6 +86,13 @@ public partial class TextElements : UserControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// When the user press Ctrl + C, copy the text element's key to the clipboard:
|
||||||
|
this.listTextElements.KeyDown += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e is {Control: true, KeyCode: Keys.C})
|
||||||
|
this.buttonCopyKey.PerformClick();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads all the text elements for the current section.
|
// Loads all the text elements for the current section.
|
||||||
@ -236,8 +243,11 @@ public partial class TextElements : UserControl
|
|||||||
|
|
||||||
private async void textBoxFilter_KeyUp(object sender, KeyEventArgs e) => await this.LoadTextElements();
|
private async void textBoxFilter_KeyUp(object sender, KeyEventArgs e) => await this.LoadTextElements();
|
||||||
|
|
||||||
private void buttonCopyKey_Click(object sender, EventArgs e)
|
private async void buttonCopyKey_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if(this.DesignMode || this.currentTextElement is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Clipboard.SetText(await TextElementProcessor.GetKey(this.currentTextElement.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user