diff --git a/OtterGui b/OtterGui index f401cea4..a9a5b2a4 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit f401cea47e45d12e09d1668187e3bb2781af21dd +Subproject commit a9a5b2a4bbf061d9cfed5234ca731bd2d94bcb96 diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index 83f0982d..8d120b67 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -44,6 +44,7 @@ public partial class Configuration : IPluginConfiguration public float ModSelectorAbsoluteSize { get; set; } = Constants.DefaultAbsoluteSize; public int ModSelectorScaledSize { get; set; } = Constants.DefaultScaledSize; public bool OpenFoldersByDefault { get; set; } = false; + public string DefaultImportFolder { get; set; } = string.Empty; public bool FixMainWindow { get; set; } = false; public bool ShowAdvanced { get; set; } diff --git a/Penumbra/UI/Classes/ModFileSystemSelector.cs b/Penumbra/UI/Classes/ModFileSystemSelector.cs index 4063850d..14dfd804 100644 --- a/Penumbra/UI/Classes/ModFileSystemSelector.cs +++ b/Penumbra/UI/Classes/ModFileSystemSelector.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Concurrent; -using System.IO; -using System.Linq; -using System.Numerics; using Dalamud.Interface; using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Logging; @@ -14,6 +9,11 @@ using OtterGui.Raii; using Penumbra.Collections; using Penumbra.Import; using Penumbra.Mods; +using System; +using System.Collections.Concurrent; +using System.IO; +using System.Linq; +using System.Numerics; namespace Penumbra.UI.Classes; @@ -31,6 +31,8 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod SubscribeRightClickFolder( DisableDescendants, 10 ); SubscribeRightClickFolder( InheritDescendants, 15 ); SubscribeRightClickFolder( OwnDescendants, 15 ); + SubscribeRightClickFolder( SetDefaultImportFolder, 100 ); + SubscribeRightClickMain( ClearDefaultImportFolder, 100 ); AddButton( AddNewModButton, 0 ); AddButton( AddImportModButton, 1 ); AddButton( AddHelpButton, 2 ); @@ -107,6 +109,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod var mod = Penumbra.ModManager.LastOrDefault(); if( mod != null ) { + MoveModToDefaultDirectory( mod ); SelectByValue( mod ); } } @@ -154,6 +157,28 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod } } + private static void SetDefaultImportFolder( ModFileSystem.Folder folder ) + { + if( ImGui.MenuItem( "Set As Default Import Folder" ) ) + { + var newName = folder.FullName(); + if( newName != Penumbra.Config.DefaultImportFolder ) + { + Penumbra.Config.DefaultImportFolder = newName; + Penumbra.Config.Save(); + } + } + } + + private static void ClearDefaultImportFolder() + { + if( ImGui.MenuItem( "Clear Default Import Folder" ) && Penumbra.Config.DefaultImportFolder.Length > 0 ) + { + Penumbra.Config.DefaultImportFolder = string.Empty; + Penumbra.Config.Save(); + } + } + // Add custom buttons. private string _newModName = string.Empty; @@ -385,6 +410,34 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod } } + // If a default import folder is setup, try to move the given mod in there. + // If the folder does not exist, create it if possible. + private void MoveModToDefaultDirectory( Mod mod ) + { + if( Penumbra.Config.DefaultImportFolder.Length == 0 ) + { + return; + } + + try + { + var leaf = FileSystem.Root.GetChildren( SortMode.Lexicographical ) + .FirstOrDefault( f => f is FileSystem< Mod >.Leaf l && l.Value == mod ); + if( leaf == null ) + { + throw new Exception( "Mod was not found at root." ); + } + + var folder = FileSystem.FindOrCreateAllFolders( Penumbra.Config.DefaultImportFolder ); + FileSystem.Move( leaf, folder ); + } + catch( Exception e ) + { + PluginLog.Warning( + $"Could not move newly imported mod {mod.Name} to default import folder {Penumbra.Config.DefaultImportFolder}:\n{e}" ); + } + } + private static void DrawHelpPopup() { ImGuiUtil.HelpPopup( "ExtendedHelp", new Vector2( 1000 * ImGuiHelpers.GlobalScale, 33.5f * ImGui.GetTextLineHeightWithSpacing() ), () => diff --git a/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs b/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs index 7acbbfb2..20954498 100644 --- a/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs +++ b/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs @@ -126,7 +126,7 @@ public partial class ConfigWindow // on the top-right corner of the window/tab. private void DrawRemoveSettings() { - const string text = "Remove Settings"; + const string text = "Inherit Settings"; if( _inherited || _emptySetting ) { return; diff --git a/Penumbra/UI/ConfigWindow.SettingsTab.General.cs b/Penumbra/UI/ConfigWindow.SettingsTab.General.cs index 7a735d06..e69fa219 100644 --- a/Penumbra/UI/ConfigWindow.SettingsTab.General.cs +++ b/Penumbra/UI/ConfigWindow.SettingsTab.General.cs @@ -91,6 +91,7 @@ public partial class ConfigWindow Penumbra.Config.AlwaysOpenDefaultImport, v => Penumbra.Config.AlwaysOpenDefaultImport = v ); DrawDefaultModImportPath(); DrawDefaultModAuthor(); + DrawDefaultModImportFolder(); ImGui.NewLine(); } @@ -225,5 +226,23 @@ public partial class ConfigWindow ImGuiUtil.LabeledHelpMarker( "Default Mod Author", "Set the default author stored for newly created mods." ); } + + private void DrawDefaultModImportFolder() + { + var tmp = Penumbra.Config.DefaultImportFolder; + ImGui.SetNextItemWidth( _window._inputTextWidth.X ); + if( ImGui.InputText( "##defaultImportFolder", ref tmp, 64 ) ) + { + Penumbra.Config.DefaultImportFolder = tmp; + } + + if( ImGui.IsItemDeactivatedAfterEdit() ) + { + Penumbra.Config.Save(); + } + + ImGuiUtil.LabeledHelpMarker( "Default Mod Import Folder", + "Set the default Penumbra mod folder to place newly imported mods into.\nLeave blank to import into Root." ); + } } } \ No newline at end of file