Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gee1k committed Jun 28, 2019
2 parents 85a3ee2 + 38744af commit 80a3f8a
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 27 deletions.
4 changes: 4 additions & 0 deletions uPic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
16068C7822AECB34004D39B7 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16068C7722AECB34004D39B7 /* PreferencesWindowController.swift */; };
16068C7C22AECD9F004D39B7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16068C7B22AECD9F004D39B7 /* Constants.swift */; };
160CAA2522B1ED6F00D04FBD /* PreferenceKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 160CAA2422B1ED6F00D04FBD /* PreferenceKey.swift */; };
1614532322C5D2AA00CA28F2 /* Public.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1614532222C5D2AA00CA28F2 /* Public.swift */; };
161C3BE122C483380092114F /* CustomUploader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 161C3BE022C4831B0092114F /* CustomUploader.swift */; };
161C3BE322C483560092114F /* CustomHostConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 161C3BE222C483560092114F /* CustomHostConfig.swift */; };
161C3BE522C4870C0092114F /* CustomConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 161C3BE422C4870B0092114F /* CustomConfigView.swift */; };
Expand Down Expand Up @@ -95,6 +96,7 @@
16068C7722AECB34004D39B7 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = "<group>"; };
16068C7B22AECD9F004D39B7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
160CAA2422B1ED6F00D04FBD /* PreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceKey.swift; sourceTree = "<group>"; };
1614532222C5D2AA00CA28F2 /* Public.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Public.swift; sourceTree = "<group>"; };
161C3BE022C4831B0092114F /* CustomUploader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomUploader.swift; sourceTree = "<group>"; };
161C3BE222C483560092114F /* CustomHostConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHostConfig.swift; sourceTree = "<group>"; };
161C3BE422C4870B0092114F /* CustomConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomConfigView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -295,6 +297,7 @@
166B4A5222B9CB4D001288ED /* UpYunConfigView.swift */,
1690E7E322BF111500FC81F8 /* QiniuConfigView.swift */,
166B4A5422B9CFD7001288ED /* ConfigSheetController.swift */,
1614532222C5D2AA00CA28F2 /* Public.swift */,
);
path = ConfigViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -640,6 +643,7 @@
1675516222ABF80300D3EB6F /* NSDragingInfoExt.swift in Sources */,
1662AC7322C0BBF7003AC924 /* AliyunRegion.swift in Sources */,
169F074422AF7A3D008E8525 /* StatusMenuController.swift in Sources */,
1614532322C5D2AA00CA28F2 /* Public.swift in Sources */,
169F073922AF4549008E8525 /* GeneralPreferencesViewController.swift in Sources */,
167D7F4D22B4D43B00DD0A7A /* HostSaveKey.swift in Sources */,
16068C7C22AECD9F004D39B7 /* Constants.swift in Sources */,
Expand Down
31 changes: 31 additions & 0 deletions uPic/General/Utils/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
//

import Foundation
import Cocoa

typealias Action = () -> ()

class Util {
static func getFileMd5(filePath: String) -> String? {
Expand Down Expand Up @@ -52,4 +55,32 @@ class Util {
return "en"
}
}

static func debounce(threshold: TimeInterval, action: @escaping Action) -> Action {
var timer: DispatchSourceTimer?
return {
if timer != nil {
timer!.cancel()
}

timer = DispatchSource.makeTimerSource()
timer!.setEventHandler {
action()
}

timer!.schedule(deadline: .now() + .milliseconds(Int(threshold * 1000)))
timer!.activate()
}
}

static func throttle(threshold: TimeInterval, action: @escaping Action) -> Action {
var last: CFAbsoluteTime = 0
return {
let current = CFAbsoluteTimeGetCurrent();
if current >= last + threshold {
action()
last = current
}
}
}
}
1 change: 0 additions & 1 deletion uPic/Models/HostConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import SwiftyJSON

