コード例 #1
0
        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            Visualization item  = (Visualization)visualizationGrid.SelectedItem;
            int           index = visualizationGrid.SelectedIndex;

            VisualizationList.RemoveAt(index);

            // Keep selection at same index, unless we just removed the item at the end.
            if (index == VisualizationList.Count)
            {
                index--;
            }
            if (index >= 0)
            {
                visualizationGrid.SelectedIndex = index;
            }

            RemovedSerials.Add(item.SerialNumber);

            // Update any animations in this set.  Animations in other sets will be updated later.
            // (This is a bit awkward because we can't modify VisualizationList while iterating
            // through it, and there's no simple "replace entry" operation on an observable
            // collection.  Fortunately we don't do this often and the data sets are small.)
            List <VisualizationAnimation> needsUpdate = new List <VisualizationAnimation>();

            foreach (Visualization vis in VisualizationList)
            {
                if (vis is VisualizationAnimation)
                {
                    VisualizationAnimation visAnim = (VisualizationAnimation)vis;
                    if (visAnim.ContainsSerial(item.SerialNumber))
                    {
                        needsUpdate.Add(visAnim);
                    }
                }
            }
            foreach (VisualizationAnimation visAnim in needsUpdate)
            {
                VisualizationAnimation newAnim;
                if (VisualizationAnimation.StripEntries(visAnim,
                                                        new List <int>(1)
                {
                    item.SerialNumber
                }, out newAnim))
                {
                    if (newAnim.Count == 0)
                    {
                        VisualizationList.Remove(visAnim);
                    }
                    else
                    {
                        newAnim.GenerateImage(CreateEditedSetList());
                        index = VisualizationList.IndexOf(visAnim);
                        VisualizationList.Remove(visAnim);
                        VisualizationList.Insert(index, newAnim);
                    }
                }
            }
        }
コード例 #2
0
        private void EditSelectedItem()
        {
            if (!IsEditEnabled)
            {
                // can get called here by a double-click
                return;
            }
            Visualization item = (Visualization)visualizationGrid.SelectedItem;
            Visualization newVis;

            if (item is VisualizationAnimation)
            {
                EditBitmapAnimation dlg = new EditBitmapAnimation(this, mOffset,
                                                                  CreateEditedSetList(), (VisualizationAnimation)item);
                if (dlg.ShowDialog() != true)
                {
                    return;
                }
                newVis = dlg.NewAnim;
            }
            else
            {
                EditVisualization dlg = new EditVisualization(this, mProject, mFormatter, mOffset,
                                                              CreateEditedSetList(), item);
                if (dlg.ShowDialog() != true)
                {
                    return;
                }
                newVis = dlg.NewVis;
            }

            int index = VisualizationList.IndexOf(item);

            VisualizationList.Remove(item);
            VisualizationList.Insert(index, newVis);
            visualizationGrid.SelectedIndex = index;

            okButton.Focus();
        }