Skip to content

Commit 704b54c

Browse files
committed
cleanup views
1 parent d60f403 commit 704b54c

18 files changed

+156
-371
lines changed

OpenUtau/Views/DebugWindow.axaml.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
using System;
2-
using Avalonia;
32
using Avalonia.Controls;
4-
using Avalonia.Markup.Xaml;
53
using OpenUtau.App.ViewModels;
64

75
namespace OpenUtau.App.Views {
86
public partial class DebugWindow : Window {
97
DebugViewModel viewModel;
108

119
public DebugWindow() {
10+
InitializeComponent();
1211
DataContext = viewModel = new DebugViewModel();
1312
viewModel.SetWindow(this);
14-
15-
InitializeComponent();
16-
#if DEBUG
17-
this.AttachDevTools();
18-
#endif
13+
viewModel.Attach();
1914
}
2015
public void CopyLogText() {
21-
var box = this.Find<TextBox>("CopyTextBox");
22-
box.Text = DebugViewModel.Sink.Inst.ToString();
23-
box.SelectAll();
24-
box.Copy();
25-
box.Clear();
26-
}
27-
28-
private void InitializeComponent() {
29-
AvaloniaXamlLoader.Load(this);
30-
viewModel.Attach();
16+
CopyTextBox.Text = DebugViewModel.Sink.Inst.ToString();
17+
CopyTextBox.SelectAll();
18+
CopyTextBox.Copy();
19+
CopyTextBox.Clear();
3120
}
3221

3322
void OnClosed(object? sender, EventArgs e) {

OpenUtau/Views/EditSubbanksDialog.axaml.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
using System;
2-
using Avalonia;
32
using Avalonia.Controls;
43
using Avalonia.Interactivity;
5-
using Avalonia.Markup.Xaml;
64
using OpenUtau.App.ViewModels;
75

86
namespace OpenUtau.App.Views {
97
public partial class EditSubbanksDialog : Window {
108
internal readonly EditSubbanksViewModel ViewModel;
119

12-
internal Action RefreshSinger;
13-
14-
private DataGrid dataGrid;
10+
internal Action? RefreshSinger;
1511

1612
public EditSubbanksDialog() {
1713
InitializeComponent();
18-
#if DEBUG
19-
this.AttachDevTools();
20-
#endif
2114
DataContext = ViewModel = new EditSubbanksViewModel();
22-
dataGrid = this.FindControl<DataGrid>("SuffixGrid");
23-
}
24-
25-
private void InitializeComponent() {
26-
AvaloniaXamlLoader.Load(this);
2715
}
2816

2917
void OnAdd(object sender, RoutedEventArgs e) {
@@ -60,15 +48,15 @@ void OnCancel(object sender, RoutedEventArgs e) {
6048
}
6149

6250
void OnSelectAll(object sender, RoutedEventArgs e) {
63-
dataGrid.SelectAll();
51+
SuffixGrid.SelectAll();
6452
}
6553

6654
void OnSet(object sender, RoutedEventArgs e) {
67-
ViewModel.Set(dataGrid.SelectedItems);
55+
ViewModel.Set(SuffixGrid.SelectedItems);
6856
}
6957

7058
void OnClear(object sender, RoutedEventArgs e) {
71-
ViewModel.Clear(dataGrid.SelectedItems);
59+
ViewModel.Clear(SuffixGrid.SelectedItems);
7260
}
7361
}
7462
}

OpenUtau/Views/ExeSetupDialog.axaml.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
using Avalonia;
2-
using Avalonia.Controls;
1+
using Avalonia.Controls;
32
using Avalonia.Interactivity;
4-
using Avalonia.Markup.Xaml;
53
using Classic;
64
using OpenUtau.App.ViewModels;
75

86
namespace OpenUtau.App.Views {
97
public partial class ExeSetupDialog : Window {
108
public ExeSetupDialog() {
119
InitializeComponent();
12-
#if DEBUG
13-
this.AttachDevTools();
14-
#endif
15-
16-
}
17-
18-
private void InitializeComponent() {
19-
AvaloniaXamlLoader.Load(this);
2010
}
2111

2212
public void InstallAsResampler(object sender, RoutedEventArgs arg) {

OpenUtau/Views/ExpressionsDialog.axaml.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
using System;
2-
using Avalonia;
32
using Avalonia.Controls;
43
using Avalonia.Interactivity;
5-
using Avalonia.Markup.Xaml;
64
using OpenUtau.App.ViewModels;
75
using OpenUtau.Core.Ustx;
86

97
namespace OpenUtau.App.Views {
108
public partial class ExpressionsDialog : Window {
119
public ExpressionsDialog() {
1210
InitializeComponent();
13-
#if DEBUG
14-
this.AttachDevTools();
15-
#endif
16-
}
17-
18-
private void InitializeComponent() {
19-
AvaloniaXamlLoader.Load(this);
2011
}
2112

2213
private void ApplyButtonClicked(object sender, RoutedEventArgs _) {

OpenUtau/Views/LyricsDialog.axaml.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
using System;
2-
using Avalonia;
32
using Avalonia.Controls;
43
using Avalonia.Input;
54
using Avalonia.Interactivity;
6-
using Avalonia.Markup.Xaml;
7-
using Avalonia.Threading;
85
using OpenUtau.App.ViewModels;
96

107
namespace OpenUtau.App.Views {
118
public partial class LyricsDialog : Window {
12-
private TextBox box;
139
public LyricsDialog() {
1410
InitializeComponent();
15-
box = this.FindControl<TextBox>("DIALOG_Box");
16-
17-
#if DEBUG
18-
this.AttachDevTools();
19-
#endif
20-
}
21-
22-
private void InitializeComponent() {
23-
AvaloniaXamlLoader.Load(this);
2411
}
2512

2613
void OnOpened(object? sender, EventArgs e) {
27-
box.Focus();
14+
DIALOG_Box.Focus();
2815
}
2916

3017
void OnReset(object? sender, RoutedEventArgs e) {

OpenUtau/Views/LyricsReplaceDialog.axaml.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
using Avalonia;
2-
using Avalonia.Controls;
1+
using Avalonia.Controls;
32
using Avalonia.Input;
43
using Avalonia.Interactivity;
5-
using Avalonia.Markup.Xaml;
64
using OpenUtau.App.ViewModels;
75

86
namespace OpenUtau.App.Views {
97
public partial class LyricsReplaceDialog : Window {
10-
118
public LyricsReplaceDialog() {
129
InitializeComponent();
13-
14-
#if DEBUG
15-
this.AttachDevTools();
16-
#endif
17-
}
18-
private void InitializeComponent() {
19-
AvaloniaXamlLoader.Load(this);
2010
}
2111

2212
void OnCancel(object? sender, RoutedEventArgs e) {

OpenUtau/Views/MainWindow.axaml.cs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
using Avalonia.Controls.Shapes;
1313
using Avalonia.Input;
1414
using Avalonia.Interactivity;
15-
using Avalonia.Markup.Xaml;
1615
using Avalonia.Threading;
17-
using Avalonia.VisualTree;
1816
using OpenUtau.App.Controls;
1917
using OpenUtau.App.ViewModels;
2018
using OpenUtau.Classic;
@@ -42,7 +40,6 @@ public partial class MainWindow : Window, ICmdSubscriber {
4240
private DispatcherTimer autosaveTimer;
4341
private bool forceClose;
4442

45-
private ContextMenu? partsContextMenu;
4643
private bool shouldOpenPartsContextMenu;
4744

4845
private readonly ReactiveCommand<UPart, Unit> PartRenameCommand;
@@ -53,10 +50,6 @@ public MainWindow() {
5350
InitializeComponent();
5451
Log.Information("Initialized main window component.");
5552
DataContext = viewModel = new MainWindowViewModel();
56-
partsContextMenu = this.Find<ContextMenu>("PartsContextMenu");
57-
#if DEBUG
58-
this.AttachDevTools();
59-
#endif
6053
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
6154
viewModel.GetInitSingerTask()!.ContinueWith(_ => {
6255
viewModel.InitProject();
@@ -65,12 +58,10 @@ public MainWindow() {
6558
viewModel.AddTimeSigChangeCmd = ReactiveCommand.Create<int>(bar => AddTimeSigChange(bar));
6659
viewModel.DelTimeSigChangeCmd = ReactiveCommand.Create<int>(bar => DelTimeSigChange(bar));
6760

68-
var splash = this.Find<Border>("Splash");
69-
splash.IsEnabled = false;
70-
splash.IsVisible = false;
71-
var mainGrid = this.Find<Grid>("MainGrid");
72-
mainGrid.IsEnabled = true;
73-
mainGrid.IsVisible = true;
61+
Splash.IsEnabled = false;
62+
Splash.IsVisible = false;
63+
MainGrid.IsEnabled = true;
64+
MainGrid.IsVisible = true;
7465
splashDone = true;
7566
}, CancellationToken.None, TaskContinuationOptions.None, scheduler);
7667

@@ -101,10 +92,6 @@ public MainWindow() {
10192
Log.Information("Created main window.");
10293
}
10394

104-
private void InitializeComponent() {
105-
AvaloniaXamlLoader.Load(this);
106-
}
107-
10895
void OnEditTimeSignature(object sender, PointerPressedEventArgs args) {
10996
var project = DocManager.Inst.Project;
11097
var timeSig = project.timeSignatures[0];
@@ -489,7 +476,7 @@ public void OpenSingersWindow() {
489476
if (viewModel.TracksViewModel.SelectedParts.Count > 0) {
490477
singer = viewModel.TracksViewModel.Tracks[viewModel.TracksViewModel.SelectedParts.First().trackNo].Singer;
491478
}
492-
if(singer == null && viewModel.TracksViewModel.Tracks.Count > 0) {
479+
if (singer == null && viewModel.TracksViewModel.Tracks.Count > 0) {
493480
singer = viewModel.TracksViewModel.Tracks.First().Singer;
494481
}
495482
dialog = new SingersDialog() {
@@ -865,8 +852,8 @@ public void PartsCanvasPointerPressed(object sender, PointerPressedEventArgs arg
865852
viewModel.TracksViewModel.DeselectParts();
866853
viewModel.TracksViewModel.SelectPart(partControl.part);
867854
}
868-
if (partsContextMenu != null && viewModel.TracksViewModel.SelectedParts.Count > 0) {
869-
partsContextMenu.DataContext = new PartsContextMenuArgs {
855+
if (PartsContextMenu != null && viewModel.TracksViewModel.SelectedParts.Count > 0) {
856+
PartsContextMenu.DataContext = new PartsContextMenuArgs {
870857
Part = partControl.part,
871858
PartDeleteCommand = viewModel.PartDeleteCommand,
872859
PartReplaceAudioCommand = PartReplaceAudioCommand,
@@ -972,21 +959,17 @@ public void PartsCanvasPointerWheelChanged(object sender, PointerWheelEventArgs
972959
var delta = args.Delta;
973960
if (args.KeyModifiers == KeyModifiers.None || args.KeyModifiers == KeyModifiers.Shift) {
974961
if (delta.X != 0) {
975-
var scrollbar = this.FindControl<ScrollBar>("HScrollBar");
976-
scrollbar.Value = Math.Max(scrollbar.Minimum,
977-
Math.Min(scrollbar.Maximum, scrollbar.Value - scrollbar.SmallChange * delta.X));
962+
HScrollBar.Value = Math.Max(HScrollBar.Minimum,
963+
Math.Min(HScrollBar.Maximum, HScrollBar.Value - HScrollBar.SmallChange * delta.X));
978964
}
979965
if (delta.Y != 0) {
980-
var scrollbar = this.FindControl<ScrollBar>("VScrollBar");
981-
scrollbar.Value = Math.Max(scrollbar.Minimum,
982-
Math.Min(scrollbar.Maximum, scrollbar.Value - scrollbar.SmallChange * delta.Y));
966+
VScrollBar.Value = Math.Max(VScrollBar.Minimum,
967+
Math.Min(VScrollBar.Maximum, VScrollBar.Value - VScrollBar.SmallChange * delta.Y));
983968
}
984969
} else if (args.KeyModifiers == KeyModifiers.Alt) {
985-
var scaler = this.FindControl<ViewScaler>("VScaler");
986-
ViewScalerPointerWheelChanged(scaler, args);
970+
ViewScalerPointerWheelChanged(VScaler, args);
987971
} else if (args.KeyModifiers == cmdKey) {
988-
var timelineCanvas = this.FindControl<Canvas>("TimelineCanvas");
989-
TimelinePointerWheelChanged(timelineCanvas, args);
972+
TimelinePointerWheelChanged(TimelineCanvas, args);
990973
}
991974
if (partEditState != null) {
992975
var point = args.GetCurrentPoint(partEditState.control);
@@ -1003,8 +986,8 @@ public void PartsContextMenuOpening(object sender, CancelEventArgs args) {
1003986
}
1004987

1005988
public void PartsContextMenuClosing(object sender, CancelEventArgs args) {
1006-
if (partsContextMenu != null) {
1007-
partsContextMenu.DataContext = null;
989+
if (PartsContextMenu != null) {
990+
PartsContextMenu.DataContext = null;
1008991
}
1009992
}
1010993

OpenUtau/Views/MessageBox.axaml.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
using System.Linq;
33
using System.Text;
44
using System.Threading.Tasks;
5-
using Avalonia;
65
using Avalonia.Controls;
7-
using Avalonia.Markup.Xaml;
86
using Avalonia.Threading;
97

108
namespace OpenUtau.App.Views {
@@ -14,18 +12,11 @@ public enum MessageBoxResult { Ok, Cancel, Yes, No }
1412

1513
public MessageBox() {
1614
InitializeComponent();
17-
#if DEBUG
18-
this.AttachDevTools();
19-
#endif
20-
}
21-
22-
private void InitializeComponent() {
23-
AvaloniaXamlLoader.Load(this);
2415
}
2516

2617
public void SetText(string text) {
2718
Dispatcher.UIThread.Post(() => {
28-
this.FindControl<TextBlock>("Text").Text = text;
19+
Text.Text = text;
2920
});
3021
}
3122

@@ -61,8 +52,7 @@ public static Task<MessageBoxResult> Show(Window parent, string text, string tit
6152
var msgbox = new MessageBox() {
6253
Title = title
6354
};
64-
msgbox.FindControl<TextBlock>("Text").Text = text;
65-
var buttonPanel = msgbox.FindControl<StackPanel>("Buttons");
55+
msgbox.Text.Text = text;
6656

6757
var res = MessageBoxResult.Ok;
6858

@@ -72,7 +62,7 @@ void AddButton(string caption, MessageBoxResult r, bool def = false) {
7262
res = r;
7363
msgbox.Close();
7464
};
75-
buttonPanel.Children.Add(btn);
65+
msgbox.Buttons.Children.Add(btn);
7666
if (def)
7767
res = r;
7868
}
@@ -99,7 +89,7 @@ public static MessageBox ShowModal(Window parent, string text, string title) {
9989
var msgbox = new MessageBox() {
10090
Title = title
10191
};
102-
msgbox.FindControl<TextBlock>("Text").Text = text;
92+
msgbox.Text.Text = text;
10393
msgbox.ShowDialog(parent);
10494
return msgbox;
10595
}

OpenUtau/Views/NoteDefaultsDialog.axaml.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System.IO;
2-
using Avalonia;
3-
using Avalonia.Controls;
1+
using Avalonia.Controls;
42
using Avalonia.Interactivity;
5-
using Avalonia.Markup.Xaml;
63
using OpenUtau.App.ViewModels;
74
using OpenUtau.Core.Util;
85

@@ -11,16 +8,9 @@ public partial class NoteDefaultsDialog : Window {
118
internal readonly NoteDefaultsViewModel ViewModel;
129
public NoteDefaultsDialog() {
1310
InitializeComponent();
14-
#if DEBUG
15-
this.AttachDevTools();
16-
#endif
1711
DataContext = ViewModel = new NoteDefaultsViewModel();
1812
}
1913

20-
private void InitializeComponent() {
21-
AvaloniaXamlLoader.Load(this);
22-
}
23-
2414
void OnSavePortamentoPreset(object sender, RoutedEventArgs e) {
2515
var dialog = new TypeInDialog() {
2616
Title = ThemeManager.GetString("notedefaults.preset.namenew"),

0 commit comments

Comments
 (0)