private void RegenerateRecentlyOpened() { // Regenerate menu item OpenRecentItem.Items.Clear(); for (int i = recentlyOpenedFiles.Count - 1; i >= 0; i--) { string path = recentlyOpenedFiles[i]; MenuItem menuItem = new MenuItem { Header = Util.ShortenPath(path), }; menuItem.Click += (sender, args) => { string filename = Path.GetFileName(path); GameDataType?type = ObjectTypeSelector.Show(this, filename.Split('.')[0]); if (type is null) { return; } OpenFile(path, (GameDataType)type, filename.EndsWith(".zst")); }; OpenRecentItem.Items.Add(menuItem); } }
public static GameDataType?Show(Window parent, GameDataType defaultValue = GameDataType.None) { ObjectTypeSelector typeSelector = new ObjectTypeSelector { SelectionBox = { SelectedIndex = (int)defaultValue }, WindowStartupLocation = WindowStartupLocation.CenterOwner, Owner = parent, }; typeSelector.ShowDialog(); if (typeSelector.submitted == true) { return((GameDataType)typeSelector.SelectionBox.SelectedIndex); } else { return(null); } }
private void CommandBinding_Open_Executed(object sender, ExecutedRoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog { FileName = "dispos_Npc.elf", DefaultExt = ".elf", Filter = "All ELF Files (*.elf; *.elf.zst)|*.elf;*.elf.zst|ELF Files (*.elf)|*.elf|Zstd Compressed ELF Files (*.elf.zst)|*.elf.zst", }; bool?result = dialog.ShowDialog(this); if (result == true) { string simpleFileName = dialog.SafeFileName.Split('.')[0]; GameDataType?type = ObjectTypeSelector.Show(this, simpleFileName); if (type is null) { return; } bool isCompressed = dialog.FilterIndex == 3 || dialog.FilterIndex == 1 && dialog.SafeFileName.EndsWith(".elf.zst"); OpenFile(dialog.FileName, (GameDataType)type, isCompressed); } }