112 lines
3.0 KiB
C#
112 lines
3.0 KiB
C#
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.Mvvm;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace BeWo.View.Detail.AI
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für AiConversationChatView.xaml
|
|
/// </summary>
|
|
public partial class AiConversationChatView : BeWoView
|
|
{
|
|
public AiConversationChatView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
((INotifyCollectionChanged)listbox_messages.Items).CollectionChanged += listbox_messages_SelectionChanged;
|
|
|
|
popup_settings.Closed += (s, e) => ViewModel.UpdateConfig();
|
|
|
|
ViewModel.SendNewMessageSuccess += (s, e) =>
|
|
{
|
|
if (txt_input_message.Visibility == Visibility.Visible)
|
|
txt_input_message.Focus();
|
|
};
|
|
}
|
|
|
|
public AiConversationChatView(string stylestring) : this()
|
|
{
|
|
rootgroupbox.Style = (Style)FindResource(stylestring);
|
|
}
|
|
|
|
public AiConversationListVM ViewModel
|
|
{
|
|
get => DataContext as AiConversationListVM;
|
|
set => DataContext = value;
|
|
}
|
|
|
|
private void BeWoView_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
if (BeWoApp.IsInDesignMode)
|
|
return;
|
|
|
|
ViewModel.ReloadConfigCommand.Execute(null);
|
|
ViewModel.ReloadConversationsCommand.Execute(null);
|
|
}
|
|
|
|
private void listbox_conversations_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (ViewModel.IsNewConversationVisible)
|
|
BeWoWpfUtils.ScrollToTop(listbox_conversations);
|
|
else
|
|
listbox_conversations.ScrollIntoView(listbox_conversations.SelectedItem);
|
|
}
|
|
|
|
private void listbox_messages_SelectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
BeWoWpfUtils.ScrollToBottom(listbox_messages);
|
|
}
|
|
|
|
private void popup_conversation_clone_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
BeWoWpfUtils.ScrollToBottom(listbox_messages_clone);
|
|
}
|
|
|
|
private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key == Key.Enter)
|
|
{
|
|
if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
|
|
{
|
|
// Shift + Enter gedrückt
|
|
Console.WriteLine("Shift + Enter erkannt");
|
|
}
|
|
else
|
|
{
|
|
// Nur Enter gedrückt
|
|
// Console.WriteLine("Enter erkannt");
|
|
|
|
object p = null;
|
|
if(ViewModel.SelectedVM is object && ViewModel.SendNewMessageCommand.CanExecute(p))
|
|
ViewModel.SendNewMessageCommand.Execute(p);
|
|
else if (ViewModel.SelectedVM is null && ViewModel.StartConversationWithMessageCommand.CanExecute(p))
|
|
ViewModel.StartConversationWithMessageCommand.Execute(p);
|
|
|
|
e.Handled = true;
|
|
}
|
|
|
|
// Optional: Event als behandelt markieren, wenn du die Standardaktion unterdrücken willst
|
|
// e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|