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