From c8b52e2411a3dbc80ec08c6977c0a8aa60ab6d95 Mon Sep 17 00:00:00 2001 From: Don McComb Date: Tue, 6 Nov 2012 23:50:11 +1100 Subject: [PATCH 1/5] [Fixes bug #1064018] Data lost when pasting images onto smaller canvases --- Pinta.Core/Classes/Document.cs | 15 +++ Pinta/Actions/Edit/PasteAction.cs | 2 +- Pinta/Actions/Edit/PasteIntoNewLayerAction.cs | 98 ++++++++++++++++--- 3 files changed, 101 insertions(+), 14 deletions(-) diff --git a/Pinta.Core/Classes/Document.cs b/Pinta.Core/Classes/Document.cs index 30b451080..9cec26802 100644 --- a/Pinta.Core/Classes/Document.cs +++ b/Pinta.Core/Classes/Document.cs @@ -278,6 +278,11 @@ public Layer CreateLayer () return CreateLayer (string.Format ("{0} {1}", Catalog.GetString ("Layer"), layer_name_int++)); } + public Layer CreateLayer (int width, int height) + { + return CreateLayer (string.Format ("{0} {1}", Catalog.GetString ("Layer"), layer_name_int++), width, height); + } + public Layer CreateLayer (string name) { return CreateLayer (name, ImageSize.Width, ImageSize.Height); @@ -301,6 +306,16 @@ public void CreateSelectionLayer () (old.Surface as IDisposable).Dispose (); } + public void CreateSelectionLayer (int width, int height) + { + Layer old = selection_layer; + + selection_layer = CreateLayer (width, height); + + if (old != null) + (old.Surface as IDisposable).Dispose (); + } + // Delete the current layer public void DeleteCurrentLayer () { diff --git a/Pinta/Actions/Edit/PasteAction.cs b/Pinta/Actions/Edit/PasteAction.cs index 9c39429d1..6f5a061ca 100644 --- a/Pinta/Actions/Edit/PasteAction.cs +++ b/Pinta/Actions/Edit/PasteAction.cs @@ -96,7 +96,7 @@ private void Activated (object sender, EventArgs e) } // Copy the paste to the temp layer - doc.CreateSelectionLayer (); + doc.CreateSelectionLayer (image.Width, image.Height); doc.ShowSelectionLayer = true; using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) diff --git a/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs b/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs index fe3093d7c..a6c6b6e2a 100644 --- a/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs +++ b/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs @@ -26,6 +26,7 @@ using System; using Gtk; +using Cairo; using Mono.Unix; using Pinta.Core; @@ -33,6 +34,8 @@ namespace Pinta.Actions { class PasteIntoNewLayerAction : IActionHandler { + private const string markup = "{0}\n\n{1}"; + #region IActionHandler Members public void Initialize () { @@ -49,26 +52,95 @@ private void Activated (object sender, EventArgs e) { Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); - if (cb.WaitIsImageAvailable ()) { - PintaCore.Tools.Commit (); + PintaCore.Tools.Commit (); + + Path p; + + // Don't dispose this, as we're going to give it to the history + Gdk.Pixbuf image = cb.WaitForImage (); + + if (image == null) + { + Dialogs.ClipboardEmptyDialog.Show (); + return; + } + else if (!PintaCore.Workspace.HasOpenDocuments) { + // Create a new document if no documents are open. + PintaCore.Workspace.NewDocument (new Gdk.Size (image.Width, image.Height), true); + } + + Document doc = PintaCore.Workspace.ActiveDocument; + + Gdk.Size canvas_size = PintaCore.Workspace.ImageSize; - Gdk.Pixbuf image = cb.WaitForImage (); + // Merge the (optional) canvas resize and the pasted image into a single history item. + var paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString ("Paste Into New Layer")); - Layer l = PintaCore.Layers.AddNewLayer (string.Empty); + // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas + if (image.Width > canvas_size.Width || image.Height > canvas_size.Height) + { + ResponseType response = ShowExpandCanvasDialog (); - using (Cairo.Context g = new Cairo.Context (l.Surface)) - g.DrawPixbuf (image, new Cairo.Point (0, 0)); + if (response == ResponseType.Accept) + { + PintaCore.Workspace.ResizeCanvas (image.Width, image.Height, + Pinta.Core.Anchor.Center, paste_action); + PintaCore.Actions.View.UpdateCanvasScale (); + } + else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent) + { + return; + } + } - // Make new layer the current layer - PintaCore.Layers.SetCurrentLayer (l); + // Create a new layer and make it the current layer + Layer l = PintaCore.Layers.AddNewLayer (string.Empty); + PintaCore.Layers.SetCurrentLayer (l); - PintaCore.Workspace.Invalidate (); + // Record in the History that a new layer was added + paste_action.Push (new AddLayerHistoryItem("Menu.Layers.AddNewLayer.png", Catalog.GetString ("Add New Layer"), PintaCore.Layers.IndexOf (l))); - AddLayerHistoryItem hist = new AddLayerHistoryItem (Stock.Paste, Catalog.GetString ("Paste Into New Layer"), PintaCore.Layers.IndexOf (l)); - PintaCore.History.PushNewItem (hist); - } else { - Pinta.Dialogs.ClipboardEmptyDialog.Show (); + // Copy the paste to the temp layer + doc.CreateSelectionLayer (image.Width, image.Height); + doc.ShowSelectionLayer = true; + + using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) + { + g.DrawPixbuf (image, new Cairo.Point (0, 0)); + p = g.CreateRectanglePath (new Rectangle (0, 0, image.Width, image.Height)); } + + PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels")); + + DocumentSelection old_selection = doc.Selection.Clone(); + bool old_show_selection = doc.ShowSelection; + + doc.Selection.SelectionPath = p; + doc.Selection.SelectionPolygons.Clear(); + doc.ShowSelection = true; + + doc.Workspace.Invalidate (); + + paste_action.Push (new PasteHistoryItem (image, old_selection, old_show_selection)); + doc.History.PushNewItem (paste_action); + } + + private ResponseType ShowExpandCanvasDialog () + { + string primary = Catalog.GetString ("Image larger than canvas"); + string secondary = Catalog.GetString ("The image being pasted is larger than the canvas size. What would you like to do?"); + string message = string.Format (markup, primary, secondary); + + var enlarge_dialog = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message); + enlarge_dialog.AddButton (Catalog.GetString ("Expand canvas"), ResponseType.Accept); + enlarge_dialog.AddButton (Catalog.GetString ("Don't change canvas size"), ResponseType.Reject); + enlarge_dialog.AddButton (Stock.Cancel, ResponseType.Cancel); + enlarge_dialog.DefaultResponse = ResponseType.Accept; + + ResponseType response = (ResponseType)enlarge_dialog.Run (); + enlarge_dialog.Destroy (); + + return response; } } } From c29d7c384a912b754153c285b0298876c86ccc1f Mon Sep 17 00:00:00 2001 From: Don McComb Date: Wed, 7 Nov 2012 22:40:27 +1100 Subject: [PATCH 2/5] [Fixes bug #1064018] Data lost when pasting images onto smaller canvases. Simplified PasteIntoNewLayer. It now activates the plain Paste action. --- Pinta/Actions/Edit/PasteIntoNewLayerAction.cs | 94 +------------------ 1 file changed, 5 insertions(+), 89 deletions(-) diff --git a/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs b/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs index a6c6b6e2a..6a3d97525 100644 --- a/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs +++ b/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs @@ -26,7 +26,6 @@ using System; using Gtk; -using Cairo; using Mono.Unix; using Pinta.Core; @@ -34,8 +33,6 @@ namespace Pinta.Actions { class PasteIntoNewLayerAction : IActionHandler { - private const string markup = "{0}\n\n{1}"; - #region IActionHandler Members public void Initialize () { @@ -54,93 +51,12 @@ private void Activated (object sender, EventArgs e) PintaCore.Tools.Commit (); - Path p; - - // Don't dispose this, as we're going to give it to the history - Gdk.Pixbuf image = cb.WaitForImage (); - - if (image == null) - { - Dialogs.ClipboardEmptyDialog.Show (); - return; - } - else if (!PintaCore.Workspace.HasOpenDocuments) { - // Create a new document if no documents are open. - PintaCore.Workspace.NewDocument (new Gdk.Size (image.Width, image.Height), true); + if (cb.WaitIsImageAvailable ()) { + PintaCore.Actions.Layers.AddNewLayer.Activate(); + PintaCore.Actions.Edit.Paste.Activate (); + } else { + Pinta.Dialogs.ClipboardEmptyDialog.Show (); } - - Document doc = PintaCore.Workspace.ActiveDocument; - - Gdk.Size canvas_size = PintaCore.Workspace.ImageSize; - - // Merge the (optional) canvas resize and the pasted image into a single history item. - var paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString ("Paste Into New Layer")); - - // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas - if (image.Width > canvas_size.Width || image.Height > canvas_size.Height) - { - ResponseType response = ShowExpandCanvasDialog (); - - if (response == ResponseType.Accept) - { - PintaCore.Workspace.ResizeCanvas (image.Width, image.Height, - Pinta.Core.Anchor.Center, paste_action); - PintaCore.Actions.View.UpdateCanvasScale (); - } - else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent) - { - return; - } - } - - // Create a new layer and make it the current layer - Layer l = PintaCore.Layers.AddNewLayer (string.Empty); - PintaCore.Layers.SetCurrentLayer (l); - - // Record in the History that a new layer was added - paste_action.Push (new AddLayerHistoryItem("Menu.Layers.AddNewLayer.png", Catalog.GetString ("Add New Layer"), PintaCore.Layers.IndexOf (l))); - - // Copy the paste to the temp layer - doc.CreateSelectionLayer (image.Width, image.Height); - doc.ShowSelectionLayer = true; - - using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) - { - g.DrawPixbuf (image, new Cairo.Point (0, 0)); - p = g.CreateRectanglePath (new Rectangle (0, 0, image.Width, image.Height)); - } - - PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels")); - - DocumentSelection old_selection = doc.Selection.Clone(); - bool old_show_selection = doc.ShowSelection; - - doc.Selection.SelectionPath = p; - doc.Selection.SelectionPolygons.Clear(); - doc.ShowSelection = true; - - doc.Workspace.Invalidate (); - - paste_action.Push (new PasteHistoryItem (image, old_selection, old_show_selection)); - doc.History.PushNewItem (paste_action); - } - - private ResponseType ShowExpandCanvasDialog () - { - string primary = Catalog.GetString ("Image larger than canvas"); - string secondary = Catalog.GetString ("The image being pasted is larger than the canvas size. What would you like to do?"); - string message = string.Format (markup, primary, secondary); - - var enlarge_dialog = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message); - enlarge_dialog.AddButton (Catalog.GetString ("Expand canvas"), ResponseType.Accept); - enlarge_dialog.AddButton (Catalog.GetString ("Don't change canvas size"), ResponseType.Reject); - enlarge_dialog.AddButton (Stock.Cancel, ResponseType.Cancel); - enlarge_dialog.DefaultResponse = ResponseType.Accept; - - ResponseType response = (ResponseType)enlarge_dialog.Run (); - enlarge_dialog.Destroy (); - - return response; } } } From c77a5759022caf017453be4555c2c60a65a3e7cb Mon Sep 17 00:00:00 2001 From: Don McComb Date: Fri, 9 Nov 2012 00:52:50 +1100 Subject: [PATCH 3/5] Modified so that PasteIntoNewLayer is a compound history item action --- Pinta.Core/Classes/Document.cs | 125 +++++++++++++++++- Pinta/Actions/Edit/PasteAction.cs | 95 ++----------- Pinta/Actions/Edit/PasteIntoNewImageAction.cs | 2 +- Pinta/Actions/Edit/PasteIntoNewLayerAction.cs | 20 +-- Pinta/Dialogs/ClipboardEmptyDialog.cs | 51 ------- 5 files changed, 145 insertions(+), 148 deletions(-) delete mode 100644 Pinta/Dialogs/ClipboardEmptyDialog.cs diff --git a/Pinta.Core/Classes/Document.cs b/Pinta.Core/Classes/Document.cs index 9cec26802..d14c31bcd 100644 --- a/Pinta.Core/Classes/Document.cs +++ b/Pinta.Core/Classes/Document.cs @@ -1,4 +1,4 @@ -// +// // Document.cs // // Author: @@ -28,9 +28,11 @@ using System.Linq; using Mono.Unix; using Gdk; +using Gtk; using System.Collections.Generic; using Cairo; using System.ComponentModel; +using Pinta; namespace Pinta.Core { @@ -720,6 +722,127 @@ public void SetCurrentLayer (Layer layer) { SetCurrentLayer (Layers.IndexOf (layer)); } + + public void Paste (bool toNewLayer) + { + // Create a compound history item for recording several + // operations so that they can all be undone/redone together. + CompoundHistoryItem paste_action; + string actionCatalogString = toNewLayer ? "Paste Into New Layer" : "Paste"; + paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString (actionCatalogString)); + + Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); + + // See if the current tool wants to handle the paste + // operation (e.g., the text tool could paste text) + if (!toNewLayer) + { + if (PintaCore.Tools.CurrentTool.TryHandlePaste (cb)) + return; + } + + PintaCore.Tools.Commit (); + + Path p; + + // Don't dispose this, as we're going to give it to the history + Gdk.Pixbuf image = cb.WaitForImage (); + + if (image == null) + { + ShowClipboardEmptyDialog(); + return; + } + + Gdk.Size canvas_size = PintaCore.Workspace.ImageSize; + + // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas + if (image.Width > canvas_size.Width || image.Height > canvas_size.Height) + { + ResponseType response = ShowExpandCanvasDialog (); + + if (response == ResponseType.Accept) + { + PintaCore.Workspace.ResizeCanvas (image.Width, image.Height, + Pinta.Core.Anchor.Center, paste_action); + PintaCore.Actions.View.UpdateCanvasScale (); + } + else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent) + { + return; + } + } + + // If requested, create a new layer, make it the current + // layer and record it's creation in the history + if (toNewLayer) + { + Layer l = AddNewLayer (string.Empty); + SetCurrentLayer (l); + paste_action.Push (new AddLayerHistoryItem ("Menu.Layers.AddNewLayer.png", Catalog.GetString ("Add New Layer"), Layers.IndexOf (l))); + } + + // Copy the paste to the temp layer + CreateSelectionLayer (image.Width, image.Height); + ShowSelectionLayer = true; + + using (Cairo.Context g = new Cairo.Context (SelectionLayer.Surface)) + { + g.DrawPixbuf (image, new Cairo.Point (0, 0)); + p = g.CreateRectanglePath (new Cairo.Rectangle (0, 0, image.Width, image.Height)); + } + + PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels")); + + DocumentSelection old_selection = Selection.Clone(); + bool old_show_selection = ShowSelection; + + Selection.SelectionPath = p; + Selection.SelectionPolygons.Clear(); + ShowSelection = true; + + Workspace.Invalidate (); + + paste_action.Push (new PasteHistoryItem (image, old_selection, old_show_selection)); + History.PushNewItem (paste_action); + } + + private ResponseType ShowExpandCanvasDialog () + { + const string markup = "{0}\n\n{1}"; + string primary = Catalog.GetString ("Image larger than canvas"); + string secondary = Catalog.GetString ("The image being pasted is larger than the canvas size. What would you like to do?"); + string message = string.Format (markup, primary, secondary); + + var enlarge_dialog = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message); + enlarge_dialog.AddButton (Catalog.GetString ("Expand canvas"), ResponseType.Accept); + enlarge_dialog.AddButton (Catalog.GetString ("Don't change canvas size"), ResponseType.Reject); + enlarge_dialog.AddButton (Stock.Cancel, ResponseType.Cancel); + enlarge_dialog.DefaultResponse = ResponseType.Accept; + + ResponseType response = (ResponseType)enlarge_dialog.Run (); + + enlarge_dialog.Destroy (); + + return response; + } + + public static void ShowClipboardEmptyDialog() + { + var primary = Catalog.GetString ("Image cannot be pasted"); + var secondary = Catalog.GetString ("The clipboard does not contain an image."); + var markup = "{0}\n\n{1}\n"; + markup = string.Format (markup, primary, secondary); + + var md = new MessageDialog (Pinta.Core.PintaCore.Chrome.MainWindow, DialogFlags.Modal, + MessageType.Error, ButtonsType.None, true, + markup); + + md.AddButton (Stock.Ok, ResponseType.Yes); + + md.Run (); + md.Destroy (); + } #endregion #region Protected Methods diff --git a/Pinta/Actions/Edit/PasteAction.cs b/Pinta/Actions/Edit/PasteAction.cs index 6f5a061ca..bfd13843a 100644 --- a/Pinta/Actions/Edit/PasteAction.cs +++ b/Pinta/Actions/Edit/PasteAction.cs @@ -1,4 +1,4 @@ -// +// // PasteAction.cs // // Author: @@ -25,7 +25,6 @@ // THE SOFTWARE. using System; -using Cairo; using Gtk; using Mono.Unix; using Pinta.Core; @@ -34,8 +33,6 @@ namespace Pinta.Actions { class PasteAction : IActionHandler { - private const string markup = "{0}\n\n{1}"; - #region IActionHandler Members public void Initialize () { @@ -50,92 +47,18 @@ public void Uninitialize () private void Activated (object sender, EventArgs e) { - Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); - if (PintaCore.Tools.CurrentTool.TryHandlePaste (cb)) - return; - - PintaCore.Tools.Commit (); - - Path p; - - // Don't dispose this, as we're going to give it to the history - Gdk.Pixbuf image = cb.WaitForImage (); - - if (image == null) + // If no documents are open, activate the + // PasteIntoNewImage action and abort this Paste action. + if (!PintaCore.Workspace.HasOpenDocuments) { - Dialogs.ClipboardEmptyDialog.Show (); + PintaCore.Actions.Edit.PasteIntoNewImage.Activate(); return; } - else if (!PintaCore.Workspace.HasOpenDocuments) { - // Create a new document if no documents are open. - PintaCore.Workspace.NewDocument (new Gdk.Size (image.Width, image.Height), true); - } - - Document doc = PintaCore.Workspace.ActiveDocument; - - Gdk.Size canvas_size = PintaCore.Workspace.ImageSize; - - // Merge the (optional) canvas resize and the pasted image into a single history item. - var paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString ("Paste")); - - // If the image being pasted is larger than the canvas size, allow the user to optionally resize the canvas - if (image.Width > canvas_size.Width || image.Height > canvas_size.Height) - { - ResponseType response = ShowExpandCanvasDialog (); - - if (response == ResponseType.Accept) - { - PintaCore.Workspace.ResizeCanvas (image.Width, image.Height, - Pinta.Core.Anchor.Center, paste_action); - PintaCore.Actions.View.UpdateCanvasScale (); - } - else if (response == ResponseType.Cancel || response == ResponseType.DeleteEvent) - { - return; - } - } - - // Copy the paste to the temp layer - doc.CreateSelectionLayer (image.Width, image.Height); - doc.ShowSelectionLayer = true; - - using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) - { - g.DrawPixbuf (image, new Cairo.Point (0, 0)); - p = g.CreateRectanglePath (new Rectangle (0, 0, image.Width, image.Height)); - } - - PintaCore.Tools.SetCurrentTool (Catalog.GetString ("Move Selected Pixels")); - - DocumentSelection old_selection = doc.Selection.Clone(); - bool old_show_selection = doc.ShowSelection; - - doc.Selection.SelectionPath = p; - doc.Selection.SelectionPolygons.Clear(); - doc.ShowSelection = true; - - doc.Workspace.Invalidate (); - - paste_action.Push (new PasteHistoryItem (image, old_selection, old_show_selection)); - doc.History.PushNewItem (paste_action); - } - - private ResponseType ShowExpandCanvasDialog () - { - string primary = Catalog.GetString ("Image larger than canvas"); - string secondary = Catalog.GetString ("The image being pasted is larger than the canvas size. What would you like to do?"); - string message = string.Format (markup, primary, secondary); - - var enlarge_dialog = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Question, ButtonsType.None, message); - enlarge_dialog.AddButton (Catalog.GetString ("Expand canvas"), ResponseType.Accept); - enlarge_dialog.AddButton (Catalog.GetString ("Don't change canvas size"), ResponseType.Reject); - enlarge_dialog.AddButton (Stock.Cancel, ResponseType.Cancel); - enlarge_dialog.DefaultResponse = ResponseType.Accept; - - ResponseType response = (ResponseType)enlarge_dialog.Run (); - enlarge_dialog.Destroy (); - return response; + // Paste into the active document. + // The 'false' argument indicates that paste should be + // performed into the current (not a new) layer. + PintaCore.Workspace.ActiveDocument.Paste (false); } } } diff --git a/Pinta/Actions/Edit/PasteIntoNewImageAction.cs b/Pinta/Actions/Edit/PasteIntoNewImageAction.cs index 1a27b4c38..44bf47fe4 100644 --- a/Pinta/Actions/Edit/PasteIntoNewImageAction.cs +++ b/Pinta/Actions/Edit/PasteIntoNewImageAction.cs @@ -57,7 +57,7 @@ private void Activated (object sender, EventArgs e) PintaCore.Actions.Edit.Paste.Activate (); PintaCore.Actions.Edit.Deselect.Activate (); } else { - Pinta.Dialogs.ClipboardEmptyDialog.Show (); + Pinta.Core.Document.ShowClipboardEmptyDialog (); } } } diff --git a/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs b/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs index 6a3d97525..25cc3b568 100644 --- a/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs +++ b/Pinta/Actions/Edit/PasteIntoNewLayerAction.cs @@ -47,16 +47,18 @@ public void Uninitialize () private void Activated (object sender, EventArgs e) { - Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false)); - - PintaCore.Tools.Commit (); - - if (cb.WaitIsImageAvailable ()) { - PintaCore.Actions.Layers.AddNewLayer.Activate(); - PintaCore.Actions.Edit.Paste.Activate (); - } else { - Pinta.Dialogs.ClipboardEmptyDialog.Show (); + // If no documents are open, activate the + // PasteIntoNewImage action and abort this Paste action. + if (!PintaCore.Workspace.HasOpenDocuments) + { + PintaCore.Actions.Edit.PasteIntoNewImage.Activate(); + return; } + + // Paste into the active document. + // The 'true' argument indicates that paste should be + // performed into a new layer. + PintaCore.Workspace.ActiveDocument.Paste (true); } } } diff --git a/Pinta/Dialogs/ClipboardEmptyDialog.cs b/Pinta/Dialogs/ClipboardEmptyDialog.cs deleted file mode 100644 index 28d3e0752..000000000 --- a/Pinta/Dialogs/ClipboardEmptyDialog.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -// ClipboardEmptyDialog.cs -// -// Author: -// Cameron White -// -// Copyright (c) 2012 Cameron White -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using Gtk; -using Mono.Unix; - -namespace Pinta.Dialogs -{ - public static class ClipboardEmptyDialog - { - public static void Show () - { - var primary = Catalog.GetString ("Image cannot be pasted"); - var secondary = Catalog.GetString ("The clipboard does not contain an image."); - var markup = "{0}\n\n{1}\n"; - markup = string.Format (markup, primary, secondary); - - var md = new MessageDialog (Pinta.Core.PintaCore.Chrome.MainWindow, DialogFlags.Modal, - MessageType.Error, ButtonsType.None, true, - markup); - - md.AddButton (Stock.Ok, ResponseType.Yes); - - md.Run (); - md.Destroy (); - } - } -} From 362e5751fec567b3b4357ed96ff0229e7096307e Mon Sep 17 00:00:00 2001 From: Don McComb Date: Fri, 9 Nov 2012 07:01:13 +1100 Subject: [PATCH 4/5] Removed Dialogs\ClipboardEmptyDialog.cs from project file --- Pinta/Pinta.csproj | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Pinta/Pinta.csproj b/Pinta/Pinta.csproj index 7bda3facf..8a3f5fece 100644 --- a/Pinta/Pinta.csproj +++ b/Pinta/Pinta.csproj @@ -1,4 +1,4 @@ - + Debug @@ -9,7 +9,6 @@ WinExe Pinta Pinta - v4.0 65001 @@ -75,18 +74,24 @@ Pinta.ico - - - - + + gtk-sharp-2.0 + - - - - - + + gtk-sharp-2.0 + + + gtk-sharp-2.0 + + + glib-sharp-2.0 + + + gtk-sharp-2.0 + @@ -131,7 +136,6 @@ - From b867e01fae56d4354404e3bba938fdd5f16f8580 Mon Sep 17 00:00:00 2001 From: Don McComb Date: Sat, 10 Nov 2012 23:29:40 +1100 Subject: [PATCH 5/5] Wrapped paste action strings in Catalog.GetString() --- Pinta.Core/Classes/Document.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Pinta.Core/Classes/Document.cs b/Pinta.Core/Classes/Document.cs index d14c31bcd..d0c30bd25 100644 --- a/Pinta.Core/Classes/Document.cs +++ b/Pinta.Core/Classes/Document.cs @@ -728,8 +728,14 @@ public void Paste (bool toNewLayer) // Create a compound history item for recording several // operations so that they can all be undone/redone together. CompoundHistoryItem paste_action; - string actionCatalogString = toNewLayer ? "Paste Into New Layer" : "Paste"; - paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString (actionCatalogString)); + if (toNewLayer) + { + paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString ("Paste Into New Layer")); + } + else + { + paste_action = new CompoundHistoryItem (Stock.Paste, Catalog.GetString ("Paste")); + } Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));