Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix preferences window not appearing when the content views are not using auto-layout #28

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
468785d
Implements more robust view size calculation and a view size cache
SamusAranX Apr 16, 2019
7162d1d
change toViewController source
SamusAranX Apr 16, 2019
a8467e6
add logging
SamusAranX Apr 16, 2019
4f266b7
set window frame when window is opened up again
SamusAranX Apr 16, 2019
90219aa
add more logging
SamusAranX Apr 16, 2019
ce6cca1
add more logging
SamusAranX Apr 17, 2019
3260cf5
Merge branch 'master' into resize-fix-wip
SamusAranX May 8, 2019
a665db8
Made PreferencePaneIdentifier conform to the Hashable protocol to fix…
SamusAranX May 8, 2019
ba81225
add more logging
SamusAranX May 8, 2019
4d9607f
wip
SamusAranX May 8, 2019
75cda18
Implemented suggested changes
SamusAranX May 8, 2019
dca09a0
add more logging
SamusAranX May 8, 2019
d107d1b
print driven development ftw
SamusAranX May 8, 2019
8438c56
give preferredContentSize a try
SamusAranX May 8, 2019
17b9f38
Make the VC's view perform layout updates before fetching its size
SamusAranX May 8, 2019
1ecd91e
wip
SamusAranX May 8, 2019
1d6ad2c
revised contentSize zero check
SamusAranX May 8, 2019
00cf359
Made view.bounds.size the default choice
SamusAranX May 8, 2019
a554795
Removed all print()s
SamusAranX May 8, 2019
ba9c27f
Forgot to undo one edit before committing
SamusAranX May 8, 2019
90e400f
Removed isAnimated property and animation options
SamusAranX Sep 23, 2019
ee04b81
Merge branch 'master' into resize-fix
SamusAranX Sep 23, 2019
875306b
Update PreferencesTabViewController.swift
sindresorhus Sep 23, 2019
288e26e
Update PreferencesTabViewController.swift
sindresorhus Sep 23, 2019
a3ca0d1
Remove usages of PreferencePane.viewController
SamusAranX Sep 23, 2019
da9ebc1
Hopefully finally fixed view controller animation
SamusAranX Sep 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Preferences/PreferencePane.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Cocoa

public struct PreferencePaneIdentifier: Equatable, RawRepresentable {
public struct PreferencePaneIdentifier: Equatable, RawRepresentable, Hashable {
SamusAranX marked this conversation as resolved.
Show resolved Hide resolved
public let rawValue: String

public init(rawValue: String) {
Expand Down
17 changes: 15 additions & 2 deletions Sources/Preferences/PreferencesTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ final class PreferencesTabViewController: NSViewController, PreferencesStyleCont
return preferencesStyleController?.toolbarItemIdentifiers() ?? []
}

private var viewSizeCache: [PreferencePaneIdentifier: NSSize] = [:]
SamusAranX marked this conversation as resolved.
Show resolved Hide resolved

var window: NSWindow! {
return view.window
}
Expand Down Expand Up @@ -177,11 +179,22 @@ final class PreferencesTabViewController: NSViewController, PreferencesStyleCont
}

private func setWindowFrame(for viewController: NSViewController, animated: Bool = false) {
guard let window = window else {
guard let window = window,
SamusAranX marked this conversation as resolved.
Show resolved Hide resolved
let preferencePane = preferencePanes.first(where: { $0.viewController == viewController })
else {
SamusAranX marked this conversation as resolved.
Show resolved Hide resolved
preconditionFailure()
}

let contentSize = viewController.view.fittingSize
var contentSize = NSSize.zero
SamusAranX marked this conversation as resolved.
Show resolved Hide resolved
if let cachedSize = self.viewSizeCache[preferencePane.preferencePaneIdentifier] {
contentSize = cachedSize
} else {
contentSize = viewController.view.fittingSize
if contentSize == .zero {
contentSize = viewController.view.bounds.size
}
self.viewSizeCache[preferencePane.preferencePaneIdentifier] = contentSize
}

let newWindowSize = window.frameRect(forContentRect: CGRect(origin: .zero, size: contentSize)).size
var frame = window.frame
Expand Down