public Gesture AddNewGesture() { if (!CanAddNewGesture) { return(null); //do not add a new gesture if any currently edited gesture doesn't contain enough data to be allowed to save } if (EditorVisible) { SaveGesture(); //CanAddNewGesture has already checked if CanSaveGesture when EditorVisible } // Clear the initial state store ExGesture = null; // Make the new gesture and name it properly Gesture g = MakeNewGesture(); g.Name = GlblRes.NewGesture; while (GestureCollection.Where(x => x.Name.StartsWith(g.Name)).Count() > 0) { g.Name += " " + Convert.ToString(GestureCollection.Where(x => x.Name.StartsWith(g.Name)).Count() + 1); } // Add the new gesture to the Gesture Collection GestureCollection.Add(g); // Go TheWorkspace.DataContext = g; ShowEditor(); return(g); }
public void AddNewGesture(object parameter) { // Clear the initial state store ExGesture = null; // Make the new gesture and name it properly Gesture g = MakeNewGesture(); g.Name = "New Gesture"; while (GestureCollection.Where(x => x.Name.StartsWith(g.Name)).Count() > 0) { g.Name += " " + Convert.ToString(GestureCollection.Where(x => x.Name.StartsWith(g.Name)).Count() + 1); } // Add the new gesture to the Gesture Collection GestureCollection.Add(g); // Go go go TheWorkspace.DataContext = g; LaunchEditor(); }
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); } } }
public void LoadGestureCollection(string filename) { string json = File.ReadAllText(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); GestureCollection.Clear(); foreach (Gesture sourceGesture in sourceList) { RemoveNoneKeys(sourceGesture.Command); //Seems somewhere at the serialization or deserialization Key.None creeps in, so remove it //copy sourceGesture to targetGesture //TODO: check why this copying is needed Gesture targetGesture = new Gesture() { Name = sourceGesture.Name, Command = new ObservableCollection <Key>(sourceGesture.Command), Hold = sourceGesture.Hold, Joint = sourceGesture.Joint }; //copy the frames too (note: this is not the same as DeepCopyGestureFrame) 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); if (GestureCollectionLoaded != null) { GestureCollectionLoaded(this, EventArgs.Empty); } } }