mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
Implement drag reorder
This commit is contained in:
parent
6b5edb99cf
commit
f6a31ddc18
@ -171,6 +171,12 @@ public class NvimView: NSView,
|
||||
.subscribe()
|
||||
.disposed(by: db)
|
||||
}
|
||||
self.tabBar?.reorderHandler = { [weak self] index, _ in
|
||||
self?.api
|
||||
.command(command: "tabm \(index)")
|
||||
.subscribe()
|
||||
.disposed(by: db)
|
||||
}
|
||||
|
||||
self.bridge.consumer = self
|
||||
self.registerForDraggedTypes([NSPasteboard.PasteboardType(String(kUTTypeFileURL))])
|
||||
|
@ -13,7 +13,7 @@ import Cocoa
|
||||
|
||||
class DraggingSingleRowStackView: NSStackView {
|
||||
var isDraggingEnabled = true
|
||||
var postDraggingHandler: ((NSStackView) -> Void)?
|
||||
var postDraggingHandler: ((NSStackView, NSView) -> Void)?
|
||||
|
||||
override func mouseDragged(with event: NSEvent) {
|
||||
guard self.isDraggingEnabled else {
|
||||
@ -24,7 +24,7 @@ class DraggingSingleRowStackView: NSStackView {
|
||||
let location = convert(event.locationInWindow, from: nil)
|
||||
if let dragged = views.first(where: { $0.hitTest(location) != nil }) {
|
||||
self.reorder(view: dragged, event: event)
|
||||
self.postDraggingHandler?(self)
|
||||
self.postDraggingHandler?(self, dragged)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ public protocol TabRepresentative: Hashable {
|
||||
public class TabBar<Entry: TabRepresentative>: NSView {
|
||||
public var theme: Theme { self._theme }
|
||||
public var selectHandler: ((Int, Entry) -> Void)?
|
||||
public var reorderHandler: ((Int, Entry) -> Void)?
|
||||
|
||||
public init(withTheme theme: Theme) {
|
||||
self._theme = theme
|
||||
@ -95,7 +96,13 @@ extension TabBar {
|
||||
stack.autoPinEdge(toSuperviewEdge: .bottom)
|
||||
|
||||
stack.spacing = self._theme.tabSpacing
|
||||
stack.postDraggingHandler = { stackView in
|
||||
stack.postDraggingHandler = { stackView, draggedView in
|
||||
if let draggedTab = draggedView as? Tab<Entry>,
|
||||
let indexOfDraggedTab = self.tabs.firstIndex(where: { $0 == draggedTab })
|
||||
{
|
||||
self.reorderHandler?(indexOfDraggedTab, draggedTab.tabRepresentative)
|
||||
}
|
||||
|
||||
let endIndex = stackView.arrangedSubviews.endIndex - 1
|
||||
stackView.arrangedSubviews.enumerated().forEach { index, view in
|
||||
guard let tab = view as? Tab<Entry> else { return }
|
||||
|
@ -25,6 +25,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
self.tabBar.autoPinEdge(toSuperviewEdge: .left)
|
||||
self.tabBar.autoPinEdge(toSuperviewEdge: .right)
|
||||
self.tabBar.autoSetDimension(.height, toSize: Theme().tabBarHeight)
|
||||
self.tabBar.selectHandler = { _, entry in Swift.print("selected \(entry)") }
|
||||
|
||||
self.tabBar.update(tabRepresentatives: [
|
||||
DummyTabEntry(title: "Test 1"),
|
||||
|
Loading…
Reference in New Issue
Block a user