@@ -15,8 +15,14 @@ public MainViewModel()
1515 ChooseFileCommand = new RelayCommand ( ChooseFile ) ;
1616 ReadFixCommand = new RelayCommand ( ReadFix ) ;
1717 WriteFixCommand = new RelayCommand ( WriteFix ) ;
18+ ImportCsvCommand = new RelayCommand ( ImportCsv ) ;
19+ ExportCsvCommand = new RelayCommand ( ExportCsv ) ;
20+ CopyOffsetCommand = new RelayCommand ( CopyOffset ) ;
21+ CopyTextCommand = new RelayCommand ( CopyText ) ;
1822 }
1923
24+ private long _previousOffset ;
25+
2026 private FixManager Manager { get ; set ; }
2127
2228 public ObservableCollection < FixString > FixStrings { get ; set ; }
@@ -26,10 +32,14 @@ public MainViewModel()
2632 public ICommand ChooseFileCommand { get ; }
2733 public ICommand ReadFixCommand { get ; }
2834 public ICommand WriteFixCommand { get ; }
35+ public ICommand ImportCsvCommand { get ; }
36+ public ICommand ExportCsvCommand { get ; }
37+ public ICommand CopyOffsetCommand { get ; }
38+ public ICommand CopyTextCommand { get ; }
2939
3040 private void ChooseFile ( )
3141 {
32- OpenFileDialog dialog = new OpenFileDialog ( ) ;
42+ OpenFileDialog dialog = new OpenFileDialog { FileName = "Fix.sna" , Filter = "SNA File (*.sna)|*.sna|All Files (*.*)|*.*" } ;
3343 dialog . ShowDialog ( ) ;
3444
3545 if ( ! string . IsNullOrWhiteSpace ( dialog . FileName ) )
@@ -46,17 +56,51 @@ private void ReadFix()
4656
4757 private void WriteFix ( )
4858 {
49- if ( ! File . Exists ( FixPath ) ) return ;
59+ if ( Manager == null || ! File . Exists ( FixPath ) ) return ;
5060
5161 Manager . BackupFix ( ) ;
5262 Manager . WriteFix ( FixStrings ) ;
5363
5464 MessageBox . Show ( $ "Written { FixStrings . Count } strings to { FixPath } .") ;
5565 }
5666
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+
57101 public void GoToOffset ( )
58102 {
59- OffsetEntryWindow dialog = new OffsetEntryWindow
103+ OffsetEntryWindow dialog = new OffsetEntryWindow ( _previousOffset )
60104 {
61105 Owner = Application . Current . MainWindow ,
62106 WindowStartupLocation = WindowStartupLocation . CenterOwner
@@ -66,7 +110,11 @@ public void GoToOffset()
66110 if ( ! dialog . Result ) return ;
67111
68112 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+ }
70118 }
71119 }
72120}
0 commit comments