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)
}
open func setupFloatingWindow() {
showFloatingWindow()
}
open func closeFloatingWindow() {
floatingWindow.window?.close()
open func setupFloatingWindow(_ hide: Bool) {
hide ? floatingWindow.window?.close() : showFloatingWindow()
}
func statusItemForPanel() -> StatusItemHandler {

4
Clocker/Panel/ParentPanelController.swift

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

115
Clocker/Preferences/General/PreferencesViewController.swift

@ -18,50 +18,39 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = "values.globalPing"
}
class TableHeaderViewCell: NSTableHeaderCell {
var backgroundColour: NSColor = NSColor.black {
didSet {
backgroundColor = backgroundColour
}
}
class PreferencesViewController: ParentViewController {
override init(textCell: String) {
super.init(textCell: textCell)
let attributedParagraphStyle = NSMutableParagraphStyle()
attributedParagraphStyle.alignment = .left
attributedStringValue = NSAttributedString(string: textCell,
attributes: [.foregroundColor: Themer.shared().mainTextColor(),
.font: NSFont(name: "Avenir", size: 14)!,
.paragraphStyle: attributedParagraphStyle])
backgroundColor = Themer.shared().textBackgroundColor()
}
@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!
required init(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@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!
override func draw(withFrame cellFrame: NSRect, in controlView: NSView) {
super.draw(withFrame: cellFrame, in: controlView)
if !controlView.isHidden {
backgroundColor?.setFill()
cellFrame.fill()
drawInterior(withFrame: cellFrame, in: controlView)
}
}
@IBOutlet private var searchField: NSSearchField!
@IBOutlet private var messageLabel: NSTextField!
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) {
if !controlView.isHidden {
if let avenirFont = NSFont(name: "Avenir", size: 14) {
font = avenirFont
}
textColor = NSColor.white
let rect = titleRect(forBounds: cellFrame)
attributedStringValue.draw(in: rect)
}
}
}
@IBOutlet private var tableview: NSView!
@IBOutlet private var additionalSortOptions: NSView!
@IBOutlet var startAtLoginLabel: NSTextField!
class PreferencesViewController: ParentViewController {
@IBOutlet var startupCheckbox: NSButton!
// Sorting
private var arePlacesSortedInAscendingOrder = false
private var arePlacesSortedInAscendingTimezoneOrder = false
private var isTimezoneSortOptionSelected = false
private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
private var isActivityInProgress = false {
didSet {
OperationQueue.main.addOperation {
@ -76,6 +65,11 @@ class PreferencesViewController: ParentViewController {
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 var dataTask: URLSessionDataTask? = .none
@ -94,43 +88,7 @@ class PreferencesViewController: ParentViewController {
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() {
super.viewDidLoad()
@ -530,12 +488,7 @@ extension PreferencesViewController {
}
private func presentError(_ errorMessage: String) {
if errorMessage == PreferencesConstants.offlineErrorMessage {
placeholderLabel.placeholderString = PreferencesConstants.noInternetConnectivityError
} else {
placeholderLabel.placeholderString = PreferencesConstants.tryAgainMessage
}
placeholderLabel.placeholderString = errorMessage == PreferencesConstants.offlineErrorMessage ? PreferencesConstants.noInternetConnectivityError : PreferencesConstants.tryAgainMessage
isActivityInProgress = false
}

Loading…
Cancel
Save