Merge remote-tracking branch 'qiuyuzhou/develop' into develop

# Conflicts:
#	ShadowsocksX-NG/PreferencesWindowController.swift
add fix duplicate profile error
This commit is contained in:
qinyuhang
2016-08-25 12:41:37 +08:00
parent 0068a96481
commit abfa8c78e1
3 changed files with 47 additions and 24 deletions
+7
View File
@@ -85,6 +85,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil
, usingBlock: {
(note) in
let profileMgr = ServerProfileManager.instance
if profileMgr.activeProfileId == nil &&
profileMgr.profiles.count > 0{
if profileMgr.profiles[0].isValid(){
profileMgr.setActiveProfiledId(profileMgr.profiles[0].uuid)
}
}
self.updateServersMenu()
SyncSSLocal()
}
@@ -21,6 +21,7 @@
<outlet property="profileBox" destination="oZ5-85-pwY" id="D19-PQ-X7E"/>
<outlet property="profilesTableView" destination="r91-ho-Lum" id="TNk-f6-Vgo"/>
<outlet property="remarkTextField" destination="q3C-S0-iNn" id="DSv-lV-PX7"/>
<outlet property="removeButton" destination="3ei-2f-kHB" id="DdP-dA-coT"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
@@ -32,6 +32,7 @@ class PreferencesWindowController: NSWindowController
@IBOutlet weak var copyURLBtn: NSButton!
@IBOutlet weak var removeButton: NSButton!
let tableViewDragType: String = "ss.server.profile.data"
var defaults: NSUserDefaults!
@@ -39,6 +40,7 @@ class PreferencesWindowController: NSWindowController
var editingProfile: ServerProfile!
override func windowDidLoad() {
super.windowDidLoad()
@@ -91,6 +93,7 @@ class PreferencesWindowController: NSWindowController
@IBAction func addProfile(sender: NSButton) {
if editingProfile != nil && !editingProfile.isValid(){
shakeWindows()
return
}
profilesTableView.beginUpdates()
@@ -121,31 +124,13 @@ class PreferencesWindowController: NSWindowController
@IBAction func ok(sender: NSButton) {
if editingProfile != nil {
if !editingProfile.isValid() {
let numberOfShakes:Int = 8
let durationOfShake:Float = 0.5
let vigourOfShake:Float = 0.05
let frame:CGRect = (self.window?.frame)!
let shakeAnimation = CAKeyframeAnimation()
let shakePath = CGPathCreateMutable()
CGPathMoveToPoint(shakePath, nil, NSMinX(frame), NSMinY(frame))
for _ in 1...numberOfShakes{
CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) - frame.size.width * CGFloat(vigourOfShake), NSMinY(frame))
CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) + frame.size.width * CGFloat(vigourOfShake), NSMinY(frame))
}
CGPathCloseSubpath(shakePath)
shakeAnimation.path = shakePath
shakeAnimation.duration = CFTimeInterval(durationOfShake)
self.window?.animations = ["frameOrigin":shakeAnimation]
self.window?.animator().setFrameOrigin(self.window!.frame.origin)
shakeWindows()
return
}
}
profileMgr.save()
window?.performClose(nil)
NSNotificationCenter.defaultCenter()
.postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil)
@@ -160,11 +145,12 @@ class PreferencesWindowController: NSWindowController
if editingProfile != nil && !editingProfile.isValid(){
return
}
let index = profilesTableView.selectedRow
if index >= 0 {
let profile = profileMgr.profiles[index]
let oldProfileIndex = profilesTableView.selectedRow
if oldProfileIndex >= 0 {
let oldProfile = profileMgr.profiles[oldProfileIndex]
profilesTableView.beginUpdates()
profileMgr.profiles.append(profile)
let newProfile = ServerProfile.fromDictionary(oldProfile.toDictionary())
profileMgr.profiles.append(newProfile)
let index = NSIndexSet(index: profileMgr.profiles.count-1)
profilesTableView.insertRowsAtIndexes(index, withAnimation: .EffectFade)
self.profilesTableView.scrollRowToVisible(self.profileMgr.profiles.count-1)
@@ -195,6 +181,12 @@ class PreferencesWindowController: NSWindowController
}
func updateProfileBoxVisible() {
if profileMgr.profiles.count <= 1 {
removeButton.enabled = false
}else{
removeButton.enabled = true
}
if profileMgr.profiles.isEmpty {
profileBox.hidden = true
} else {
@@ -371,4 +363,27 @@ class PreferencesWindowController: NSWindowController
}
}
}
func shakeWindows(){
let numberOfShakes:Int = 8
let durationOfShake:Float = 0.5
let vigourOfShake:Float = 0.05
let frame:CGRect = (window?.frame)!
let shakeAnimation = CAKeyframeAnimation()
let shakePath = CGPathCreateMutable()
CGPathMoveToPoint(shakePath, nil, NSMinX(frame), NSMinY(frame))
for _ in 1...numberOfShakes{
CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) - frame.size.width * CGFloat(vigourOfShake), NSMinY(frame))
CGPathAddLineToPoint(shakePath, nil, NSMinX(frame) + frame.size.width * CGFloat(vigourOfShake), NSMinY(frame))
}
CGPathCloseSubpath(shakePath)
shakeAnimation.path = shakePath
shakeAnimation.duration = CFTimeInterval(durationOfShake)
window?.animations = ["frameOrigin":shakeAnimation]
window?.animator().setFrameOrigin(window!.frame.origin)
}
}