Merge branch 'develop' into develop

This commit is contained in:
Gong Zhang
2017-07-21 10:19:12 +08:00
committed by GitHub

View File

@ -107,6 +107,7 @@ class PreferencesWindowController: NSWindowController
override func awakeFromNib() { override func awakeFromNib() {
profilesTableView.register(forDraggedTypes: [tableViewDragType]) profilesTableView.register(forDraggedTypes: [tableViewDragType])
profilesTableView.allowsMultipleSelection = true
} }
@IBAction func addProfile(_ sender: NSButton) { @IBAction func addProfile(_ sender: NSButton) {
@ -129,13 +130,20 @@ class PreferencesWindowController: NSWindowController
} }
@IBAction func removeProfile(_ sender: NSButton) { @IBAction func removeProfile(_ sender: NSButton) {
let index = profilesTableView.selectedRow let index = Int(profilesTableView.selectedRowIndexes.first!)
var deleteCount = 0
if index >= 0 { if index >= 0 {
profilesTableView.beginUpdates() profilesTableView.beginUpdates()
profileMgr.profiles.remove(at: index) for (_, toDeleteIndex) in profilesTableView.selectedRowIndexes.enumerated() {
profilesTableView.removeRows(at: IndexSet(integer: index), withAnimation: .effectFade) print(profileMgr.profiles.count)
profileMgr.profiles.remove(at: toDeleteIndex - deleteCount)
profilesTableView.removeRows(at: IndexSet(integer: toDeleteIndex - deleteCount), withAnimation: .effectFade)
deleteCount += 1
}
profilesTableView.endUpdates() profilesTableView.endUpdates()
} }
self.profilesTableView.scrollRowToVisible(index-1)
self.profilesTableView.selectRowIndexes(IndexSet(integer: index-1), byExtendingSelection: false)
updateProfileBoxVisible() updateProfileBoxVisible()
} }
@ -160,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()
} }