feat(themes): add an export button for the active theme
This commit is contained in:
@@ -37,6 +37,12 @@ internal sealed class ThemeImportExportRow
|
||||
OpenThemesFolder();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Export active theme…"))
|
||||
{
|
||||
ExportActive();
|
||||
}
|
||||
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
ImGui.InputTextWithHint(
|
||||
"##theme-import-path",
|
||||
@@ -293,4 +299,43 @@ internal sealed class ThemeImportExportRow
|
||||
_logger.LogWarning(ex, "Could not open themes folder {Dir}", dir);
|
||||
}
|
||||
}
|
||||
|
||||
private void ExportActive()
|
||||
{
|
||||
// Capture the active theme now, not in the async dialog callback — the user
|
||||
// could switch themes while the dialog is open.
|
||||
var theme = _themes.Active;
|
||||
var defaultName = $"{theme.Slug}.json";
|
||||
|
||||
Plugin.FileDialogManager.SaveFileDialog(
|
||||
"Export theme",
|
||||
".json",
|
||||
defaultName,
|
||||
".json",
|
||||
(ok, path) =>
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
ExportTo(theme, path);
|
||||
}
|
||||
},
|
||||
null,
|
||||
isModal: true
|
||||
);
|
||||
}
|
||||
|
||||
private void ExportTo(Theme theme, string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = ThemeJsonWriter.Serialize(theme);
|
||||
File.WriteAllText(path, json);
|
||||
_logger.LogInformation("Exported theme {Slug} to {Path}", theme.Slug, path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
when (ex is IOException or UnauthorizedAccessException or SecurityException)
|
||||
{
|
||||
_logger.LogWarning(ex, "Theme export to {Path} failed", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user