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 57f7ffb..4b02fae 100644 --- a/ShadowsocksX-NG/ServerProfile.swift +++ b/ShadowsocksX-NG/ServerProfile.swift @@ -8,7 +8,9 @@ import Cocoa -class ServerProfile: NSObject { + +class ServerProfile: NSObject, NSCopying { + var uuid: String var serverHost: String = "" @@ -75,8 +77,19 @@ class ServerProfile: NSObject { ota = NSString(string: otaStr).boolValue } } - - static func fromDictionary(_ data:[String: Any?]) -> ServerProfile { + + 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:Any?]) -> ServerProfile { let cp = { (profile: ServerProfile) in profile.serverHost = data["ServerHost"] as! String diff --git a/ShadowsocksX-NG/zh-Hans.lproj/PreferencesWindowController.strings b/ShadowsocksX-NG/zh-Hans.lproj/PreferencesWindowController.strings index afd97be..5e15b09 100644 --- a/ShadowsocksX-NG/zh-Hans.lproj/PreferencesWindowController.strings +++ b/ShadowsocksX-NG/zh-Hans.lproj/PreferencesWindowController.strings @@ -34,3 +34,6 @@ /* Class = "NSButtonCell"; title = "OK"; ObjectID = "zPE-oD-PwK"; */ "zPE-oD-PwK.title" = "确定"; + +/* Class = "NSMenuItem"; title = "Duplicate"; ObjectID = "bl9-lq-u9V"; */ +"bl9-lq-u9V.title" = "复制";