Skip to content

Commit

Permalink
[ModManager] Rename and Duplicate pack options (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyvinia committed Aug 11, 2023
1 parent 4fb2a33 commit 4610d3a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
6 changes: 4 additions & 2 deletions 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 Expand Up @@ -41,7 +43,7 @@ private void addButton_Click(object sender, RoutedEventArgs e)
return;
}

ProfileName = profileNameTextBox.Text;
ProfileName = profileNameTextBox.Text.Trim();
DialogResult = true;
Close();
}
Expand Down
6 changes: 6 additions & 0 deletions FrostyModManager/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@
<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" />
Expand Down
63 changes: 63 additions & 0 deletions FrostyModManager/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,69 @@ 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) {
FrostyPack newPack = new FrostyPack(newPackName);
foreach (var mod in oldPack.AppliedMods) {
newPack.AppliedMods.Add(mod);
}

Config.Add(newPackName, ConfigScope.Pack);
Config.Remove(oldPack.Name, ConfigScope.Pack);

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)
{
int selectedIndex = appliedModsList.SelectedIndex;
Expand Down

0 comments on commit 4610d3a

Please sign in to comment.