Skip to content

Commit

Permalink
Export list as CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeeynamo committed May 13, 2020
1 parent b62b403 commit 93f1ea2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions OpenKh.Tools.Kh2PlaceEditor/ViewModels/PlaceEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum EncodingType
}

private static readonly List<FileDialogFilter> Filters = FileDialogFilterComposer.Compose().AddExtensions("00place.bin or place.bin", "bin").AddAllFiles();
private static readonly List<FileDialogFilter> CsvFilter = FileDialogFilterComposer.Compose().AddExtensions("Map names as CSV", "csv");
private static readonly string ApplicationName = Utilities.GetApplicationName();

private Window Window => Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);
Expand All @@ -47,6 +48,7 @@ private string FileName
public RelayCommand OpenCommand { get; }
public RelayCommand SaveCommand { get; }
public RelayCommand SaveAsCommand { get; }
public RelayCommand ExportAsCsvCommand { get; }
public RelayCommand ExitCommand { get; }
public RelayCommand AboutCommand { get; }
public RelayCommand LoadSupportIdxCommand { get; }
Expand Down Expand Up @@ -108,6 +110,27 @@ public PlaceEditorViewModel()
new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
}, x => true);

ExportAsCsvCommand = new RelayCommand(_ =>
{
FileDialog.OnSave(fileName => File.CreateText(fileName).Using(writer =>
{
foreach (var place in Places.Items.Cast<PlaceViewModel>())
{
var row = new string[]
{
place.Map,
place.MessageId.ToString(),
place.Name,
place.Message
}
.Select(x => $"\"{x}\"");
writer.WriteLine(string.Join(",", row));
}
})
, CsvFilter);
});

LoadSupportIdxCommand = new RelayCommand(_ => Utilities.Catch(() =>
{
Kh2Utilities.OpenMsgFromIdxDialog(LoadMessages);
Expand Down
3 changes: 3 additions & 0 deletions OpenKh.Tools.Kh2PlaceEditor/Views/PlaceEditorWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<MenuItem Header="Save 00objentry _as..."
Command="{Binding SaveAsCommand}"/>
<Separator/>
<MenuItem Header="Export as CSV..."
Command="{Binding ExportAsCsvCommand}"/>
<Separator/>
<MenuItem Header="Su_pport files">
<MenuItem Header="Load _IDX/IMG" Command="{Binding LoadSupportIdxCommand}"/>
<MenuItem Header="Load MSG only" Command="{Binding LoadSupportMsgCommand}"/>
Expand Down

0 comments on commit 93f1ea2

Please sign in to comment.