1
1
using Avalonia ;
2
2
using Avalonia . Controls ;
3
3
using Avalonia . Controls . ApplicationLifetimes ;
4
- using OpenLoco . Dat ;
5
4
using OpenLoco . Dat . Data ;
6
5
using OpenLoco . Dat . FileParsing ;
7
6
using OpenLoco . Dat . Objects . Sound ;
@@ -46,7 +45,7 @@ public class DatObjectEditorViewModel : BaseLocoFileViewModel
46
45
public ReactiveCommand < Unit , Unit > ViewHexCommand { get ; }
47
46
public Interaction < HexWindowViewModel , HexWindowViewModel ? > HexViewerShowDialog { get ; }
48
47
49
- public ReactiveCommand < Unit , ObjectIndexEntry ? > SelectObjectCommand { get ; }
48
+ // public ReactiveCommand<Unit, ObjectIndexEntry?> SelectObjectCommand { get; }
50
49
public Interaction < ObjectSelectionWindowViewModel , ObjectSelectionWindowViewModel ? > SelectObjectShowDialog { get ; }
51
50
52
51
public DatObjectEditorViewModel ( FileSystemItemObject currentFile , ObjectEditorModel model )
@@ -61,20 +60,20 @@ public DatObjectEditorViewModel(FileSystemItemObject currentFile, ObjectEditorMo
61
60
62
61
ViewHexCommand = ReactiveCommand . CreateFromTask ( async ( ) =>
63
62
{
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 ) ;
66
64
_ = await HexViewerShowDialog . Handle ( vm ) ;
67
65
} ) ;
68
66
69
67
SelectObjectShowDialog = new ( ) ;
70
68
_ = 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
+ //});
78
77
}
79
78
80
79
static async Task DoShowDialogAsync < TViewModel , TWindow > ( IInteractionContext < TViewModel , TViewModel ? > interaction ) where TWindow : Window , new ( )
@@ -168,25 +167,25 @@ public override void Delete()
168
167
}
169
168
170
169
// delete file
171
- var path = Path . Combine ( Model . Settings . ObjDataDirectory , CurrentFile . Filename ) ;
172
- if ( File . Exists ( path ) )
170
+ if ( File . Exists ( CurrentFile . Filename ) )
173
171
{
174
- logger . Info ( $ "Deleting file \" { path } \" ") ;
175
- File . Delete ( path ) ;
172
+ logger . Info ( $ "Deleting file \" { CurrentFile . Filename } \" ") ;
173
+ File . Delete ( CurrentFile . Filename ) ;
176
174
}
177
175
else
178
176
{
179
- logger . Info ( $ "File already deleted \" { path } \" ") ;
177
+ logger . Info ( $ "File already deleted \" { CurrentFile . Filename } \" ") ;
180
178
}
181
179
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
184
183
}
185
184
186
185
public override void Save ( )
187
186
{
188
187
var savePath = CurrentFile . FileLocation == FileLocation . Local
189
- ? Path . Combine ( Model . Settings . ObjDataDirectory , CurrentFile . Filename )
188
+ ? CurrentFile . Filename
190
189
: Path . Combine ( Model . Settings . DownloadFolder , Path . ChangeExtension ( CurrentFile . DisplayName , ".dat" ) ) ;
191
190
SaveCore ( savePath ) ;
192
191
}
0 commit comments