From 35d764fe2aff4b1e5af5f693f709197c532a84e5 Mon Sep 17 00:00:00 2001 From: Rizwan Date: Thu, 5 Jan 2017 18:26:33 +0800 Subject: [PATCH 1/2] [ADD] option to duplicate server profile on preference --- .../PreferencesWindowController.xib | 19 ++++++++++++++++--- .../PreferencesWindowController.swift | 14 ++++++++++++++ ShadowsocksX-NG/ServerProfile.swift | 14 +++++++++++++- 3 files changed, 43 insertions(+), 4 deletions(-) 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 From 59e3de16975ae6d1012c44903fbe4b8936444627 Mon Sep 17 00:00:00 2001 From: Rizwan Date: Thu, 5 Jan 2017 18:52:39 +0800 Subject: [PATCH 2/2] [ADD] localised text --- .../zh-Hans.lproj/PreferencesWindowController.strings | 3 +++ 1 file changed, 3 insertions(+) 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" = "复制";