Hello,
I was wondering if anyone has had the same bug and found (ideally!) a solution. I have a NSTableView setup to receive folders via drag and drop from the finder, and although everything works as expected, before the first folder is processed there is a 20-30 seconds pause where the app is frozen, then the items I dragged are visually going back to where they came from, then another 4 second pause and finally the app keeps going.
I have tried a dozen changes, inserted a log call between all my lines of code to see which one was doing that and it happens during the first loop of a repeat loop that looks at all the items in the dragged items.
There is never any error logged, that’s the strange thing. And it does the same on other computers. If I drage 2 or 200 folders, same thing. Anyone has any idea?
Thanks.
Here’s my code if you think it would help:
on tableView_validateDrop_proposedRow_proposedDropOperation_(tv, info, theRow, proposedOp)
return current application's NSDragOperationLink
end tableView_validateDrop_proposedRow_proposedDropOperation_
on tableView_acceptDrop_row_dropOperation_(tableView, info, theRow, proposedOp)
set pasteBoardContent to info's draggingPasteboard()
set theOptions to {NSPasteboardURLReadingContentsConformToTypesKey:{"public.folder"}}
set pasteboardURLs to pasteBoardContent's readObjectsForClasses_options_({current application's |NSURL|}, theOptions)
IBprogressBar's setDoubleValue_(0)
IBprogressBar's setNeedsDisplay_(true)
set countOfUrlsToAdd to (pasteboardURLs's |count|()) as integer
if countOfUrlsToAdd > 0 then
set progressCounter to 1
repeat with currentURL in pasteboardURLs
--%%%% THIS IS WHERE THE PAUSE BEGINS AND ENDS, AND ONLY ON THE FIRST LOOP. %%%%
IBprogressBar's setDoubleValue_(progressCounter)
my addFolderToTableViewWithUrl_(currentURL)
set progressCounter to progressCounter + 1
IBprogressBar's displayIfNeeded()
end repeat
IBprogressBar's setDoubleValue_(countOfUrlsToAdd)
IBfoldersToMergeArrayController's rearrangeObjects()
end if
return true
end tableView_acceptDrop_row_dropOperation_
Modified to reflect my latest version.
Don’t – make that don’t – use delay. If you need a screen update, ask for one with something like displayIfNeeded.
Well, i tried many things, but unless I use delay, the process goes too fast and neither the progress bar nor the text field’s content get updated with the progress (“1 of 10 scanned”, etc.). I tried to use do shell script “sleep 1”, but it’s like a punch through the air, it’s exactly like if it wasn’t there.
What would displayIfNeeded change if i’m telling it to change already (the prog indicator)? shouldn’t it change because i’m sending it a new double value?
And like I said, my problem with slow-mo dragging was there long before I put delays in there. I tried a new version without the delays, doesnt change a thing. It takes exactly 25 seconds to actually start processing the dragged files, wether it be 2 or 200 folders. After 20 seconds I see that ghosting effect like the folders were being rejected and dragged back to their original position in the finder.
Any ideas on what that might be?
I did make use of setNeedsDisplay and displayIfNeeded and it works nicely. Thanks for that, does make an improvement over using delay!
But still, the 25-second delay is still present…
Add some log statements so you can see where the time is being spent. It may be in addFolderToTableViewWithUrl_.
I did, first thing I tried. I put one log statement between every line of code to be sure. Like I said in my first post, it pauses right when it goes through the first loop in the repeat loop, right after the repeat with… Then it keeps on going, loop 2 and up keep going fine. It’ like if the drag process from the finder was too much and it stalls the app for 25 seconds… Really strange. I was using drag and drop in ASS apps before and nothing like that ever happened.
Why are you using:
repeat with currentURL in pasteboardURLs
instead of:
repeat with currentURL in theListOfUrlsToAdd
?
oh, that’s old. Found out I could go through the provided list of URLs, without coercing them first. Why? You think it might help? The repeat loop is going thru a list or NSUrl objects, and this is what my method is expecting to add them to the table view. I’ll change the code, and see if it helps…
But you already coerced them a couple of lines before…
Nope. Removed the theListOfUrlsToAdd parts from the code and changed the counting of items in the array with a more ASOC-like method, no change. Same 25-second lag. This makes no sense. If only there were an error in the log, but no, everything seems normal.
What other methods is there for getting dragged objects besides tableView:acceptDrop:row:dropOperation:. Because I seemed to notice that when I drag my folders onto the table view, it displays a blue line in between rows, like if I were trying to insert them right there. Maybe this is the problem. In ASS, we only had the add to version, where the mouse cursor would get a shiny green + sign… I’ve looked for other methods, but that seems to be the only one.
Yep, for the purpose of counting the number of items. Which I have now changed to
set pasteboardURLs to pasteBoardContent's readObjectsForClasses_options_({current application's |NSURL|}, theOptions)
set countOfUrlsToAdd to (pasteboardURLs's |count|()) as integer
but like I said, no change in behavior.
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
I have just modified my original post to reflect the changes I just made. Thought it might help.
Humor me. Stop trying to make the coercion to a list happen automatically in the repeat line, and do it yourself first. And wrap the coercion line in log statements to see how long it takes.
Alright, after much experimentation and a bit of luck, i’ve discovered that it wasn’t the method that takes care of dragged folders, but rather the method that was adding items to the table view. More precisely it was my command asking the finder the size of the folder, and for some weird reason it was stalling for 25 seconds ONLY if the folders were dragged to the table view and with the first folder, not added via an open panel nor via drag and drop onto the app’s icon in the dock.
Really strange because it’s the same method for all 3 ways of adding folders to the table view… To solve this problem I changed it to a do shell script command that returns the size of the folder in kilobytes.
Thanks for your help Shane, as always.