Inheritance: BaseViewModel
Exemplo n.º 1
0
        public void PerformSearch()
        {
            if (_MatchingItemEnumerator == null || !_MatchingItemEnumerator.MoveNext())
            {
                VerifyMatchingItemEnumerator();
            }
            if (_MatchingItemEnumerator == null)
            {
                return;
            }

            var item = _MatchingItemEnumerator.Current;

            if (item == null)
            {
                return;
            }

            if (item.Parent != null)
            {
                GridItemViewModel parent = (GridItemViewModel)item.Parent;
                parent.IsExpanded = true;
            }

            // TODO switch search to filter (hide unmatched items), probably handled by the UI instead

            item.IsSelected = true;
        }
Exemplo n.º 2
0
        public void SetGrid(Interop.Grid grid)
        {
            GridItemViewModel vm = CreateGridViewModel(grid);

            _Grid.Clear();
            _Grid.Add(vm);
        }
Exemplo n.º 3
0
        public void PerformRenameBlock()
        {
            if (SelectedItemType != Models.GridItemType.Block)
            {
                return;
            }

            GridItemViewModel selected = SelectedItem;

            Views.RenameDialog dialog = new Views.RenameDialog()
            {
                ItemName = selected.Name
            };

            Nullable <bool> result = dialog.ShowDialog();

            if (result == true)
            {
                string name = dialog.ItemName;
                try
                {
                    RootItem.Definitions = Interop.Blueprint.SaveBlockName(RootItem.Path, RootItem.Definitions, selected.EntityID, name);

                    selected.Name = name;
                }
                catch (Exception ex)
                {
                    MessageBox.ShowError("Unable to change block name", ex);
                }
            }
        }
Exemplo n.º 4
0
        public void PerformEditProgram()
        {
            if (SelectedItemType != Models.GridItemType.Program)
            {
                return;
            }

            GridItemViewModel selected = SelectedItem;

            Views.ProgramView dialog = new Views.ProgramView()
            {
                Program   = selected.Program,
                Blueprint = RootItem.Name,
                Block     = selected.Name,
            };

            Nullable <bool> result = dialog.ShowDialog();

            if (result == true)
            {
                string program = dialog.Program;

                RootItem.Definitions = Interop.Blueprint.SaveProgram(RootItem.Path, RootItem.Definitions, selected.EntityID, program);

                selected.Program = program;
            }
        }
Exemplo n.º 5
0
        private GridItemViewModel CreateGridViewModel(Interop.Grid grid)
        {
            GridItemViewModel root = new GridItemViewModel(
                new GridItem()
            {
                Name = grid.Name,
                Type = GridItemType.Root
            },
                grid.Definitions,
                grid.Path
                );

            foreach (KeyValuePair <string, List <Interop.TerminalBlock> > pair in grid.Blocks)
            {
                GridItemViewModel node = new GridItemViewModel(
                    new GridItem()
                {
                    Name = pair.Key,
                    Type = GridItemType.Group
                },
                    root
                    );

                foreach (Interop.TerminalBlock block in pair.Value)
                {
                    if (block.IsProgram)
                    {
                        node.AddChild(
                            new GridItemViewModel(
                                new GridItem()
                        {
                            Name     = block.Name,
                            EntityID = block.EntityID,
                            Type     = GridItemType.Program,
                            Program  = block.Program
                        },
                                node
                                )
                            );
                    }
                    else
                    {
                        node.AddChild(
                            new GridItemViewModel(
                                new GridItem()
                        {
                            Name     = block.Name,
                            EntityID = block.EntityID,
                            Type     = GridItemType.Block
                        },
                                node
                                )
                            );
                    }
                }
                root.AddChild(node);
            }
            return(root);
        }
Exemplo n.º 6
0
        public GridItemViewModel(GridItem item, GridItemViewModel parent) : base(parent)
        {
            _Model = item;

            _Children = new Services.ObservableSortedList <GridItemViewModel>(
                (from child in _Model.Children select new GridItemViewModel(item, null)).ToList <GridItemViewModel>(),
                new Comparers.GridItemComparer()
                );
        }
Exemplo n.º 7
0
        public GridItemViewModel(GridItem item, GridItemViewModel parent)
            : base(parent)
        {
            _Model = item;

            _Children = new Services.ObservableSortedList<GridItemViewModel>(
                (from child in _Model.Children select new GridItemViewModel(item, null)).ToList<GridItemViewModel>(),
                new Comparers.GridItemComparer()
            );
        }
