173 lines
4.6 KiB
C#
173 lines
4.6 KiB
C#
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
using BeWo.ViewModel.View.AI;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.Mvvm;
|
|
using DevExpress.Xpf.Core.Native;
|
|
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;
|
|
using System.Windows.Threading;
|
|
|
|
namespace BeWo.View.Detail.AI
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für AiConversationChatView.xaml
|
|
/// </summary>
|
|
public partial class AiConversationChatView : BeWoView
|
|
{
|
|
private bool _loaded = false;
|
|
|
|
public AiConversationChatView(AiConversationChatViewModel viewModel)
|
|
{
|
|
InitializeComponent();
|
|
|
|
ViewModel = viewModel;
|
|
((INotifyCollectionChanged)listview_messages.Items).CollectionChanged += listview_messages_CollectionChanged;
|
|
|
|
popup_settings.Closed += (s, e) => ViewModel.UpdateConfig();
|
|
|
|
ViewModel.SendNewMessageSuccess += (s, e) =>
|
|
{
|
|
if (txt_input_message.Visibility == Visibility.Visible)
|
|
txt_input_message.Focus();
|
|
};
|
|
}
|
|
|
|
public AiConversationChatView(AiConversationChatViewModel viewModel, string stylestring) : this(viewModel)
|
|
{
|
|
rootgroupbox.Style = (Style)FindResource(stylestring);
|
|
}
|
|
|
|
public AiConversationChatViewModel ViewModel
|
|
{
|
|
get => DataContext as AiConversationChatViewModel;
|
|
set => DataContext = value;
|
|
}
|
|
|
|
private void BeWoView_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
if (BeWoApp.IsInDesignMode || _loaded)
|
|
return;
|
|
|
|
_loaded = true;
|
|
|
|
ViewModel.ReloadConfigCommand.Execute(null);
|
|
ViewModel.ReloadConversationsCommand.Execute(null);
|
|
|
|
ViewModel.Start();
|
|
}
|
|
|
|
private void listview_conversations_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (ViewModel.IsNewConversationVisible)
|
|
BeWoWpfUtils.ScrollToTop(listview_conversations);
|
|
else
|
|
listview_conversations.ScrollIntoView(listview_conversations.SelectedItem);
|
|
}
|
|
|
|
private void listview_messages_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() => BeWoWpfUtils.ScrollToBottom(listview_messages)));
|
|
}
|
|
|
|
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.IsNewConversationVisible && ViewModel.SendNewMessageCommand.CanExecute(p))
|
|
ViewModel.SendNewMessageCommand.Execute(p);
|
|
else if (ViewModel.IsNewConversationVisible && 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;
|
|
}
|
|
}
|
|
|
|
private void ConversationRenameTextBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (sender is TextBox textBox && e.NewValue is bool b && b)
|
|
{
|
|
textBox.Focus();
|
|
textBox.SelectAll();
|
|
}
|
|
}
|
|
|
|
|
|
private void ConversationRenameTextBox_LostFocus(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is TextBox textbox && textbox.DataContext is AiConversationVM vm && vm.IsEditing)
|
|
{
|
|
vm.SaveDisplayname();
|
|
}
|
|
}
|
|
|
|
private void ConversationRenameTextBox_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (sender is TextBox textbox && textbox.DataContext is AiConversationVM vm && vm.IsEditing)
|
|
{
|
|
if (e.Key == Key.Enter)
|
|
{
|
|
vm.SaveDisplayname();
|
|
e.Handled = true;
|
|
}
|
|
else if (e.Key == Key.Escape)
|
|
{
|
|
vm.IsEditing = true;
|
|
vm.ResetDisplayname();
|
|
e.Handled = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void ConversationRenameTextBlock_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (e.ClickCount == 2)
|
|
{
|
|
if (sender is TextBlock textBlock && textBlock.DataContext is AiConversationVM vm && !vm.IsEditing)
|
|
{
|
|
vm.IsEditing = true;
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
}
|