using System;
using System.Drawing;
using System.Windows.Forms;
namespace Netron.Diagramming.Core {
// ----------------------------------------------------------------------
///
/// A tool that uses the ImageExporter to create an image from the
/// currently selected entities and adds the image to the clipboard.
/// The ImageExporter is used indirectly by calling
/// 'Selection.ToBitmap()'.
///
// ----------------------------------------------------------------------
public class ImageExportTool : AbstractTool {
// ------------------------------------------------------------------
///
/// Initializes a new instance of the
/// class.
///
/// string: The name of the tool.
// ------------------------------------------------------------------
public ImageExportTool(string toolName)
: base(toolName) {
}
#region Methods
// ------------------------------------------------------------------
///
/// Called when the tool is activated.
///
// ------------------------------------------------------------------
protected override void OnActivateTool() {
if (this.Controller.Model.Selection.SelectedItems.Count == 0) {
MessageBox.Show("No shapes are selected. " +
"Please make a selection first.",
"Image Export Error",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
try {
// Create an image using the ImageExporter and copy it to
// the clipboard.
Bitmap image = this.Controller.Model.Selection.ToBitmap();
if (image != null) {
Clipboard.SetImage(image);
}
}
catch (Exception exc) {
throw new InconsistencyException(
"The Copy operation failed.", exc);
}
finally {
DeactivateTool();
}
}
#endregion
}
}