120 lines
3.4 KiB
C#
120 lines
3.4 KiB
C#
using BeWo.AI.View;
|
|
using BeWo.Services;
|
|
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)
|
|
{
|
|
ButtonOpenTranskriptionView.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
}
|
|
|
|
public TextBox TargetTextBox
|
|
{
|
|
get => (TextBox)GetValue(TargetTextBoxProperty);
|
|
set => SetValue(TargetTextBoxProperty, value);
|
|
}
|
|
|
|
public 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 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.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;
|
|
}
|
|
|
|
}
|
|
}
|