Skip to content

Commit

Permalink
Add right click menu options to remove all loaded or unloaded archives
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxEG committed Sep 17, 2022
1 parent 44f5036 commit 26efc16
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 23 deletions.
42 changes: 33 additions & 9 deletions BSA Browser/BSABrowser.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 46 additions & 14 deletions BSA Browser/BSABrowser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
using System;
using BSA_Browser.Classes;
using BSA_Browser.Dialogs;
using BSA_Browser.Enums;
using BSA_Browser.Extensions;
using BSA_Browser.Properties;
using BSA_Browser.Sorting;
using BSA_Browser.Tools;
using SharpBSABA2;
using SharpBSABA2.BA2Util;
using SharpBSABA2.Enums;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
Expand All @@ -12,16 +22,6 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using BSA_Browser.Classes;
using BSA_Browser.Dialogs;
using BSA_Browser.Enums;
using BSA_Browser.Extensions;
using BSA_Browser.Properties;
using BSA_Browser.Sorting;
using BSA_Browser.Tools;
using SharpBSABA2;
using SharpBSABA2.BA2Util;
using SharpBSABA2.Enums;

namespace BSA_Browser
{
Expand Down Expand Up @@ -69,6 +69,7 @@ public BSABrowser()
};
archiveNode.Loaded = true;
tvFolders.Nodes.Add(archiveNode);
tvFolders.ContextMenu = foldersContextMenu;

lvFiles.ContextMenu = contextMenu1;

Expand Down Expand Up @@ -1321,6 +1322,29 @@ private void unloadedRemoveMenuItem_Click(object sender, EventArgs e)

#endregion

#region foldersContextMenu

private void removeLoadedMenuItem_Click(object sender, EventArgs e)
{
this.CloseArchives(true);
}

private void removeUnloadedMenuItem_Click(object sender, EventArgs e)
{
for (int i = tvFolders.Nodes.Count - 1; i > 0; i--)
{
if (!(tvFolders.Nodes[i] as ArchiveNode).Loaded)
this.CloseArchive((ArchiveNode)tvFolders.Nodes[i]);
}

if (tvFolders.Nodes.Count == 1)
this.ClearList();
else
this.DoSearch();
}

#endregion

/// <summary>
/// Opens the given archive, adding it to the <see cref="tvFolders"/> and making it browsable, then returns containing <see cref="ArchiveNode"/>.
/// </summary>
Expand Down Expand Up @@ -1588,15 +1612,19 @@ private void CloseArchive(ArchiveNode archiveNode)
/// <summary>
/// Closes all open archives, clearing the <see cref="TreeView"/>.
/// </summary>
private void CloseArchives()
private void CloseArchives(bool loadedOnly = false)
{
this.ClearList();
if (!loadedOnly || this.SelectedArchiveNode.Loaded)
this.ClearList();

_pauseFiltering = true;
for (int i = tvFolders.Nodes.Count - 1; i > 0; i--)
{
var node = (ArchiveNode)tvFolders.Nodes[i];

if (loadedOnly && !node.Loaded)
continue;

if (node.Loaded)
{
node.Archive.Close();
Expand All @@ -1610,7 +1638,11 @@ private void CloseArchives()
GC.Collect();

// Disable buttons
btnExtractAllFolders.Enabled = btnExtractAll.Enabled = false;
if (tvFolders.GetNodeCount(false) == 1)
{
btnExtractAllFolders.Enabled = false;
btnExtractAll.Enabled = false;
}
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions BSA Browser/BSABrowser.resx
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,18 @@
<metadata name="archiveContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>421, 17</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>585, 17</value>
</metadata>
<metadata name="label2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="unloadedArchiveContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>948, 17</value>
</metadata>
<metadata name="foldersContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1165, 17</value>
</metadata>
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down

0 comments on commit 26efc16

Please sign in to comment.