@objcMembers
class HostConfig: NSObject, Codable {

private var addedObserver = false

//注册监听
Expand Down
19 changes: 0 additions & 19 deletions uPic/PreferencesWindow/Base.lproj/Preferences.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -687,25 +687,6 @@
<view key="contentView" identifier="UpYunConfigView" id="6bq-nL-Uwf">
<rect key="frame" x="1" y="1" width="358" height="278"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ckx-QO-hjQ">
<rect key="frame" x="148" y="54" width="25" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="help" bezelStyle="helpButton" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="FMf-pK-Ea5">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DLc-hJ-3Bg">
<rect key="frame" x="161" y="153" width="96" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="4Me-w3-eZE">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
<color key="borderColor" red="1" green="1" blue="1" alpha="0.14789509113504556" colorSpace="custom" customColorSpace="sRGB"/>
</box>
Expand Down
20 changes: 20 additions & 0 deletions uPic/PreferencesWindow/ConfigViews/AliyunConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AliyunConfigView: NSView {


func createView() {

var nextKeyViews = [NSView]()

let paddingTop = 50, paddingLeft = 6, gapTop = 10, gapLeft = 5, labelWidth = 75, labelHeight = 20,
viewWidth = Int(self.frame.width), viewHeight = Int(self.frame.height),
Expand Down Expand Up @@ -83,6 +85,7 @@ class AliyunConfigView: NSView {

self.addSubview(regionLabel)
self.addSubview(regionButtonPopUp)
nextKeyViews.append(regionButtonPopUp)


// MARK: Bucket
Expand All @@ -94,10 +97,13 @@ class AliyunConfigView: NSView {

let bucketField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
bucketField.identifier = NSUserInterfaceItemIdentifier(rawValue: "bucket")
bucketField.usesSingleLineMode = true
bucketField.lineBreakMode = .byTruncatingTail
bucketField.delegate = self.data
bucketField.stringValue = self.data.bucket ?? ""
self.addSubview(bucketLabel)
self.addSubview(bucketField)
nextKeyViews.append(bucketField)

// MARK: AccessKey
y = y - gapTop - labelHeight
Expand All @@ -109,10 +115,13 @@ class AliyunConfigView: NSView {

let accessKeyField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
accessKeyField.identifier = NSUserInterfaceItemIdentifier(rawValue: "accessKey")
accessKeyField.usesSingleLineMode = true
accessKeyField.lineBreakMode = .byTruncatingTail
accessKeyField.delegate = self.data
accessKeyField.stringValue = self.data.accessKey ?? ""
self.addSubview(accessKeyLabel)
self.addSubview(accessKeyField)
nextKeyViews.append(accessKeyField)


// MARK: Password
Expand All @@ -125,10 +134,13 @@ class AliyunConfigView: NSView {

let secretKeyField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
secretKeyField.identifier = NSUserInterfaceItemIdentifier(rawValue: "secretKey")
secretKeyField.usesSingleLineMode = true
secretKeyField.lineBreakMode = .byTruncatingTail
secretKeyField.delegate = self.data
secretKeyField.stringValue = self.data.secretKey ?? ""
self.addSubview(secretKeyLabel)
self.addSubview(secretKeyField)
nextKeyViews.append(secretKeyField)


// MARK: domain
Expand All @@ -142,6 +154,8 @@ class AliyunConfigView: NSView {

let domainField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth - settingsBtnWith, height: labelHeight))
domainField.identifier = NSUserInterfaceItemIdentifier(rawValue: "domain")
domainField.usesSingleLineMode = true
domainField.lineBreakMode = .byTruncatingTail
domainField.delegate = self.data
domainField.stringValue = self.data.domain ?? ""
self.domainField = domainField
Expand All @@ -153,6 +167,8 @@ class AliyunConfigView: NSView {
self.addSubview(domainLabel)
self.addSubview(domainField)
self.addSubview(settingsBtn)
nextKeyViews.append(domainField)
nextKeyViews.append(settingsBtn)

// MARK: help
y = y - gapTop * 2 - labelHeight
Expand All @@ -163,6 +179,10 @@ class AliyunConfigView: NSView {
helpBtn.setButtonType(.momentaryPushIn)
helpBtn.toolTip = NSLocalizedString("tutorial.tooltip", comment: "tutorial")
self.addSubview(helpBtn)


// set nextKeyView
setNextKeyViews(nextKeyViews: nextKeyViews)
}

func addObserver() {
Expand Down
19 changes: 18 additions & 1 deletion uPic/PreferencesWindow/ConfigViews/CustomConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class CustomConfigView: NSView {


func createView() {

var nextKeyViews = [NSView]()

let paddingTop = 30, paddingLeft = 6, gapTop = 10, gapLeft = 5, labelWidth = 75, labelHeight = 20, textAreaHeight = 50,
viewWidth = Int(self.frame.width), viewHeight = Int(self.frame.height),
Expand All @@ -61,10 +63,13 @@ class CustomConfigView: NSView {

let urlField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
urlField.identifier = NSUserInterfaceItemIdentifier(rawValue: "url")
urlField.usesSingleLineMode = true
urlField.lineBreakMode = .byTruncatingTail
urlField.delegate = self.data
urlField.stringValue = self.data.url ?? ""
self.addSubview(urlLabel)
self.addSubview(urlField)
nextKeyViews.append(urlField)

// MARK: Method
y = y - gapTop - labelHeight
Expand Down Expand Up @@ -94,6 +99,7 @@ class CustomConfigView: NSView {

self.addSubview(methodLabel)
self.addSubview(methodButtonPopUp)
nextKeyViews.append(methodButtonPopUp)


// MARK: field
Expand All @@ -105,10 +111,13 @@ class CustomConfigView: NSView {

let fieldField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
fieldField.identifier = NSUserInterfaceItemIdentifier(rawValue: "field")
fieldField.usesSingleLineMode = true
fieldField.lineBreakMode = .byTruncatingTail
fieldField.delegate = self.data
fieldField.stringValue = self.data.field ?? ""
self.addSubview(fieldLabel)
self.addSubview(fieldField)
nextKeyViews.append(fieldField)

// MARK: Extensions
y = y - gapTop - labelHeight
Expand All @@ -127,6 +136,7 @@ class CustomConfigView: NSView {
extensionsField.placeholderString = "eg: key=value&key2=value2"
self.addSubview(extensionsLabel)
self.addSubview(extensionsField)
nextKeyViews.append(extensionsField)

// MARK: Headers
y = y - gapTop - textAreaHeight
Expand All @@ -145,7 +155,7 @@ class CustomConfigView: NSView {
headersField.placeholderString = "eg: key=value&key2=value2"
self.addSubview(headersLabel)
self.addSubview(headersField)

nextKeyViews.append(headersField)

// MARK: domain
y = y - gapTop - textAreaHeight
Expand All @@ -158,6 +168,8 @@ class CustomConfigView: NSView {

let domainField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth - settingsBtnWith, height: labelHeight))
domainField.identifier = NSUserInterfaceItemIdentifier(rawValue: "domain")
domainField.usesSingleLineMode = true
domainField.lineBreakMode = .byTruncatingTail
domainField.delegate = self.data
domainField.stringValue = self.data.domain ?? ""
self.domainField = domainField
Expand All @@ -169,6 +181,8 @@ class CustomConfigView: NSView {
self.addSubview(domainLabel)
self.addSubview(domainField)
self.addSubview(settingsBtn)
nextKeyViews.append(domainField)
nextKeyViews.append(settingsBtn)

// MARK: help
y = y - gapTop - labelHeight
Expand All @@ -179,6 +193,9 @@ class CustomConfigView: NSView {
helpBtn.setButtonType(.momentaryPushIn)
helpBtn.toolTip = NSLocalizedString("tutorial.tooltip", comment: "tutorial")
self.addSubview(helpBtn)

// set nextKeyView
setNextKeyViews(nextKeyViews: nextKeyViews)
}

func addObserver() {
Expand Down
23 changes: 23 additions & 0 deletions uPic/PreferencesWindow/ConfigViews/Public.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Public.swift
// uPic
//
// Created by Svend Jin on 2019/6/28.
// Copyright © 2019 Svend Jin. All rights reserved.
//

import Cocoa

func setNextKeyViews(nextKeyViews: [NSView]) {
if nextKeyViews.count > 1 {
for (index, item) in nextKeyViews.enumerated() {
if index == nextKeyViews.count - 1 {
break
}

let currentView = item
let nextView = nextKeyViews[index + 1]
currentView.nextKeyView = nextView
}
}
}
19 changes: 19 additions & 0 deletions uPic/PreferencesWindow/ConfigViews/QiniuConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class QiniuConfigView: NSView {


func createView() {
var nextKeyViews = [NSView]()

let paddingTop = 50, paddingLeft = 6, gapTop = 10, gapLeft = 5, labelWidth = 75, labelHeight = 20,
viewWidth = Int(self.frame.width), viewHeight = Int(self.frame.height),
Expand Down Expand Up @@ -81,6 +82,7 @@ class QiniuConfigView: NSView {

self.addSubview(regionLabel)
self.addSubview(regionButtonPopUp)
nextKeyViews.append(regionButtonPopUp)


// MARK: Bucket
Expand All @@ -92,10 +94,13 @@ class QiniuConfigView: NSView {

let bucketField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
bucketField.identifier = NSUserInterfaceItemIdentifier(rawValue: "bucket")
bucketField.usesSingleLineMode = true
bucketField.lineBreakMode = .byTruncatingTail
bucketField.delegate = self.data
bucketField.stringValue = self.data.bucket ?? ""
self.addSubview(bucketLabel)
self.addSubview(bucketField)
nextKeyViews.append(bucketField)

// MARK: AccessKey
y = y - gapTop - labelHeight
Expand All @@ -107,10 +112,13 @@ class QiniuConfigView: NSView {

let accessKeyField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
accessKeyField.identifier = NSUserInterfaceItemIdentifier(rawValue: "accessKey")
accessKeyField.usesSingleLineMode = true
accessKeyField.lineBreakMode = .byTruncatingTail
accessKeyField.delegate = self.data
accessKeyField.stringValue = self.data.accessKey ?? ""
self.addSubview(accessKeyLabel)
self.addSubview(accessKeyField)
nextKeyViews.append(accessKeyField)


// MARK: Password
Expand All @@ -123,10 +131,13 @@ class QiniuConfigView: NSView {

let secretKeyField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight))
secretKeyField.identifier = NSUserInterfaceItemIdentifier(rawValue: "secretKey")
secretKeyField.usesSingleLineMode = true
secretKeyField.lineBreakMode = .byTruncatingTail
secretKeyField.delegate = self.data
secretKeyField.stringValue = self.data.secretKey ?? ""
self.addSubview(secretKeyLabel)
self.addSubview(secretKeyField)
nextKeyViews.append(secretKeyField)


// MARK: domain
Expand All @@ -140,6 +151,8 @@ class QiniuConfigView: NSView {

let domainField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth - settingsBtnWith, height: labelHeight))
domainField.identifier = NSUserInterfaceItemIdentifier(rawValue: "domain")
domainField.usesSingleLineMode = true
domainField.lineBreakMode = .byTruncatingTail
domainField.delegate = self.data
domainField.stringValue = self.data.domain ?? ""
self.domainField = domainField
Expand All @@ -151,6 +164,8 @@ class QiniuConfigView: NSView {
self.addSubview(domainLabel)
self.addSubview(domainField)
self.addSubview(settingsBtn)
nextKeyViews.append(domainField)
nextKeyViews.append(settingsBtn)

// MARK: help
y = y - gapTop * 2 - labelHeight
Expand All @@ -161,6 +176,10 @@ class QiniuConfigView: NSView {
helpBtn.setButtonType(.momentaryPushIn)
helpBtn.toolTip = NSLocalizedString("tutorial.tooltip", comment: "tutorial")
self.addSubview(helpBtn)


// set nextKeyView
setNextKeyViews(nextKeyViews: nextKeyViews)
}

func addObserver() {
Expand Down
Loading

0 comments on commit 80a3f8a

Please sign in to comment.