@@ -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 ,
0 commit comments