Skip to content

Commit

Permalink
Rename and Duplicate pack options (#53)
Browse files Browse the repository at this point in the history
* Rename and Duplicate pack options

* Reimplement pack duplicate and rename

* Proper naming for Rename Profile and Duplicate Profile naming windows
  • Loading branch information
Dyvinia authored Apr 28, 2022
1 parent 1173d9e commit d5605bd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
4 changes: 3 additions & 1 deletion FrostyModManager/Windows/AddProfileWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public partial class AddProfileWindow : FrostyDockableWindow
{
public string ProfileName { get; set; }

public AddProfileWindow()
public AddProfileWindow(string title = "Add Profile")
{
InitializeComponent();

this.Title = title;

Window mainWin = Application.Current.MainWindow;
if (mainWin != null)
{
Expand Down
2 changes: 2 additions & 0 deletions FrostyModManager/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
<Menu Grid.Row="0">
<MenuItem Header="File" Height="22">
<MenuItem Header="Pack">
<MenuItem x:Name="packRename" Header="Rename" Click="packRename_Click"/>
<MenuItem x:Name="packDuplicate" Header="Duplicate" Click="packDuplicate_Click"/>
<MenuItem x:Name="packExport" Header="Export" Click="packExport_Click"/>
<MenuItem x:Name="packImport" Header="Import" Click="packImport_Click"/>
</MenuItem>
Expand Down
62 changes: 62 additions & 0 deletions FrostyModManager/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,68 @@ private void removeProfileButton_Click(object sender, RoutedEventArgs e)
}
}

private void packRename_Click(object sender, RoutedEventArgs e) {

AddProfileWindow win = new AddProfileWindow("Rename Pack");
win.ShowDialog();

if (win.DialogResult == true) {
string newPackName = win.ProfileName;
var oldPack = selectedPack;

FrostyPack existingPack = packs.Find((FrostyPack a) => {
return a.Name.CompareTo(newPackName) == 0;
});

if (existingPack == null) {
Config.Rename(oldPack.Name, newPackName, ConfigScope.Pack);

FrostyPack newPack = new FrostyPack(newPackName);
foreach (var mod in oldPack.AppliedMods) {
newPack.AppliedMods.Add(mod);
}

packs.Add(newPack);
packs.Remove(oldPack);

packsComboBox.Items.Refresh();
packsComboBox.SelectedItem = newPack;
}
else FrostyMessageBox.Show("A pack with the same name already exists", "Frosty Mod Manager");

}
}

private void packDuplicate_Click(object sender, RoutedEventArgs e) {

AddProfileWindow win = new AddProfileWindow("Duplicate Pack");
win.ShowDialog();

if (win.DialogResult == true) {
string newPackName = win.ProfileName;
var oldPack = selectedPack;

FrostyPack existingPack = packs.Find((FrostyPack a) => {
return a.Name.CompareTo(newPackName) == 0;
});

if (existingPack == null) {
Config.Add(newPackName, ConfigScope.Pack);

FrostyPack newPack = new FrostyPack(newPackName);
foreach (var mod in oldPack.AppliedMods) {
newPack.AppliedMods.Add(mod);
}

packs.Add(newPack);

packsComboBox.Items.Refresh();
packsComboBox.SelectedItem = newPack;
}
else FrostyMessageBox.Show("A pack with the same name already exists", "Frosty Mod Manager");
}
}

private void removeButton_Click(object sender, RoutedEventArgs e)
{
FrostyAppliedMod mod = appliedModsList.SelectedItem as FrostyAppliedMod;
Expand Down
18 changes: 18 additions & 0 deletions FrostyPlugin/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ internal void Remove(string option, ConfigScope scope = ConfigScope.Game)
}
}

internal void Rename(string option, string newoption, ConfigScope scope = ConfigScope.Game) {
if (scope == ConfigScope.Pack) {
if (Packs.ContainsKey(option)) {
Packs.TryGetValue(option, out var value);
Packs.Add(newoption, value);
Packs.Remove(option);
}

}
}

internal IEnumerable<string> EnumerateKeys(ConfigScope scope = ConfigScope.Game)
{
if (scope == ConfigScope.Game)
Expand Down Expand Up @@ -169,6 +180,13 @@ public static void Remove(string option, ConfigScope scope = ConfigScope.Global,
Current.GlobalOptions.Remove(option);
}

public static void Rename(string option, string newoption, ConfigScope scope = ConfigScope.Global, string profile = null) {
if (scope == ConfigScope.Game || scope == ConfigScope.Pack)
Current.Games[profile ?? ProfilesLibrary.ProfileName].Rename(option, newoption, scope);
else if (Current.GlobalOptions.ContainsKey(option))
Current.GlobalOptions.Remove(option);
}

/// <summary>
/// Determines whether the <see cref="Config"/> contains the specified key.
/// </summary>
Expand Down

0 comments on commit d5605bd

Please sign in to comment.