Skip to content

Commit

Permalink
Add new collapsing button to music library (fully or any listed), add…
Browse files Browse the repository at this point in the history
… tooltips
  • Loading branch information
Sogolumbo committed Jan 27, 2022
1 parent e55f89e commit 0ae27a0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 53 deletions.
27 changes: 25 additions & 2 deletions PlaylistSyncGUI/EditMusicLibraryForm.Designer.cs

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

116 changes: 65 additions & 51 deletions PlaylistSyncGUI/EditMusicLibraryForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public EditMusicLibraryForm()
{
InitializeComponent();
itemTypeComboBox.DataSource = Enum.GetValues(typeof(PlaylistItemType));
toolTip.SetToolTip(reduceListedButton, "Collapse folders in which all songs are contained in at least one playlist.");
toolTip.SetToolTip(reduceIfAnyIsListedButton, "Collapse folders in which any song is contained in at least one playlist.");
}

Form _libraryConfiguration;
Expand Down Expand Up @@ -583,6 +585,20 @@ private void OpenItem(string fullPath)
#endregion

#region Reduce and Expand (Tree view items)
private void reduceChildrenButton_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
var current = libraryTreeView.SelectedNode;
current.Collapse();
foreach (TreeNode child in current.Nodes)
{
child.Collapse(true);
}
current.Expand();
current.EnsureVisible();
Cursor = DefaultCursor;
libraryTreeView.Focus();
}
private void expandAllButton_Click(object sender, EventArgs e)
{
libraryTreeView.ExpandAll();
Expand All @@ -591,46 +607,62 @@ private void expandAllButton_Click(object sender, EventArgs e)
libraryTreeView.SelectedNode.EnsureVisible();
}
}

private void reduceAllButton_Click(object sender, EventArgs e)
{
libraryTreeView.CollapseAll();

foreach (TreeNode rootNode in libraryTreeView.Nodes)
{
rootNode.Expand();
TreeNode subject = rootNode;
while (subject.Nodes.Count == 1)
{
subject = subject.Nodes[0];
subject.Expand();
}
}
EnsureVisibilityOfLibraryBaseNodes();
}

private void reduceAllExceptMissingItemsButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(item => item is MusicLibraryMissingElement);
}
private void reduceAllExceptBadArtistItemsButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isArtistBad);
}
private void reduceNonlistedButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isListed);
}
private void reduceListedButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isNonlisted);
}
private void reduceIfAnyIsListedButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isNonlisted, true);
}

void ReduceAllTreeViewItemsExceptConditionMet(Func<MusicLibraryItem, bool> ConditionMet)
private void ReduceAllTreeViewItemsExceptConditionMet(Func<MusicLibraryItem, bool> ConditionMet, bool ConditionNeedsToBeMetByAll = false)
{
libraryTreeView.CollapseAll();

foreach (TreeNode rootNode in libraryTreeView.Nodes)
{
ExpandIfConditionMetRecursive(rootNode, ConditionMet);
ExpandIfConditionMetRecursive(rootNode, ConditionMet, ConditionNeedsToBeMetByAll);
}
}

bool ExpandIfConditionMetRecursive(TreeNode treeNode, Func<MusicLibraryItem, bool> ConditionMet)
if (ConditionNeedsToBeMetByAll)
{
EnsureVisibilityOfLibraryBaseNodes();
}
}
private bool ExpandIfConditionMetRecursive(TreeNode treeNode, Func<MusicLibraryItem, bool> ConditionMet, bool ConditionNeedsToBeMetByAll = false)
{
bool conditionMet = false;
bool conditionMet = ConditionNeedsToBeMetByAll;
if (treeNode.Nodes.Count > 0)
{
foreach (TreeNode node in treeNode.Nodes)
{
conditionMet |= ExpandIfConditionMetRecursive(node, ConditionMet);
if (ConditionNeedsToBeMetByAll)
{
conditionMet &= ExpandIfConditionMetRecursive(node, ConditionMet, ConditionNeedsToBeMetByAll);
}
else
{
conditionMet |= ExpandIfConditionMetRecursive(node, ConditionMet, ConditionNeedsToBeMetByAll);
}
}
if (conditionMet)
{
Expand All @@ -644,11 +676,6 @@ bool ExpandIfConditionMetRecursive(TreeNode treeNode, Func<MusicLibraryItem, boo
return conditionMet;
}

private void reduceAllExceptBadArtistItemsButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isArtistBad);
}

/// <summary>
/// Returns wether the item has music tags that don't fit to the parent folders. In most cases this means that the file is not well organized.
/// </summary>
Expand All @@ -660,34 +687,8 @@ private bool isArtistBad(MusicLibraryItem item)
}
return false;
}

private void reduceChildrenButton_Click(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
var current = libraryTreeView.SelectedNode;
current.Collapse();
foreach (TreeNode child in current.Nodes)
{
child.Collapse(true);
}
current.Expand();
current.EnsureVisible();
Cursor = DefaultCursor;
libraryTreeView.Focus();
}

private void reduceNonlistedButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isListed);
}
private void reduceListedButton_Click(object sender, EventArgs e)
{
ReduceAllTreeViewItemsExceptConditionMet(isNonlisted);

}

/// <summary>
/// Returns whether the item is in not in any playlist
/// Returns whether the item is in any playlist
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
Expand All @@ -703,6 +704,20 @@ private bool isNonlisted(MusicLibraryItem item)
{
return !isListed(item);
}

private void EnsureVisibilityOfLibraryBaseNodes()
{
foreach (TreeNode rootNode in libraryTreeView.Nodes)
{
rootNode.Expand();
TreeNode subject = rootNode;
while (subject.Nodes.Count == 1)
{
subject = subject.Nodes[0];
subject.Expand();
}
}
}
#endregion

#region Handle key presses
Expand Down Expand Up @@ -782,6 +797,5 @@ private void debugButton_Click(object sender, EventArgs e)
{
}
#endregion

}
}
6 changes: 6 additions & 0 deletions PlaylistSyncGUI/EditMusicLibraryForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>53</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down

0 comments on commit 0ae27a0

Please sign in to comment.