Implement next and previous subscription navigation. Also: on first-run, position and size the window a bit nicer.
This commit is contained in:
parent
662a273d7f
commit
a4c82739b6
@ -32,9 +32,21 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
if !AppDefaults.shared.showTitleOnMainWindow {
|
||||
window?.titleVisibility = .hidden
|
||||
}
|
||||
|
||||
|
||||
window?.setFrameUsingName(windowAutosaveName, force: true)
|
||||
|
||||
if AppDefaults.shared.isFirstRun {
|
||||
|
||||
if let window = window, let screen = window.screen {
|
||||
let width: CGFloat = 1280.0
|
||||
let height: CGFloat = 768.0
|
||||
let insetX: CGFloat = 192.0
|
||||
let insetY: CGFloat = 96.0
|
||||
|
||||
window.setContentSize(NSSize(width: width, height: height))
|
||||
window.setFrameTopLeftPoint(NSPoint(x: insetX, y: screen.visibleFrame.maxY - insetY))
|
||||
}
|
||||
}
|
||||
|
||||
detailSplitViewItem?.minimumThickness = 384
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminate(_:)), name: NSApplication.willTerminateNotification, object: nil)
|
||||
@ -228,6 +240,16 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
||||
|
||||
sidebarViewController?.focus()
|
||||
}
|
||||
|
||||
@IBAction func goToPreviousSubscription(_ sender: Any?) {
|
||||
|
||||
sidebarViewController?.outlineView.selectPreviousRow(sender)
|
||||
}
|
||||
|
||||
@IBAction func goToNextSubscription(_ sender: Any?) {
|
||||
|
||||
sidebarViewController?.outlineView.selectNextRow(sender)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
@ -202,6 +202,11 @@ import RSCore
|
||||
return proposedSelectionIndexes
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool {
|
||||
|
||||
return !self.outlineView(outlineView, isGroupItem: item)
|
||||
}
|
||||
|
||||
func outlineViewSelectionDidChange(_ notification: Notification) {
|
||||
|
||||
// TODO: support multiple selection
|
||||
|
@ -23,6 +23,62 @@ public extension NSOutlineView {
|
||||
}
|
||||
}
|
||||
|
||||
var firstSelectedRow: Int? {
|
||||
|
||||
if selectionIsEmpty {
|
||||
return nil
|
||||
}
|
||||
return selectedRowIndexes.first
|
||||
}
|
||||
|
||||
var lastSelectedRow: Int? {
|
||||
|
||||
if selectionIsEmpty {
|
||||
return nil
|
||||
}
|
||||
return selectedRowIndexes.last
|
||||
}
|
||||
|
||||
@IBAction func selectPreviousRow(_ sender: Any?) {
|
||||
|
||||
guard var row = firstSelectedRow else {
|
||||
return
|
||||
}
|
||||
|
||||
if row < 1 {
|
||||
return
|
||||
}
|
||||
while true {
|
||||
row -= 1
|
||||
if row < 0 {
|
||||
return
|
||||
}
|
||||
if canSelect(row) {
|
||||
rs_selectRowAndScrollToVisible(row)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func selectNextRow(_ sender: Any?) {
|
||||
|
||||
// If no selectedRow, end up at first selectable row.
|
||||
var row = lastSelectedRow ?? -1
|
||||
|
||||
while true {
|
||||
row += 1
|
||||
if let _ = item(atRow: row) {
|
||||
if canSelect(row) {
|
||||
rs_selectRowAndScrollToVisible(row)
|
||||
return
|
||||
}
|
||||
}
|
||||
else {
|
||||
return // if there are no more items, we’re out of rows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func collapseSelectedRows(_ sender: Any?) {
|
||||
|
||||
for item in selectedItems {
|
||||
@ -97,4 +153,15 @@ public extension NSOutlineView {
|
||||
|
||||
return delegate?.outlineView?(self, isGroupItem: item) ?? false
|
||||
}
|
||||
|
||||
func canSelect(_ row: Int) -> Bool {
|
||||
|
||||
guard let item = item(atRow: row) else {
|
||||
return false
|
||||
}
|
||||
let isSelectable = delegate?.outlineView?(self, shouldSelectItem: item) ?? true
|
||||
return isSelectable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user