Skip to content

Commit

Permalink
try implement file drag&drop...ensue weirdness
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Aug 30, 2017
1 parent 508e646 commit 7c689f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions jmc/Delegate:Main Window Controller/AppDelegate.swift
Expand Up @@ -93,7 +93,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
self.setupWindowController = InitialSetupWindowController(windowNibName: "InitialSetupWindowController")
self.setupWindowController?.setupForNilLibrary()
}
self.locationManager = LocationManager(delegate: self)
//self.locationManager = LocationManager(delegate: self)
self.addFilesQueueLoop = AddFilesQueueLoop(delegate: self)
self.locationManager?.initializeEventStream()
self.lastFMDelegate = LastFMDelegate()
Expand Down Expand Up @@ -245,7 +245,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
}
//NotificationCenter.default.addObserver(self, selector: #selector(managedObjectsDidChangeDebug), name: Notification.Name.NSManagedObjectContextObjectsDidChange, object: managedObjectContext)
NotificationCenter.default.addObserver(self, selector: #selector(managedObjectsDidUndo), name: Notification.Name.NSUndoManagerDidUndoChange, object: managedObjectContext.undoManager)
self.mediaKeyListener = MediaKeyListener(self)
//self.mediaKeyListener = MediaKeyListener(self)
}

func managedObjectsDidUndo() {
Expand Down
Expand Up @@ -224,25 +224,32 @@ class DragAndDropArrayController: NSArrayController, NSTableViewDataSource, NSTa
func tableView(_ tableView: NSTableView, writeRowsWith rowIndexes: IndexSet, to pboard: NSPasteboard) -> Bool {
print("table view writerows called")
let rows = NSMutableArray()
var filenames = [String]()
var fileURLs = [NSURL]()
for index in rowIndexes {
let trackView = (self.arrangedObjects as! [TrackView])[index]
let trackView = (self.arrangedObjects as! NSArray)[index] as! TrackView
rows.add(trackView.track!.objectID.uriRepresentation())
filenames.append(URL(string: trackView.track!.location!)!.path)
fileURLs.append(URL(string: trackView.track!.location!)! as NSURL)
}
pboard.setPropertyList(filenames, forType: NSFilenamesPboardType)
print("writing urls")
//pboard.addTypes([NSURLPboardType], owner: nil)
pboard.writeObjects(fileURLs)
draggedRowIndexes = rowIndexes
let encodedIDs = NSKeyedArchiver.archivedData(withRootObject: rows)
let context = mainWindow?.currentSourceListItem?.name
print("context is \(context)")
if context != nil {
pboard.setString(context!, forType: "context")
//pboard.setString(context!, forType: "context")
}
if mainWindow?.currentSourceListItem?.is_network == true {
print("settin network pboard data")
pboard.setData(encodedIDs, forType: "NetworkTrack")
} else {
pboard.setData(encodedIDs, forType: "Track")
//pboard.setData(encodedIDs, forType: "Track")
}
print(pboard.types)
for item in pboard.pasteboardItems! {
print(item.types)
print(item.data(forType: "public.file-url"))
}
return true
}
Expand All @@ -253,10 +260,6 @@ class DragAndDropArrayController: NSArrayController, NSTableViewDataSource, NSTa
return array[index] as? TrackView
}

func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: IndexSet) {
print("dragypoo called")
}

func tableView(_ tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableViewDropOperation) -> Bool {
if info.draggingPasteboard().types!.contains(NSFilenamesPboardType) {
let files = info.draggingPasteboard().propertyList(forType: NSFilenamesPboardType) as! NSArray
Expand Down Expand Up @@ -298,7 +301,7 @@ class DragAndDropArrayController: NSArrayController, NSTableViewDataSource, NSTa
}

func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableViewDropOperation) -> NSDragOperation {
if info.draggingPasteboard().types!.contains(NSFilenamesPboardType) {
/*if info.draggingPasteboard().types!.contains(NSFilenamesPboardType) {
print("doingle")
tableView.setDropRow(-1, dropOperation: NSTableViewDropOperation.on)
return .copy
Expand All @@ -307,6 +310,7 @@ class DragAndDropArrayController: NSArrayController, NSTableViewDataSource, NSTa
return .move
} else {
return NSDragOperation()
}
}*/
return []
}
}

0 comments on commit 7c689f6

Please sign in to comment.