实现在多选状态下的多个profile复制

This commit is contained in:
秦宇航
2017-04-24 15:36:08 +08:00
parent f6a46311c3
commit 923aad5d94

View File

@ -168,16 +168,23 @@ class PreferencesWindowController: NSWindowController
} }
@IBAction func duplicate(_ sender: Any) { @IBAction func duplicate(_ sender: Any) {
let profile = profileMgr.profiles[profilesTableView.clickedRow] var copyCount = 0
let duplicateProfile = profile.copy() as! ServerProfile for (_, toDuplicateIndex) in profilesTableView.selectedRowIndexes.enumerated() {
duplicateProfile.uuid = UUID().uuidString print(profileMgr.profiles.count)
profileMgr.profiles.insert(duplicateProfile, at: profilesTableView.clickedRow+1) let profile = profileMgr.profiles[toDuplicateIndex + copyCount]
profilesTableView.beginUpdates() let duplicateProfile = profile.copy() as! ServerProfile
let index = IndexSet(integer: profileMgr.profiles.count-1) duplicateProfile.uuid = UUID().uuidString
profilesTableView.insertRows(at: index, withAnimation: .effectFade) profileMgr.profiles.insert(duplicateProfile, at:toDuplicateIndex + copyCount)
self.profilesTableView.scrollRowToVisible(profilesTableView.clickedRow+1)
self.profilesTableView.selectRowIndexes(index, byExtendingSelection: false) profilesTableView.beginUpdates()
profilesTableView.endUpdates() let index = IndexSet(integer: toDuplicateIndex + copyCount)
profilesTableView.insertRows(at: index, withAnimation: .effectFade)
self.profilesTableView.scrollRowToVisible(toDuplicateIndex + copyCount)
self.profilesTableView.selectRowIndexes(index, byExtendingSelection: false)
profilesTableView.endUpdates()
copyCount += 1
}
updateProfileBoxVisible() updateProfileBoxVisible()
} }