Merge branch 'pr/41' into develop

This commit is contained in:
Charlie Qiu
2016-08-23 17:34:19 +08:00
3 changed files with 42 additions and 0 deletions

View File

@ -78,6 +78,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil notifyCenter.addObserverForName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil, queue: nil
, usingBlock: { , usingBlock: {
(note) in (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() self.updateServersMenu()
SyncSSLocal() SyncSSLocal()
} }

View File

@ -16,6 +16,7 @@
<outlet property="profileBox" destination="oZ5-85-pwY" id="D19-PQ-X7E"/> <outlet property="profileBox" destination="oZ5-85-pwY" id="D19-PQ-X7E"/>
<outlet property="profilesTableView" destination="r91-ho-Lum" id="TNk-f6-Vgo"/> <outlet property="profilesTableView" destination="r91-ho-Lum" id="TNk-f6-Vgo"/>
<outlet property="remarkTextField" destination="q3C-S0-iNn" id="DSv-lV-PX7"/> <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"/> <outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections> </connections>
</customObject> </customObject>

View File

@ -26,6 +26,7 @@ class PreferencesWindowController: NSWindowController
@IBOutlet weak var copyURLBtn: NSButton! @IBOutlet weak var copyURLBtn: NSButton!
@IBOutlet weak var removeButton: NSButton!
let tableViewDragType: String = "ss.server.profile.data" let tableViewDragType: String = "ss.server.profile.data"
var defaults: NSUserDefaults! var defaults: NSUserDefaults!
@ -33,6 +34,7 @@ class PreferencesWindowController: NSWindowController
var editingProfile: ServerProfile! var editingProfile: ServerProfile!
override func windowDidLoad() { override func windowDidLoad() {
super.windowDidLoad() super.windowDidLoad()
@ -64,6 +66,7 @@ class PreferencesWindowController: NSWindowController
@IBAction func addProfile(sender: NSButton) { @IBAction func addProfile(sender: NSButton) {
if editingProfile != nil && !editingProfile.isValid(){ if editingProfile != nil && !editingProfile.isValid(){
shakeWindows()
return return
} }
profilesTableView.beginUpdates() profilesTableView.beginUpdates()
@ -95,12 +98,14 @@ class PreferencesWindowController: NSWindowController
if editingProfile != nil { if editingProfile != nil {
if !editingProfile.isValid() { if !editingProfile.isValid() {
// TODO Shake window? // TODO Shake window?
shakeWindows()
return return
} }
} }
profileMgr.save() profileMgr.save()
window?.performClose(nil) window?.performClose(nil)
NSNotificationCenter.defaultCenter() NSNotificationCenter.defaultCenter()
.postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil) .postNotificationName(NOTIFY_SERVER_PROFILES_CHANGED, object: nil)
} }
@ -130,6 +135,12 @@ class PreferencesWindowController: NSWindowController
} }
func updateProfileBoxVisible() { func updateProfileBoxVisible() {
if profileMgr.profiles.count <= 1 {
removeButton.enabled = false
}else{
removeButton.enabled = true
}
if profileMgr.profiles.isEmpty { if profileMgr.profiles.isEmpty {
profileBox.hidden = true profileBox.hidden = true
} else { } else {
@ -293,4 +304,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)
}
} }