private bool PromptFileSave(out string fileName, out string formatId) { var exportFormats = ModelViewerPlugin.GetExportFormats() .Select(f => new { FormatId = f, Extension = ModelViewerPlugin.GetFormatExtension(f), Description = ModelViewerPlugin.GetFormatDescription(f) }).ToList(); var filter = string.Join("|", exportFormats.Select(f => $"{f.Description}|*.{f.Extension}")); var sfd = new SaveFileDialog { OverwritePrompt = true, FileName = model.Name, Filter = filter, FilterIndex = 1 + exportFormats.TakeWhile(f => f.FormatId != ModelViewerPlugin.Settings.DefaultSaveFormat).Count(), AddExtension = true }; if (sfd.ShowDialog() != true) { fileName = formatId = null; return(false); } fileName = sfd.FileName; formatId = exportFormats[sfd.FilterIndex - 1].FormatId; ModelViewerPlugin.Settings.DefaultSaveFormat = formatId; return(true); }
public ItemCollection GetValues() { var items = ModelViewerPlugin.GetExportFormats() .Select(id => new Item { Value = id, DisplayName = ModelViewerPlugin.GetFormatDescription(id) }) .OrderBy(i => i.DisplayName); var result = new ItemCollection(); result.AddRange(items); return(result); }