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

This reverts commit efd0c76763.
This commit is contained in:
Qiu Yuzhou
2017-07-20 15:09:54 +08:00
parent 0cbcbf8e91
commit e8e4f9ad11

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
for (_, toDuplicateIndex) in profilesTableView.selectedRowIndexes.enumerated() {
print(profileMgr.profiles.count)
let profile = profileMgr.profiles[toDuplicateIndex + copyCount]
let duplicateProfile = profile.copy() as! ServerProfile let duplicateProfile = profile.copy() as! ServerProfile
duplicateProfile.uuid = UUID().uuidString duplicateProfile.uuid = UUID().uuidString
profileMgr.profiles.insert(duplicateProfile, at: profilesTableView.clickedRow+1) profileMgr.profiles.insert(duplicateProfile, at:toDuplicateIndex + copyCount)
profilesTableView.beginUpdates() profilesTableView.beginUpdates()
let index = IndexSet(integer: profileMgr.profiles.count-1) let index = IndexSet(integer: toDuplicateIndex + copyCount)
profilesTableView.insertRows(at: index, withAnimation: .effectFade) profilesTableView.insertRows(at: index, withAnimation: .effectFade)
self.profilesTableView.scrollRowToVisible(profilesTableView.clickedRow+1) self.profilesTableView.scrollRowToVisible(toDuplicateIndex + copyCount)
self.profilesTableView.selectRowIndexes(index, byExtendingSelection: false) self.profilesTableView.selectRowIndexes(index, byExtendingSelection: false)
profilesTableView.endUpdates() profilesTableView.endUpdates()
copyCount += 1
}
updateProfileBoxVisible() updateProfileBoxVisible()
} }