Skip to content

Commit

Permalink
Merge pull request #134 from josefdolezal/patch-1
Browse files Browse the repository at this point in the history
Enable mouse interactions
  • Loading branch information
IvanMathy authored Jul 25, 2020
2 parents de8a49e + 7504d1d commit 1e42625
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 25 additions & 11 deletions Boop/Boop/Controllers/PopoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class PopoverViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Double-click script selection
tableView.doubleAction = #selector(runSelectedScript)

// Dismiss popover on background view click
overlayView.onMouseDown = { [weak self] in
self?.hide()
}

setupKeyHandlers()
}
Expand Down Expand Up @@ -55,18 +63,12 @@ class PopoverViewController: NSViewController {
}

if theEvent.keyCode == 36 && self.enabled { // ENTER
guard let script = self.tableViewController.selectedScript else {
return theEvent // Return event to beep

guard self.tableViewController.selectedScript != nil else {
return theEvent
}


// Let's dismiss the popover
self.hide()

// Run the script afterwards in case we need to show a status
self.scriptManager.runScript(script, into: self.editorView)


self.runSelectedScript()

didSomething = true
}
Expand Down Expand Up @@ -142,6 +144,18 @@ class PopoverViewController: NSViewController {
func runScriptAgain() {
self.scriptManager.runScriptAgain(editor: self.editorView)
}

@objc private func runSelectedScript() {
guard let script = tableViewController.selectedScript else {
return
}

// Let's dismiss the popover
hide()

// Run the script afterwards in case we need to show a status
scriptManager.runScript(script, into: editorView)
}

}

Expand Down
4 changes: 3 additions & 1 deletion Boop/Boop/Views/OverlayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Cocoa

class OverlayView: NSView {

var onMouseDown: (() -> Void)?

required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
self.wantsLayer = true
Expand All @@ -32,7 +34,7 @@ class OverlayView: NSView {
}

override func mouseDown(with event: NSEvent) {
return
onMouseDown?()
}

}

0 comments on commit 1e42625

Please sign in to comment.