Fixed Systray NotifyPropertyChanged, shortcut setting window
This commit is contained in:
27
Views/DelegateCommand.cs
Normal file
27
Views/DelegateCommand.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public class DelegateCommand : ICommand
|
||||
{
|
||||
public Action CommandAction { get; set; }
|
||||
public Func<bool> CanExecuteFunc { get; set; }
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
CommandAction();
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return CanExecuteFunc == null || CanExecuteFunc();
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
xmlns:local="clr-namespace:unison"
|
||||
mc:Ignorable="d"
|
||||
Title="unison"
|
||||
Closing="Window_Closing" Icon="/unison.ico" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight">
|
||||
Closing="Window_Closing" Icon="/images/unison.ico" ResizeMode="CanMinimize" SizeToContent="WidthAndHeight">
|
||||
|
||||
<Grid Background="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" MinHeight="270">
|
||||
<Grid x:Name="TopLayout" Margin="10,0,10,0" VerticalAlignment="Stretch" Width="Auto" Height="Auto">
|
||||
|
@ -6,7 +6,7 @@
|
||||
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
|
||||
xmlns:local="clr-namespace:unison"
|
||||
mc:Ignorable="d"
|
||||
Closing="Window_Closing" Title="Settings" ResizeMode="CanMinimize" Icon="/unison.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
|
||||
Closing="Window_Closing" Title="Settings" ResizeMode="CanMinimize" Icon="/images/unison.ico" WindowStyle="ToolWindow" SizeToContent="WidthAndHeight">
|
||||
<Grid>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TabControl Margin="10">
|
||||
@ -68,6 +68,47 @@
|
||||
</DockPanel>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="Shortcuts">
|
||||
<DockPanel Margin="8">
|
||||
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<emoji:TextBlock Text="⌨️ Shortcuts"/>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid MinWidth="220">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="Next track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="0" Margin="1"/>
|
||||
<TextBlock Text="Previous track" TextWrapping="Wrap" Grid.Column="0" Grid.Row="1" Margin="1"/>
|
||||
<TextBlock Text="Play / Pause" TextWrapping="Wrap" Grid.Column="0" Grid.Row="2" Margin="1"/>
|
||||
<TextBlock Text="Volume up" TextWrapping="Wrap" Grid.Column="0" Grid.Row="3" Margin="1"/>
|
||||
<TextBlock Text="Volume down" TextWrapping="Wrap" Grid.Column="0" Grid.Row="4" Margin="1"/>
|
||||
<TextBlock Text="Show window" TextWrapping="Wrap" Grid.Column="0" Grid.Row="5" Margin="1"/>
|
||||
|
||||
<TextBlock Text="ctrl + media_next" TextWrapping="Wrap" Grid.Column="1" Grid.Row="0" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
|
||||
<TextBlock Text="ctrl + media_prev" TextWrapping="Wrap" Grid.Column="1" Grid.Row="1" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
|
||||
<TextBlock Text="ctrl + media_play" TextWrapping="Wrap" Grid.Column="1" Grid.Row="2" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
|
||||
<TextBlock Text="ctrl + volume_up" TextWrapping="Wrap" Grid.Column="1" Grid.Row="3" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
|
||||
<TextBlock Text="ctrl + volume_down" TextWrapping="Wrap" Grid.Column="1" Grid.Row="4" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
|
||||
<TextBlock Text="ctrl + alt + enter" TextWrapping="Wrap" Grid.Column="1" Grid.Row="5" Margin="1" HorizontalAlignment="Right" FontWeight="Bold"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</DockPanel>
|
||||
</TabItem>
|
||||
|
||||
<TabItem Header="About" Height="20" VerticalAlignment="Bottom">
|
||||
<DockPanel Margin="8">
|
||||
<GroupBox DockPanel.Dock="Top" Padding="0,4,0,0">
|
||||
|
@ -1,16 +1,15 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:local="clr-namespace:unison">
|
||||
|
||||
<tb:TaskbarIcon x:Name="SystrayTaskbar" xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
|
||||
IconSource="/unison.ico" ToolTipText="{Binding GetAppText}" DoubleClickCommand="{Binding ShowWindowCommand}" x:Key="SystrayTaskbar">
|
||||
IconSource="/images/unison.ico" ToolTipText="{Binding GetAppText}" DoubleClickCommand="{Binding ShowWindowCommand}" x:Key="SystrayTaskbar">
|
||||
<tb:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem IsEnabled="False">
|
||||
<MenuItem.Icon>
|
||||
<Image Source="/unison.ico" Width="16" Height="16"/>
|
||||
<Image Source="/images/unison.ico" Width="16" Height="16"/>
|
||||
</MenuItem.Icon>
|
||||
<MenuItem.Header>
|
||||
<TextBlock Text="{Binding GetAppText}" />
|
||||
@ -46,7 +45,7 @@
|
||||
</ContextMenu>
|
||||
</tb:TaskbarIcon.ContextMenu>
|
||||
<tb:TaskbarIcon.DataContext>
|
||||
<local:NotifyIconViewModel />
|
||||
<local:SystrayViewModel />
|
||||
</tb:TaskbarIcon.DataContext>
|
||||
</tb:TaskbarIcon>
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
/*namespace unison
|
||||
{
|
||||
public partial class Systray : ResourceDictionary, INotifyPropertyChanged
|
||||
{
|
||||
public Systray()
|
||||
{
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged(string propertyName = "")
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}*/
|
88
Views/SystrayViewModel.cs
Normal file
88
Views/SystrayViewModel.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
using System;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public class SystrayViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public SystrayViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public string GetAppText => "unison v" + Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
|
||||
|
||||
public ICommand ShowWindowCommand => new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
Window AppWindow = Application.Current.MainWindow;
|
||||
AppWindow.Show();
|
||||
AppWindow.Activate();
|
||||
|
||||
if (AppWindow.WindowState == WindowState.Minimized)
|
||||
AppWindow.WindowState = WindowState.Normal;
|
||||
},
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
|
||||
public ICommand ExitApplicationCommand => new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
},
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
|
||||
public string SnapcastText
|
||||
{
|
||||
get
|
||||
{
|
||||
SnapcastHandler snapcast = (SnapcastHandler)Application.Current.Properties["snapcast"];
|
||||
return snapcast.Started ? "Stop Snapcast" : "Start Snapcast";
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand Snapcast
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("SnapcastText")));
|
||||
((MainWindow)Application.Current.MainWindow).Snapcast_Clicked(null, null);
|
||||
},
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DelegateCommand
|
||||
{
|
||||
CommandAction = () =>
|
||||
{
|
||||
((MainWindow)Application.Current.MainWindow).Settings_Clicked(null, null);
|
||||
},
|
||||
CanExecuteFunc = () => true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user