Browse Source

Copy to Clipboard taking scroller in consideration.

pull/101/head
Abhishek 3 years ago
parent
commit
eebbbc6741
  1. 26
      Clocker/Panel/ParentPanelController.swift

26
Clocker/Panel/ParentPanelController.swift

@ -1098,16 +1098,9 @@ extension ParentPanelController: NSSharingServicePickerDelegate {
}
func sharingServicePicker(_: NSSharingServicePicker, sharingServicesForItems _: [Any], proposedSharingServices proposed: [NSSharingService]) -> [NSSharingService] {
let copySharingService = NSSharingService(title: "Copy All Times", image: NSImage(), alternateImage: nil) {
let timezones = DataStore.shared().timezones()
var clipboardCopy = String()
for encodedTimezone in timezones {
if let timezoneObject = TimezoneData.customObject(from: encodedTimezone) {
let operations = TimezoneDataOperations(with: timezoneObject)
clipboardCopy.append("\(timezoneObject.formattedTimezoneLabel()) - \(operations.time(with: 0))\n")
}
}
let copySharingService = NSSharingService(title: "Copy All Times", image: NSImage(), alternateImage: nil) { [weak self] in
guard let strongSelf = self else { return }
let clipboardCopy = strongSelf.retrieveAllTimes()
let pasteboard = NSPasteboard.general
pasteboard.declareTypes([.string], owner: nil)
pasteboard.setString(clipboardCopy, forType: .string)
@ -1121,4 +1114,17 @@ extension ParentPanelController: NSSharingServicePickerDelegate {
newProposedServices.append(contentsOf: filteredServices)
return newProposedServices
}
private func retrieveAllTimes() -> String {
var clipboardCopy = String()
let timezones = DataStore.shared().timezones()
stride(from: 0, to: timezones.count, by: 1).forEach {
if $0 < mainTableView.numberOfRows,
let cellView = mainTableView.view(atColumn: 0, row: $0, makeIfNecessary: false) as? TimezoneCellView
{
clipboardCopy.append("\(cellView.customName.stringValue) - \(cellView.time.stringValue)\n")
}
}
return clipboardCopy
}
}

Loading…
Cancel
Save