Browse Source

Minor refactor

pull/113/head
Abhishek 3 years ago
parent
commit
75596d6e31
  1. 8
      Clocker/AppDelegate.swift
  2. 4
      Clocker/Panel/ParentPanelController.swift
  3. 115
      Clocker/Preferences/General/PreferencesViewController.swift

8
Clocker/AppDelegate.swift

@ -279,12 +279,8 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
NSApp.activate(ignoringOtherApps: true) NSApp.activate(ignoringOtherApps: true)
} }
open func setupFloatingWindow() { open func setupFloatingWindow(_ hide: Bool) {
showFloatingWindow() hide ? floatingWindow.window?.close() : showFloatingWindow()
}
open func closeFloatingWindow() {
floatingWindow.window?.close()
} }
func statusItemForPanel() -> StatusItemHandler { func statusItemForPanel() -> StatusItemHandler {

4
Clocker/Panel/ParentPanelController.swift

@ -773,9 +773,9 @@ class ParentPanelController: NSWindowController {
close() close()
if inverseSelection.isEqual(to: NSNumber(value: 1)) { if inverseSelection.isEqual(to: NSNumber(value: 1)) {
sharedDelegate.setupFloatingWindow() sharedDelegate.setupFloatingWindow(false)
} else { } else {
sharedDelegate.closeFloatingWindow() sharedDelegate.setupFloatingWindow(true)
sharedDelegate.setPanelDefaults() sharedDelegate.setPanelDefaults()
} }

115
Clocker/Preferences/General/PreferencesViewController.swift

@ -18,50 +18,39 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = "values.globalPing" static let hotKeyPathIdentifier = "values.globalPing"
} }
class TableHeaderViewCell: NSTableHeaderCell { class PreferencesViewController: ParentViewController {
var backgroundColour: NSColor = NSColor.black {
didSet {
backgroundColor = backgroundColour
}
}
override init(textCell: String) { @IBOutlet private var placeholderLabel: NSTextField!
super.init(textCell: textCell) @IBOutlet private var timezoneTableView: NSTableView!
let attributedParagraphStyle = NSMutableParagraphStyle() @IBOutlet private var availableTimezoneTableView: NSTableView!
attributedParagraphStyle.alignment = .left @IBOutlet private var timezonePanel: Panelr!
attributedStringValue = NSAttributedString(string: textCell, @IBOutlet private var progressIndicator: NSProgressIndicator!
attributes: [.foregroundColor: Themer.shared().mainTextColor(), @IBOutlet private var addButton: NSButton!
.font: NSFont(name: "Avenir", size: 14)!, @IBOutlet private var recorderControl: SRRecorderControl!
.paragraphStyle: attributedParagraphStyle]) @IBOutlet private var closeButton: NSButton!
backgroundColor = Themer.shared().textBackgroundColor()
}
required init(coder _: NSCoder) { @IBOutlet private var timezoneSortButton: NSButton!
fatalError("init(coder:) has not been implemented") @IBOutlet private var timezoneNameSortButton: NSButton!
} @IBOutlet private var labelSortButton: NSButton!
@IBOutlet private var deleteButton: NSButton!
@IBOutlet private var addTimezoneButton: NSButton!
override func draw(withFrame cellFrame: NSRect, in controlView: NSView) { @IBOutlet private var searchField: NSSearchField!
super.draw(withFrame: cellFrame, in: controlView) @IBOutlet private var messageLabel: NSTextField!
if !controlView.isHidden {
backgroundColor?.setFill()
cellFrame.fill()
drawInterior(withFrame: cellFrame, in: controlView)
}
}
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) { @IBOutlet private var tableview: NSView!
if !controlView.isHidden { @IBOutlet private var additionalSortOptions: NSView!
if let avenirFont = NSFont(name: "Avenir", size: 14) { @IBOutlet var startAtLoginLabel: NSTextField!
font = avenirFont
} @IBOutlet var startupCheckbox: NSButton!
textColor = NSColor.white
let rect = titleRect(forBounds: cellFrame) // Sorting
attributedStringValue.draw(in: rect) private var arePlacesSortedInAscendingOrder = false
} private var arePlacesSortedInAscendingTimezoneOrder = false
} private var isTimezoneSortOptionSelected = false
} private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
class PreferencesViewController: ParentViewController {
private var isActivityInProgress = false { private var isActivityInProgress = false {
didSet { didSet {
OperationQueue.main.addOperation { OperationQueue.main.addOperation {
@ -76,6 +65,11 @@ class PreferencesViewController: ParentViewController {
return DataStore.shared().timezones() return DataStore.shared().timezones()
} }
private var themeDidChangeNotification: NSObjectProtocol?
// Selected Timezones Data Source
private var selectionsDataSource: PreferencesDataSource!
// Search Results Data Source Handler
private var searchResultsDataSource: SearchDataSource!
private lazy var startupManager = StartupManager() private lazy var startupManager = StartupManager()
private var dataTask: URLSessionDataTask? = .none private var dataTask: URLSessionDataTask? = .none
@ -94,43 +88,7 @@ class PreferencesViewController: ParentViewController {
return apiKey return apiKey
}() }()
// Sorting
private var arePlacesSortedInAscendingOrder = false
private var arePlacesSortedInAscendingTimezoneOrder = false
private var isTimezoneSortOptionSelected = false
private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
@IBOutlet private var placeholderLabel: NSTextField!
@IBOutlet private var timezoneTableView: NSTableView!
@IBOutlet private var availableTimezoneTableView: NSTableView!
@IBOutlet private var timezonePanel: Panelr!
@IBOutlet private var progressIndicator: NSProgressIndicator!
@IBOutlet private var addButton: NSButton!
@IBOutlet private var recorderControl: SRRecorderControl!
@IBOutlet private var closeButton: NSButton!
@IBOutlet private var timezoneSortButton: NSButton!
@IBOutlet private var timezoneNameSortButton: NSButton!
@IBOutlet private var labelSortButton: NSButton!
@IBOutlet private var deleteButton: NSButton!
@IBOutlet private var addTimezoneButton: NSButton!
@IBOutlet private var searchField: NSSearchField!
@IBOutlet private var messageLabel: NSTextField!
@IBOutlet private var tableview: NSView!
@IBOutlet private var additionalSortOptions: NSView!
@IBOutlet var startAtLoginLabel: NSTextField!
@IBOutlet var startupCheckbox: NSButton!
private var themeDidChangeNotification: NSObjectProtocol?
// Selected Timezones Data Source
private var selectionsDataSource: PreferencesDataSource!
// Search Results Data Source Handler
private var searchResultsDataSource: SearchDataSource!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
@ -530,12 +488,7 @@ extension PreferencesViewController {
} }
private func presentError(_ errorMessage: String) { private func presentError(_ errorMessage: String) {
if errorMessage == PreferencesConstants.offlineErrorMessage { placeholderLabel.placeholderString = errorMessage == PreferencesConstants.offlineErrorMessage ? PreferencesConstants.noInternetConnectivityError : PreferencesConstants.tryAgainMessage
placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError
} else {
placeholderLabel.placeholderString = PreferencesConstants.tryAgainMessage
}
isActivityInProgress = false isActivityInProgress = false
} }

Loading…
Cancel
Save