using System.Windows.Forms;
namespace Netron.Diagramming.Core {
// ----------------------------------------------------------------------
///
/// Tool to align shapes in various ways
///
// ----------------------------------------------------------------------
public class AlignTool : AbstractTool {
#region Fields
// ------------------------------------------------------------------
///
/// The type of alignment to apply.
///
// ------------------------------------------------------------------
private ShapeAlignment mAlignment;
// ------------------------------------------------------------------
///
/// Gets or sets the type of alignment to apply.
///
// ------------------------------------------------------------------
public ShapeAlignment Alignment {
get { return mAlignment; }
set { mAlignment = value; }
}
#endregion
#region Constructor
// ------------------------------------------------------------------
///
/// Initializes a new instance of the class.
///
/// The name of the tool.
// ------------------------------------------------------------------
public AlignTool(string name)
: base(name) {
}
#endregion
#region Methods
///
/// Called when the tool is activated.
///
protected override void OnActivateTool() {
bool valid = true;
#region Validation of the selection
//make sure we have the correct stuff on the table
if (this.Controller.Model.Selection.SelectedItems == null || this.Controller.Model.Selection.SelectedItems.Count == 0) {
MessageBox.Show("Nothing is selected, you need to select an existing group.", "Nothing selected.", MessageBoxButtons.OK, MessageBoxIcon.Hand);
valid = false;
} else if (this.Controller.Model.Selection.SelectedItems.Count != 1) {
MessageBox.Show("Multiple items are selected, select only one group.", "Multiple items", MessageBoxButtons.OK, MessageBoxIcon.Hand);
valid = false;
} else if (!(this.Controller.Model.Selection.SelectedItems[0] is IGroup)) {
MessageBox.Show("The selected item is not a group.", "Not a group.", MessageBoxButtons.OK, MessageBoxIcon.Hand);
valid = false;
}
#endregion
if (valid) {
UngroupCommand cmd = new UngroupCommand(
this.Controller,
this.Controller.Model.Selection.SelectedItems[0] as IGroup);
this.Controller.UndoManager.AddUndoCommand(cmd);
cmd.Redo();
}
DeactivateTool();
return;
}
#endregion
}
}