Files
BeWoPlaner/BeWo/AI/Controls/VoiceToTextButtonControl.xaml.cs

135 lines
3.7 KiB
C#
Raw Permalink Normal View History

2026-01-30 19:35:18 +01:00
using BeWo.AI.View;
using BeWo.Services;
using BeWo.ViewModel.ListViewModel;
2026-01-30 19:35:18 +01:00
using BS.Shared.Translation;
using System;
using System.Collections.Generic;
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.AI.Controls
{
/// <summary>
/// Interaktionslogik für VoiceToTextButtonControl.xaml
/// </summary>
public partial class VoiceToTextButtonControl : UserControl
{
public static readonly DependencyProperty TargetTextBoxProperty =
DependencyProperty.Register(
nameof(TargetTextBox),
typeof(TextBox),
typeof(VoiceToTextButtonControl));
public VoiceToTextButtonControl()
{
InitializeComponent();
if (!HasRightToUseAIVoice)
{
root.Visibility = Visibility.Collapsed;
}
2026-01-30 19:35:18 +01:00
}
public TextBox TargetTextBox
{
get => (TextBox)GetValue(TargetTextBoxProperty);
set => SetValue(TargetTextBoxProperty, value);
}
2026-03-16 11:08:14 +01:00
public static bool HasRightToUseAIVoice
{
get
{
if (!BeWoApp.AppSettings.ShowAIVoice || String.IsNullOrEmpty(BeWoApp.LoggedOnEmployeeOwnChatCode) || !BeWoApp.HasLoggedOnUserRight(BS.Shared.UserRightType.AiVoiceView))
{
return false;
}
return true;
}
}
2026-01-30 19:35:18 +01:00
private void ButtonOpenTranskriptionView_Click(object sender, RoutedEventArgs e)
{
OpenTranskriptionView();
}
public void OpenTranskriptionView()
{
var view = new AiTranskriptionView();
view.InitView();
var serviceRecordList = DataContext as ServiceRecordListVM;
if (serviceRecordList is null)
throw new NotImplementedException("Can't find DataContext");
var settings = serviceRecordList.AiUserSetting;
if (settings is null)
throw new NotImplementedException("Can't find DataContext (settings)");
view.DataContext = settings;
2026-01-30 19:35:18 +01:00
var factory = new BeWoWindowFactory();
var beWoWindow = factory.GetAnimatedBeWoWindow(Translator.Translate("BeWoPlaner"), view, 500, 600);
view.ApplyClicked += (s, e) =>
{
if (TargetTextBox != null)
{
InsertTextAtSelection(view.GetText());
}
beWoWindow.Close();
};
view.CancelClicked += (s, e) =>
{
if (!String.IsNullOrEmpty(view.GetText()))
{
if (MessageBox.Show("Sind Sie sicher, dass Sie abbrechnen und den Text verwerfen möchten?", "Abbrechen", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
beWoWindow.Close();
}
}
else
{
beWoWindow.Close();
}
};
2026-01-30 19:35:18 +01:00
beWoWindow.Closed += (s, e) =>
{
settings.AutoStartRecording = settings.DataContract.AutoStartRecording;
};
2026-01-30 19:35:18 +01:00
beWoWindow.ShowDialog();
2026-01-30 19:35:18 +01:00
}
private void InsertTextAtSelection(string neuerText)
{
int start = TargetTextBox.SelectionStart;
int length = TargetTextBox.SelectionLength;
TargetTextBox.Text =
TargetTextBox.Text.Remove(start, length)
.Insert(start, neuerText);
TargetTextBox.CaretIndex = start + neuerText.Length;
}
}
}