Skip to content

Commit

Permalink
Adding Show All/Hide All operations for LaunchBox Platform visibility…
Browse files Browse the repository at this point in the history
… and also some explanation as to how the tool is changing the visibility of platforms.
  • Loading branch information
dreasgrech committed May 24, 2022
1 parent d0e65ad commit 2f688d1
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 13 deletions.
91 changes: 89 additions & 2 deletions DROMsM/Forms/LaunchBoxPlatformsForm.Designer.cs

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

83 changes: 72 additions & 11 deletions DROMsM/Forms/LaunchBoxPlatformsForm.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Frontend;

Expand All @@ -12,6 +10,8 @@ public partial class LaunchBoxPlatformsForm : Form
{
private LaunchBoxManager launchBoxManager;

private List<LaunchBoxPlatform> launchBoxPlatforms;

public LaunchBoxPlatformsForm()
{
InitializeComponent();
Expand All @@ -35,9 +35,10 @@ public bool Initialize()
}

launchBoxManager = new LaunchBoxManager(launchBoxDirectory);
var platformsCollection = launchBoxManager.GetPlatforms();
launchBoxPlatforms = launchBoxManager.GetPlatforms();

olvLaunchBoxPlatformsListView.SetObjects(platformsCollection);
// Bind the platforms list to the list view
olvLaunchBoxPlatformsListView.SetObjects(launchBoxPlatforms);

return true;
}
Expand All @@ -49,26 +50,86 @@ private void olvLaunchBoxPlatformsListView_SubItemChecking(object sender, Bright
var newVisibilityValue = e.NewValue == CheckState.Checked;

// Change the platform's visibility
var platformVisibilityChanged = launchBoxManager.SetPlatformVisibility(platform, newVisibilityValue);
var platformVisibilityChanged = SetPlatformVisibility(platform, newVisibilityValue);

// If we weren't able to successfully change the visibility of a platform, leave the list view item checkbox unchanged
if (!platformVisibilityChanged)
{
e.Canceled = true;
Logger.LogError($"Unable to change platform {platform.Name}'s visibility to {GetVisibilityVerb(newVisibilityValue)}");

return;
}

// Refresh the model in the list view since it's now been updated
olvLaunchBoxPlatformsListView.RefreshObject(platform);
}

Logger.Log($"Changed platform {platform.Name}'s visibility to {GetVisibilityVerb(newVisibilityValue)}.");
private void SetAllPlatformsVisibility(bool newVisibility)
{
var totalPlatforms = launchBoxPlatforms.Count;
var visibleVerb = GetVisibilityVerb(newVisibility);
var confirmResult = MessageBoxOperations.ShowConfirmation($"Are you sure you want set the visibility of all {totalPlatforms} platforms to {visibleVerb}?", $"Setting {totalPlatforms} platforms to {visibleVerb}");
if (!confirmResult)
{
return;
}

int totalPlatformsSet = 0;
Parallel.ForEach(launchBoxPlatforms, platform =>
{
var platformVisibilityChanged = SetPlatformVisibility(platform, newVisibility);
if (platformVisibilityChanged)
{
Interlocked.Increment(ref totalPlatformsSet);
}
});

olvLaunchBoxPlatformsListView.RefreshObjects(launchBoxPlatforms);

Logger.Log($"Set the visibility of {totalPlatformsSet} LaunchBox platforms to {visibleVerb}.");
}

private bool SetPlatformVisibility(LaunchBoxPlatform platform, bool visibility)
{
var platformVisibilityChanged = launchBoxManager.SetPlatformVisibility(platform, visibility);
if (platformVisibilityChanged)
{
Logger.Log($"Changed LaunchBox platform {platform.Name}'s visibility to {GetVisibilityVerb(visibility)}.");
return true;
}


Logger.LogError($"Unable to change LaunchBox platform {platform.Name}'s visibility to {GetVisibilityVerb(visibility)}");

return false;
}

private void showAllToolStripMenuItem_Click(object sender, System.EventArgs e)
{
SetAllPlatformsVisibility(true);
}

private void hideAllToolStripMenuItem_Click(object sender, System.EventArgs e)
{
SetAllPlatformsVisibility(false);
}

private static string GetVisibilityVerb(bool visibility)
{
return visibility ? "visible" : "hidden";
}

private void closeToolStripMenuItem_Click(object sender, System.EventArgs e)
{
Close();
}

private void howDoesThisWorkToolStripMenuItem_Click(object sender, System.EventArgs e)
{
var text = @"Launchbox keeps a record of your platforms in XML files in the Data\Platforms directory.
By changing the file extension of these individual files, we can hide or show platforms in LaunchBox and that's what this tool does.";

MessageBoxOperations.ShowInformation(text, "How are the LaunchBox platforms changing visibility?");
}
}
}
3 changes: 3 additions & 0 deletions DROMsM/Forms/LaunchBoxPlatformsForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

0 comments on commit 2f688d1

Please sign in to comment.