feat(desktop): add context menu to tabs
This commit is contained in:
parent
03697c336b
commit
f6e362e9f3
|
@ -47,11 +47,6 @@
|
||||||
<MenuItem Header="Exit"
|
<MenuItem Header="Exit"
|
||||||
Click="Exit_Click" />
|
Click="Exit_Click" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Tabs"
|
|
||||||
WindowChrome.IsHitTestVisibleInChrome="{Binding App.Config.CompactMode}">
|
|
||||||
<MenuItem Header="Manage"
|
|
||||||
Click="ManageTabs_Click" />
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem Header="Players"
|
<MenuItem Header="Players"
|
||||||
WindowChrome.IsHitTestVisibleInChrome="{Binding App.Config.CompactMode}">
|
WindowChrome.IsHitTestVisibleInChrome="{Binding App.Config.CompactMode}">
|
||||||
<MenuItem Header="Friend list"
|
<MenuItem Header="Friend list"
|
||||||
|
@ -65,6 +60,57 @@
|
||||||
Loaded="Tabs_Loaded"
|
Loaded="Tabs_Loaded"
|
||||||
SelectionChanged="Tabs_SelectionChanged"
|
SelectionChanged="Tabs_SelectionChanged"
|
||||||
ItemsSource="{Binding App.Config.Tabs}">
|
ItemsSource="{Binding App.Config.Tabs}">
|
||||||
|
<TabControl.CommandBindings>
|
||||||
|
<CommandBinding Command="local:MainWindow.AddTab"
|
||||||
|
Executed="AddTab_OnExecuted"
|
||||||
|
CanExecute="AlwaysTrue_CanExecute" />
|
||||||
|
<CommandBinding Command="local:MainWindow.ManageTabs"
|
||||||
|
Executed="ManageTabs_OnExecuted"
|
||||||
|
CanExecute="AlwaysTrue_CanExecute" />
|
||||||
|
<CommandBinding Command="local:MainWindow.EditTab"
|
||||||
|
Executed="EditTab_OnExecuted"
|
||||||
|
CanExecute="AlwaysTrue_CanExecute" />
|
||||||
|
<CommandBinding Command="local:MainWindow.DeleteTab"
|
||||||
|
Executed="DeleteTab_OnExecuted"
|
||||||
|
CanExecute="AlwaysTrue_CanExecute" />
|
||||||
|
</TabControl.CommandBindings>
|
||||||
|
|
||||||
|
<TabControl.Resources>
|
||||||
|
<Style TargetType="{x:Type MenuItem}"
|
||||||
|
BasedOn="{StaticResource DefaultMenuItemStyle}">
|
||||||
|
<Setter Property="CommandTarget"
|
||||||
|
Value="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}" />
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<ContextMenu x:Key="TabContextMenu"
|
||||||
|
DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"
|
||||||
|
d:DataContext="{d:DesignInstance local:Tab}">
|
||||||
|
<MenuItem Header="Edit"
|
||||||
|
Command="local:MainWindow.EditTab"
|
||||||
|
CommandParameter="{Binding}" />
|
||||||
|
<MenuItem Header="Delete"
|
||||||
|
Command="local:MainWindow.DeleteTab"
|
||||||
|
CommandParameter="{Binding}" />
|
||||||
|
</ContextMenu>
|
||||||
|
</TabControl.Resources>
|
||||||
|
|
||||||
|
<TabControl.ItemContainerStyle>
|
||||||
|
<Style TargetType="{x:Type TabItem}"
|
||||||
|
BasedOn="{StaticResource DefaultTabItemStyle}">
|
||||||
|
<Setter Property="ContextMenu"
|
||||||
|
Value="{StaticResource TabContextMenu}" />
|
||||||
|
</Style>
|
||||||
|
</TabControl.ItemContainerStyle>
|
||||||
|
|
||||||
|
<TabControl.ContextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<MenuItem Header="Add tab"
|
||||||
|
Command="local:MainWindow.AddTab" />
|
||||||
|
<MenuItem Header="Manage tabs"
|
||||||
|
Command="local:MainWindow.ManageTabs" />
|
||||||
|
</ContextMenu>
|
||||||
|
</TabControl.ContextMenu>
|
||||||
|
|
||||||
<TabControl.ItemTemplate>
|
<TabControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding Name}" />
|
<TextBlock Text="{Binding Name}" />
|
||||||
|
|
|
@ -15,6 +15,63 @@ namespace XIVChat_Desktop {
|
||||||
/// Interaction logic for MainWindow.xaml
|
/// Interaction logic for MainWindow.xaml
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : INotifyPropertyChanged {
|
public partial class MainWindow : INotifyPropertyChanged {
|
||||||
|
#region commands
|
||||||
|
|
||||||
|
private void AlwaysTrue_CanExecute(object sender, CanExecuteRoutedEventArgs e) {
|
||||||
|
e.CanExecute = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedUICommand EditTab = new RoutedUICommand(
|
||||||
|
"EditTab",
|
||||||
|
"EditTab",
|
||||||
|
typeof(MainWindow)
|
||||||
|
);
|
||||||
|
|
||||||
|
private void EditTab_OnExecuted(object sender, ExecutedRoutedEventArgs e) {
|
||||||
|
if (!(e.Parameter is Tab tab)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new ManageTab(this, tab).Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedUICommand DeleteTab = new RoutedUICommand(
|
||||||
|
"DeleteTab",
|
||||||
|
"DeleteTab",
|
||||||
|
typeof(MainWindow)
|
||||||
|
);
|
||||||
|
|
||||||
|
private void DeleteTab_OnExecuted(object sender, ExecutedRoutedEventArgs e) {
|
||||||
|
if (!(e.Parameter is Tab tab)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.App.Config.Tabs.Remove(tab);
|
||||||
|
this.App.Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedUICommand AddTab = new RoutedUICommand(
|
||||||
|
"AddTab",
|
||||||
|
"AddTab",
|
||||||
|
typeof(MainWindow)
|
||||||
|
);
|
||||||
|
|
||||||
|
private void AddTab_OnExecuted(object sender, ExecutedRoutedEventArgs e) {
|
||||||
|
new ManageTab(this, null).Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedUICommand ManageTabs = new RoutedUICommand(
|
||||||
|
"ManageTabs",
|
||||||
|
"ManageTabs",
|
||||||
|
typeof(MainWindow)
|
||||||
|
);
|
||||||
|
|
||||||
|
private void ManageTabs_OnExecuted(object sender, ExecutedRoutedEventArgs e) {
|
||||||
|
new ManageTabs(this).Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public App App => (App)Application.Current;
|
public App App => (App)Application.Current;
|
||||||
|
|
||||||
public List<ServerMessage> Messages { get; } = new List<ServerMessage>();
|
public List<ServerMessage> Messages { get; } = new List<ServerMessage>();
|
||||||
|
@ -169,10 +226,6 @@ namespace XIVChat_Desktop {
|
||||||
scroller?.ScrollToBottom();
|
scroller?.ScrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ManageTabs_Click(object sender, RoutedEventArgs e) {
|
|
||||||
new ManageTabs(this).Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Scan_Click(object sender, RoutedEventArgs e) {
|
private void Scan_Click(object sender, RoutedEventArgs e) {
|
||||||
new ServerScan(this).Show();
|
new ServerScan(this).Show();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user