Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+ New feauture from wishlist: drag'n'drop pictures from web browser\n* F... #80

Merged
merged 2 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Pinta.Core/Classes/DocumentWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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
6 changes: 6 additions & 0 deletions Pinta.Core/Managers/WorkspaceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -95,6 +96,11 @@ public void CallSelectionChanged(object sender, EventArgs e)

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
3 changes: 3 additions & 0 deletions Pinta.Gui.Widgets/Widgets/OpenImages/OpenImagesListWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed, since I think the bug you were trying to fix was recently fixed in master

return;

PintaCore.Workspace.SetActiveDocument (path.Indices[0]);
PintaCore.Actions.File.Close.Activate ();
UpdateSelectedDocument ();
Expand Down
49 changes: 44 additions & 5 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear why HasOpenPendingDocuments is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember not setting this flag up could lead to something like NullPointerException or so in case of user trying to open more than one document at the same time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it should be removed - the only place it's checked is inside WindowPointToCanvas, but mouse events shouldn't be handled while an image is being downloaded. The progress dialog should be a modal dialog, while the image is downloaded in the background.


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) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should test this further. It doesn't appear that this ever gets called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I will test it better when I have free time. Thanks for pointing to that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue is the DownloadFile blocks until the download is complete. You probably want to look into using DownloadFileAsync or DownloadFileTaskAsync

{
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