Skip to content

Commit

Permalink
Fix preview failure when lyrics replacement contains characters that …
Browse files Browse the repository at this point in the history
…cannot be used in regular expressions
  • Loading branch information
まいこ committed May 1, 2024
1 parent bd73561 commit 81accd2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<system:String x:Key="errors.failed.runeditingmacro">Failed to run editing macro</system:String>
<system:String x:Key="errors.failed.save">Failed to save</system:String>
<system:String x:Key="errors.failed.savesingerconfig">Failed to save singer config file</system:String>
<system:String x:Key="errors.lyrics.regex">Character not allowed in regular expression</system:String>
<system:String x:Key="errors.lyrics.regexpreview">- regular expression error -</system:String>

<system:String x:Key="exps.abbr">Abbreviation</system:String>
<system:String x:Key="exps.apply">Apply</system:String>
Expand Down
2 changes: 2 additions & 0 deletions OpenUtau/Strings/Strings.ja-JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<system:String x:Key="errors.failed.runeditingmacro">一括処理に失敗しました</system:String>
<system:String x:Key="errors.failed.save">保存に失敗しました</system:String>
<system:String x:Key="errors.failed.savesingerconfig">シンガー設定の保存に失敗しました</system:String>
<system:String x:Key="errors.lyrics.regex">正規表現に使用できない文字が含まれています</system:String>
<system:String x:Key="errors.lyrics.regexpreview">- 正規表現エラー -</system:String>

<system:String x:Key="exps.abbr">パラメータの略称</system:String>
<system:String x:Key="exps.apply">適用</system:String>
Expand Down
18 changes: 14 additions & 4 deletions OpenUtau/ViewModels/LyricsReplaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public LyricsReplaceViewModel(UVoicePart part, UNote[] notes, string[] lyrics) {

this.WhenAnyValue(x => x.OldValue, x => x.NewValue)
.Subscribe(t => {
Preview = Replace();
try {
Preview = Replace();
} catch {
Preview = ThemeManager.GetString("errors.lyrics.regexpreview");
}
});
this.WhenValueChanged(x => SelectedPreset)
.Subscribe(p => {
Expand All @@ -55,16 +59,22 @@ public string Replace() {
return string.Join(", ", Lyrics);
}

public void Finish() {
DocManager.Inst.StartUndoGroup();
public bool Finish() {
try {
Replace();
} catch (Exception ex) {
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(new MessageCustomizableException("Character not allowed in regular expression.", "<translate:errors.lyrics.regex>", ex)));
return false;
}

DocManager.Inst.StartUndoGroup();
for (int i = 0; i < Lyrics.Length && i < notes.Length; ++i) {
if (notes[i].lyric != Lyrics[i]) {
DocManager.Inst.ExecuteCmd(new ChangeNoteLyricCommand(part, notes[i], Lyrics[i]));
}
}

DocManager.Inst.EndUndoGroup();
return true;
}
}

Expand Down
5 changes: 3 additions & 2 deletions OpenUtau/Views/LyricsReplaceDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ void OnCancel(object? sender, RoutedEventArgs e) {
}

void OnFinish(object? sender, RoutedEventArgs e) {
(DataContext as LyricsReplaceViewModel)!.Finish();
Close();
if((DataContext as LyricsReplaceViewModel)!.Finish()) {
Close();
}
}

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

0 comments on commit 81accd2

Please sign in to comment.