@@ -15,8 +15,14 @@ public MainViewModel()
15
15
ChooseFileCommand = new RelayCommand ( ChooseFile ) ;
16
16
ReadFixCommand = new RelayCommand ( ReadFix ) ;
17
17
WriteFixCommand = new RelayCommand ( WriteFix ) ;
18
+ ImportCsvCommand = new RelayCommand ( ImportCsv ) ;
19
+ ExportCsvCommand = new RelayCommand ( ExportCsv ) ;
20
+ CopyOffsetCommand = new RelayCommand ( CopyOffset ) ;
21
+ CopyTextCommand = new RelayCommand ( CopyText ) ;
18
22
}
19
23
24
+ private long _previousOffset ;
25
+
20
26
private FixManager Manager { get ; set ; }
21
27
22
28
public ObservableCollection < FixString > FixStrings { get ; set ; }
@@ -26,10 +32,14 @@ public MainViewModel()
26
32
public ICommand ChooseFileCommand { get ; }
27
33
public ICommand ReadFixCommand { get ; }
28
34
public ICommand WriteFixCommand { get ; }
35
+ public ICommand ImportCsvCommand { get ; }
36
+ public ICommand ExportCsvCommand { get ; }
37
+ public ICommand CopyOffsetCommand { get ; }
38
+ public ICommand CopyTextCommand { get ; }
29
39
30
40
private void ChooseFile ( )
31
41
{
32
- OpenFileDialog dialog = new OpenFileDialog ( ) ;
42
+ OpenFileDialog dialog = new OpenFileDialog { FileName = "Fix.sna" , Filter = "SNA File (*.sna)|*.sna|All Files (*.*)|*.*" } ;
33
43
dialog . ShowDialog ( ) ;
34
44
35
45
if ( ! string . IsNullOrWhiteSpace ( dialog . FileName ) )
@@ -46,17 +56,51 @@ private void ReadFix()
46
56
47
57
private void WriteFix ( )
48
58
{
49
- if ( ! File . Exists ( FixPath ) ) return ;
59
+ if ( Manager == null || ! File . Exists ( FixPath ) ) return ;
50
60
51
61
Manager . BackupFix ( ) ;
52
62
Manager . WriteFix ( FixStrings ) ;
53
63
54
64
MessageBox . Show ( $ "Written { FixStrings . Count } strings to { FixPath } .") ;
55
65
}
56
66
67
+ private void ImportCsv ( )
68
+ {
69
+ if ( FixStrings == null ) return ;
70
+
71
+ OpenFileDialog dialog = new OpenFileDialog { Filter = "Comma-separated values (*.csv)|*.csv" } ;
72
+ dialog . ShowDialog ( ) ;
73
+
74
+ if ( ! string . IsNullOrWhiteSpace ( dialog . FileName ) )
75
+ CsvUtils . ImportCsv ( FixStrings , dialog . FileName ) ;
76
+ }
77
+
78
+ private void ExportCsv ( )
79
+ {
80
+ if ( FixStrings == null ) return ;
81
+
82
+ SaveFileDialog dialog = new SaveFileDialog { Filter = "Comma-separated values (*.csv)|*.csv" } ;
83
+ dialog . ShowDialog ( ) ;
84
+
85
+ if ( string . IsNullOrWhiteSpace ( dialog . FileName ) ) return ;
86
+
87
+ CsvUtils . ExportCsv ( FixStrings , dialog . FileName ) ;
88
+ MessageBox . Show ( $ "Strings successfully exported to { dialog . FileName } ") ;
89
+ }
90
+
91
+ public void CopyOffset ( )
92
+ {
93
+ Clipboard . SetText ( SelectedItem ? . Offset . ToString ( "X" ) ?? string . Empty ) ;
94
+ }
95
+
96
+ public void CopyText ( )
97
+ {
98
+ Clipboard . SetText ( SelectedItem ? . Text ?? string . Empty ) ;
99
+ }
100
+
57
101
public void GoToOffset ( )
58
102
{
59
- OffsetEntryWindow dialog = new OffsetEntryWindow
103
+ OffsetEntryWindow dialog = new OffsetEntryWindow ( _previousOffset )
60
104
{
61
105
Owner = Application . Current . MainWindow ,
62
106
WindowStartupLocation = WindowStartupLocation . CenterOwner
@@ -66,7 +110,11 @@ public void GoToOffset()
66
110
if ( ! dialog . Result ) return ;
67
111
68
112
FixString foundOffset = FixStrings . FirstOrDefault ( x => x . Offset == dialog . Offset ) ;
69
- if ( foundOffset != null ) SelectedItem = foundOffset ;
113
+ if ( foundOffset != null )
114
+ {
115
+ SelectedItem = foundOffset ;
116
+ _previousOffset = foundOffset . Offset ;
117
+ }
70
118
}
71
119
}
72
120
}
0 commit comments