From c5d6415e060088491a843bf4dd3ca7d25124b2ae Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 11 Dec 2014 00:15:47 +0300 Subject: [PATCH 1/2] + New feauture from wishlist: drag'n'drop pictures from web browser\n* Fixed: OpenImagesListWidget caused NullPointerException when clicked fast more than one times. --- Pinta.Core/Classes/DocumentWorkspace.cs | 3 ++ Pinta.Core/Classes/ScaleFactor.cs | 4 +-- Pinta.Core/Managers/WorkspaceManager.cs | 6 ++++ .../OpenImages/OpenImagesListWidget.cs | 3 ++ Pinta/MainWindow.cs | 33 ++++++++++++++++--- 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Pinta.Core/Classes/DocumentWorkspace.cs b/Pinta.Core/Classes/DocumentWorkspace.cs index c2c2e15d4..99fc9aee3 100644 --- a/Pinta.Core/Classes/DocumentWorkspace.cs +++ b/Pinta.Core/Classes/DocumentWorkspace.cs @@ -194,6 +194,9 @@ public void ScrollCanvas (int dx, int dy) /// public Cairo.PointD WindowPointToCanvas (double x, double y) { + if (PintaCore.Workspace.HasOpenPendingDocuments) + return new Cairo.PointD(); + ScaleFactor sf = new ScaleFactor (PintaCore.Workspace.ImageSize.Width, PintaCore.Workspace.CanvasSize.Width); Cairo.PointD pt = sf.ScalePoint (new Cairo.PointD (x - Offset.X, y - Offset.Y)); diff --git a/Pinta.Core/Classes/ScaleFactor.cs b/Pinta.Core/Classes/ScaleFactor.cs index 3e134e9e7..df9af9cde 100644 --- a/Pinta.Core/Classes/ScaleFactor.cs +++ b/Pinta.Core/Classes/ScaleFactor.cs @@ -362,11 +362,11 @@ public static ScaleFactor FromDouble (double scalar) public ScaleFactor (int numerator, int denominator) { if (denominator <= 0) { - throw new ArgumentOutOfRangeException ("denominator", "must be greater than 0"); + throw new ArgumentOutOfRangeException ("denominator", "must be greater than 0(denominator = " + denominator + ")"); } if (numerator < 0) { - throw new ArgumentOutOfRangeException ("numerator", "must be greater than 0"); + throw new ArgumentOutOfRangeException ("numerator", "must be greater than 0(numerator = " + numerator + ")"); } this.numerator = numerator; diff --git a/Pinta.Core/Managers/WorkspaceManager.cs b/Pinta.Core/Managers/WorkspaceManager.cs index bfb07bd3a..902f407b5 100644 --- a/Pinta.Core/Managers/WorkspaceManager.cs +++ b/Pinta.Core/Managers/WorkspaceManager.cs @@ -37,6 +37,7 @@ public class WorkspaceManager { private int active_document_index = -1; private int new_file_name = 1; + private bool has_open_pending_documents = false; // If there is an ongoing open document operation public event EventHandler SelectionChanged; @@ -95,6 +96,11 @@ public void CallSelectionChanged(object sender, EventArgs e) public List OpenDocuments { get; private set; } public bool HasOpenDocuments { get { return OpenDocuments.Count > 0; } } + + public bool HasOpenPendingDocuments { + get { return this.has_open_pending_documents; } + set { this.has_open_pending_documents = value; } + } public Document CreateAndActivateDocument (string filename, Gdk.Size size) { diff --git a/Pinta.Gui.Widgets/Widgets/OpenImages/OpenImagesListWidget.cs b/Pinta.Gui.Widgets/Widgets/OpenImages/OpenImagesListWidget.cs index 5a028ed75..affc4bc09 100644 --- a/Pinta.Gui.Widgets/Widgets/OpenImages/OpenImagesListWidget.cs +++ b/Pinta.Gui.Widgets/Widgets/OpenImages/OpenImagesListWidget.cs @@ -142,6 +142,9 @@ void HandleTreeButtonPressEvent (object o, ButtonPressEventArgs args) TreePath path; tree.GetPathAtPos ((int)click_x, (int)click_y, out path); + if (path == null) + return; + PintaCore.Workspace.SetActiveDocument (path.Indices[0]); PintaCore.Actions.File.Close.Activate (); UpdateSelectedDocument (); diff --git a/Pinta/MainWindow.cs b/Pinta/MainWindow.cs index 5c943d516..82e47a363 100644 --- a/Pinta/MainWindow.cs +++ b/Pinta/MainWindow.cs @@ -399,11 +399,36 @@ private void MainWindow_DragDataReceived (object o, DragDataReceivedArgs args) string fullData = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data); - foreach (string individualFile in fullData.Split ('\n')) { - string file = individualFile.Trim (); + try { + PintaCore.Workspace.HasOpenPendingDocuments = true; - if (file.StartsWith ("file://")) - PintaCore.Workspace.OpenFile (new Uri (file).LocalPath); + foreach (string individualFile in fullData.Split ('\n')) { + string file = individualFile.Trim (); + Console.WriteLine (file); + + if (file.StartsWith ("http")) { + System.Net.WebClient client = new System.Net.WebClient (); + string tempFilePath = System.IO.Path.GetTempPath () + System.IO.Path.GetFileName(file); + + Console.WriteLine (">>File downloaded; " + file + "; " + tempFilePath); + + try { + client.DownloadFile (file, @tempFilePath); + } finally { + client.Dispose (); + } + + if (System.IO.File.Exists (tempFilePath)) + file = "file://" + tempFilePath; + else + Console.WriteLine ("Unable to download target file: " + tempFilePath); + } + + if (file.StartsWith ("file://")) + PintaCore.Workspace.OpenFile (new Uri (file).LocalPath); + } + } finally { + PintaCore.Workspace.HasOpenPendingDocuments = false; } } From 365c18cc4f6676929fbf1000117c200ba3da65c2 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 22 Feb 2015 17:01:47 +0300 Subject: [PATCH 2/2] Progress notification added for file, dragged from the Internet --- Pinta/MainWindow.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Pinta/MainWindow.cs b/Pinta/MainWindow.cs index 82e47a363..91c5a2794 100644 --- a/Pinta/MainWindow.cs +++ b/Pinta/MainWindow.cs @@ -393,6 +393,8 @@ private void MainWindow_DeleteEvent (object o, DeleteEventArgs args) private void MainWindow_DragDataReceived (object o, DragDataReceivedArgs args) { + // TODO: Generate random name for the picture being downloaded + // Only handle URIs if (args.Info != 100) return; @@ -406,22 +408,34 @@ private void MainWindow_DragDataReceived (object o, DragDataReceivedArgs args) string file = individualFile.Trim (); Console.WriteLine (file); - if (file.StartsWith ("http")) { + if (file.StartsWith ("http") || file.StartsWith("ftp")) { System.Net.WebClient client = new System.Net.WebClient (); string tempFilePath = System.IO.Path.GetTempPath () + System.IO.Path.GetFileName(file); - Console.WriteLine (">>File downloaded; " + file + "; " + tempFilePath); + var progressDialog = PintaCore.Chrome.ProgressDialog; try { + progressDialog.Show (); + progressDialog.Title = "Downloading file"; + progressDialog.Text = "File " + file + " is being downloaded to " + + tempFilePath; + client.DownloadFile (file, @tempFilePath); + client.DownloadProgressChanged += (sender, e) => + { + progressDialog.Progress = e.ProgressPercentage; + }; } finally { client.Dispose (); + progressDialog.Hide(); } if (System.IO.File.Exists (tempFilePath)) file = "file://" + tempFilePath; else - Console.WriteLine ("Unable to download target file: " + tempFilePath); + PintaCore.Chrome.ShowErrorDialog(PintaCore.Chrome.MainWindow, + "Download failed", + "Unable to download target file: " + tempFilePath); } if (file.StartsWith ("file://"))