11using Avalonia ;
22using Avalonia . Controls ;
33using Avalonia . Controls . ApplicationLifetimes ;
4- using OpenLoco . Dat ;
54using OpenLoco . Dat . Data ;
65using OpenLoco . Dat . FileParsing ;
76using OpenLoco . Dat . Objects . Sound ;
@@ -46,7 +45,7 @@ public class DatObjectEditorViewModel : BaseLocoFileViewModel
4645 public ReactiveCommand < Unit , Unit > ViewHexCommand { get ; }
4746 public Interaction < HexWindowViewModel , HexWindowViewModel ? > HexViewerShowDialog { get ; }
4847
49- public ReactiveCommand < Unit , ObjectIndexEntry ? > SelectObjectCommand { get ; }
48+ // public ReactiveCommand<Unit, ObjectIndexEntry?> SelectObjectCommand { get; }
5049 public Interaction < ObjectSelectionWindowViewModel , ObjectSelectionWindowViewModel ? > SelectObjectShowDialog { get ; }
5150
5251 public DatObjectEditorViewModel ( FileSystemItemObject currentFile , ObjectEditorModel model )
@@ -61,20 +60,20 @@ public DatObjectEditorViewModel(FileSystemItemObject currentFile, ObjectEditorMo
6160
6261 ViewHexCommand = ReactiveCommand . CreateFromTask ( async ( ) =>
6362 {
64- var filename = Path . Combine ( Model . Settings . ObjDataDirectory , CurrentFile . Filename ) ;
65- var vm = new HexWindowViewModel ( filename , logger ) ;
63+ var vm = new HexWindowViewModel ( CurrentFile . Filename , logger ) ;
6664 _ = await HexViewerShowDialog . Handle ( vm ) ;
6765 } ) ;
6866
6967 SelectObjectShowDialog = new ( ) ;
7068 _ = SelectObjectShowDialog . RegisterHandler ( DoShowDialogAsync < ObjectSelectionWindowViewModel , ObjectSelectionWindow > ) ;
71- SelectObjectCommand = ReactiveCommand . CreateFromTask ( async ( ) =>
72- {
73- var objects = model . ObjectIndex . Objects . Where ( x => x . ObjectType == ObjectType . Tree ) ;
74- var vm = new ObjectSelectionWindowViewModel ( objects ) ;
75- var result = await SelectObjectShowDialog . Handle ( vm ) ;
76- return result . SelectedObject ;
77- } ) ;
69+
70+ //SelectObjectCommand = ReactiveCommand.CreateFromTask(async () =>
71+ //{
72+ // var objects = model.ObjectIndex.Objects.Where(x => x.ObjectType == ObjectType.Tree);
73+ // var vm = new ObjectSelectionWindowViewModel(objects);
74+ // var result = await SelectObjectShowDialog.Handle(vm);
75+ // return result.SelectedObject;
76+ //});
7877 }
7978
8079 static async Task DoShowDialogAsync < TViewModel , TWindow > ( IInteractionContext < TViewModel , TViewModel ? > interaction ) where TWindow : Window , new ( )
@@ -168,25 +167,25 @@ public override void Delete()
168167 }
169168
170169 // delete file
171- var path = Path . Combine ( Model . Settings . ObjDataDirectory , CurrentFile . Filename ) ;
172- if ( File . Exists ( path ) )
170+ if ( File . Exists ( CurrentFile . Filename ) )
173171 {
174- logger . Info ( $ "Deleting file \" { path } \" ") ;
175- File . Delete ( path ) ;
172+ logger . Info ( $ "Deleting file \" { CurrentFile . Filename } \" ") ;
173+ File . Delete ( CurrentFile . Filename ) ;
176174 }
177175 else
178176 {
179- logger . Info ( $ "File already deleted \" { path } \" ") ;
177+ logger . Info ( $ "File already deleted \" { CurrentFile . Filename } \" ") ;
180178 }
181179
182- // remove from object index
183- Model . ObjectIndex . Delete ( x => x . Filename == CurrentFile . Filename ) ;
180+ // note: it is not really possible to delete the entry from the index since if the user
181+ // has changed objdata folders but still has this item tab open, then there is no way
182+ // to delete. user can reindex to fix, or rely on automatic reindex at startup
184183 }
185184
186185 public override void Save ( )
187186 {
188187 var savePath = CurrentFile . FileLocation == FileLocation . Local
189- ? Path . Combine ( Model . Settings . ObjDataDirectory , CurrentFile . Filename )
188+ ? CurrentFile . Filename
190189 : Path . Combine ( Model . Settings . DownloadFolder , Path . ChangeExtension ( CurrentFile . DisplayName , ".dat" ) ) ;
191190 SaveCore ( savePath ) ;
192191 }
0 commit comments