@@ -68,11 +68,10 @@ class PrefsViewController: NSViewController {
6868
6969 @IBOutlet weak var showMoreButton : NSButton !
7070 @IBOutlet weak var additionalShortcutsStackView : NSStackView !
71-
71+
7272 // Settings
7373 override func awakeFromNib( ) {
74-
75- // Main section shortcuts (storyboard-connected)
74+
7675 actionsToViews = [
7776 . leftHalf: leftHalfShortcutView,
7877 . rightHalf: rightHalfShortcutView,
@@ -92,135 +91,49 @@ class PrefsViewController: NSViewController {
9291 . larger: makeLargerShortcutView,
9392 . smaller: makeSmallerShortcutView,
9493 . restore: restoreShortcutView,
94+ . firstThird: firstThirdShortcutView,
95+ . firstTwoThirds: firstTwoThirdsShortcutView,
96+ . centerThird: centerThirdShortcutView,
97+ . centerTwoThirds: centerTwoThirdsShortcutView,
98+ . lastTwoThirds: lastTwoThirdsShortcutView,
99+ . lastThird: lastThirdShortcutView,
100+ . moveLeft: moveLeftShortcutView,
101+ . moveRight: moveRightShortcutView,
102+ . moveUp: moveUpShortcutView,
103+ . moveDown: moveDownShortcutView,
104+ . firstFourth: firstFourthShortcutView,
105+ . secondFourth: secondFourthShortcutView,
106+ . thirdFourth: thirdFourthShortcutView,
107+ . lastFourth: lastFourthShortcutView,
108+ . firstThreeFourths: firstThreeFourthsShortcutView,
109+ . centerThreeFourths: centerThreeFourthsShortcutView,
110+ . lastThreeFourths: lastThreeFourthsShortcutView,
111+ . topLeftSixth: topLeftSixthShortcutView,
112+ . topCenterSixth: topCenterSixthShortcutView,
113+ . topRightSixth: topRightSixthShortcutView,
114+ . bottomLeftSixth: bottomLeftSixthShortcutView,
115+ . bottomCenterSixth: bottomCenterSixthShortcutView,
116+ . bottomRightSixth: bottomRightSixthShortcutView
95117 ]
96-
97- // Replace the storyboard additional section with simplified category rows
98- setupCategoryShortcuts ( )
99-
118+
100119 for (action, view) in actionsToViews {
101120 view. setAssociatedUserDefaultsKey ( action. name, withTransformerName: MASDictionaryTransformerName)
102121 }
103-
122+
104123 if Defaults . allowAnyShortcut. enabled {
105124 let passThroughValidator = PassthroughShortcutValidator ( )
106125 actionsToViews. values. forEach { $0. shortcutValidator = passThroughValidator }
107126 }
108-
127+
109128 subscribeToAllowAnyShortcutToggle ( )
110-
111- // Default the extra shortcuts section to open
112- additionalShortcutsStackView. isHidden = false
113- showMoreButton. title = " ▼ "
114- }
115-
116- private var extraSectionsAdded = false
117-
118- /// Replaces the storyboard's individual shortcut rows with one row per category.
119- /// Each category shortcut cycles through all positions on repeated presses.
120- private func setupCategoryShortcuts( ) {
121- guard !extraSectionsAdded else { return }
122- extraSectionsAdded = true
123-
124- guard let leftColumn = additionalShortcutsStackView. arrangedSubviews. first as? NSStackView ,
125- let rightColumn = additionalShortcutsStackView. arrangedSubviews. last as? NSStackView else { return }
126-
127- // Clear all existing storyboard rows (individual thirds, fourths, sixths, move)
128- for view in leftColumn. arrangedSubviews {
129- leftColumn. removeArrangedSubview ( view)
130- view. removeFromSuperview ( )
131- }
132- for view in rightColumn. arrangedSubviews {
133- rightColumn. removeArrangedSubview ( view)
134- view. removeFromSuperview ( )
135- }
136-
137- // Grid Layout categories - one shortcut each, cycles through all positions
138- leftColumn. addArrangedSubview ( createShortcutRow ( for: . firstThird, label: " Thirds " ) )
139- leftColumn. addArrangedSubview ( createShortcutRow ( for: . firstFourth, label: " Fourths " ) )
140- leftColumn. addArrangedSubview ( createShortcutRow ( for: . topLeftSixth, label: " Sixths " ) )
141-
142- rightColumn. addArrangedSubview ( createShortcutRow ( for: . topLeftEighth, label: " Eighths " ) )
143- rightColumn. addArrangedSubview ( createShortcutRow ( for: . topLeftTwelfth, label: " Twelfths " ) )
144- rightColumn. addArrangedSubview ( createShortcutRow ( for: . topLeftSixteenth, label: " Sixteenths " ) )
145-
129+
130+ additionalShortcutsStackView. isHidden = true
146131 }
147-
148- private func createSectionSpacer( ) -> NSView {
149- let spacer = NSView ( )
150- spacer. translatesAutoresizingMaskIntoConstraints = false
151- spacer. heightAnchor. constraint ( equalToConstant: 5 ) . isActive = true
152- return spacer
153- }
154-
155- /// Creates a left-aligned bold label used as a section header in the left column.
156- /// The matching right column gets only a separator via createSectionSeparator().
157- private func createSectionHeader( title: String ) -> NSView {
158- let separator = createSectionSeparator ( )
159-
160- let label = NSTextField ( labelWithString: title)
161- label. font = NSFont . systemFont ( ofSize: NSFont . smallSystemFontSize, weight: . semibold)
162- label. textColor = . secondaryLabelColor
163- label. alignment = . left
164- label. translatesAutoresizingMaskIntoConstraints = false
165-
166- let container = NSStackView ( views: [ separator, label] )
167- container. orientation = . vertical
168- container. alignment = . leading
169- container. spacing = 4
170- container. translatesAutoresizingMaskIntoConstraints = false
171- return container
172- }
173-
174- /// Creates a full-width NSBox horizontal separator line.
175- private func createSectionSeparator( ) -> NSBox {
176- let box = NSBox ( )
177- box. boxType = . separator
178- box. translatesAutoresizingMaskIntoConstraints = false
179- return box
180- }
181-
182- private func createShortcutRow( for action: WindowAction , label customLabel: String ? = nil ) -> NSStackView {
183- let shortcutView = MASShortcutView ( )
184- shortcutView. translatesAutoresizingMaskIntoConstraints = false
185- shortcutView. widthAnchor. constraint ( equalToConstant: 160 ) . isActive = true
186- shortcutView. heightAnchor. constraint ( equalToConstant: 19 ) . isActive = true
187-
188- let label = customLabel ?? action. displayName ?? action. name
189- let textField = NSTextField ( labelWithString: label)
190- textField. alignment = . right
191- textField. lineBreakMode = . byClipping
192- textField. translatesAutoresizingMaskIntoConstraints = false
193- textField. setContentHuggingPriority ( . init( 251 ) , for: . horizontal)
194- textField. setContentHuggingPriority ( . init( 750 ) , for: . vertical)
195-
196- let imageView = NSImageView ( )
197- imageView. translatesAutoresizingMaskIntoConstraints = false
198- imageView. widthAnchor. constraint ( equalToConstant: 21 ) . isActive = true
199- imageView. heightAnchor. constraint ( equalToConstant: 14 ) . isActive = true
200- imageView. image = action. image
201- imageView. imageScaling = . scaleProportionallyDown
202- imageView. setContentHuggingPriority ( . init( 251 ) , for: . horizontal)
203- imageView. setContentHuggingPriority ( . init( 251 ) , for: . vertical)
204-
205- let labelStack = NSStackView ( views: [ textField, imageView] )
206- labelStack. orientation = . horizontal
207- labelStack. alignment = . centerY
208- labelStack. distribution = . fill
209-
210- let row = NSStackView ( views: [ labelStack, shortcutView] )
211- row. orientation = . horizontal
212- row. alignment = . centerY
213- row. distribution = . fill
214- row. spacing = 18
215-
216- actionsToViews [ action] = shortcutView
217- return row
218- }
219-
132+
220133 @IBAction func toggleShowMore( _ sender: NSButton ) {
221- let hide = !additionalShortcutsStackView. isHidden
222- additionalShortcutsStackView . isHidden = hide
223- showMoreButton . title = hide ? " ▶︎ ⋯ " : " ▼ "
134+ additionalShortcutsStackView . isHidden = !additionalShortcutsStackView. isHidden
135+ showMoreButton . title = additionalShortcutsStackView . isHidden
136+ ? " ▶︎ ⋯ " : " ▼ "
224137 }
225138
226139 private func subscribeToAllowAnyShortcutToggle( ) {
0 commit comments