Skip to content

Commit

Permalink
Fix a few issues with opening images from URLs
Browse files Browse the repository at this point in the history
- Remove the HasPendingOpenDocuments member, which shouldn't be necessary.
- Make the strings translatable.
- Ensure that the new image isn't marked as being associated with a file, so that the user can't save to the temp file and later lose their work.

#80
  • Loading branch information
cameronwhite committed Jul 19, 2020
1 parent 0f53747 commit 12dd846
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Thanks to the following contributors who worked on this release:
- @rajter
- @dandv
- @jaburns
- @aivel

### Added
- Added a tab view to switch between images. The tabs can also be docked side-by-side or pulled into new windows. (#94).
Expand All @@ -30,6 +31,7 @@ Thanks to the following contributors who worked on this release:
- Added support for JASC PaintShop Pro palette files (#126).
- The transform tools can now rotate in fixed increments by holding Shift (#134).
- The Move Selected tool can now scale by holding Ctrl (#138).
- Dragging and dropping a URL (e.g. image from a web browser) to download and open the image is now supported (#80, [#644123](https://bugs.launchpad.net/pinta/+bug/644123)).
- Performance improvements when interacting with selections, particularly for large images ([#1428740](https://bugs.launchpad.net/pinta/+bug/1428740)).
- The Rectangle Select tool now shows different arrow cursors at each corner of the selection ([#1188143](https://bugs.launchpad.net/pinta/+bug/1188143)).
- Added an AppData file for integration with some Linux app stores (#121).
Expand Down
3 changes: 0 additions & 3 deletions Pinta.Core/Classes/DocumentWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ 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
5 changes: 0 additions & 5 deletions Pinta.Core/Managers/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ 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
76 changes: 37 additions & 39 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,48 +536,46 @@ private void MainWindow_DragDataReceived (object o, DragDataReceivedArgs args)

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

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();
}
foreach (string individualFile in fullData.Split ('\n')) {
string file = individualFile.Trim ();

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 ("http") || file.StartsWith ("ftp")) {
var client = new System.Net.WebClient ();
string tempFilePath = System.IO.Path.GetTempPath () + System.IO.Path.GetFileName (file);

var progressDialog = PintaCore.Chrome.ProgressDialog;

try {
PintaCore.Chrome.MainWindowBusy = true;

progressDialog.Title = Catalog.GetString ("Downloading Image");
progressDialog.Text = "";
progressDialog.Show ();

if (file.StartsWith ("file://"))
PintaCore.Workspace.OpenFile (new Uri (file).LocalPath);
client.DownloadProgressChanged += (sender, e) => {
progressDialog.Progress = e.ProgressPercentage;
};

client.DownloadFile (file, tempFilePath);

if (PintaCore.Workspace.OpenFile (tempFilePath)) {
// Mark as not having a file, so that the user doesn't unintentionally
// save using the temp file.
PintaCore.Workspace.ActiveDocument.HasFile = false;
}
} catch (Exception e) {
progressDialog.Hide ();
PintaCore.Chrome.ShowErrorDialog (PintaCore.Chrome.MainWindow,
Catalog.GetString ("Download failed"),
string.Format (Catalog.GetString ("Unable to download image from {0}.\nDetails: {1}"), file, e.Message));
} finally {
client.Dispose ();
progressDialog.Hide ();
PintaCore.Chrome.MainWindowBusy = false;
}
} else if (file.StartsWith ("file://")) {
PintaCore.Workspace.OpenFile (new Uri (file).LocalPath);
}
} finally {
PintaCore.Workspace.HasOpenPendingDocuments = false;
}
}

Expand Down

0 comments on commit 12dd846

Please sign in to comment.