1
1
mirror of https://github.com/qvacua/vimr.git synced 2025-01-04 03:48:55 +03:00

Use private where appropriate

This commit is contained in:
Tae Won Ha 2017-12-17 21:11:45 +01:00
parent d5e6c54d79
commit 83c4b579a8
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
5 changed files with 64 additions and 62 deletions

View File

@ -21,18 +21,18 @@ class CustomToolBar: NSView {
*/
class InnerToolBar: NSView, NSUserInterfaceValidations {
fileprivate static let separatorThickness = CGFloat(1)
fileprivate static let height = InnerToolBar.iconDimension + 2 + 2 + InnerToolBar.separatorThickness
private static let separatorThickness = CGFloat(1)
private static let height = InnerToolBar.iconDimension + 2 + 2 + InnerToolBar.separatorThickness
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
fileprivate let titleField = NSTextField(forAutoLayout: ())
fileprivate let closeButton = NSButton(forAutoLayout: ())
fileprivate let cogButton = NSPopUpButton(forAutoLayout: ())
private let titleField = NSTextField(forAutoLayout: ())
private let closeButton = NSButton(forAutoLayout: ())
private let cogButton = NSPopUpButton(forAutoLayout: ())
fileprivate let locToSelector: [WorkspaceBarLocation: Selector] = [
private let locToSelector: [WorkspaceBarLocation: Selector] = [
.top: #selector(InnerToolBar.moveToTopAction(_:)),
.right: #selector(InnerToolBar.moveToRightAction(_:)),
.bottom: #selector(InnerToolBar.moveToBottomAction(_:)),
@ -138,13 +138,13 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
}
}
fileprivate func removeCustomUiElements() {
private func removeCustomUiElements() {
self.customToolbar?.removeFromSuperview()
[self.titleField, self.closeButton, self.cogButton].forEach { $0.removeFromSuperview() }
self.cogButton.menu = nil
}
fileprivate func addViews() {
private func addViews() {
let title = self.titleField
let close = self.closeButton
let cog = self.cogButton
@ -243,12 +243,12 @@ class InnerToolBar: NSView, NSUserInterfaceValidations {
}
}
fileprivate func bottomSeparatorRect() -> CGRect {
private func bottomSeparatorRect() -> CGRect {
let bounds = self.bounds
return CGRect(x: bounds.minX, y: bounds.minY, width: bounds.width, height: InnerToolBar.separatorThickness)
}
fileprivate func innerSeparatorRect() -> CGRect {
private func innerSeparatorRect() -> CGRect {
let cogBounds = self.cogButton.frame
let bounds = self.bounds
return CGRect(x: cogBounds.minX + 6, y: bounds.minY + 4, width: 1, height: bounds.height - 4 - 4)
@ -278,7 +278,7 @@ extension InnerToolBar {
self.move(to: .left)
}
fileprivate func move(to location: WorkspaceBarLocation) {
private func move(to location: WorkspaceBarLocation) {
guard let tool = self.tool else {
return
}

View File

@ -51,25 +51,25 @@ class Workspace: NSView, WorkspaceBarDelegate {
var toolbarBackground = NSColor(red: 0.899, green: 0.934, blue: 0.997, alpha: 1)
}
fileprivate(set) var isAllToolsVisible = true {
private(set) var isAllToolsVisible = true {
didSet {
self.relayout()
}
}
fileprivate(set) var isToolButtonsVisible = true {
private(set) var isToolButtonsVisible = true {
didSet {
self.bars.values.forEach { $0.isButtonVisible = !$0.isButtonVisible }
}
}
fileprivate var tools = [WorkspaceTool]()
private var tools = [WorkspaceTool]()
var orderedTools: [WorkspaceTool] {
return self.bars.values.reduce([]) { [$0, $1.tools].flatMap { $0 } }
}
fileprivate var isDragOngoing = false
fileprivate var draggedOnBarLocation: WorkspaceBarLocation?
fileprivate let proxyBar = ProxyWorkspaceBar(forAutoLayout: ())
private var isDragOngoing = false
private var draggedOnBarLocation: WorkspaceBarLocation?
private let proxyBar = ProxyWorkspaceBar(forAutoLayout: ())
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@ -165,7 +165,7 @@ extension Workspace {
self.endDrag()
}
fileprivate func endDrag() {
private func endDrag() {
self.isDragOngoing = false
self.draggedOnBarLocation = nil
self.proxyBar.removeFromSuperview()
@ -190,7 +190,7 @@ extension Workspace {
return true
}
fileprivate func barLocation(inPoint loc: CGPoint) -> WorkspaceBarLocation? {
private func barLocation(inPoint loc: CGPoint) -> WorkspaceBarLocation? {
for barLoc in WorkspaceBarLocation.all {
if rect(forBar: barLoc).contains(loc) {
return barLoc
@ -201,7 +201,7 @@ extension Workspace {
}
// We copy and pasted WorkspaceBar.barFrame() since we need the rect for the proxy bars.
fileprivate func rect(forBar location: WorkspaceBarLocation) -> CGRect {
private func rect(forBar location: WorkspaceBarLocation) -> CGRect {
let size = self.bounds.size
let dimension = self.bars[location]!.dimensionWithoutTool()
@ -241,13 +241,13 @@ extension Workspace {
// MARK: - Layout
extension Workspace {
fileprivate func repaint() {
private func repaint() {
self.bars.values.forEach { $0.repaint() }
self.proxyBar.repaint()
self.needsDisplay = true
}
fileprivate func relayout() {
private func relayout() {
// FIXME: I did not investigate why toggleButtons does not work correctly if we store all constraints in an array
// and remove them here by self.removeConstraints(${all constraints). The following seems to work...
self.subviews.forEach { $0.removeAllConstraints() }

View File

@ -22,11 +22,12 @@ protocol WorkspaceBarDelegate: class {
drop due to the drag & drop infrastructure of Cocoa.
*/
fileprivate class ProxyBar: NSView {
private class ProxyBar: NSView {
fileprivate var isDragOngoing = false
fileprivate var draggedOnToolIdx: Int?
fileprivate var buttonFrames: [CGRect] = []
private var isDragOngoing = false
private var buttonFrames: [CGRect] = []
fileprivate weak var container: WorkspaceBar?
@ -46,17 +47,18 @@ fileprivate class ProxyBar: NSView {
class WorkspaceBar: NSView, WorkspaceToolDelegate {
static fileprivate let separatorThickness = CGFloat(1)
static private let separatorThickness = CGFloat(1)
fileprivate(set) var tools = [WorkspaceTool]()
fileprivate weak var selectedTool: WorkspaceTool?
private weak var selectedTool: WorkspaceTool?
fileprivate var isMouseDownOngoing = false
fileprivate var dragIncrement = CGFloat(1)
private var isMouseDownOngoing = false
private var dragIncrement = CGFloat(1)
fileprivate var layoutConstraints = [NSLayoutConstraint]()
private var layoutConstraints = [NSLayoutConstraint]()
fileprivate let proxyBar = ProxyBar()
private let proxyBar = ProxyBar()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@ -246,7 +248,7 @@ class WorkspaceBar: NSView, WorkspaceToolDelegate {
extension ProxyBar {
fileprivate func isTool(atIndex idx: Int, beingDragged info: NSDraggingInfo) -> Bool {
private func isTool(atIndex idx: Int, beingDragged info: NSDraggingInfo) -> Bool {
let pasteboard = info.draggingPasteboard()
guard let uuid = pasteboard.string(forType: NSPasteboard.PasteboardType(WorkspaceToolButton.toolUti)) else {
@ -367,7 +369,7 @@ extension ProxyBar {
return true
}
fileprivate func endDrag() {
private func endDrag() {
self.isDragOngoing = false
self.draggedOnToolIdx = nil
self.container!.relayout()
@ -477,7 +479,7 @@ extension WorkspaceBar {
}
}
fileprivate func drawInnerSeparator(_ dirtyRect: NSRect) {
private func drawInnerSeparator(_ dirtyRect: NSRect) {
self.theme.separator.set()
let innerLineRect = self.innerSeparatorRect()
@ -486,7 +488,7 @@ extension WorkspaceBar {
}
}
fileprivate func drawOuterSeparator(_ dirtyRect: NSRect) {
private func drawOuterSeparator(_ dirtyRect: NSRect) {
self.theme.separator.set()
let outerLineRect = self.outerSeparatorRect()
@ -495,7 +497,7 @@ extension WorkspaceBar {
}
}
fileprivate func buttonSize() -> CGSize {
private func buttonSize() -> CGSize {
if self.isEmpty() {
return CGSize.zero
}
@ -503,7 +505,7 @@ extension WorkspaceBar {
return WorkspaceToolButton.size(forLocation: self.location)
}
fileprivate func innerSeparatorRect() -> CGRect {
private func innerSeparatorRect() -> CGRect {
let bounds = self.bounds
let thickness = WorkspaceBar.separatorThickness
let bar = self.buttonSize()
@ -520,12 +522,12 @@ extension WorkspaceBar {
}
}
fileprivate func newDimension(forLocationInSuperview locInSuperview: CGPoint) -> CGFloat {
private func newDimension(forLocationInSuperview locInSuperview: CGPoint) -> CGFloat {
let dimension = self.dimension(forLocationInSuperview: locInSuperview)
return self.dragIncrement * floor(dimension / self.dragIncrement)
}
fileprivate func dimension(forLocationInSuperview locInSuperview: CGPoint) -> CGFloat {
private func dimension(forLocationInSuperview locInSuperview: CGPoint) -> CGFloat {
let superviewBounds = self.superview!.bounds
switch self.location {
@ -540,11 +542,11 @@ extension WorkspaceBar {
}
}
fileprivate func sq(_ number: CGFloat) -> CGFloat {
private func sq(_ number: CGFloat) -> CGFloat {
return number * number
}
fileprivate func outerSeparatorRect() -> CGRect {
private func outerSeparatorRect() -> CGRect {
let thickness = WorkspaceBar.separatorThickness
switch self.location {
@ -559,7 +561,7 @@ extension WorkspaceBar {
}
}
fileprivate func resizeRect() -> CGRect {
private func resizeRect() -> CGRect {
let separatorRect = self.outerSeparatorRect()
let clickDimension = CGFloat(4)
@ -575,7 +577,7 @@ extension WorkspaceBar {
}
}
fileprivate func set(dimension: CGFloat) {
private func set(dimension: CGFloat) {
let saneDimension = self.saneDimension(from: dimension)
self.dimensionConstraint.constant = saneDimension
@ -592,7 +594,7 @@ extension WorkspaceBar {
self.needsDisplay = true
}
fileprivate func saneDimension(from dimension: CGFloat) -> CGFloat {
private func saneDimension(from dimension: CGFloat) -> CGFloat {
if dimension == 0 {
return 0
}
@ -609,15 +611,15 @@ extension WorkspaceBar {
extension WorkspaceBar {
fileprivate func isEmpty() -> Bool {
private func isEmpty() -> Bool {
return self.tools.isEmpty
}
fileprivate func hasTools() -> Bool {
private func hasTools() -> Bool {
return !self.isEmpty()
}
fileprivate func layoutWithoutButtons(_ tool: WorkspaceTool) {
private func layoutWithoutButtons(_ tool: WorkspaceTool) {
let view = tool
let thickness = WorkspaceBar.separatorThickness
@ -662,7 +664,7 @@ extension WorkspaceBar {
}
}
fileprivate func layout(_ tool: WorkspaceTool) {
private func layout(_ tool: WorkspaceTool) {
let view = tool
let button = tool.button
let thickness = WorkspaceBar.separatorThickness
@ -709,7 +711,7 @@ extension WorkspaceBar {
}
}
fileprivate func draggedButtonDimension() -> CGFloat {
private func draggedButtonDimension() -> CGFloat {
guard let idx = self.proxyBar.draggedOnToolIdx else {
return 0
}
@ -734,7 +736,7 @@ extension WorkspaceBar {
}
}
fileprivate func layoutButtons() {
private func layoutButtons() {
guard let firstTool = self.tools.first else {
return
}
@ -808,7 +810,7 @@ extension WorkspaceBar {
}
}
fileprivate func barDimensionWithButtonsWithoutTool() -> CGFloat {
private func barDimensionWithButtonsWithoutTool() -> CGFloat {
switch self.location {
case .top, .bottom:
return self.buttonSize().height + WorkspaceBar.separatorThickness
@ -817,15 +819,15 @@ extension WorkspaceBar {
}
}
fileprivate func barDimensionWithoutButtons(withToolDimension toolDimension: CGFloat) -> CGFloat {
private func barDimensionWithoutButtons(withToolDimension toolDimension: CGFloat) -> CGFloat {
return toolDimension + WorkspaceBar.separatorThickness
}
fileprivate func barDimension(withToolDimension toolDimension: CGFloat) -> CGFloat {
private func barDimension(withToolDimension toolDimension: CGFloat) -> CGFloat {
return self.barDimensionWithButtonsWithoutTool() + toolDimension + WorkspaceBar.separatorThickness
}
fileprivate func toolDimension(fromBarDimension barDimension: CGFloat) -> CGFloat {
private func toolDimension(fromBarDimension barDimension: CGFloat) -> CGFloat {
if self.isButtonVisible {
return barDimension - WorkspaceBar.separatorThickness - barDimensionWithButtonsWithoutTool()
}

View File

@ -13,7 +13,7 @@ protocol WorkspaceToolDelegate: class {
class WorkspaceTool: NSView {
fileprivate var innerToolbar: InnerToolBar?
private var innerToolbar: InnerToolBar?
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@ -145,7 +145,7 @@ class WorkspaceTool: NSView {
self.needsDisplay = true
}
fileprivate func addViews() {
private func addViews() {
let view = self.view
self.addSubview(view)

View File

@ -7,13 +7,13 @@ import Cocoa
class WorkspaceToolButton: NSView, NSDraggingSource {
static fileprivate let titlePadding = CGSize(width: 8, height: 2)
static fileprivate let dummyButton = WorkspaceToolButton(title: "Dummy")
static private let titlePadding = CGSize(width: 8, height: 2)
static private let dummyButton = WorkspaceToolButton(title: "Dummy")
fileprivate var isHighlighted = false
private var isHighlighted = false
fileprivate let title: NSMutableAttributedString
fileprivate var trackingArea = NSTrackingArea()
private let title: NSMutableAttributedString
private var trackingArea = NSTrackingArea()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
@ -180,7 +180,7 @@ extension WorkspaceToolButton {
}
// Modified version of snapshot() from https://www.raywenderlich.com/136272/drag-and-drop-tutorial-for-macos
fileprivate func snapshot() -> NSImage {
private func snapshot() -> NSImage {
let pdfData = self.dataWithPDF(inside: self.bounds)
guard let image = NSImage(data: pdfData) else {
return NSImage()