1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 03:25:03 +03:00

Implement drag reorder

This commit is contained in:
Tae Won Ha 2020-12-06 20:28:33 +01:00
parent 6b5edb99cf
commit f6a31ddc18
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 17 additions and 3 deletions

View File

@ -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))])

View File

@ -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)
}
}

View File

@ -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 }

View File

@ -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"),