Skip to content

Commit 20381b0

Browse files
maiko3tattunMaiko
authored andcommitted
Fixed unexpected behavior of welcome page (stakira#1550)
* Fixed unexpected behavior of welcome page * Delete LaunchBehaviour from preference, add template list in welcome page * change timing of page transition --------- Co-authored-by: Maiko <[email protected]>
1 parent 56f5a4b commit 20381b0

File tree

7 files changed

+111
-90
lines changed

7 files changed

+111
-90
lines changed

OpenUtau.Core/Util/Preferences.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public class SerializablePreferences {
188188
public bool RememberMid = false;
189189
public bool RememberUst = true;
190190
public bool RememberVsqx = true;
191-
public int LaunchBehaviour = 0;
192191
public int ImportTempo = 0;
193192
public string PhoneticAssistant = string.Empty;
194193
public string RecentOpenSingerDirectory = string.Empty;

OpenUtau/Strings/Strings.axaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ Warning: this option removes custom presets.</system:String>
375375
<system:String x:Key="prefs.advanced.importtempo.always">Always</system:String>
376376
<system:String x:Key="prefs.advanced.importtempo.ask">Ask me each time</system:String>
377377
<system:String x:Key="prefs.advanced.importtempo.never">Never</system:String>
378-
<system:String x:Key="prefs.advanced.launch">When launching</system:String>
379-
<system:String x:Key="prefs.advanced.launch.newproject">Open a new project</system:String>
380-
<system:String x:Key="prefs.advanced.launch.welcome">Show welcome page</system:String>
381378
<system:String x:Key="prefs.advanced.lyricshelper">Lyrics Helper</system:String>
382379
<system:String x:Key="prefs.advanced.lyricshelper.brackets">Lyrics Helper Adds Brackets</system:String>
383380
<system:String x:Key="prefs.advanced.rememberfiletypes">Remember these file types in "Open Recent"</system:String>
@@ -607,5 +604,6 @@ General
607604
<system:String x:Key="welcome.open.description">Open a local project</system:String>
608605
<system:String x:Key="welcome.recent">Recent</system:String>
609606
<system:String x:Key="welcome.start">Start</system:String>
607+
<system:String x:Key="welcome.template">Template</system:String>
610608

611609
</ResourceDictionary>

OpenUtau/ViewModels/MainWindowViewModel.cs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public class RecentFileInfo {
3232
public DateTime LastWriteTime { get; }
3333
public string LastWriteTimeStr { get; }
3434

35-
public RecentFileInfo(string directoryName) {
36-
PathName = directoryName;
37-
Name = Path.GetFileName(directoryName);
38-
Directory = Path.GetDirectoryName(directoryName) ?? string.Empty;
39-
LastWriteTime = System.IO.File.GetLastWriteTime(directoryName);
35+
public RecentFileInfo(string path) {
36+
PathName = path;
37+
Name = Path.GetFileName(path);
38+
Directory = Path.GetDirectoryName(path) ?? string.Empty;
39+
LastWriteTime = File.GetLastWriteTime(path);
4040
LastWriteTimeStr = LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
4141
}
4242
}
@@ -51,13 +51,14 @@ public class MainWindowViewModel : ViewModelBase, ICmdSubscriber {
5151
/// </summary>
5252
[Reactive] public int Page { get; set; } = 0;
5353
ObservableCollectionExtended<RecentFileInfo> RecentFiles { get; } = new ObservableCollectionExtended<RecentFileInfo>();
54+
ObservableCollectionExtended<RecentFileInfo> TemplateFiles { get; } = new ObservableCollectionExtended<RecentFileInfo>();
5455

5556
[Reactive] public PlaybackViewModel PlaybackViewModel { get; set; }
5657
[Reactive] public TracksViewModel TracksViewModel { get; set; }
5758
[Reactive] public ReactiveCommand<string, Unit>? OpenRecentCommand { get; private set; }
5859
[Reactive] public ReactiveCommand<string, Unit>? OpenTemplateCommand { get; private set; }
59-
public ObservableCollectionExtended<MenuItemViewModel> OpenRecent => openRecent;
60-
public ObservableCollectionExtended<MenuItemViewModel> OpenTemplates => openTemplates;
60+
public ObservableCollectionExtended<MenuItemViewModel> OpenRecentMenuItems => openRecentMenuItems;
61+
public ObservableCollectionExtended<MenuItemViewModel> OpenTemplatesMenuItems => openTemplatesMenuItems;
6162
public ObservableCollectionExtended<MenuItemViewModel> TimelineContextMenuItems { get; }
6263
= new ObservableCollectionExtended<MenuItemViewModel>();
6364

@@ -72,15 +73,12 @@ public class MainWindowViewModel : ViewModelBase, ICmdSubscriber {
7273
public ReactiveCommand<int, Unit>? AddTimeSigChangeCmd { get; set; }
7374
public ReactiveCommand<int, Unit>? DelTimeSigChangeCmd { get; set; }
7475

75-
private ObservableCollectionExtended<MenuItemViewModel> openRecent
76+
private ObservableCollectionExtended<MenuItemViewModel> openRecentMenuItems
7677
= new ObservableCollectionExtended<MenuItemViewModel>();
77-
private ObservableCollectionExtended<MenuItemViewModel> openTemplates
78+
private ObservableCollectionExtended<MenuItemViewModel> openTemplatesMenuItems
7879
= new ObservableCollectionExtended<MenuItemViewModel>();
7980

8081
public MainWindowViewModel() {
81-
if(Preferences.Default.LaunchBehaviour == 1){
82-
Page = 1;
83-
}
8482
PlaybackViewModel = new PlaybackViewModel();
8583
TracksViewModel = new TracksViewModel();
8684
ClearCacheHeader = string.Empty;
@@ -89,25 +87,12 @@ public MainWindowViewModel() {
8987
RecentFiles.AddRange(Preferences.Default.RecentFiles
9088
.Select(file => new RecentFileInfo(file))
9189
.OrderByDescending(f => f.LastWriteTime));
92-
OpenRecentCommand = ReactiveCommand.Create<string>(file => {
93-
Page = 1;
94-
try {
95-
OpenProject(new[] { file });
96-
} catch (Exception e) {
97-
var customEx = new MessageCustomizableException("Failed to open recent", "<translate:errors.failed.openfile>: recent project", e);
98-
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
99-
}
100-
});
101-
OpenTemplateCommand = ReactiveCommand.Create<string>(file => {
102-
try {
103-
OpenProject(new[] { file });
104-
DocManager.Inst.Project.Saved = false;
105-
DocManager.Inst.Project.FilePath = string.Empty;
106-
} catch (Exception e) {
107-
var customEx = new MessageCustomizableException("Failed to open template", "<translate:errors.failed.openfile>: project template", e);
108-
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
109-
}
110-
});
90+
TemplateFiles.Clear();
91+
Directory.CreateDirectory(PathManager.Inst.TemplatesPath);
92+
TemplateFiles.AddRange(Directory.GetFiles(PathManager.Inst.TemplatesPath, "*.ustx")
93+
.Select(file => new RecentFileInfo(file)));
94+
OpenRecentCommand = ReactiveCommand.Create<string>(OpenRecent);
95+
OpenTemplateCommand = ReactiveCommand.Create<string>(OpenTemplate);
11196
PartDeleteCommand = ReactiveCommand.Create<UPart>(part => {
11297
TracksViewModel.DeleteSelectedParts();
11398
});
@@ -133,6 +118,7 @@ public async void InitProject(MainWindow window) {
133118
DocManager.Inst.ExecuteCmd(new LoadingNotification(typeof(MainWindow), true, "project"));
134119
try {
135120
Core.Format.Formats.RecoveryProject(new string[] { recPath });
121+
Page = 1;
136122
DocManager.Inst.ExecuteCmd(new VoiceColorRemappingNotification(-1, true));
137123
DocManager.Inst.Recovered = true;
138124
this.RaisePropertyChanged(nameof(Title));
@@ -145,9 +131,9 @@ public async void InitProject(MainWindow window) {
145131

146132
var args = Environment.GetCommandLineArgs();
147133
if (args.Length == 2 && File.Exists(args[1])) {
148-
Page = 1;
149134
try {
150135
Core.Format.Formats.LoadProject(new string[] { args[1] });
136+
Page = 1;
151137
DocManager.Inst.ExecuteCmd(new VoiceColorRemappingNotification(-1, true));
152138
} catch (Exception e) {
153139
var customEx = new MessageCustomizableException($"Failed to open file {args[1]}", $"<translate:errors.failed.openfile>: {args[1]}", e);
@@ -163,6 +149,7 @@ public void NewProject() {
163149
OpenProject(new[] { defaultTemplate });
164150
DocManager.Inst.Project.Saved = false;
165151
DocManager.Inst.Project.FilePath = string.Empty;
152+
this.RaisePropertyChanged(nameof(Title));
166153
return;
167154
} catch (Exception e) {
168155
var customEx = new MessageCustomizableException("Failed to load default template", "<translate:errors.failed.load>: default template", e);
@@ -188,6 +175,29 @@ public void OpenProject(string[] files) {
188175
DocManager.Inst.Recovered = false;
189176
}
190177

178+
public void OpenRecent(string file) {
179+
try {
180+
OpenProject(new string[] { file });
181+
Page = 1;
182+
} catch (Exception e) {
183+
var customEx = new MessageCustomizableException("Failed to open recent", "<translate:errors.failed.openfile>: recent project", e);
184+
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
185+
}
186+
}
187+
188+
public void OpenTemplate(string file) {
189+
try {
190+
OpenProject(new string[] { file });
191+
Page = 1;
192+
DocManager.Inst.Project.Saved = false;
193+
DocManager.Inst.Project.FilePath = string.Empty;
194+
this.RaisePropertyChanged(nameof(Title));
195+
} catch (Exception e) {
196+
var customEx = new MessageCustomizableException("Failed to open template", "<translate:errors.failed.openfile>: project template", e);
197+
DocManager.Inst.ExecuteCmd(new ErrorMessageNotification(customEx));
198+
}
199+
}
200+
191201
public void SaveProject(string file = "") {
192202
if (file == null) {
193203
return;
@@ -252,8 +262,8 @@ public void ImportMidi(string file) {
252262
}
253263

254264
public void RefreshOpenRecent() {
255-
openRecent.Clear();
256-
openRecent.AddRange(Core.Util.Preferences.Default.RecentFiles.Select(file => new MenuItemViewModel() {
265+
openRecentMenuItems.Clear();
266+
openRecentMenuItems.AddRange(Preferences.Default.RecentFiles.Select(file => new MenuItemViewModel() {
257267
Header = file,
258268
Command = OpenRecentCommand,
259269
CommandParameter = file,
@@ -263,8 +273,8 @@ public void RefreshOpenRecent() {
263273
public void RefreshTemplates() {
264274
Directory.CreateDirectory(PathManager.Inst.TemplatesPath);
265275
var templates = Directory.GetFiles(PathManager.Inst.TemplatesPath, "*.ustx");
266-
openTemplates.Clear();
267-
openTemplates.AddRange(templates.Select(file => new MenuItemViewModel() {
276+
openTemplatesMenuItems.Clear();
277+
openTemplatesMenuItems.AddRange(templates.Select(file => new MenuItemViewModel() {
268278
Header = Path.GetRelativePath(PathManager.Inst.TemplatesPath, file),
269279
Command = OpenTemplateCommand,
270280
CommandParameter = file,

OpenUtau/ViewModels/PreferencesViewModel.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public override string ToString() {
100100
[Reactive] public bool RememberMid{ get; set; }
101101
[Reactive] public bool RememberUst{ get; set; }
102102
[Reactive] public bool RememberVsqx{ get; set; }
103-
[Reactive] public int LaunchBehaviour{ get; set; }
104103
[Reactive] public int ImportTempo{ get; set; }
105104

106105
private List<AudioOutputDevice>? audioOutputDevices;
@@ -168,7 +167,6 @@ public PreferencesViewModel() {
168167
RememberMid = Preferences.Default.RememberMid;
169168
RememberUst = Preferences.Default.RememberUst;
170169
RememberVsqx = Preferences.Default.RememberVsqx;
171-
LaunchBehaviour = Preferences.Default.LaunchBehaviour;
172170
ImportTempo = Preferences.Default.ImportTempo;
173171
ClearCacheOnQuit = Preferences.Default.ClearCacheOnQuit;
174172

@@ -328,11 +326,6 @@ public PreferencesViewModel() {
328326
Preferences.Default.RememberVsqx = index;
329327
Preferences.Save();
330328
});
331-
this.WhenAnyValue(vm => vm.LaunchBehaviour)
332-
.Subscribe(index => {
333-
Preferences.Default.LaunchBehaviour = index;
334-
Preferences.Save();
335-
});
336329
this.WhenAnyValue(vm => vm.ImportTempo)
337330
.Subscribe(index => {
338331
Preferences.Default.ImportTempo = index;

OpenUtau/Views/MainWindow.axaml

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
<Menu Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" HorizontalAlignment="Left" Height="24"
2222
Opened="OnMainMenuOpened" Closed="OnMainMenuClosed" PointerExited="OnMainMenuPointerLeave"
2323
ZIndex="1">
24-
<MenuItem Header="{DynamicResource menu.file}">
24+
<MenuItem Header="{DynamicResource menu.file}" IsEnabled="{Binding Page}">
2525
<MenuItem Header="{DynamicResource menu.file.new}" InputGesture="Ctrl+N" Click="OnMenuNew"/>
26-
<MenuItem Header="{DynamicResource menu.file.newfromtemplate}" ItemsSource="{Binding OpenTemplates}" Classes="MenuItemWithSubMenu"/>
26+
<MenuItem Header="{DynamicResource menu.file.newfromtemplate}" ItemsSource="{Binding OpenTemplatesMenuItems}" Classes="MenuItemWithSubMenu"/>
2727
<MenuItem Header="{DynamicResource menu.file.savetemplate}" Click="OnMenuSaveTemplate"/>
2828
<MenuItem Header="-" Height="1"/>
2929
<MenuItem Header="{DynamicResource menu.file.open}" InputGesture="Ctrl+O" Click="OnMenuOpen"/>
30-
<MenuItem Header="{DynamicResource menu.file.openrecent}" ItemsSource="{Binding OpenRecent}" Classes="MenuItemWithSubMenu"/>
30+
<MenuItem Header="{DynamicResource menu.file.openrecent}" ItemsSource="{Binding OpenRecentMenuItems}" Classes="MenuItemWithSubMenu"/>
3131
<MenuItem Header="{DynamicResource menu.file.openprojectlocation}" Click="OnMenuOpenProjectLocation"/>
3232
<MenuItem Header="-" Height="1"/>
3333
<MenuItem Header="{DynamicResource menu.file.save}" InputGesture="Ctrl+S" Click="OnMenuSave"/>
@@ -53,11 +53,11 @@
5353
</MenuItem>
5454
<MenuItem Header="{DynamicResource menu.file.openexportlocation}" Click="OnMenuOpenProjectLocation"/>
5555
</MenuItem>
56-
<MenuItem Header="{DynamicResource menu.edit}">
56+
<MenuItem Header="{DynamicResource menu.edit}" IsEnabled="{Binding Page}">
5757
<MenuItem Header="{DynamicResource menu.edit.undo}" InputGesture="Ctrl+Z" Command="{Binding Undo}"/>
5858
<MenuItem Header="{DynamicResource menu.edit.redo}" InputGesture="Ctrl+Y" Command="{Binding Redo}"/>
5959
</MenuItem>
60-
<MenuItem Header="{DynamicResource menu.project}">
60+
<MenuItem Header="{DynamicResource menu.project}" IsEnabled="{Binding Page}">
6161
<MenuItem Header="{DynamicResource menu.project.expressions}" Click="OnMenuExpressionss"/>
6262
<MenuItem Header="{DynamicResource menu.project.remaptimeaxis}" Click="OnMenuRemapTimeaxis"/>
6363
</MenuItem>
@@ -89,8 +89,8 @@
8989
</Menu>
9090
<Carousel SelectedIndex="{Binding Page}" >
9191
<!--Welcome page-->
92-
<ScrollViewer>
93-
<StackPanel Margin="60" Spacing="8">
92+
<Grid Margin="60,50,60,40" RowDefinitions="Auto,Auto,*" ColumnDefinitions="*,*">
93+
<StackPanel Grid.Row="0" Grid.ColumnSpan="2" Spacing="8">
9494
<!--Create new project or open existing project-->
9595
<TextBlock Text="{DynamicResource welcome.start}" FontSize="20"/>
9696
<WrapPanel Margin="-4" Orientation="Horizontal">
@@ -160,28 +160,49 @@
160160
</Grid>
161161
</Button>
162162
</WrapPanel>
163-
164-
<!-- Recent files -->
165-
<TextBlock Margin="0,24,0,0" Text="{DynamicResource welcome.recent}" FontSize="20"/>
166-
<ListBox ItemsSource="{Binding RecentFiles}">
167-
<ListBox.Styles>
168-
<Style Selector="ListBoxItem">
169-
<Setter Property="Height" Value="48" />
170-
<Setter Property="Padding" Value="16,0" />
171-
<Setter Property="VerticalContentAlignment" Value="Center" />
172-
</Style>
173-
</ListBox.Styles>
174-
<ListBox.ItemTemplate>
175-
<DataTemplate x:DataType="vm:RecentFileInfo">
176-
<StackPanel Margin="0,4" PointerPressed="OnWelcomeRecent" Background="Transparent">
177-
<TextBlock FontSize="16" Text="{Binding Name}"/>
178-
<TextBlock FontSize="12" Text="{Binding Directory}"/>
179-
</StackPanel>
180-
</DataTemplate>
181-
</ListBox.ItemTemplate>
182-
</ListBox>
183163
</StackPanel>
184-
</ScrollViewer>
164+
165+
<!-- Recent files -->
166+
<TextBlock Grid.Row="1" Grid.Column="0" Margin="0,24,0,8" Text="{DynamicResource welcome.recent}" FontSize="20"/>
167+
<ListBox ItemsSource="{Binding RecentFiles}" Grid.Row="2" Grid.Column="0" Margin="0,0,15,0">
168+
<ListBox.Styles>
169+
<Style Selector="ListBoxItem">
170+
<Setter Property="Height" Value="NaN" />
171+
<Setter Property="MinHeight" Value="48" />
172+
<Setter Property="Padding" Value="16,0" />
173+
<Setter Property="VerticalContentAlignment" Value="Center" />
174+
</Style>
175+
</ListBox.Styles>
176+
<ListBox.ItemTemplate>
177+
<DataTemplate x:DataType="vm:RecentFileInfo">
178+
<StackPanel Margin="0,4" PointerPressed="OnWelcomeRecent" Background="Transparent">
179+
<TextBlock FontSize="16" Text="{Binding Name}"/>
180+
<TextBlock FontSize="12" Text="{Binding Directory}" TextWrapping="Wrap"/>
181+
</StackPanel>
182+
</DataTemplate>
183+
</ListBox.ItemTemplate>
184+
</ListBox>
185+
186+
<!-- Template files -->
187+
<TextBlock Grid.Row="1" Grid.Column="1" Margin="15,24,0,8" Text="{DynamicResource welcome.template}" FontSize="20"/>
188+
<ListBox ItemsSource="{Binding TemplateFiles}" Grid.Row="2" Grid.Column="1" Margin="15,0,0,0">
189+
<ListBox.Styles>
190+
<Style Selector="ListBoxItem">
191+
<Setter Property="Height" Value="NaN" />
192+
<Setter Property="MinHeight" Value="48" />
193+
<Setter Property="Padding" Value="16,0" />
194+
<Setter Property="VerticalContentAlignment" Value="Center" />
195+
</Style>
196+
</ListBox.Styles>
197+
<ListBox.ItemTemplate>
198+
<DataTemplate x:DataType="vm:RecentFileInfo">
199+
<StackPanel Margin="0,4" PointerPressed="OnWelcomeTemplate" Background="Transparent">
200+
<TextBlock FontSize="16" Text="{Binding Name}"/>
201+
</StackPanel>
202+
</DataTemplate>
203+
</ListBox.ItemTemplate>
204+
</ListBox>
205+
</Grid>
185206

186207
<!--Main page-->
187208
<Grid RowDefinitions="24,24,1*,20,4" ColumnDefinitions="300,*,24" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

0 commit comments

Comments
 (0)