1 // 2 // PasteHistoryItem.cs 3 // 4 // Author: 5 // Jonathan Pobst <monkey@jpobst.com> 6 // 7 // Copyright (c) 2010 Jonathan Pobst 8 // 9 // Permission is hereby granted, free of charge, to any person obtaining a copy 10 // of this software and associated documentation files (the "Software"), to deal 11 // in the Software without restriction, including without limitation the rights 12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 // copies of the Software, and to permit persons to whom the Software is 14 // furnished to do so, subject to the following conditions: 15 // 16 // The above copyright notice and this permission notice shall be included in 17 // all copies or substantial portions of the Software. 18 // 19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 // THE SOFTWARE. 26 27 using System; 28 using Cairo; 29 using Mono.Unix; 30 using Gtk; 31 32 namespace Pinta.Core 33 { 34 public class PasteHistoryItem : BaseHistoryItem 35 { 36 private Gdk.Pixbuf paste_image; 37 private DocumentSelection old_selection; 38 39 public override bool CausesDirty { get { return true; } } 40 PasteHistoryItem(Gdk.Pixbuf pasteImage, DocumentSelection oldSelection)41 public PasteHistoryItem (Gdk.Pixbuf pasteImage, DocumentSelection oldSelection) 42 { 43 Text = Catalog.GetString ("Paste"); 44 Icon = Stock.Paste; 45 46 paste_image = pasteImage; 47 old_selection = oldSelection; 48 } 49 Redo()50 public override void Redo () 51 { 52 Document doc = PintaCore.Workspace.ActiveDocument; 53 54 // Copy the paste to the temp layer 55 doc.CreateSelectionLayer (); 56 doc.ShowSelectionLayer = true; 57 58 using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) { 59 g.DrawPixbuf (paste_image, new Cairo.Point (0, 0)); 60 } 61 62 Swap (); 63 64 PintaCore.Workspace.Invalidate (); 65 PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels")); 66 } 67 Undo()68 public override void Undo () 69 { 70 Swap (); 71 72 PintaCore.Layers.DestroySelectionLayer (); 73 PintaCore.Workspace.Invalidate (); 74 } 75 Dispose()76 public override void Dispose () 77 { 78 if (paste_image != null) 79 (paste_image as IDisposable).Dispose (); 80 81 if (old_selection != null) 82 old_selection.Dispose (); 83 } 84 Swap()85 private void Swap () 86 { 87 // Swap the selection paths, and whether the 88 // selection path should be visible 89 Document doc = PintaCore.Workspace.ActiveDocument; 90 91 DocumentSelection swap_selection = doc.Selection; 92 doc.Selection = old_selection; 93 old_selection = swap_selection; 94 } 95 } 96 } 97