Browse Source

Saving some server costs!

pull/92/head
Abhishek 5 years ago
parent
commit
3889e2d36d
  1. 34
      Clocker/Onboarding/OnboardingSearchController.swift
  2. 2
      Clocker/Preferences/General/PreferencesViewController.swift

34
Clocker/Onboarding/OnboardingSearchController.swift

@ -211,7 +211,8 @@ class OnboardingSearchController: NSViewController {
appName.stringValue = "Quick Add Locations".localized() appName.stringValue = "Quick Add Locations".localized()
onboardingTypeLabel.stringValue = "More search options in Clocker Preferences.".localized() onboardingTypeLabel.stringValue = "More search options in Clocker Preferences.".localized()
setInfoLabel(CLEmptyString) setInfoLabel(CLEmptyString)
searchBar.placeholderString = "Enter 3 or more characters for locations you'll like to add".localized() searchBar.placeholderString = "Press Enter to Search!"
searchBar.delegate = self
resultsTableView.backgroundColor = Themer.shared().mainBackgroundColor() resultsTableView.backgroundColor = Themer.shared().mainBackgroundColor()
resultsTableView.enclosingScrollView?.backgroundColor = Themer.shared().mainBackgroundColor() resultsTableView.enclosingScrollView?.backgroundColor = Themer.shared().mainBackgroundColor()
@ -243,7 +244,14 @@ class OnboardingSearchController: NSViewController {
} }
NSObject.cancelPreviousPerformRequests(withTarget: self) NSObject.cancelPreviousPerformRequests(withTarget: self)
perform(#selector(OnboardingSearchController.actualSearch), with: nil, afterDelay: 0.5) perform(#selector(OnboardingSearchController.actualSearch), with: nil, afterDelay: 0.2)
}
fileprivate func resetIfNeccesary(_ searchString: String) {
if searchString.isEmpty {
resetSearchView()
setInfoLabel(CLEmptyString)
}
} }
@objc func actualSearch() { @objc func actualSearch() {
@ -260,6 +268,7 @@ class OnboardingSearchController: NSViewController {
searchString = words.joined(separator: CLEmptyString) searchString = words.joined(separator: CLEmptyString)
if searchString.count < 3 { if searchString.count < 3 {
resetIfNeccesary(searchString)
return return
} }
@ -403,3 +412,24 @@ class ResultSectionHeaderTableViewCell: NSTableCellView {
class ResultTableViewCell: NSTableCellView { class ResultTableViewCell: NSTableCellView {
@IBOutlet var result: NSTextField! @IBOutlet var result: NSTextField!
} }
extension OnboardingSearchController: NSSearchFieldDelegate {
func control(_ control: NSControl, textView _: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
guard let searchField = control as? NSSearchField else {
return false
}
if commandSelector == #selector(NSResponder.insertNewline(_:)) {
self.search(searchField)
return true
} else if commandSelector == #selector(NSResponder.deleteForward(_:)) || commandSelector == #selector(NSResponder.deleteBackward(_:)) {
// Handle DELETE key
self.search(searchField)
return false
}
print("Not Handled")
// return true if the action was handled; otherwise false
return false
}
}

2
Clocker/Preferences/General/PreferencesViewController.swift

@ -597,7 +597,7 @@ extension PreferencesViewController {
} }
private func installTimezone(_ timezone: Timezone) { private func installTimezone(_ timezone: Timezone) {
guard let dataObject = self.searchResultsDataSource.filteredArray[self.availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else { guard let dataObject = searchResultsDataSource.filteredArray[availableTimezoneTableView.selectedRow % searchResultsDataSource.filteredArray.count] as? TimezoneData else {
assertionFailure("Data was unexpectedly nil") assertionFailure("Data was unexpectedly nil")
return return
} }

Loading…
Cancel
Save