Exemplo n.º 8
0
 private void SetBlueprint(GridItemViewModel root)
 {
     if (root != null)
     {
         root.Model.Blueprint = this;
         foreach (GridItemViewModel item in root.Children)
         {
             SetBlueprint(item);
         }
     }
 }
Exemplo n.º 9
0
        private void VerifySelectedItemEnumerator()
        {
            GridItemViewModel root = RootItem;

            var matches = FindSelected(root);

            _SelectedItemEnumerator = matches.GetEnumerator();
            if (!_SelectedItemEnumerator.MoveNext())
            {
                // none selected
            }
        }
Exemplo n.º 10
0
        private IEnumerable <GridItemViewModel> FindMatches(string text, GridItemViewModel item)
        {
            if (item == null)
            {
                yield return(null);
            }
            if (item.NameContainsText(text))
            {
                yield return(item);
            }

            foreach (GridItemViewModel child in item.Children)
            {
                foreach (GridItemViewModel match in FindMatches(text, child))
                {
                    yield return(match);
                }
            }
        }
Exemplo n.º 11
0
        private IEnumerable <GridItemViewModel> FindSelected(GridItemViewModel item)
        {
            if (item == null)
            {
                yield return(null);
            }

            if (item.IsSelected)
            {
                yield return(item);
            }

            foreach (GridItemViewModel child in item.Children)
            {
                foreach (GridItemViewModel match in FindSelected(child))
                {
                    // TODO fix collection modified exception
                    yield return(match);
                }
            }
        }
Exemplo n.º 12
0
 public void AddChild(GridItemViewModel item)
 {
     _Children.Add(item);
     Model.Children.Add(item.Model);
 }
Exemplo n.º 13
0
        private GridItemViewModel CreateGridViewModel(Interop.Grid grid)
        {
            GridItemViewModel root = new GridItemViewModel(
                new GridItem()
                {
                    Name = grid.Name,
                    Type = GridItemType.Root
                },
                grid.Definitions,
                grid.Path
            );

            foreach(KeyValuePair<string, List<Interop.TerminalBlock>> pair in grid.Blocks)
            {
                GridItemViewModel node = new GridItemViewModel(
                    new GridItem()
                    {
                        Name = pair.Key,
                        Type = GridItemType.Group
                    },
                    root
                );

                foreach(Interop.TerminalBlock block in pair.Value)
                {
                    if (block.IsProgram)
                    {
                        node.AddChild(
                            new GridItemViewModel(
                                new GridItem()
                                {
                                    Name = block.Name,
                                    EntityID = block.EntityID,
                                    Type = GridItemType.Program,
                                    Program = block.Program
                                },
                                node
                            )
                        );
                    }
                    else
                    {
                        node.AddChild(
                            new GridItemViewModel(
                                new GridItem()
                                {
                                    Name = block.Name,
                                    EntityID = block.EntityID,
                                    Type = GridItemType.Block
                                },
                                node
                            )
                        );
                    }
                }
                root.AddChild(node);
            }
            return root;
        }
Exemplo n.º 14
0
 public void AddChild(GridItemViewModel item)
 {
     _Children.Add(item);
     Model.Children.Add(item.Model);
 }
Exemplo n.º 15
0
 private void SetBlueprint(GridItemViewModel root)
 {
     if (root != null)
     {
         root.Model.Blueprint = this;
         foreach(GridItemViewModel item in root.Children)
         {
             SetBlueprint(item);
         }
     }
 }
Exemplo n.º 16
0
        private IEnumerable<GridItemViewModel> FindSelected(GridItemViewModel item)
        {
            if (item == null)
            {
                yield return null;
            }

            if (item.IsSelected)
            {
                yield return item;
            }

            foreach (GridItemViewModel child in item.Children)
            {
                foreach (GridItemViewModel match in FindSelected(child))
                {
                    // TODO fix collection modified exception
                    yield return match;
                }
            }
        }
Exemplo n.º 17
0
        private IEnumerable<GridItemViewModel> FindMatches(string text, GridItemViewModel item)
        {
            if (item == null)
            {
                yield return null;
            }
            if (item.NameContainsText(text))
            {
                yield return item;
            }

            foreach (GridItemViewModel child in item.Children)
            {
                foreach (GridItemViewModel match in FindMatches(text, child))
                {
                    yield return match;
                }
            }
        }