Skip to content

Commit

Permalink
Press enter key to login
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriskuei committed Jul 11, 2016
1 parent 04720cb commit 3f4781f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Bon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
8317308D1D33B02D009B0323 /* BonTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8317308C1D33B02D009B0323 /* BonTextField.swift */; };
832058571CE802AF00BC0FEF /* Double+Bon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832058561CE802AF00BC0FEF /* Double+Bon.swift */; };
832058591CE80F7900BC0FEF /* SwiftyTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832058581CE80F7900BC0FEF /* SwiftyTimer.swift */; };
8320585B1CE8171100BC0FEF /* BonConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8320585A1CE8171100BC0FEF /* BonConfig.swift */; };
Expand Down Expand Up @@ -34,6 +35,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
8317308C1D33B02D009B0323 /* BonTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonTextField.swift; sourceTree = "<group>"; };
832058561CE802AF00BC0FEF /* Double+Bon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Double+Bon.swift"; sourceTree = "<group>"; };
832058581CE80F7900BC0FEF /* SwiftyTimer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyTimer.swift; sourceTree = "<group>"; };
8320585A1CE8171100BC0FEF /* BonConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BonConfig.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -182,6 +184,7 @@
83A4B2CF1CE758DE000E83B4 /* BonScrollView.swift */,
83A4B2D11CE759A2000E83B4 /* BonCell.swift */,
83A4B2D41CE76327000E83B4 /* BonButton.swift */,
8317308C1D33B02D009B0323 /* BonTextField.swift */,
83A4B2D91CE76C17000E83B4 /* BonLoginView.swift */,
);
name = Views;
Expand Down Expand Up @@ -285,6 +288,7 @@
832058601CE8C6D700BC0FEF /* LaunchStarter.swift in Sources */,
83A4B2C81CE752FD000E83B4 /* BonViewController.swift in Sources */,
832444FE1CDF2D5C0031CFE0 /* BonUserDefaults.swift in Sources */,
8317308D1D33B02D009B0323 /* BonTextField.swift in Sources */,
832058591CE80F7900BC0FEF /* SwiftyTimer.swift in Sources */,
83A4B2D01CE758DE000E83B4 /* BonScrollView.swift in Sources */,
83A4B2D51CE76327000E83B4 /* BonButton.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions Bon/BonTextField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// BonTextField.swift
// Bon
//
// Created by Chris on 16/7/11.
// Copyright © 2016年 Chris. All rights reserved.
//

import Cocoa

class BonTextField: NSTextField {

override func becomeFirstResponder() -> Bool {
let source = CGEventSourceCreate(CGEventSourceStateID.HIDSystemState)
let tapLocation = CGEventTapLocation.CGHIDEventTap
let cmdA = CGEventCreateKeyboardEvent(source, 0x00, true)
CGEventSetFlags(cmdA, CGEventFlags.MaskCommand)
CGEventPost(tapLocation, cmdA)
return true
}

}
11 changes: 10 additions & 1 deletion Bon/BonViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ class BonViewController: NSViewController {

}

@IBAction func switchToPasswordTextField(sender: AnyObject) {
usernameTextField.resignFirstResponder()
passwordTextField.becomeFirstResponder()
}


@IBAction func enterKeyPressed(sender: AnyObject) {
onLoginButton(sender)
}

@IBAction func onSettingsButton(sender: BonButton) {
SettingsMenuAction.makeSettingsMenu(sender)
}


func showLoginView() {
bonLoginView.hidden = false
Expand Down
12 changes: 9 additions & 3 deletions Bon/BonViewController.xib
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,33 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bg3-0n-Dyq">
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="bg3-0n-Dyq" customClass="BonTextField" customModule="Bon" customModuleProvider="target">
<rect key="frame" x="101" y="135" width="98" height="22"/>
<constraints>
<constraint firstAttribute="height" constant="22" id="P0F-ZO-Mhu"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" alignment="left" placeholderString="username" bezelStyle="round" id="CVa-q4-vyn">
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" state="on" borderStyle="bezel" alignment="left" placeholderString="username" bezelStyle="round" id="CVa-q4-vyn">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="switchToPasswordTextField:" target="-2" id="2mL-Qj-1i5"/>
</connections>
</textField>
<secureTextField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="JU4-Rh-2ep">
<rect key="frame" x="101" y="95" width="98" height="22"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" alignment="left" placeholderString="password" usesSingleLineMode="YES" bezelStyle="round" id="9mN-tY-ayJ">
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" alignment="left" placeholderString="password" usesSingleLineMode="YES" bezelStyle="round" id="9mN-tY-ayJ">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<allowedInputSourceLocales>
<string>NSAllRomanInputSourcesLocaleIdentifier</string>
</allowedInputSourceLocales>
</secureTextFieldCell>
<connections>
<action selector="enterKeyPressed:" target="-2" id="zSZ-zr-Syk"/>
</connections>
</secureTextField>
<progressIndicator hidden="YES" wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="56N-LU-1yu">
<rect key="frame" x="142" y="62" width="16" height="16"/>
Expand Down
4 changes: 2 additions & 2 deletions Bon/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.3.6</string>
<string>0.3.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>160529</string>
<string>160711</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down

0 comments on commit 3f4781f

Please sign in to comment.