Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/CopyTool.cs @ 12328

Last change on this file since 12328 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 3.0 KB
Line 
1using System;
2using System.Drawing;
3using System.Windows.Forms;
4namespace Netron.Diagramming.Core {
5  // ----------------------------------------------------------------------
6  /// <summary>
7  /// A tool that copies the selected entities to the clipboard.
8  /// </summary>
9  // ----------------------------------------------------------------------
10  public class CopyTool : AbstractTool {
11    #region Fields
12    #endregion
13
14    #region Constructor
15
16    // ------------------------------------------------------------------
17    /// <summary>
18    /// Initializes a new instance of the <see cref="T:CopyTool"/> class.
19    /// </summary>
20    /// <param name="name">string: The name of the tool.</param>
21    // ------------------------------------------------------------------
22    public CopyTool(string name)
23      : base(name) {
24    }
25    #endregion
26
27    #region Methods
28
29    // ------------------------------------------------------------------
30    /// <summary>
31    /// Called when the tool is activated.
32    /// </summary>
33    // ------------------------------------------------------------------
34    protected override void OnActivateTool() {
35      if (this.Controller.Model.Selection.SelectedItems.Count == 0)
36        return;
37
38      try {
39        //Clear the Anchors otherwise subsequent Copy operations will
40        // raise an exception due to the fact that the Anchors class
41        // is a static helper class.
42        Anchors.Clear();
43
44        // First add the image to the Windows Clipboard so it can be
45        // pasted into other applications, like PowerPoint.
46        Bitmap image = this.Controller.Model.Selection.ToBitmap();
47        Clipboard.SetDataObject(image, true);
48
49        // This will create a volatile collection of entities, but they
50        // need to be unwrapped!  I never managed to get things
51        // working by putting the serialized collection directly onto
52        // the Clipboad. Thanks to Leppie's suggestion it works by
53        // putting the Stream onto the Clipboard, which is weird but
54        // it works.
55        //MemoryStream copy = Selection.SelectedItems.ToStream();
56        //DataFormats.Format format =
57        //    DataFormats.GetFormat(typeof(CopyTool).FullName);
58
59        //IDataObject dataObject = new DataObject();
60        //dataObject.SetData(format.Name, false, copy);
61        //Clipboard.SetDataObject(dataObject, false);
62
63        // Rather than placing the stream of entities on the Windows
64        // Clipboard, we're using our custom clipboard to keep the
65        // Windows clipboard for moving data across apps.
66        NetronClipboard.Clear();
67        NetronClipboard.Add(this.Controller.Model.Selection.SelectedItems.Copy());
68
69      }
70      catch (Exception exc) {
71        //throw new InconsistencyException(
72        //    "The Copy operation failed.", exc);
73        MessageBox.Show("Unable to copy the selection.\n\n" +
74            "Error Message: " + exc.Message);
75      }
76      finally {
77        DeactivateTool();
78      }
79    }
80
81    #endregion
82  }
83
84}
Note: See TracBrowser for help on using the repository browser.