Skip to content

Commit

Permalink
Add ability to change number of sound buttons per page (with undo)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo committed Aug 23, 2019
1 parent abcffde commit 1c5e1fe
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 247 deletions.
84 changes: 84 additions & 0 deletions SoundBoard/ButtonGridDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<soundBoard:ChildWindowBase x:Class="SoundBoard.ButtonGridDialog" x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:soundBoard="clr-namespace:SoundBoard"
mc:Ignorable="d"

Title="Change Button Grid"
IsModal="true"
Padding="100"
ShowCloseButton="true"
AllowMove="true"
CloseByEscape="true">

<simpleChildWindow:ChildWindow.OverlayBrush>
<SolidColorBrush Opacity="0.7" Color="{StaticResource BlackColor}" />
</simpleChildWindow:ChildWindow.OverlayBrush>

<!-- Content -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="20"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>

<xctk:IntegerUpDown x:Name="RowUpDown"
Grid.Column="1"
Minimum="1"
ValueChanged="RowUpDown_ValueChanged"
DefaultValue="5"
DisplayDefaultValueOnEmptyText="true"
KeyUp="RowUpDown_KeyUp"/>
<Label Grid.Column="2" Content="Row(s)"/>
<Label Grid.Column="4" Content=""/>
<xctk:IntegerUpDown x:Name="ColumnUpDown"
Grid.Column="6"
Minimum="1"
ValueChanged="ColumnUpDown_ValueChanged"
DefaultValue="2"
DisplayDefaultValueOnEmptyText="true"
KeyUp="ColumnUpDown_KeyUp"/>
<Label Grid.Column="7" Content="Column(s)"/>
</Grid>

<Label x:Name="WarningLabel"
HorizontalAlignment="Center"
Grid.Row="4" Content="Warning! Removing row(s) or column(s) could result in losing sounds!"
Foreground="Red"
FontWeight="Medium"
Visibility="Hidden"/>

<Grid Grid.Row="5" Margin="20, 20, 20, 20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<Button Grid.Column="1" Content="OK" Style="{StaticResource MyAccentedSquareButtonStyle}" Width="80" Height="35" Click="OKButton_Click"/>
<Button Grid.Column="3" Content="Cancel" Style="{StaticResource MySquareButtonStyle}" Width="80" Height="35" Click="CancelButton_Click"/>
</Grid>
</Grid>
</soundBoard:ChildWindowBase>
132 changes: 132 additions & 0 deletions SoundBoard/ButtonGridDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#region Usings

using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;

#endregion

namespace SoundBoard
{
/// <summary>
/// Interaction logic for ButtonGridDialog.xaml
/// </summary>
internal partial class ButtonGridDialog
{
#region Constructor

/// <summary>
/// Constructor
/// </summary>
public ButtonGridDialog()
{
InitializeComponent();
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="startingRowCount"></param>
/// <param name="startingColumnCount"></param>
public ButtonGridDialog(int startingRowCount, int startingColumnCount) : this()
{
RowCount = _startingRowCount = startingRowCount;
ColumnCount = _startingColumnCount = startingColumnCount;
}

#endregion

#region Public properties

/// <summary>
/// The result of the dialog
/// </summary>
public DialogResult DialogResult;

/// <summary>
/// Number of rows
/// </summary>
public int RowCount
{
get => RowUpDown.Value ?? default;
set => RowUpDown.Value = value;
}

/// <summary>
/// Number of columns
/// </summary>
public int ColumnCount
{
get => ColumnUpDown.Value ?? default;
set => ColumnUpDown.Value = value;
}

#endregion

#region Private fields

private readonly int _startingRowCount;

private readonly int _startingColumnCount;

#endregion

#region Event handlers

private void OKButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}

private void CancelButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}

private void ColumnUpDown_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
DialogResult = DialogResult.OK;
Close();
}
}

private void RowUpDown_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
DialogResult = DialogResult.OK;
Close();
}
}

private void RowUpDown_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
ShowHideWarningLabel();
}

private void ColumnUpDown_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
ShowHideWarningLabel();
}

#endregion

#region Private methods

private void ShowHideWarningLabel()
{
if (WarningLabel is null == false)
{
WarningLabel.Visibility = RowUpDown.Value < _startingRowCount || ColumnUpDown.Value < _startingColumnCount
? Visibility.Visible
: Visibility.Hidden;
}
}

#endregion
}
}
18 changes: 18 additions & 0 deletions SoundBoard/Buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,24 @@ void timer_Elapsed(object sender, EventArgs e)
};
}

/// <summary>
/// Returns the row
/// </summary>
/// <returns></returns>
public int GetRow()
{
return Grid.GetRow(this);
}

/// <summary>
/// Returns the column
/// </summary>
/// <returns></returns>
public int GetColumn()
{
return Grid.GetColumn(this);
}

#endregion

#region Private methods
Expand Down
39 changes: 39 additions & 0 deletions SoundBoard/ChildWindowBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#region Usings

using System.Collections.Generic;
using MahApps.Metro.SimpleChildWindow;

#endregion

namespace SoundBoard
{
/// <summary>
/// Defines a ChildWindow from which all other ChildWindows in this project shall derive
/// </summary>
internal class ChildWindowBase : ChildWindow
{
#region Constructor

/// <summary>
/// Constructor
/// </summary>
public ChildWindowBase()
{
_instances.Add(this);
}

#endregion

#region Public properties

public static IEnumerable<ChildWindowBase> Instances => _instances;

#endregion

#region Private fields

private static readonly List<ChildWindowBase> _instances = new List<ChildWindowBase>();

#endregion
}
}
79 changes: 79 additions & 0 deletions SoundBoard/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,85 @@ public static bool IsSelectedItem(this TabItem tabItem)
{
return tabItem == (tabItem.Parent as TabControl)?.SelectedItem;
}

#region Rows property

/// <summary>
/// Get the Rows property
/// </summary>
/// <param name="tabItem"></param>
/// <returns></returns>
public static int GetRows(this TabItem tabItem)
{
if (_rows.TryGetValue(tabItem, out int result))
{
return result;
}
else return GetDefaultRows(tabItem);
}

/// <summary>
/// Set the Rows property
/// </summary>
/// <param name="tabItem"></param>
/// <param name="value"></param>
public static void SetRows(this TabItem tabItem, int value)
{
_rows[tabItem] = value;
}

/// <summary>
/// Get the default value for the Rows property
/// </summary>
/// <param name="tabItem"></param>
public static int GetDefaultRows(this TabItem tabItem)
{
return 5;
}

private static readonly Dictionary<TabItem, int> _rows = new Dictionary<TabItem, int>();

#endregion

#region Columns property

/// <summary>
/// Get the Columns property
/// </summary>
/// <param name="tabItem"></param>
/// <returns></returns>
public static int GetColumns(this TabItem tabItem)
{
if (_columns.TryGetValue(tabItem, out int result))
{
return result;
}
else return GetDefaultColumns(tabItem);
}

/// <summary>
/// Set the Columns property
/// </summary>
/// <param name="tabItem"></param>
/// <param name="value"></param>
public static void SetColumns(this TabItem tabItem, int value)
{
_columns[tabItem] = value;
}

/// <summary>
/// Get the default value for the Columns property
/// </summary>
/// <param name="tabItem"></param>
/// <returns></returns>
public static int GetDefaultColumns(this TabItem tabItem)
{
return 2;
}

private static readonly Dictionary<TabItem, int> _columns = new Dictionary<TabItem, int>();

#endregion
}

#endregion
Expand Down
Loading

0 comments on commit 1c5e1fe

Please sign in to comment.