/
FinetuneWpfControl.xaml.cs
150 lines (136 loc) · 4.84 KB
/
FinetuneWpfControl.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.ServiceModel;
using System.Text;
using System.Text.RegularExpressions;
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 FiskmoTranslationProvider
{
/// <summary>
/// Interaction logic for FinetuneWpfControl.xaml
/// </summary>
public partial class FinetuneWpfControl : UserControl, INotifyPropertyChanged, IHasFiskmoOptions
{
private FinetuneBatchTaskSettings settings;
private FiskmoOptions options;
public FinetuneBatchTaskSettings Settings
{
get
{
return settings;
}
set
{
settings = value;
}
}
public FiskmoOptions Options
{
get
{
return options;
}
set
{
options = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public FinetuneWpfControl(FinetuneBatchTaskSettings Settings)
{
this.DataContext = this;
//Settings is the object that is passed on to the batch task.
this.Settings = Settings;
//Mode defaults, changeable with radio buttons
this.Settings.Finetune = true;
this.Settings.PreOrderMtForNewSegments = true;
//Some settings are initially held in a FiskmoOptions object (the shared properties
//with the translation provider settings).
this.Options = new FiskmoOptions();
//Whenever the options change, also update the option URI string in settings
this.Options.PropertyChanged += Options_PropertyChanged;
InitializeComponent();
this.TagBox.ItemsSource = new ObservableCollection<string>() { "<new tag>" };
}
private void Options_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
this.settings.ProviderOptions = this.Options.Uri.ToString();
}
private void ModeButton_Checked(object sender, RoutedEventArgs e)
{
var radioButton = ((RadioButton)sender);
if (radioButton.IsChecked.Value)
{
switch (radioButton.Name)
{
case "FinetuneAndTranslate":
this.Settings.PreOrderMtForNewSegments = true;
this.Settings.Finetune = true;
break;
case "FinetuneOnly":
this.Settings.Finetune = true;
this.Settings.PreOrderMtForNewSegments = false;
break;
case "TranslateOnly":
this.Settings.Finetune = false;
this.Settings.PreOrderMtForNewSegments = true;
break;
}
if (this.ConnectionControl != null && this.ConnectionControl.AllModelTags != null)
{
if (this.Settings.Finetune)
{
this.TagBox.ItemsSource = new ObservableCollection<string>() { "" };
this.TagBox.SelectedIndex = 0;
}
else
{
this.TagBox.ItemsSource = this.ConnectionControl.AllModelTags;
}
}
}
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
private void TagBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.settings.Finetune)
{
}
else
{
this.ConnectionControl.TagBox_SelectionChanged(sender, e);
}
}
private void NumberBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^0-9]");
e.Handled = regex.IsMatch(e.Text);
}
}
}