Skip to content

Commit

Permalink
#250 implements drag & drop files from outside into the app
Browse files Browse the repository at this point in the history
  • Loading branch information
hosy committed Mar 12, 2019
1 parent 549dcd3 commit f38d3c8
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions ownCloud/Client/ClientQueryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class ClientQueryViewController: UITableViewController, Themeable {
return UITableViewDropProposal(operation: .move, intent: .insertIntoDestinationIndexPath)
}
} else {
return UITableViewDropProposal(operation: .forbidden)
return UITableViewDropProposal(operation: .copy)
}
}

Expand Down Expand Up @@ -911,47 +911,54 @@ extension ClientQueryViewController: UITableViewDropDelegate {
guard let core = self.core else { return }

for item in coordinator.items {

var destinationItem: OCItem

guard let item = item.dragItem.localObject as? OCItem, let itemName = item.name else {
return
}

if coordinator.proposal.intent == .insertIntoDestinationIndexPath {

guard let destinationIP = coordinator.destinationIndexPath else {
if item.dragItem.localObject != nil {
var destinationItem: OCItem

guard let item = item.dragItem.localObject as? OCItem, let itemName = item.name else {
return
}

guard items.count >= destinationIP.row else {
return

if coordinator.proposal.intent == .insertIntoDestinationIndexPath {

guard let destinationIP = coordinator.destinationIndexPath else {
return
}

guard items.count >= destinationIP.row else {
return
}

let rootItem = items[destinationIP.row]

guard rootItem.type == .collection else {
return
}

destinationItem = rootItem

} else {

guard let rootItem = self.query.rootItem, item.parentFileID != rootItem.fileID else {
return
}

destinationItem = rootItem

}

let rootItem = items[destinationIP.row]

guard rootItem.type == .collection else {
return

if let progress = core.move(item, to: destinationItem, withName: itemName, options: nil, resultHandler: { (error, _, _, _) in
if error != nil {
Log.log("Error \(String(describing: error)) moving \(String(describing: item.path))")
}
}) {
self.progressSummarizer?.startTracking(progress: progress)
}

destinationItem = rootItem

} else {

guard let rootItem = self.query.rootItem, item.parentFileID != rootItem.fileID else {
return
}

destinationItem = rootItem

}

if let progress = core.move(item, to: destinationItem, withName: itemName, options: nil, resultHandler: { (error, _, _, _) in
if error != nil {
Log.log("Error \(String(describing: error)) moving \(String(describing: item.path))")
guard let UTI = item.dragItem.itemProvider.registeredTypeIdentifiers.last else { return }
item.dragItem.itemProvider.loadFileRepresentation(forTypeIdentifier: UTI) { (url, _ error) in
guard let url = url else { return }
self.upload(itemURL: url, name: url.lastPathComponent)
}
}) {
self.progressSummarizer?.startTracking(progress: progress)
}
}
}
Expand Down

0 comments on commit f38d3c8

Please sign in to comment.