Skip to content

Commit c3e763d

Browse files
authored
Merge pull request #1124 from maiko3tattun/0501_FixLyricReplace
Fix LyricsReplaceDialog bug
2 parents b969d52 + 1b2a1ae commit c3e763d

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

OpenUtau/Strings/Strings.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
<system:String x:Key="errors.failed.save">Failed to save</system:String>
8787
<system:String x:Key="errors.failed.savesingerconfig">Failed to save singer config file</system:String>
8888
<system:String x:Key="errors.failed.searchsinger">Failed to search singers</system:String>
89+
<system:String x:Key="errors.lyrics.regex">Character not allowed in regular expression</system:String>
90+
<system:String x:Key="errors.lyrics.regexpreview">- regular expression error -</system:String>
8991

9092
<system:String x:Key="exps.abbr">Abbreviation</system:String>
9193
<system:String x:Key="exps.apply">Apply</system:String>

OpenUtau/Strings/Strings.ja-JP.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
<system:String x:Key="errors.failed.save">保存に失敗しました</system:String>
8686
<system:String x:Key="errors.failed.savesingerconfig">シンガー設定の保存に失敗しました</system:String>
8787
<system:String x:Key="errors.failed.searchsinger">シンガーの取得に失敗しました</system:String>
88+
<system:String x:Key="errors.lyrics.regex">正規表現に使用できない文字が含まれています</system:String>
89+
<system:String x:Key="errors.lyrics.regexpreview">- 正規表現エラー -</system:String>
8890

8991
<system:String x:Key="exps.abbr">パラメータの略称</system:String>
9092
<system:String x:Key="exps.apply">適用</system:String>

OpenUtau/ViewModels/LyricsReplaceViewModel.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public LyricsReplaceViewModel(UVoicePart part, UNote[] notes, string[] lyrics) {
3636

3737
this.WhenAnyValue(x => x.OldValue, x => x.NewValue)
3838
.Subscribe(t => {
39-
Preview = Replace();
39+
try {
40+
Preview = Replace();
41+
} catch {
42+
Preview = ThemeManager.GetString("errors.lyrics.regexpreview");
43+
}
4044
});
4145
this.WhenValueChanged(x => SelectedPreset)
4246
.Subscribe(p => {
@@ -55,16 +59,22 @@ public string Replace() {
5559
return string.Join(", ", Lyrics);
5660
}
5761

58-
public void Finish() {
59-
DocManager.Inst.StartUndoGroup();
62+
public bool Finish() {
63+
try {
64+
Replace();
65+
} catch (Exception ex) {
66+
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(new MessageCustomizableException("Character not allowed in regular expression.", "<translate:errors.lyrics.regex>", ex)));
67+
return false;
68+
}
6069

70+
DocManager.Inst.StartUndoGroup();
6171
for (int i = 0; i < Lyrics.Length && i < notes.Length; ++i) {
6272
if (notes[i].lyric != Lyrics[i]) {
6373
DocManager.Inst.ExecuteCmd(new ChangeNoteLyricCommand(part, notes[i], Lyrics[i]));
6474
}
6575
}
66-
6776
DocManager.Inst.EndUndoGroup();
77+
return true;
6878
}
6979
}
7080

OpenUtau/Views/LyricsReplaceDialog.axaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ void OnCancel(object? sender, RoutedEventArgs e) {
1414
}
1515

1616
void OnFinish(object? sender, RoutedEventArgs e) {
17-
(DataContext as LyricsReplaceViewModel)!.Finish();
18-
Close();
17+
if((DataContext as LyricsReplaceViewModel)!.Finish()) {
18+
Close();
19+
}
1920
}
2021

2122
private void OnKeyDown(object? sender, KeyEventArgs e) {

0 commit comments

Comments
 (0)