public PatternTabItem(PatternHolder pattern) { InitializeComponent(); ViewMap = new Dictionary <TreeViewItem, IHolder>(); TreeViewItem root = new TreeViewItem(); root.Header = "root"; root.Selected += TabItemSelected; ViewMap.Add(root, pattern); for (int i = 0; i < pattern.Layers.Length; i++) { TreeViewItem layerItem = new TreeViewItem(); layerItem.Header = "layer " + i; ViewMap.Add(layerItem, pattern.Layers[i]); foreach (LayerContent b in pattern.Layers[i].Content) { TreeViewItem contentItem = new TreeViewItem(); switch (b.Type) { case LayerContent.ContentType.Batch: contentItem.Header = "batch"; break; case LayerContent.ContentType.Laser: contentItem.Header = "laser"; break; case LayerContent.ContentType.Cover: contentItem.Header = "cover"; break; case LayerContent.ContentType.Rebound: contentItem.Header = "rebound"; break; case LayerContent.ContentType.Force: contentItem.Header = "force"; break; } ViewMap.Add(contentItem, b); contentItem.Selected += TabItemSelected; layerItem.Items.Add(contentItem); } layerItem.Selected += TabItemSelected; root.Items.Add(layerItem); } root.ExpandSubtree(); TreeView.Items.Add(root); Pattern = pattern; }
private void OpenAsPattern(object sender, RoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Encrypted Files (*.*)|*.*|Plain Files (*.*)|*.*"; dialog.Multiselect = true; if (dialog.ShowDialog() == true) { foreach (string path in dialog.FileNames) { string content; if (dialog.FilterIndex == 1) { try { content = Crypt.ReadFromFile(path, FDF1Checkbox.IsChecked, GetSelectedKeyIndex()); } catch (Exception ex) { MessageBox.Show("Error decrypting file " + path + "\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); continue; } } else { content = File.ReadAllText(path); } try { PatternHolder pHolder = PatternHolder.Parse(new MemoryStream(Encoding.UTF8.GetBytes(content))); OpenTab(Path.GetFileName(path), new PatternTabItem(pHolder)); } catch (Exception ex) { MessageBox.Show("Error parsing file " + path + "\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); continue; } } } }
public PatternView(PatternHolder holder) { InitializeComponent(); DataContext = holder; this.holder = holder; }