From cd9977a967bb4ca0b88b05e7a61be3532c78cb3a Mon Sep 17 00:00:00 2001 From: Brandon Chong Date: Tue, 4 Jun 2019 14:04:40 -0700 Subject: [PATCH 01/17] Refactor and split text parsing into different classes - Add TextSegment classes. - Add placeholder classes. Each placeholder will now be responsible for updating and providing its own values - Turn text parsing into a static method. The text parser no longer worries about maintaining state as that responsibility is moved to the segments --- src/AudioBand/AudioBand.csproj | 10 + .../TextFormatting/AlbumNamePlaceholder.cs | 25 ++ .../TextFormatting/FormattedTextParser.cs | 245 +++--------------- .../TextFormatting/PlaceholderTextSegment.cs | 34 +++ .../TextFormatting/SongArtistPlaceholder.cs | 25 ++ .../TextFormatting/SongLengthPlaceholder.cs | 25 ++ .../TextFormatting/SongNamePlaceholder.cs | 25 ++ .../TextFormatting/SongProgressPlaceholder.cs | 25 ++ .../TextFormatting/StaticTextSegment.cs | 24 ++ .../TextFormatting/TextPlaceholder.cs | 49 ++++ .../TextFormatting/TextPlaceholderFactory.cs | 45 ++++ .../TextPlaceholderParameter.cs | 18 ++ src/AudioBand/TextFormatting/TextSegment.cs | 24 +- .../ViewModels/CustomLabelViewModel.cs | 48 +--- 14 files changed, 362 insertions(+), 260 deletions(-) create mode 100644 src/AudioBand/TextFormatting/AlbumNamePlaceholder.cs create mode 100644 src/AudioBand/TextFormatting/PlaceholderTextSegment.cs create mode 100644 src/AudioBand/TextFormatting/SongArtistPlaceholder.cs create mode 100644 src/AudioBand/TextFormatting/SongLengthPlaceholder.cs create mode 100644 src/AudioBand/TextFormatting/SongNamePlaceholder.cs create mode 100644 src/AudioBand/TextFormatting/SongProgressPlaceholder.cs create mode 100644 src/AudioBand/TextFormatting/StaticTextSegment.cs create mode 100644 src/AudioBand/TextFormatting/TextPlaceholder.cs create mode 100644 src/AudioBand/TextFormatting/TextPlaceholderFactory.cs create mode 100644 src/AudioBand/TextFormatting/TextPlaceholderParameter.cs diff --git a/src/AudioBand/AudioBand.csproj b/src/AudioBand/AudioBand.csproj index 5205809e..45885066 100644 --- a/src/AudioBand/AudioBand.csproj +++ b/src/AudioBand/AudioBand.csproj @@ -182,6 +182,16 @@ + + + + + + + + + + diff --git a/src/AudioBand/TextFormatting/AlbumNamePlaceholder.cs b/src/AudioBand/TextFormatting/AlbumNamePlaceholder.cs new file mode 100644 index 00000000..d715d9f2 --- /dev/null +++ b/src/AudioBand/TextFormatting/AlbumNamePlaceholder.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace AudioBand.TextFormatting +{ + /// + /// A with the value based on the album name. + /// + public class AlbumNamePlaceholder : TextPlaceholder + { + /// + /// Initializes a new instance of the class. + /// + /// The placeholder parameters. + public AlbumNamePlaceholder(IEnumerable parameters) + : base(parameters) + { + } + + /// + public override string GetText() + { + return "album name"; + } + } +} diff --git a/src/AudioBand/TextFormatting/FormattedTextParser.cs b/src/AudioBand/TextFormatting/FormattedTextParser.cs index 848e99ec..39339450 100644 --- a/src/AudioBand/TextFormatting/FormattedTextParser.cs +++ b/src/AudioBand/TextFormatting/FormattedTextParser.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.Text; using System.Text.RegularExpressions; using System.Windows.Media; -using AudioBand.Extensions; namespace AudioBand.TextFormatting { @@ -15,239 +13,107 @@ internal class FormattedTextParser { private const char PlaceholderStartToken = '{'; private const char PlaceholderEndToken = '}'; - private const string ArtistPlaceholder = "artist"; - private const string SongNamePlaceholder = "song"; - private const string AlbumNamePlaceholder = "album"; - private const string CurrentTimePlaceholder = "time"; - private const string SongLengthPlaceholder = "length"; private const string BoldStyle = "*"; private const string ItalicsStyle = "&"; private const string UnderlineStyle = "_"; private const string Styles = BoldStyle + ItalicsStyle + UnderlineStyle; - private const string Tags = ArtistPlaceholder + "|" + SongNamePlaceholder + "|" + AlbumNamePlaceholder + "|" + CurrentTimePlaceholder + "|" + SongLengthPlaceholder; + private static readonly string Tags = string.Join("|", TextPlaceholderFactory.Tags); private static readonly Regex PlaceholderPattern = new Regex($@"(? - @@ -189,35 +221,36 @@ - + + Opacity="0" /> + Opacity="1" /> + Width="{TemplateBinding Height}" + Height="{TemplateBinding Height}" + HorizontalAlignment="Left"> + Fill="{theme:ThemeResource SystemBaseHighColor}" /> @@ -241,7 +274,7 @@ - + @@ -250,7 +283,7 @@ - + @@ -258,7 +291,7 @@ - + @@ -272,24 +305,24 @@ - - diff --git a/src/AudioBand/Resources/ComboBoxStyles.xaml b/src/AudioBand/Resources/ComboBoxStyles.xaml index 6a7ae951..9384e96e 100644 --- a/src/AudioBand/Resources/ComboBoxStyles.xaml +++ b/src/AudioBand/Resources/ComboBoxStyles.xaml @@ -4,38 +4,41 @@ xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:theme="clr-namespace:AudioBand.Resources.Theming"> - - + + - - - - + + + - + \ No newline at end of file diff --git a/src/AudioBand/Resources/ContextMenuStyles.xaml b/src/AudioBand/Resources/ContextMenuStyles.xaml index 546bf264..47b00804 100644 --- a/src/AudioBand/Resources/ContextMenuStyles.xaml +++ b/src/AudioBand/Resources/ContextMenuStyles.xaml @@ -1,44 +1,56 @@  + xmlns:resources="clr-namespace:AudioBand.Resources" + xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:theme="clr-namespace:AudioBand.Resources.Theming"> - + - + diff --git a/src/AudioBand/Resources/Icons.xaml b/src/AudioBand/Resources/Icons.xaml index 71f04b5d..9ccd6b71 100644 --- a/src/AudioBand/Resources/Icons.xaml +++ b/src/AudioBand/Resources/Icons.xaml @@ -1,7 +1,7 @@  12 @@ -10,15 +10,25 @@ - + - + - + @@ -31,13 +41,21 @@ - + - + @@ -51,7 +69,11 @@ - + @@ -64,13 +86,21 @@ - + - + @@ -84,20 +114,34 @@ - + - + - + - + @@ -110,23 +154,37 @@ - + - + - + - + - + @@ -142,29 +200,47 @@ - + - + - + - + - + - + @@ -178,13 +254,27 @@ - + - + @@ -202,42 +292,70 @@ - + - + - + - + - + - + - + - + @@ -250,12 +368,20 @@ - + - + @@ -268,27 +394,47 @@ - + - + - + - + - + diff --git a/src/AudioBand/Resources/NavigationPaneStyles.xaml b/src/AudioBand/Resources/NavigationPaneStyles.xaml index 6ce96978..406063ab 100644 --- a/src/AudioBand/Resources/NavigationPaneStyles.xaml +++ b/src/AudioBand/Resources/NavigationPaneStyles.xaml @@ -1,73 +1,88 @@  + xmlns:local="clr-namespace:AudioBand.Resources" + xmlns:theme="clr-namespace:AudioBand.Resources.Theming" + xmlns:valueConverters="clr-namespace:AudioBand.ValueConverters"> - + \ No newline at end of file diff --git a/src/AudioBand/Resources/NumericInputStyles.xaml b/src/AudioBand/Resources/NumericInputStyles.xaml index dbadac0b..ee33dd00 100644 --- a/src/AudioBand/Resources/NumericInputStyles.xaml +++ b/src/AudioBand/Resources/NumericInputStyles.xaml @@ -1,34 +1,34 @@  - + - diff --git a/src/AudioBand/Resources/PasswordBoxStyles.xaml b/src/AudioBand/Resources/PasswordBoxStyles.xaml index fbbb3945..1ef1e1d7 100644 --- a/src/AudioBand/Resources/PasswordBoxStyles.xaml +++ b/src/AudioBand/Resources/PasswordBoxStyles.xaml @@ -4,41 +4,46 @@ xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" xmlns:theming="clr-namespace:AudioBand.Resources.Theming"> - - + + - \ No newline at end of file diff --git a/src/AudioBand/Resources/ScrollbarStyle.xaml b/src/AudioBand/Resources/ScrollbarStyle.xaml index 27ba6fe7..48094ac3 100644 --- a/src/AudioBand/Resources/ScrollbarStyle.xaml +++ b/src/AudioBand/Resources/ScrollbarStyle.xaml @@ -1,8 +1,8 @@  + xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:theme="clr-namespace:AudioBand.Resources.Theming"> 14 0:0:0.1 0:0:0.3 @@ -16,6 +16,12 @@ + @@ -42,9 +48,6 @@ - - @@ -70,23 +73,23 @@ - + - + - + - + - + @@ -98,53 +101,83 @@ - - - + + + - + - + - + - + - + - - - - + + + + - - - - + + + + @@ -160,19 +193,27 @@ - - + + - + - + - + - + diff --git a/src/AudioBand/Resources/SettingsWindowStyle.xaml b/src/AudioBand/Resources/SettingsWindowStyle.xaml index 40b30c29..24a6cf30 100644 --- a/src/AudioBand/Resources/SettingsWindowStyle.xaml +++ b/src/AudioBand/Resources/SettingsWindowStyle.xaml @@ -1,35 +1,35 @@  + xmlns:sys="clr-namespace:System;assembly=mscorlib"> - + - - - - - - - - - - - + + + + + + + + + + + - - - - - - \ No newline at end of file diff --git a/src/AudioBand/Resources/Shared.xaml b/src/AudioBand/Resources/Shared.xaml index 81972fe7..3623125d 100644 --- a/src/AudioBand/Resources/Shared.xaml +++ b/src/AudioBand/Resources/Shared.xaml @@ -1,16 +1,20 @@  + xmlns:theme="clr-namespace:AudioBand.Resources.Theming"> - + 2 - + #88FFFFFF 32 32 @@ -21,61 +25,60 @@ 34 30 18 - + - - - + + + - - - + + + - - + + - + - + - + - + 0.6 - + - - + + - - - + + + - - - + + + diff --git a/src/AudioBand/Resources/Strings.xaml b/src/AudioBand/Resources/Strings.xaml index 2f8d549c..e6a9b5e5 100644 --- a/src/AudioBand/Resources/Strings.xaml +++ b/src/AudioBand/Resources/Strings.xaml @@ -1,7 +1,7 @@  - + Width Height Visibility @@ -21,14 +21,14 @@ Background color Change the relative positioning of the control - + Play button content Pause button content - + Button content - + Button Image Button image when hovered Button image when clicked @@ -37,16 +37,16 @@ Select the font family for the text Button text - + Repeat off button content Repeat on button content Repeat track button content - + Shuffle off button content Shuffle on button content - + Label name Choose a name for the label Font Family @@ -81,7 +81,7 @@ Showing the album name in bold : {*album} Showing the song progress in gray : {time:#A9A9A9} : {length:#A9A9A9} Using style and color : {*artist:#a9a9a9} - + General Playback Controls Play/Pause Button @@ -99,7 +99,7 @@ Using style and color : {*artist:#a9a9a9} Add a new label Delete this label - + Reset Settings Browse Default @@ -119,17 +119,17 @@ Using style and color : {*artist:#a9a9a9} This setting will be saved. Are you sure? Remember - + Colors Foreground color Background color Background color when hovered - + Image Placeholder image - + About AudioBand Delete label Are you sure you want to delete the label '{0}'? @@ -145,7 +145,7 @@ Using style and color : {*artist:#a9a9a9} Delete profile Are you sure you want to delete the profile '{0}' - + New profile Delete the current profile Rename the current profile @@ -153,7 +153,7 @@ Using style and color : {*artist:#a9a9a9} Export profiles Default Profile - + Click here to reset No image selected \ No newline at end of file diff --git a/src/AudioBand/Resources/TextBoxStyles.xaml b/src/AudioBand/Resources/TextBoxStyles.xaml index 50dedff0..3cc1caff 100644 --- a/src/AudioBand/Resources/TextBoxStyles.xaml +++ b/src/AudioBand/Resources/TextBoxStyles.xaml @@ -5,41 +5,46 @@ xmlns:theme="clr-namespace:AudioBand.Resources.Theming"> - - + + - - - - \ No newline at end of file diff --git a/src/AudioBand/Resources/ToolbarButtonStyles.xaml b/src/AudioBand/Resources/ToolbarButtonStyles.xaml index a8d09a04..4d34c0fc 100644 --- a/src/AudioBand/Resources/ToolbarButtonStyles.xaml +++ b/src/AudioBand/Resources/ToolbarButtonStyles.xaml @@ -1,22 +1,32 @@  - - + + - - + + @@ -25,8 +35,7 @@ - + @@ -35,10 +44,9 @@ - + - + @@ -48,10 +56,9 @@ - + - + @@ -61,10 +68,8 @@ - - + + @@ -73,11 +78,13 @@ - - + + - + @@ -88,12 +95,23 @@ - - + + - + @@ -109,11 +127,11 @@ - - - - - + + + + + @@ -122,17 +140,19 @@ - - - - - + + + + + - + @@ -141,12 +161,12 @@ 0:0:0.1 - + - - + + @@ -156,8 +176,8 @@ - - + + @@ -166,8 +186,8 @@ - - + + @@ -176,111 +196,116 @@ - + - + - + - - + + - + - + - + - + - + diff --git a/src/AudioBand/Resources/ToolbarContextMenuStyles.xaml b/src/AudioBand/Resources/ToolbarContextMenuStyles.xaml index e924fa45..64e203e3 100644 --- a/src/AudioBand/Resources/ToolbarContextMenuStyles.xaml +++ b/src/AudioBand/Resources/ToolbarContextMenuStyles.xaml @@ -2,29 +2,34 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:fluentWpf="clr-namespace:SourceChord.FluentWPF;assembly=FluentWPF"> #44FFFFFF - + #44ffffff - + #AA000000 - + + None diff --git a/src/AudioBand/Resources/ToolbarProgressBarStyle.xaml b/src/AudioBand/Resources/ToolbarProgressBarStyle.xaml index 0a58a863..4196431a 100644 --- a/src/AudioBand/Resources/ToolbarProgressBarStyle.xaml +++ b/src/AudioBand/Resources/ToolbarProgressBarStyle.xaml @@ -1,28 +1,28 @@  - + - + - + Style="{StaticResource SliderRepeatButtonStyle}" /> - + Style="{StaticResource SliderRepeatButtonStyle}" /> - + - + 3 @@ -86,7 +94,7 @@ - + 3 @@ -103,7 +111,9 @@ + From="0" + To="1" + Duration="0:0:0.1" /> @@ -114,7 +124,9 @@ + From="1" + To="0" + Duration="0:0:0.1" /> @@ -127,11 +139,11 @@ - - - - - + + + + + diff --git a/src/AudioBand/Resources/Tooltips.xaml b/src/AudioBand/Resources/Tooltips.xaml index a6b8e039..ee3ea34a 100644 --- a/src/AudioBand/Resources/Tooltips.xaml +++ b/src/AudioBand/Resources/Tooltips.xaml @@ -1,23 +1,26 @@  + xmlns:resources="clr-namespace:AudioBand.Resources" + xmlns:theme="clr-namespace:AudioBand.Resources.Theming"> - + - + - + - @@ -167,13 +191,15 @@ - + - + TextOverflow="{Binding TextOverflow}" /> - - - + - + Opacity="0" + TextAlignment="{Binding TextAlignment, Converter={x:Static converters:Converters.TextAlignment}}" + TextTrimming="None" + TextWrapping="NoWrap" + Visibility="{Binding IsVisible, Converter={x:Static converters:Converters.BoolToVisibility}}" /> diff --git a/src/AudioBand/Views/Dialogs/AboutDialog.xaml b/src/AudioBand/Views/Dialogs/AboutDialog.xaml index 0802041b..40f17494 100644 --- a/src/AudioBand/Views/Dialogs/AboutDialog.xaml +++ b/src/AudioBand/Views/Dialogs/AboutDialog.xaml @@ -1,43 +1,47 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" + xmlns:behaviors="clr-namespace:AudioBand.Behaviors" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:resources="clr-namespace:AudioBand.Resources" + xmlns:theme="clr-namespace:AudioBand.Resources.Theming" + xmlns:viewmodels="clr-namespace:AudioBand.ViewModels" + Title="About Audio Band" + Width="600" + Height="500" + d:DesignHeight="450" + d:DesignWidth="800" + Background="{theme:ThemeResource SystemAltHighColor}" + Foreground="{theme:ThemeResource SystemBaseHighColor}" + Icon="pack://application:,,,/AudioBand;component/audioband.ico" + WindowStartupLocation="CenterScreen" + mc:Ignorable="d"> - - + + - - + + - + - - + + - + @@ -53,57 +57,77 @@ - - + + - - + + - + - + - - + - - - + + + - - + + - - + + - + - + - + - - diff --git a/src/AudioBand/Views/Settings/CustomLabelSettingsView.xaml b/src/AudioBand/Views/Settings/CustomLabelSettingsView.xaml index c882d5d0..81df32ce 100644 --- a/src/AudioBand/Views/Settings/CustomLabelSettingsView.xaml +++ b/src/AudioBand/Views/Settings/CustomLabelSettingsView.xaml @@ -1,47 +1,54 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:behaviors="clr-namespace:AudioBand.Behaviors" + xmlns:converters="clr-namespace:AudioBand.ValueConverters" + xmlns:local="clr-namespace:AudioBand.Views.Settings" + xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:models="clr-namespace:AudioBand.Models" + xmlns:resources="clr-namespace:AudioBand.Resources" + xmlns:theming="clr-namespace:AudioBand.Resources.Theming" + xmlns:viewmodels="clr-namespace:AudioBand.ViewModels"> - - - - - + + + + + - - - - + + + + - - - . + + + + . - + - - + + @@ -51,9 +58,8 @@ - - + + @@ -62,74 +68,116 @@ - - - + + + - + - - - Tags - - Styles - - Colors - - Example formats - + + + Tags + + Styles + + Colors + + Example formats + - - - - - - - - + + + + + + + + - - - + + + - - - - + + + + - - - - - + + + + + - - - - + - + Style="{StaticResource NavigationPaneRadioButton}"> - - - + + + - - - @@ -201,27 +250,33 @@ - + - + - + - + Style="{StaticResource NavigationPaneRadioButton}"> - - + + - - + + @@ -230,136 +285,162 @@ - - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/AudioBand/Views/Settings/ShuffleModeButtonSettingsView.xaml b/src/AudioBand/Views/Settings/ShuffleModeButtonSettingsView.xaml index 79416597..9b589099 100644 --- a/src/AudioBand/Views/Settings/ShuffleModeButtonSettingsView.xaml +++ b/src/AudioBand/Views/Settings/ShuffleModeButtonSettingsView.xaml @@ -1,32 +1,43 @@  + xmlns:resources="clr-namespace:AudioBand.Resources" + xmlns:viewmodels="clr-namespace:AudioBand.ViewModels"> - - - - + + + + - + - - + + - - + + - +