Skip to content

Change file opening action to double click #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions BuildTimeAnalyzer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ViewController: NSViewController {

tableView.tableColumns[0].sortDescriptorPrototype = NSSortDescriptor(key: CompileMeasure.Order.time.rawValue, ascending: true)
tableView.tableColumns[1].sortDescriptorPrototype = NSSortDescriptor(key: CompileMeasure.Order.filename.rawValue, ascending: true)
tableView.doubleAction = #selector(didDoubleClickTableView(_:))

NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose(notification:)), name: NSWindow.willCloseNotification, object: nil)
}
Expand All @@ -74,6 +75,27 @@ class ViewController: NSViewController {
processor.shouldCancel = true
NSApp.terminate(self)
}

@objc func didDoubleClickTableView(_ tableView: NSTableView) {
guard let item = dataSource.measure(index: tableView.selectedRow) else { return }
NSWorkspace.shared.openFile(item.path)

let gotoLineScript =
"tell application \"Xcode\"\n" +
" activate\n" +
"end tell\n" +
"tell application \"System Events\"\n" +
" keystroke \"l\" using command down\n" +
" keystroke \"\(item.location)\"\n" +
" keystroke return\n" +
"end tell"

DispatchQueue.main.async {
if let script = NSAppleScript(source: gotoLineScript) {
script.executeAndReturnError(nil)
}
}
}

// MARK: Layout

Expand Down Expand Up @@ -261,25 +283,7 @@ extension ViewController: NSTableViewDataSource {
}

func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
guard let item = dataSource.measure(index: row) else { return false }
NSWorkspace.shared.openFile(item.path)

let gotoLineScript =
"tell application \"Xcode\"\n" +
" activate\n" +
"end tell\n" +
"tell application \"System Events\"\n" +
" keystroke \"l\" using command down\n" +
" keystroke \"\(item.location)\"\n" +
" keystroke return\n" +
"end tell"

DispatchQueue.main.async {
if let script = NSAppleScript(source: gotoLineScript) {
script.executeAndReturnError(nil)
}
}

guard let _ = dataSource.measure(index: row) else { return false }
return true
}
}
Expand Down