1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Windows.Forms;
|
---|
4 |
|
---|
5 | namespace Netron.Diagramming.Core {
|
---|
6 | // ----------------------------------------------------------------------
|
---|
7 | /// <summary>
|
---|
8 | /// A tool that uses the ImageExporter to create an image from the
|
---|
9 | /// currently selected entities and adds the image to the clipboard.
|
---|
10 | /// The ImageExporter is used indirectly by calling
|
---|
11 | /// 'Selection.ToBitmap()'.
|
---|
12 | /// </summary>
|
---|
13 | // ----------------------------------------------------------------------
|
---|
14 | public class ImageExportTool : AbstractTool {
|
---|
15 | // ------------------------------------------------------------------
|
---|
16 | /// <summary>
|
---|
17 | /// Initializes a new instance of the <see cref="T:ImageExportTool"/>
|
---|
18 | /// class.
|
---|
19 | /// </summary>
|
---|
20 | /// <param name="name">string: The name of the tool.</param>
|
---|
21 | // ------------------------------------------------------------------
|
---|
22 | public ImageExportTool(string toolName)
|
---|
23 | : base(toolName) {
|
---|
24 | }
|
---|
25 |
|
---|
26 | #region Methods
|
---|
27 |
|
---|
28 | // ------------------------------------------------------------------
|
---|
29 | /// <summary>
|
---|
30 | /// Called when the tool is activated.
|
---|
31 | /// </summary>
|
---|
32 | // ------------------------------------------------------------------
|
---|
33 | protected override void OnActivateTool() {
|
---|
34 | if (this.Controller.Model.Selection.SelectedItems.Count == 0) {
|
---|
35 | MessageBox.Show("No shapes are selected. " +
|
---|
36 | "Please make a selection first.",
|
---|
37 | "Image Export Error",
|
---|
38 | MessageBoxButtons.OK,
|
---|
39 | MessageBoxIcon.Information);
|
---|
40 | return;
|
---|
41 | }
|
---|
42 |
|
---|
43 | try {
|
---|
44 | // Create an image using the ImageExporter and copy it to
|
---|
45 | // the clipboard.
|
---|
46 | Bitmap image = this.Controller.Model.Selection.ToBitmap();
|
---|
47 | if (image != null) {
|
---|
48 | Clipboard.SetImage(image);
|
---|
49 | }
|
---|
50 | }
|
---|
51 | catch (Exception exc) {
|
---|
52 | throw new InconsistencyException(
|
---|
53 | "The Copy operation failed.", exc);
|
---|
54 | }
|
---|
55 | finally {
|
---|
56 | DeactivateTool();
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | #endregion
|
---|
61 | }
|
---|
62 | }
|
---|