diff --git a/uPic.xcodeproj/project.pbxproj b/uPic.xcodeproj/project.pbxproj index e31bf38..1f5954d 100644 --- a/uPic.xcodeproj/project.pbxproj +++ b/uPic.xcodeproj/project.pbxproj @@ -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 */; }; @@ -95,6 +96,7 @@ 16068C7722AECB34004D39B7 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = ""; }; 16068C7B22AECD9F004D39B7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; 160CAA2422B1ED6F00D04FBD /* PreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferenceKey.swift; sourceTree = ""; }; + 1614532222C5D2AA00CA28F2 /* Public.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Public.swift; sourceTree = ""; }; 161C3BE022C4831B0092114F /* CustomUploader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomUploader.swift; sourceTree = ""; }; 161C3BE222C483560092114F /* CustomHostConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHostConfig.swift; sourceTree = ""; }; 161C3BE422C4870B0092114F /* CustomConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomConfigView.swift; sourceTree = ""; }; @@ -295,6 +297,7 @@ 166B4A5222B9CB4D001288ED /* UpYunConfigView.swift */, 1690E7E322BF111500FC81F8 /* QiniuConfigView.swift */, 166B4A5422B9CFD7001288ED /* ConfigSheetController.swift */, + 1614532222C5D2AA00CA28F2 /* Public.swift */, ); path = ConfigViews; sourceTree = ""; @@ -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 */, diff --git a/uPic/General/Utils/Util.swift b/uPic/General/Utils/Util.swift index 30cc05a..651c728 100644 --- a/uPic/General/Utils/Util.swift +++ b/uPic/General/Utils/Util.swift @@ -7,6 +7,9 @@ // import Foundation +import Cocoa + +typealias Action = () -> () class Util { static func getFileMd5(filePath: String) -> String? { @@ -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 + } + } + } } diff --git a/uPic/Models/HostConfig.swift b/uPic/Models/HostConfig.swift index ad31a17..6e0d7e1 100644 --- a/uPic/Models/HostConfig.swift +++ b/uPic/Models/HostConfig.swift @@ -11,7 +11,6 @@ import SwiftyJSON @objcMembers class HostConfig: NSObject, Codable { - private var addedObserver = false //注册监听 diff --git a/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard b/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard index b3aedf7..cc1b9c5 100644 --- a/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard +++ b/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard @@ -687,25 +687,6 @@ - - - - - - - - - - - - diff --git a/uPic/PreferencesWindow/ConfigViews/AliyunConfigView.swift b/uPic/PreferencesWindow/ConfigViews/AliyunConfigView.swift index 653eaf1..43b7855 100644 --- a/uPic/PreferencesWindow/ConfigViews/AliyunConfigView.swift +++ b/uPic/PreferencesWindow/ConfigViews/AliyunConfigView.swift @@ -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), @@ -83,6 +85,7 @@ class AliyunConfigView: NSView { self.addSubview(regionLabel) self.addSubview(regionButtonPopUp) + nextKeyViews.append(regionButtonPopUp) // MARK: Bucket @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() { diff --git a/uPic/PreferencesWindow/ConfigViews/CustomConfigView.swift b/uPic/PreferencesWindow/ConfigViews/CustomConfigView.swift index 7b52819..62b9e99 100644 --- a/uPic/PreferencesWindow/ConfigViews/CustomConfigView.swift +++ b/uPic/PreferencesWindow/ConfigViews/CustomConfigView.swift @@ -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), @@ -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 @@ -94,6 +99,7 @@ class CustomConfigView: NSView { self.addSubview(methodLabel) self.addSubview(methodButtonPopUp) + nextKeyViews.append(methodButtonPopUp) // MARK: field @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() { diff --git a/uPic/PreferencesWindow/ConfigViews/Public.swift b/uPic/PreferencesWindow/ConfigViews/Public.swift new file mode 100644 index 0000000..84a185b --- /dev/null +++ b/uPic/PreferencesWindow/ConfigViews/Public.swift @@ -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 + } + } +} diff --git a/uPic/PreferencesWindow/ConfigViews/QiniuConfigView.swift b/uPic/PreferencesWindow/ConfigViews/QiniuConfigView.swift index ed44e28..554ffb7 100644 --- a/uPic/PreferencesWindow/ConfigViews/QiniuConfigView.swift +++ b/uPic/PreferencesWindow/ConfigViews/QiniuConfigView.swift @@ -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), @@ -81,6 +82,7 @@ class QiniuConfigView: NSView { self.addSubview(regionLabel) self.addSubview(regionButtonPopUp) + nextKeyViews.append(regionButtonPopUp) // MARK: Bucket @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() { diff --git a/uPic/PreferencesWindow/ConfigViews/TencentConfigView.swift b/uPic/PreferencesWindow/ConfigViews/TencentConfigView.swift index 7a50e0f..8c4c798 100644 --- a/uPic/PreferencesWindow/ConfigViews/TencentConfigView.swift +++ b/uPic/PreferencesWindow/ConfigViews/TencentConfigView.swift @@ -48,6 +48,8 @@ class TencentConfigView: 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), textFieldX = labelWidth + paddingLeft + gapLeft, textFieldWidth = viewWidth - paddingLeft - textFieldX @@ -83,6 +85,7 @@ class TencentConfigView: NSView { self.addSubview(regionLabel) self.addSubview(regionButtonPopUp) + nextKeyViews.append(regionButtonPopUp) // MARK: Bucket @@ -94,10 +97,13 @@ class TencentConfigView: 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: SecretId y = y - gapTop - labelHeight @@ -109,10 +115,13 @@ class TencentConfigView: NSView { let secretIdField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight)) secretIdField.identifier = NSUserInterfaceItemIdentifier(rawValue: "secretId") + secretIdField.usesSingleLineMode = true + secretIdField.lineBreakMode = .byTruncatingTail secretIdField.delegate = self.data secretIdField.stringValue = self.data.secretId ?? "" self.addSubview(secretIdLabel) self.addSubview(secretIdField) + nextKeyViews.append(secretIdField) // MARK: Password @@ -125,10 +134,13 @@ class TencentConfigView: 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 @@ -142,6 +154,8 @@ class TencentConfigView: 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 @@ -153,6 +167,8 @@ class TencentConfigView: NSView { self.addSubview(domainLabel) self.addSubview(domainField) self.addSubview(settingsBtn) + nextKeyViews.append(domainField) + nextKeyViews.append(settingsBtn) // MARK: help y = y - gapTop * 2 - labelHeight @@ -163,6 +179,10 @@ class TencentConfigView: NSView { helpBtn.setButtonType(.momentaryPushIn) helpBtn.toolTip = NSLocalizedString("tutorial.tooltip", comment: "tutorial") self.addSubview(helpBtn) + + + // set nextKeyView + setNextKeyViews(nextKeyViews: nextKeyViews) } func addObserver() { diff --git a/uPic/PreferencesWindow/ConfigViews/UpYunConfigView.swift b/uPic/PreferencesWindow/ConfigViews/UpYunConfigView.swift index 615e82c..3a7adf9 100644 --- a/uPic/PreferencesWindow/ConfigViews/UpYunConfigView.swift +++ b/uPic/PreferencesWindow/ConfigViews/UpYunConfigView.swift @@ -47,6 +47,7 @@ class UpYunConfigView: NSView { func createView() { + var nextKeyViews = [NSView]() let paddingTop = 50, paddingLeft = 10, gapTop = 10, gapLeft = 5, labelWidth = 60, labelHeight = 20, viewWidth = Int(self.frame.width), viewHeight = Int(self.frame.height), @@ -62,10 +63,13 @@ class UpYunConfigView: 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: Operator y = y - gapTop - labelHeight @@ -77,10 +81,13 @@ class UpYunConfigView: NSView { let operatorField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight)) operatorField.identifier = NSUserInterfaceItemIdentifier(rawValue: "operatorName") + operatorField.usesSingleLineMode = true + operatorField.lineBreakMode = .byTruncatingTail operatorField.delegate = self.data operatorField.stringValue = self.data.operatorName ?? "" self.addSubview(operatorLabel) self.addSubview(operatorField) + nextKeyViews.append(operatorField) // MARK: Password @@ -93,10 +100,13 @@ class UpYunConfigView: NSView { let passwordField = NSTextField(frame: NSRect(x: textFieldX, y: y, width: textFieldWidth, height: labelHeight)) passwordField.identifier = NSUserInterfaceItemIdentifier(rawValue: "password") + passwordField.usesSingleLineMode = true + passwordField.lineBreakMode = .byTruncatingTail passwordField.delegate = self.data passwordField.stringValue = self.data.password ?? "" self.addSubview(passwordLabel) self.addSubview(passwordField) + nextKeyViews.append(passwordField) // MARK: domain @@ -110,6 +120,8 @@ class UpYunConfigView: 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 @@ -121,6 +133,8 @@ class UpYunConfigView: NSView { self.addSubview(domainLabel) self.addSubview(domainField) self.addSubview(settingsBtn) + nextKeyViews.append(domainField) + nextKeyViews.append(settingsBtn) // MARK: help y = y - gapTop * 2 - labelHeight @@ -131,6 +145,10 @@ class UpYunConfigView: NSView { helpBtn.setButtonType(.momentaryPushIn) helpBtn.toolTip = NSLocalizedString("tutorial.tooltip", comment: "tutorial") self.addSubview(helpBtn) + + + // set nextKeyView + setNextKeyViews(nextKeyViews: nextKeyViews) } func addObserver() { diff --git a/uPic/PreferencesWindow/HostPreferencesViewController.swift b/uPic/PreferencesWindow/HostPreferencesViewController.swift index 4ce796f..9d9ddef 100644 --- a/uPic/PreferencesWindow/HostPreferencesViewController.swift +++ b/uPic/PreferencesWindow/HostPreferencesViewController.swift @@ -23,6 +23,9 @@ class HostPreferencesViewController: PreferencesViewController { @IBOutlet weak var configView: NSView! var hostItems: [Host]? + + // 配置更改状态变化节流函数 + var hostConfigChangedDebouncedFunc:Action! /* Obserber start */ var hostItemsChanged = false { @@ -30,7 +33,7 @@ class HostPreferencesViewController: PreferencesViewController { self.refreshButtonStatus() } } - + /* Obserber start */ var selectedRow: Int = -1 { didSet { @@ -218,6 +221,7 @@ class HostPreferencesViewController: PreferencesViewController { // MARK: 添加图床 func addHost(type: HostType) { let data = HostConfig.create(type: type) + data?.observerValues() self.hostItems?.append(Host(type, data: data)) self.tableView.reloadData() self.hostItemsChanged = true @@ -251,10 +255,17 @@ class HostPreferencesViewController: PreferencesViewController { @objc func hostConfigChanged() { - self.hostItemsChanged = true + hostConfigChangedDebouncedFunc() } func addObserver() { + // 设置监听配置变化的节流函数,当0.5秒后没有再次变化就刷新当前状态 + hostConfigChangedDebouncedFunc = Util.debounce(threshold: 0.5) { + DispatchQueue.main.async { + self.hostItemsChanged = true + } + + } PreferencesNotifier.addObserver(observer: self, selector: #selector(hostConfigChanged), notification: .hostConfigChanged) } diff --git a/uPic/Supporting Files/Info.plist b/uPic/Supporting Files/Info.plist index 25a65cb..8974f7f 100644 --- a/uPic/Supporting Files/Info.plist +++ b/uPic/Supporting Files/Info.plist @@ -19,9 +19,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.6.0 + 0.6.1 CFBundleVersion - 20190627 + 20190628 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/uPic/en.lproj/Localizable.strings b/uPic/en.lproj/Localizable.strings index 8b0704c..1d52391 100644 --- a/uPic/en.lproj/Localizable.strings +++ b/uPic/en.lproj/Localizable.strings @@ -111,7 +111,7 @@ "host.saveKey" = "File Name"; "host.url" = "Upload url"; "host.method" = "Request method"; -"host.field" = "Field"; +"host.field" = "File field"; "host.extensions" = "Extension field"; "host.headers" = "Request Headers"; diff --git a/uPic/zh-Hans.lproj/Localizable.strings b/uPic/zh-Hans.lproj/Localizable.strings index f7e05db..a87150a 100644 --- a/uPic/zh-Hans.lproj/Localizable.strings +++ b/uPic/zh-Hans.lproj/Localizable.strings @@ -109,7 +109,7 @@ "host.saveKey" = "文件名"; "host.url" = "上传地址"; "host.method" = "请求方式"; -"host.field" = "上传字段"; +"host.field" = "文件字段名"; "host.extensions" = "扩展字段"; "host.headers" = "请求头";