diff --git a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib index aa75978..16b3928 100644 --- a/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib +++ b/ShadowsocksX-NG/Base.lproj/PreferencesWindowController.xib @@ -1,9 +1,10 @@ - + - + + @@ -26,7 +27,7 @@ - + @@ -70,6 +71,7 @@ + @@ -339,6 +341,17 @@ DQ + + + + + + + + + + + diff --git a/ShadowsocksX-NG/PreferencesWindowController.swift b/ShadowsocksX-NG/PreferencesWindowController.swift index b24939c..5bca47b 100644 --- a/ShadowsocksX-NG/PreferencesWindowController.swift +++ b/ShadowsocksX-NG/PreferencesWindowController.swift @@ -114,6 +114,20 @@ class PreferencesWindowController: NSWindowController window?.performClose(self) } + @IBAction func duplicate(_ sender: Any) { + let profile = profileMgr.profiles[profilesTableView.clickedRow] + let duplicateProfile = profile.copy() as! ServerProfile + duplicateProfile.uuid = UUID().uuidString + profileMgr.profiles.insert(duplicateProfile, at: profilesTableView.clickedRow+1) + profilesTableView.beginUpdates() + let index = IndexSet(integer: profileMgr.profiles.count-1) + profilesTableView.insertRows(at: index, withAnimation: .effectFade) + self.profilesTableView.scrollRowToVisible(profilesTableView.clickedRow+1) + self.profilesTableView.selectRowIndexes(index, byExtendingSelection: false) + profilesTableView.endUpdates() + updateProfileBoxVisible() + } + @IBAction func copyCurrentProfileURL2Pasteboard(_ sender: NSButton) { let index = profilesTableView.selectedRow if index >= 0 { diff --git a/ShadowsocksX-NG/ServerProfile.swift b/ShadowsocksX-NG/ServerProfile.swift index c63085d..6a9cc44 100644 --- a/ShadowsocksX-NG/ServerProfile.swift +++ b/ShadowsocksX-NG/ServerProfile.swift @@ -10,7 +10,8 @@ import Cocoa -class ServerProfile: NSObject { +class ServerProfile: NSObject, NSCopying { + var uuid: String var serverHost: String = "" @@ -28,6 +29,17 @@ class ServerProfile: NSObject { self.uuid = uuid } + public func copy(with zone: NSZone? = nil) -> Any { + let copy = ServerProfile() + copy.serverHost = self.serverHost + copy.serverPort = self.serverPort + copy.method = self.method + copy.password = self.password + copy.remark = self.remark + copy.ota = self.ota + return copy; + } + static func fromDictionary(_ data:[String:AnyObject]) -> ServerProfile { let cp = { (profile: ServerProfile) in