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 1 commit
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
33 changes: 29 additions & 4 deletions Pinta/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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.


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);
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 error handling and progress notifications need to be improved here (e.g. showing dialogs instead of dumping messages to the console).


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

Expand Down