Add display of ImportDate and allow resetting it, add button to open local data json.

This commit is contained in:
Ottermandias 2024-09-08 23:42:19 +02:00
parent 22cbecc6a4
commit bd59591ed8
4 changed files with 58 additions and 11 deletions

View file

@ -249,6 +249,17 @@ public class ModDataEditor(SaveService saveService, CommunicatorService communic
communicatorService.ModDataChanged.Invoke(ModDataChangeType.Favorite, mod, null); communicatorService.ModDataChanged.Invoke(ModDataChangeType.Favorite, mod, null);
} }
public void ResetModImportDate(Mod mod)
{
var newDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
if (mod.ImportDate == newDate)
return;
mod.ImportDate = newDate;
saveService.QueueSave(new ModLocalData(mod));
communicatorService.ModDataChanged.Invoke(ModDataChangeType.ImportDate, mod, null);
}
public void ChangeModNote(Mod mod, string newNote) public void ChangeModNote(Mod mod, string newNote)
{ {
if (mod.Note == newNote) if (mod.Note == newNote)

View file

@ -77,7 +77,7 @@ public partial class ModCreator(
if (modDataChange.HasFlag(ModDataChangeType.Deletion) || mod.Name.Length == 0) if (modDataChange.HasFlag(ModDataChangeType.Deletion) || mod.Name.Length == 0)
return false; return false;
dataEditor.LoadLocalData(mod); modDataChange |= dataEditor.LoadLocalData(mod);
LoadDefaultOption(mod); LoadDefaultOption(mod);
LoadAllGroups(mod); LoadAllGroups(mod);
if (incorporateMetaChanges) if (incorporateMetaChanges)

View file

@ -447,16 +447,15 @@ public sealed class ModFileSystemSelector : FileSystemSelector<Mod, ModFileSyste
private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName) private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName)
{ {
switch (type) const ModDataChangeType relevantFlags =
{ ModDataChangeType.Name
case ModDataChangeType.Name: | ModDataChangeType.Author
case ModDataChangeType.Author: | ModDataChangeType.ModTags
case ModDataChangeType.ModTags: | ModDataChangeType.LocalTags
case ModDataChangeType.LocalTags: | ModDataChangeType.Favorite
case ModDataChangeType.Favorite: | ModDataChangeType.ImportDate;
SetFilterDirty(); if ((type & relevantFlags) != 0)
break; SetFilterDirty();
}
} }
private void OnInheritanceChange(ModCollection collection, bool _) private void OnInheritanceChange(ModCollection collection, bool _)

View file

@ -7,6 +7,7 @@ using OtterGui.Raii;
using OtterGui.Widgets; using OtterGui.Widgets;
using OtterGui.Classes; using OtterGui.Classes;
using OtterGui.Services; using OtterGui.Services;
using OtterGui.Text;
using Penumbra.Mods; using Penumbra.Mods;
using Penumbra.Mods.Editor; using Penumbra.Mods.Editor;
using Penumbra.Mods.Manager; using Penumbra.Mods.Manager;
@ -50,6 +51,8 @@ public class ModPanelEditTab(
EditButtons(); EditButtons();
EditRegularMeta(); EditRegularMeta();
UiHelpers.DefaultLineSpace(); UiHelpers.DefaultLineSpace();
EditLocalData();
UiHelpers.DefaultLineSpace();
if (Input.Text("Mod Path", Input.Path, Input.None, _leaf.FullName(), out var newPath, 256, UiHelpers.InputTextWidth.X)) if (Input.Text("Mod Path", Input.Path, Input.None, _leaf.FullName(), out var newPath, 256, UiHelpers.InputTextWidth.X))
try try
@ -182,6 +185,40 @@ public class ModPanelEditTab(
DrawOpenDefaultMod(); DrawOpenDefaultMod();
} }
private void EditLocalData()
{
DrawImportDate();
DrawOpenLocalData();
}
private void DrawImportDate()
{
ImUtf8.TextFramed($"{DateTimeOffset.FromUnixTimeMilliseconds(_mod.ImportDate).ToLocalTime():yyyy/MM/dd HH:mm}",
ImGui.GetColorU32(ImGuiCol.FrameBg, 0.5f), new Vector2(UiHelpers.InputTextMinusButton3, 0));
ImGui.SameLine(0, 3 * ImUtf8.GlobalScale);
var canRefresh = config.DeleteModModifier.IsActive();
var tt = canRefresh
? "Reset the import date to the current date and time."
: $"Reset the import date to the current date and time.\nHold {config.DeleteModModifier} while clicking to refresh.";
if (ImUtf8.IconButton(FontAwesomeIcon.Sync, tt, disabled: !canRefresh))
modManager.DataEditor.ResetModImportDate(_mod);
ImUtf8.SameLineInner();
ImUtf8.Text("Import Date"u8);
}
private void DrawOpenLocalData()
{
var file = filenames.LocalDataFile(_mod);
var fileExists = File.Exists(file);
var tt = fileExists
? "Open the local mod data file in the text editor of your choice."u8
: "The local mod data file does not exist."u8;
if (ImUtf8.ButtonEx("Open Local Data"u8, tt, UiHelpers.InputTextWidth, !fileExists))
Process.Start(new ProcessStartInfo(file) { UseShellExecute = true });
}
private void DrawOpenDefaultMod() private void DrawOpenDefaultMod()
{ {
var file = filenames.OptionGroupFile(_mod, -1, false); var file = filenames.OptionGroupFile(_mod, -1, false);