using BeWo.AI.View; using BeWo.Services; using BeWo.ViewModel.ListViewModel; 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 { /// /// Interaktionslogik für VoiceToTextButtonControl.xaml /// 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; } } public TextBox TargetTextBox { get => (TextBox)GetValue(TargetTextBoxProperty); set => SetValue(TargetTextBoxProperty, value); } public static bool HasRightToUseAIVoice { get { if (!BeWoApp.AppSettings.ShowAIVoice || String.IsNullOrEmpty(BeWoApp.LoggedOnEmployeeOwnChatCode) || !BeWoApp.HasLoggedOnUserRight(BS.Shared.UserRightType.AiVoiceView)) { return false; } return true; } } 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; 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(); } }; beWoWindow.Closed += (s, e) => { settings.AutoStartRecording = settings.DataContract.AutoStartRecording; }; beWoWindow.ShowDialog(); } 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; } } }