예제 #1
0
        private void GroupSelectedItems()
        {
            var sbl   = BlockList.GetSelectedBlockList();
            int count = sbl.listBlocks.SelectedItems.Count;

            if (count == 0)
            {
                System.Media.SystemSounds.Beep.Play();
                return;
            }

            string prompt;

            if (count == 1)
            {
                prompt = "Group Selected Block?";
            }
            else if (count == sbl.listBlocks.Items.Count)
            {
                prompt = "Group All Blocks?";
            }
            else
            {
                prompt = string.Format("Group {0} Selected Blocks?", sbl.listBlocks.SelectedItems.Count);
            }

            if (MessageBox.Show(prompt, "Block Editor", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
            {
                inSelectionChanged = true;
                IBlockGroup   group     = BlockManager.NewBlockGroup();
                List <IBlock> blockList = new List <IBlock>();
                blockList.AddRange(sbl.Blocks);

                IBlock[] selectedBlocks = sbl.AdjacentSelectedBlocks;
                int      index          = blockList.IndexOf(selectedBlocks[0]);
                blockList.Insert(index, group);
                foreach (IBlock block in selectedBlocks)
                {
                    group.Add(block);
                    blockList.Remove(block);
                }
                foreach (IBlock block in blockList)
                {
                    block.NewBlockItem();
                }
                sbl.Clear();
                sbl.Add(blockList.ToArray());
                sbl.listBlocks.SelectedItem = group.BlockItem;
                listCode.UnselectAll();

                if (sbl.ParentGroup != null)
                {
                    sbl.ParentGroup.Blocks = sbl.Blocks;
                }

                Edited = true;
                btnDelete.IsEnabled = btnCut.IsEnabled = btnCopy.IsEnabled = btnGroup.IsEnabled = btnUngroup.IsEnabled = true;
                inSelectionChanged  = false;
            }
        }
예제 #2
0
        private void UngroupSelectedGroup()
        {
            var         sbl   = BlockList.GetSelectedBlockList();
            ListBoxItem item  = (ListBoxItem)sbl.listBlocks.SelectedItem;
            IBlockGroup group = item.Tag as IBlockGroup;

            if (group == null)
            {
                System.Media.SystemSounds.Beep.Play();
                return;
            }

            if (MessageBox.Show("Ungroup Selected Group?", "Block Editor", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
            {
                inSelectionChanged = true;
                int index = sbl.listBlocks.SelectedItemIndex;
                sbl.listBlocks.Items.Remove(item);
                sbl.Insert(index, group.Blocks);
                group.Blocks = new IBlock[] { };

                listCode.UnselectAll();
                if (sbl.ParentGroup != null)
                {
                    sbl.ParentGroup.Blocks = sbl.Blocks;
                }
                sbl.Focus();

                tbLine.Text         = string.Format("{0} lines", listCode.Items.Count);
                Edited              = true;
                btnDelete.IsEnabled = btnCut.IsEnabled = btnCopy.IsEnabled = btnGroup.IsEnabled = btnUngroup.IsEnabled = false;
                inSelectionChanged  = false;
            }
        }
예제 #3
0
        private ListBoxItem InsertCodeItemBefore(IBlock[] blocks, IBlockGroup group, ref bool found)
        {
            foreach (IBlock block in blocks)
            {
                if (block is IBlockGroup)
                {
                    IBlockGroup group2 = (IBlockGroup)block;
                    if (group2 == group)
                    {
                        found = true;
                        continue;
                    }
                    ListBoxItem item = InsertCodeItemBefore(group2.Blocks, group, ref found);
                    if (item != null)
                    {
                        return(item);
                    }
                }
                else
                {
                    if (found && block.BlockGroup != group)
                    {
                        return(block.CodeItem);
                    }
                    if (block.BlockGroup == group)
                    {
                        found = true;
                    }
                }
            }

            return(null);
        }
예제 #4
0
        public bool ReadFile(string path, out IBlock[] blocks)
        {
            blocks = null;
            if (!File.Exists(path))
            {
                return(false);
            }

            List <IBlock> listBlocks = new List <IBlock>();

            using (var sr = new StreamReader(path))
            {
                IBlockGroup         group      = null;
                Stack <IBlockGroup> groupStack = new Stack <IBlockGroup>();
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    if (group != null && line == BlockGroup.EndMarker)
                    {
                        groupStack.Pop();
                        group = (groupStack.Count > 0) ? groupStack.Peek() : null;
                        continue;
                    }

                    IBlock block = NewBlock(line);
                    if (block != null)
                    {
                        if (group != null)
                        {
                            group.Add(block);
                        }
                        else
                        {
                            listBlocks.Add(block);
                        }

                        if (block is IBlockGroup)
                        {
                            group = (IBlockGroup)block;
                            groupStack.Push(group);
                        }
                    }
                }
            }

            if (listBlocks.Count == 0)
            {
                return(false);
            }
            blocks = listBlocks.ToArray();
            return(true);
        }
        public event EventHandler <long> SelectedAdrressChanged;                 //选定的扇区地址发生变化时;

        /// <summary>
        /// 添加块/簇组;
        /// </summary>
        /// <param name="group">需添加的块组</param>
        public void AddGroup(IBlockGroup group)
        {
            if (group != null)
            {
                Groups.Add(group);
                for (int i = 0; i < group.Count; i++)
                {
                    Items.Add(new AddressItem(group.BlockAddress + i));
                }
                Items.Add(SpliterItem.StaticInstance);
            }
        }
예제 #6
0
 private void RemoveCode(IBlock block)
 {
     if (block is IBlockGroup)
     {
         IBlockGroup group = (IBlockGroup)block;
         foreach (var block2 in group.Blocks)
         {
             RemoveCode(block2);
         }
     }
     else
     {
         listCode.Items.Remove(block.CodeItem);
     }
 }
예제 #7
0
 private void InsertCode(IBlockGroup group, ref int index)
 {
     foreach (IBlock block in group.Blocks)
     {
         if (block is IBlockGroup)
         {
             InsertCode((IBlockGroup)block, ref index);
         }
         else
         {
             listCode.Items.Insert(index, block.CodeItem);
             ++index;
         }
     }
 }
예제 #8
0
        public void Select(IBlock block)
        {
            // Push block groups on the stack up to the root:
            Stack <IBlockGroup> groupStack = new Stack <IBlockGroup>();
            IBlockGroup         group      = block.BlockGroup;

            while (group != null)
            {
                groupStack.Push(group);
                group = group.BlockGroup;
            }

            // Pop block groups off the stack and open them:
            ListBoxItem   item;
            BlockListView bl = this.GetView() as MyView;

            while (groupStack.Count > 0)
            {
                group = groupStack.Pop();
                item  = group.BlockItem;
                if (bl.listBlocks.Items.Contains(item))
                {
                    if (!bl.SplitterOpen && bl.listBlocks.SelectedItem == item)
                    {
                        bl.listBlocks.SelectedItem = null;
                    }
                    bl.listBlocks.SelectedItem = item;
                    bl.listBlocks.ScrollIntoView(item);
                }
                bl = bl.GroupList;
            }

            // Select the item:
            item = block.BlockItem;
            if (bl != null && bl.listBlocks.Items.Contains(item))
            {
                bl.listBlocks.SelectedItem = item;
                bl.listBlocks.ScrollIntoView(item);
                if (bl.GroupList != null)
                {
                    bl.GroupList.listBlocks.UnselectAll();
                }
            }
        }
예제 #9
0
        public IBlock[] NewBlocks(string buffer)
        {
            List <IBlock>       listBlocks = new List <IBlock>();
            IBlockGroup         group      = null;
            Stack <IBlockGroup> groupStack = new Stack <IBlockGroup>();

            string[] lines = buffer.Split('\n');
            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i].Trim();
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                if (group != null && line == BlockGroup.EndMarker)
                {
                    groupStack.Pop();
                    group = (groupStack.Count > 0) ? groupStack.Peek() : null;
                    continue;
                }

                IBlock block = NewBlock(line);
                if (block != null)
                {
                    if (group != null)
                    {
                        group.Add(block);
                    }
                    else
                    {
                        listBlocks.Add(block);
                    }

                    if (block is IBlockGroup)
                    {
                        group = (IBlockGroup)block;
                        groupStack.Push(group);
                    }
                }
            }

            return(listBlocks.ToArray());
        }
예제 #10
0
        private void UngroupSelectedGroup()
        {
            var         sbl   = BlockList.GetSelectedBlockList();
            ListBoxItem item  = (ListBoxItem)sbl.listBlocks.SelectedItem;
            IBlock      block = (IBlock)item.Tag;

            if (!(block is IBlockGroup))
            {
                System.Media.SystemSounds.Beep.Play();
                return;
            }

            if (MessageBox.Show("Ungroup Selected Group?", "Block Editor", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
            {
                inSelectionChanged = true;
                IBlockGroup   group     = (IBlockGroup)block;
                List <IBlock> blockList = new List <IBlock>();
                blockList.AddRange(sbl.Blocks);
                int index = blockList.IndexOf(group);
                blockList.InsertRange(index, group.Blocks);
                blockList.Remove(group);
                group.Blocks = new IBlock[] { };
                foreach (IBlock block2 in blockList)
                {
                    block2.NewBlockItem();
                }
                sbl.Clear();
                sbl.Add(blockList.ToArray());
                listCode.UnselectAll();
                if (sbl.ParentGroup != null)
                {
                    sbl.ParentGroup.Blocks = sbl.Blocks;
                }
                sbl.Focus();

                tbLine.Text         = string.Format("{0} lines", listCode.Items.Count);
                Edited              = true;
                btnDelete.IsEnabled = btnCut.IsEnabled = btnCopy.IsEnabled = btnGroup.IsEnabled = btnUngroup.IsEnabled = false;
                inSelectionChanged  = false;
            }
        }
예제 #11
0
        private void ToStringBuilder(StringBuilder sb, IBlock[] blocks, ref int indent)
        {
            foreach (IBlock block in blocks)
            {
                for (int i = 0; i < indent; i++)
                {
                    sb.Append("  ");
                }
                sb.AppendLine(block.ToString().Trim());

                if (block is IBlockGroup)
                {
                    ++indent;
                    IBlockGroup group = (IBlockGroup)block;
                    ToStringBuilder(sb, group.Blocks, ref indent);
                    --indent;
                    for (int i = 0; i < indent; i++)
                    {
                        sb.Append("  ");
                    }
                    sb.AppendLine(BlockGroup.EndMarker);
                }
            }
        }
예제 #12
0
        private void WriteLines(StreamWriter sw, IBlock[] blocks, ref int indent)
        {
            foreach (IBlock block in blocks)
            {
                for (int i = 0; i < indent; i++)
                {
                    sw.Write("  ");
                }
                sw.WriteLine(block.ToString().Trim());

                if (block is IBlockGroup)
                {
                    ++indent;
                    IBlockGroup group = (IBlockGroup)block;
                    WriteLines(sw, group.Blocks, ref indent);
                    --indent;
                    for (int i = 0; i < indent; i++)
                    {
                        sw.Write("  ");
                    }
                    sw.WriteLine(BlockGroup.EndMarker);
                }
            }
        }
예제 #13
0
 public virtual TReturn Visit(IBlockGroup entity, TData data)
 {
     return(default(TReturn));
 }
예제 #14
0
 public override object Visit(IBlockGroup entity, GridContext data)
 {
     return(new BlockGroupSettings(entity, data));
 }
예제 #15
0
        private void AddBlock(IBlock block)
        {
            var sbl = BlockList.GetSelectedBlockList(true);

            sbl.listBlocks.UnselectAll();
            listCode.UnselectAll();

            ListBoxItem item = block.BlockItem;

            sbl.listBlocks.Items.Add(item);
            sbl.listBlocks.ScrollIntoView(item);

            if (sbl.ParentGroup != null)
            {
                sbl.ParentGroup.Add(block);
            }

            if (block is IBlockGroup)
            {
                IBlockGroup group = (IBlockGroup)block;
                if (sbl.ParentGroup != null)
                {
                    bool        found = false;
                    ListBoxItem item2 = InsertCodeItemBefore(BlockList.Blocks, sbl.ParentGroup, ref found);
                    if (item2 != null)
                    {
                        int index = listCode.Items.IndexOf(item2);
                        InsertCode(group, ref index);
                    }
                    else
                    {
                        AddCode(group.Blocks);
                    }
                }
                else
                {
                    AddCode(group.Blocks);
                }
            }
            else
            {
                item = block.CodeItem;
                if (sbl.ParentGroup != null)
                {
                    bool        found = false;
                    ListBoxItem item2 = InsertCodeItemBefore(BlockList.Blocks, sbl.ParentGroup, ref found);
                    if (item2 != null)
                    {
                        int index = listCode.Items.IndexOf(item2);
                        listCode.Items.Insert(index, item);
                    }
                    else
                    {
                        listCode.Items.Add(item);
                    }
                }
                else
                {
                    listCode.Items.Add(item);
                }
            }
        }
 public Entry(IBlockGroup blockGroup, string description)
 {
     this.blockGroup  = blockGroup;
     this.description = description;
 }
예제 #17
0
 public override IEntityState Visit(IBlockGroup entity, RailwayState data)
 {
     return(new BlockGroupState(entity, data));
 }