Skip to content

Commit

Permalink
Merge branch 'pr/80'
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Jul 19, 2020
2 parents 11757dc + 365c18c commit 0f53747
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Pinta.Core/Classes/DocumentWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public void ScrollCanvas (int dx, int dy)
/// </param>
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));
Expand Down
4 changes: 2 additions & 2 deletions Pinta.Core/Classes/ScaleFactor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Pinta.Core/Managers/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public WorkspaceManager ()

public List<Document> 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)
{
Expand Down
49 changes: 44 additions & 5 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,56 @@ 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;

string fullData = System.Text.Encoding.UTF8.GetString (args.SelectionData.Data);

foreach (string individualFile in fullData.Split ('\n')) {
string file = individualFile.Trim ();

if (file.StartsWith ("file://"))
PintaCore.Workspace.OpenFile (new Uri (file).LocalPath);
try {
PintaCore.Workspace.HasOpenPendingDocuments = true;

foreach (string individualFile in fullData.Split ('\n')) {
string file = individualFile.Trim ();
Console.WriteLine (file);

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);

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
PintaCore.Chrome.ShowErrorDialog(PintaCore.Chrome.MainWindow,
"Download failed",
"Unable to download target file: " + tempFilePath);
}

if (file.StartsWith ("file://"))
PintaCore.Workspace.OpenFile (new Uri (file).LocalPath);
}
} finally {
PintaCore.Workspace.HasOpenPendingDocuments = false;
}
}

Expand Down

0 comments on commit 0f53747

Please sign in to comment.