TableTool
TableTool copied to clipboard
Feature request: (automatic) refresh
I often work with csv's that get updated while I have them open in TableTool. Now I must close the window and reopen it to see the most recent version, which can be cumbersome if the location of the file is somewhere far away on a server. It would be nice to see the updates come through in the app automatically or through a Refresh button.
No Objectiv-C experience here, so I'm afraid I can't add this myself, but I think it would be a good idea.
Keep up the good work!
If the file is changed by an app that uses the file coordination APIs (like Apple's TextEdit), TableTool does automatically update -- you don't even need to explicitly save the file! Unfortunately most apps don't use the (relatively new) file coordination APIs.
It would certainly be a good idea to have TableTool watch the file system. However, I'm not sure if that would work for network drives.
A refresh button would be a lot easier to implement.
So nice to learn how stuff works through a feature request. Thanks!
As far as I know, my app TableFlip work with network drives -- @mclaeysb shoot me an e-mail for the link if you want to try, I don't want to add product placements on GitHub :)
The presentedItemDidChange
callback works well. In Swift:
override func presentedItemDidChange() {
guard fileContentsDidChange() else { return }
guard isDocumentEdited else {
dispatch_async_main { self.reloadFromFile() }
return
}
dispatch_async_main { self.showReloadDialog() }
}
/// - returns: `true` if the contents did change, not just the metadata.
fileprivate func fileContentsDidChange() -> Bool {
guard let fileModificationDate = fileModificationDateOnDisk()
else { return false }
return fileModificationDate > canonicalModificationDate
}
fileprivate func fileModificationDateOnDisk() -> Date? {
guard let fileURL = self.fileURL else { return nil }
let fileManager = FileManager.default
return fileManager.fileModificationDate(fileURL: fileURL)
}
I had to keep track of the last load or save operation using a timestamp to make this work, but detecting changes then worked fine.
@DivineDominion Awesome, thanks for the tips! And feel free to mention your own app; I have absolutely no problem with product placement if it comes with useful information like this 👍
So, just to make sure I understand: at the moment Table Tool refreshes automatically whenever another NSDocument based app writes changes. This behavior came for free with NSDocument. But with your method I could detect changes even from other apps (eg. like TextMate) or network things? Sounds great! I'll have to try this at some point.
Yes, this is put on top of the macOS-provided document behavior. I haven't yet caused any conflicts (TextEdit and TableFlip work fine together) and when you implement a "which version wins?" alert, the flow is just fine. TableFlip has a trial, so you can see if you like what happens. :)
Will be interesting to see if you come up with something even better I could put back into my app :)
Any update on this? :)
At present, this is not an issue with TableTool -- we have implemented the behavior correctly. So I will close here.
FYI: You can "Save" the document in Table Tool, receive a warning that the document has changed on the disk, and "Revert" to that version. This has the same effect as a "Refresh", albeit in a roundabout way.