1 | using System;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using System.Collections;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Windows.Forms;
|
---|
6 |
|
---|
7 | namespace Netron.Diagramming.Core
|
---|
8 | {
|
---|
9 | // ----------------------------------------------------------------------
|
---|
10 | /// <summary>
|
---|
11 | /// Tool to align shapes in various ways
|
---|
12 | /// </summary>
|
---|
13 | // ----------------------------------------------------------------------
|
---|
14 | public class AlignTool : AbstractTool
|
---|
15 | {
|
---|
16 |
|
---|
17 | #region Fields
|
---|
18 |
|
---|
19 | // ------------------------------------------------------------------
|
---|
20 | /// <summary>
|
---|
21 | /// The type of alignment to apply.
|
---|
22 | /// </summary>
|
---|
23 | // ------------------------------------------------------------------
|
---|
24 | private ShapeAlignment mAlignment;
|
---|
25 |
|
---|
26 | // ------------------------------------------------------------------
|
---|
27 | /// <summary>
|
---|
28 | /// Gets or sets the type of alignment to apply.
|
---|
29 | /// </summary>
|
---|
30 | // ------------------------------------------------------------------
|
---|
31 | public ShapeAlignment Alignment
|
---|
32 | {
|
---|
33 | get { return mAlignment; }
|
---|
34 | set { mAlignment = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | #endregion
|
---|
39 |
|
---|
40 | #region Constructor
|
---|
41 |
|
---|
42 | // ------------------------------------------------------------------
|
---|
43 | /// <summary>
|
---|
44 | /// Initializes a new instance of the <see cref="T:AlignTool"/> class.
|
---|
45 | /// </summary>
|
---|
46 | /// <param name="name">The name of the tool.</param>
|
---|
47 | // ------------------------------------------------------------------
|
---|
48 | public AlignTool(string name) : base(name)
|
---|
49 | {
|
---|
50 | }
|
---|
51 | #endregion
|
---|
52 |
|
---|
53 | #region Methods
|
---|
54 |
|
---|
55 | /// <summary>
|
---|
56 | /// Called when the tool is activated.
|
---|
57 | /// </summary>
|
---|
58 | protected override void OnActivateTool()
|
---|
59 | {
|
---|
60 | bool valid = true;
|
---|
61 |
|
---|
62 | #region Validation of the selection
|
---|
63 |
|
---|
64 | //make sure we have the correct stuff on the table
|
---|
65 | if (this.Controller.Model.Selection.SelectedItems == null || this.Controller.Model.Selection.SelectedItems.Count == 0)
|
---|
66 | {
|
---|
67 | MessageBox.Show("Nothing is selected, you need to select an existing group.", "Nothing selected.", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
---|
68 | valid = false;
|
---|
69 | } else if (this.Controller.Model.Selection.SelectedItems.Count != 1)
|
---|
70 | {
|
---|
71 | MessageBox.Show("Multiple items are selected, select only one group.", "Multiple items", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
---|
72 | valid = false;
|
---|
73 | } else if (!(this.Controller.Model.Selection.SelectedItems[0] is IGroup))
|
---|
74 | {
|
---|
75 | MessageBox.Show("The selected item is not a group.", "Not a group.", MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
---|
76 | valid = false;
|
---|
77 | }
|
---|
78 | #endregion
|
---|
79 |
|
---|
80 | if (valid)
|
---|
81 | {
|
---|
82 | UngroupCommand cmd = new UngroupCommand(
|
---|
83 | this.Controller,
|
---|
84 | this.Controller.Model.Selection.SelectedItems[0] as IGroup);
|
---|
85 |
|
---|
86 | this.Controller.UndoManager.AddUndoCommand(cmd);
|
---|
87 | cmd.Redo();
|
---|
88 | }
|
---|
89 | DeactivateTool();
|
---|
90 | return;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | #endregion
|
---|
95 |
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 | }
|
---|