Exemplo n.º 1
0
        public void CreateNewGestureCollection()
        {
            if (MessageBox.Show(GlblRes.DiscardGestureCollectionConfirmation,
                                GlblRes.CreateNewGestureCollection, MessageBoxButton.YesNo)
                == MessageBoxResult.Yes)
            {
                GestureCollection.Clear();
            }

            if (GestureCollectionLoaded != null)
            {
                GestureCollectionLoaded(this, EventArgs.Empty);
            }
        }
Exemplo n.º 2
0
        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);
                }
            }
        }