Browse Source

Headers aren't neccesary while searching!

pull/92/head
Abhishek 4 years ago
parent
commit
c7e18543aa
  1. 7
      Clocker/Preferences/General/PreferencesViewController.swift
  2. 36
      Clocker/Preferences/General/SearchDataSource.swift

7
Clocker/Preferences/General/PreferencesViewController.swift

@ -722,9 +722,6 @@ extension PreferencesViewController {
let currentRowType = searchResultsDataSource.placeForRow(availableTimezoneTableView.selectedRow) let currentRowType = searchResultsDataSource.placeForRow(availableTimezoneTableView.selectedRow)
switch currentRowType { switch currentRowType {
case .timezoneHeader, .cityHeader:
isActivityInProgress = false
return
case .timezone: case .timezone:
cleanupAfterInstallingTimezone() cleanupAfterInstallingTimezone()
default: default:
@ -736,11 +733,9 @@ extension PreferencesViewController {
let currentRowType = searchResultsDataSource.placeForRow(availableTimezoneTableView.selectedRow) let currentRowType = searchResultsDataSource.placeForRow(availableTimezoneTableView.selectedRow)
switch currentRowType { switch currentRowType {
case .timezoneHeader, .cityHeader:
isActivityInProgress = false
return
case .timezone: case .timezone:
cleanupAfterInstallingTimezone() cleanupAfterInstallingTimezone()
return
case .city: case .city:
cleanupAfterInstallingCity() cleanupAfterInstallingCity()
} }

36
Clocker/Preferences/General/SearchDataSource.swift

@ -4,8 +4,6 @@ import Cocoa
import CoreModelKit import CoreModelKit
enum RowType { enum RowType {
case timezoneHeader
case cityHeader
case city case city
case timezone case timezone
} }
@ -100,9 +98,6 @@ class SearchDataSource: NSObject {
var changesets: [RowType] = [] var changesets: [RowType] = []
func addTimezonesIfNeeded(_ data: [TimezoneMetadata]) { func addTimezonesIfNeeded(_ data: [TimezoneMetadata]) {
if !data.isEmpty {
changesets.append(.timezoneHeader)
}
data.forEach { _ in data.forEach { _ in
changesets.append(.timezone) changesets.append(.timezone)
} }
@ -111,9 +106,6 @@ class SearchDataSource: NSObject {
if searchField.stringValue.isEmpty { if searchField.stringValue.isEmpty {
addTimezonesIfNeeded(timezoneArray) addTimezonesIfNeeded(timezoneArray)
} else { } else {
if !filteredArray.isEmpty {
changesets.append(.cityHeader)
}
filteredArray.forEach { _ in filteredArray.forEach { _ in
changesets.append(.city) changesets.append(.city)
} }
@ -142,7 +134,7 @@ class SearchDataSource: NSObject {
func retrieveSelectedTimezone(_ searchString: String, _ selectedIndex: Int) -> TimezoneMetadata { func retrieveSelectedTimezone(_ searchString: String, _ selectedIndex: Int) -> TimezoneMetadata {
return searchString.isEmpty == false ? timezoneFilteredArray[selectedIndex % timezoneFilteredArray.count] : return searchString.isEmpty == false ? timezoneFilteredArray[selectedIndex % timezoneFilteredArray.count] :
timezoneArray[selectedIndex - 1] timezoneArray[selectedIndex]
} }
} }
@ -155,8 +147,6 @@ extension SearchDataSource: NSTableViewDataSource {
let currentRowType = finalArray[row] let currentRowType = finalArray[row]
switch currentRowType { switch currentRowType {
case .timezoneHeader, .cityHeader:
return headerCell(tableView, currentRowType)
case .timezone: case .timezone:
return timezoneCell(tableView, currentRowType, row) return timezoneCell(tableView, currentRowType, row)
case .city: case .city:
@ -166,18 +156,6 @@ extension SearchDataSource: NSTableViewDataSource {
} }
extension SearchDataSource: NSTableViewDelegate { extension SearchDataSource: NSTableViewDelegate {
func tableView(_: NSTableView, isGroupRow row: Int) -> Bool {
let currentRowType = finalArray[row]
return
currentRowType == .timezoneHeader ||
currentRowType == .cityHeader
}
func tableView(_: NSTableView, shouldSelectRow row: Int) -> Bool {
let currentRowType = finalArray[row]
return !(currentRowType == .timezoneHeader || currentRowType == .cityHeader)
}
func tableView(_: NSTableView, heightOfRow _: Int) -> CGFloat { func tableView(_: NSTableView, heightOfRow _: Int) -> CGFloat {
return 30 return 30
} }
@ -190,8 +168,7 @@ extension SearchDataSource {
guard !datasource.isEmpty else { guard !datasource.isEmpty else {
return nil return nil
} }
let index = searchField.stringValue.isEmpty ? row - 1 : row message.sourceName.stringValue = datasource[row % datasource.count].formattedName + " (\(datasource[row % datasource.count].abbreviation))"
message.sourceName.stringValue = datasource[index % datasource.count].formattedName + " (\(datasource[index % datasource.count].abbreviation))"
return message return message
} }
return nil return nil
@ -206,15 +183,6 @@ extension SearchDataSource {
return nil return nil
} }
private func headerCell(_ tableView: NSTableView, _ headerType: RowType) -> NSView? {
if let message = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "headerCell"), owner: self) as? HeaderTableViewCell {
message.headerField.stringValue = headerType == .timezoneHeader ? "Timezones" : "Places"
return message
}
return nil
}
} }
class SearchResultTableViewCell: NSTableCellView { class SearchResultTableViewCell: NSTableCellView {

Loading…
Cancel
Save