Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/DeleteTool.cs @ 2768

Last change on this file since 2768 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Netron.Diagramming.Core
6{
7    public class DeleteTool : AbstractTool
8    {
9        /// <summary>
10        /// Constructor.
11        /// </summary>
12        /// <param name="toolName"></param>
13        public DeleteTool(string toolName)
14            : base(toolName)
15        {
16        }
17
18        protected override void OnActivateTool()
19        {
20            base.OnActivateTool();
21
22            DeleteCommand cmd;
23
24            if (Selection.SelectedItems.Count > 0)
25            {
26                // If any one entity in the selction can't be deleted,
27                // remove it from the selection.
28                for (int i = 0; i < Selection.SelectedItems.Count; i++ )
29                {
30                    IDiagramEntity entity = Selection.SelectedItems[i];
31                    if (entity.AllowDelete == false)
32                    {
33                        Selection.SelectedItems.Remove(entity);
34                        i--;
35                    }
36                }
37                cmd = new DeleteCommand(
38                        this.Controller,
39                        Selection.SelectedItems.Copy());
40                this.Controller.UndoManager.AddUndoCommand(cmd);
41
42                // Alert each entity that they're about to be deleted.
43                foreach (IDiagramEntity entity in Selection.SelectedItems)
44                {
45                    entity.OnBeforeDelete(cmd);
46                }
47
48                cmd.Redo();
49
50                // Alert each entity that they have been deleted.
51                foreach (IDiagramEntity entity in Selection.SelectedItems)
52                {
53                    entity.OnAfterDelete(cmd);
54                }
55            }
56
57            DeactivateTool();
58        }
59    }
60}
Note: See TracBrowser for help on using the repository browser.