feat(desktop): right click on message to send tell

This commit is contained in:
Anna 2020-11-17 23:47:13 -05:00
parent 01f4634505
commit 11a12bc696
4 changed files with 50 additions and 14 deletions

View File

@ -6,7 +6,6 @@ using System.Windows;
using System.Windows.Markup;
using ModernWpf;
// TODO: Up/down to cycle through input history
// TODO: key word notification, notifications on message type, targeted message (like emote targeting you)
// TODO: right click message to send tell to sender?

View File

@ -43,20 +43,16 @@ namespace XIVChat_Desktop {
return;
}
var input = this.App.Window.GetCurrentInputBox();
if (input == null) {
var name = player.Name;
var world = player.HomeWorldName;
if (name == null || world == null) {
return;
}
var tell = $"/tell {player.Name}@{player.HomeWorldName} ";
input.Text = input.Text.Insert(0, tell);
input.SelectionStart = tell.Length;
input.SelectionLength = input.Text.Length - tell.Length;
this.App.Window.InsertTellCommand(name, world);
this.Close();
input.Focus();
}
private void SendTell_CanExecute(object sender, CanExecuteRoutedEventArgs e) {

View File

@ -157,7 +157,23 @@
<cc:MessageTextBlock
FontFamily="Global User Interface, /Resources/fonts/#XIV AXIS Std ATK"
ProcessMarkdown="{Binding DataContext.ProcessMarkdown, ElementName=TabGrid}"
Message="{Binding .}" />
Message="{Binding .}">
<cc:MessageTextBlock.CommandBindings>
<CommandBinding Command="local:MainWindow.MessageSendTell"
Executed="MessageSendTell_OnExecuted"
CanExecute="MessageSendTell_CanExecute" />
</cc:MessageTextBlock.CommandBindings>
<cc:MessageTextBlock.ContextMenu>
<ContextMenu
DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"
d:DataContext="{d:DesignInstance server:ServerMessage}">
<MenuItem Header="Send /tell to sender"
Command="local:MainWindow.MessageSendTell"
CommandParameter="{Binding}" />
</ContextMenu>
</cc:MessageTextBlock.ContextMenu>
</cc:MessageTextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

View File

@ -77,6 +77,14 @@ namespace XIVChat_Desktop {
typeof(MainWindow)
);
private void MessageSendTell_CanExecute(object sender, CanExecuteRoutedEventArgs e) {
if (!(e.Parameter is ServerMessage message)) {
return;
}
e.CanExecute = message.GetSenderPlayer() != null;
}
private void MessageSendTell_OnExecuted(object eventSender, ExecutedRoutedEventArgs e) {
if (!(e.Parameter is ServerMessage message)) {
return;
@ -87,12 +95,12 @@ namespace XIVChat_Desktop {
return;
}
var input = this.GetCurrentInputBox();
if (input == null) {
var worldName = Util.WorldName(sender.Server);
if (worldName == null) {
return;
}
input.Text.Insert(0, $"/tell {sender.Name}@{sender.Server} ");
this.InsertTellCommand(sender.Name, worldName);
}
#endregion
@ -224,6 +232,23 @@ namespace XIVChat_Desktop {
}
}
public void InsertTellCommand(string name, string world, bool focus = true) {
var input = this.App.Window.GetCurrentInputBox();
if (input == null) {
return;
}
var tell = $"/tell {name}@{world} ";
input.Text = input.Text.Insert(0, tell);
input.SelectionStart = tell.Length;
input.SelectionLength = input.Text.Length - tell.Length;
if (focus) {
input.Focus();
}
}
private void Connect_Click(object sender, RoutedEventArgs e) {
new ConnectDialog(this).ShowDialog();
}