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);
}
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)
{
if (mod.Note == newNote)

View file

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

View file

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

View file

@ -7,6 +7,7 @@ using OtterGui.Raii;
using OtterGui.Widgets;
using OtterGui.Classes;
using OtterGui.Services;
using OtterGui.Text;
using Penumbra.Mods;
using Penumbra.Mods.Editor;
using Penumbra.Mods.Manager;
@ -50,6 +51,8 @@ public class ModPanelEditTab(
EditButtons();
EditRegularMeta();
UiHelpers.DefaultLineSpace();
EditLocalData();
UiHelpers.DefaultLineSpace();
if (Input.Text("Mod Path", Input.Path, Input.None, _leaf.FullName(), out var newPath, 256, UiHelpers.InputTextWidth.X))
try
@ -182,6 +185,40 @@ public class ModPanelEditTab(
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()
{
var file = filenames.OptionGroupFile(_mod, -1, false);