public void CreateNewGestureCollection(object parameter) { if (MessageBox.Show("Do you really want to discard the current gesture collection and create a new one?", "Create New Gesture Collection", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { while (GestureCollection.Count > 0) { GestureCollection.RemoveAt(0); } } }
public void LoadGestureCollection(object parameter) { // Conjure file explorer OpenFileDialog openDialog = new OpenFileDialog(); // F*****g around with file formats openDialog.Filter = "Hotspotizer Gesture files (*.hsjson)|*.hsjson"; // Read and load if dialog returns OK if (openDialog.ShowDialog() == true) { string json = File.ReadAllText(openDialog.FileName); // DeserializeObject() does not appear to correctly deserialize Gesture objects // Below is a kinda-dirty solution around that List <Gesture> sourceList = JsonConvert.DeserializeObject <List <Gesture> >(json); while (GestureCollection.Count > 0) { GestureCollection.RemoveAt(0); } foreach (Gesture sourceGesture in sourceList) { Gesture targetGesture = new Gesture(); targetGesture.Name = sourceGesture.Name; targetGesture.Command = new ObservableCollection <Key>(sourceGesture.Command); targetGesture.Hold = sourceGesture.Hold; targetGesture.Joint = sourceGesture.Joint; while (targetGesture.Frames.Count > 0) { targetGesture.Frames.RemoveAt(0); } foreach (GestureFrame sourceFrame in sourceGesture.Frames) { GestureFrame targetFrame = new GestureFrame(); for (int i = 0; i < 400; i++) { targetFrame.FrontCells[i] = sourceFrame.FrontCells[i]; targetFrame.SideCells[i] = sourceFrame.SideCells[i]; } targetGesture.Frames.Add(targetFrame); } GestureCollection.Add(targetGesture); } } }