|
| 1 | +{View} = require 'atom' |
| 2 | +{Subscriber} = require 'emissary' |
| 3 | +{Stacktrace} = require './stacktrace' |
| 4 | + |
| 5 | +class NavigationView extends View |
| 6 | + |
| 7 | + Subscriber.includeInto this |
| 8 | + |
| 9 | + @content: -> |
| 10 | + activatedClass = if Stacktrace.getActivated()? then '' else 'inactive' |
| 11 | + |
| 12 | + @div class: "tool-panel panel-bottom padded stacktrace navigation #{activatedClass}", => |
| 13 | + @div class: 'inline-block trace-name', => |
| 14 | + @h2 class: 'inline-block text-highlight message', outlet: 'message', click: 'backToTrace' |
| 15 | + @span class: 'inline-block icon icon-x', click: 'deactivateTrace' |
| 16 | + @div class: 'inline-block current-frame unfocused', outlet: 'frameContainer', => |
| 17 | + @span class: 'inline-block icon icon-code' |
| 18 | + @span class: 'inline-block function', outlet: 'frameFunction', click: 'navigateToLastActive' |
| 19 | + @span class: 'inline-block index', outlet: 'frameIndex' |
| 20 | + @span class: 'inline-block divider', '/' |
| 21 | + @span class: 'inline-block total', outlet: 'frameTotal' |
| 22 | + @div class: 'pull-right controls', => |
| 23 | + @button class: 'inline-block btn', click: 'navigateToCaller', => |
| 24 | + @span class: 'icon icon-arrow-up' |
| 25 | + @text 'Caller' |
| 26 | + @button class: 'inline-block btn', click: 'navigateToCalled', => |
| 27 | + @span class: 'icon icon-arrow-down' |
| 28 | + @text 'Follow Call' |
| 29 | + |
| 30 | + initialize: -> |
| 31 | + @subscribe Stacktrace, 'active-changed', (e) => |
| 32 | + if e.newTrace? then @useTrace(e.newTrace) else @noTrace() |
| 33 | + |
| 34 | + # Subscribe to opening editors. Set the current frame when a cursor is moved over a frame's |
| 35 | + # line. |
| 36 | + atom.workspace.eachEditor (e) => |
| 37 | + @subscribe e, 'cursors-moved', => |
| 38 | + if @trace? |
| 39 | + pos = |
| 40 | + position: e.getCursorBufferPosition() |
| 41 | + path: e.getPath() |
| 42 | + |
| 43 | + # Allow the already-set @frame a chance to see if it still applies. |
| 44 | + # This lets the caller and called navigation work properly, even if multiple frames are |
| 45 | + # on the same line. |
| 46 | + if @frame? and @frame.isOn(pos) |
| 47 | + @useFrame(@frame) |
| 48 | + else |
| 49 | + # Otherwise, scan the trace for a matching frame. |
| 50 | + frame = @trace.atEditorPosition(pos) |
| 51 | + if frame? then @useFrame(frame) else @unfocusFrame() |
| 52 | + |
| 53 | + if Stacktrace.getActivated? then @hide() |
| 54 | + |
| 55 | + beforeRemove: -> |
| 56 | + @unsubscribe Stacktrace |
| 57 | + |
| 58 | + useTrace: (@trace) -> |
| 59 | + @removeClass 'inactive' |
| 60 | + @message.text(trace.message) |
| 61 | + @noFrame() |
| 62 | + @show() |
| 63 | + |
| 64 | + noTrace: -> |
| 65 | + @addClass 'inactive' |
| 66 | + @message.text('') |
| 67 | + @noFrame() |
| 68 | + @hide() |
| 69 | + |
| 70 | + useFrame: (@frame) -> |
| 71 | + @frameContainer.removeClass 'unfocused' |
| 72 | + @frameFunction.text @frame.functionName |
| 73 | + @frameFunction.addClass 'highlight-info' |
| 74 | + @frameIndex.text @frame.humanIndex().toString() |
| 75 | + @frameTotal.text @trace.frames.length.toString() |
| 76 | + |
| 77 | + unfocusFrame: -> |
| 78 | + @frameContainer.addClass 'unfocused' |
| 79 | + @frameFunction.removeClass 'highlight-info' |
| 80 | + |
| 81 | + noFrame: -> |
| 82 | + @unfocusFrame() |
| 83 | + @frameFunction.text '' |
| 84 | + @frameIndex.text '' |
| 85 | + @frameTotal.text '' |
| 86 | + |
| 87 | + deactivateTrace: -> |
| 88 | + Stacktrace.getActivated().deactivate() |
| 89 | + |
| 90 | + backToTrace: -> |
| 91 | + url = Stacktrace.getActivated()?.getUrl() |
| 92 | + atom.workspace.open(url) if url |
| 93 | + |
| 94 | + navigateToCaller: -> |
| 95 | + return unless @trace? and @frame? |
| 96 | + |
| 97 | + f = @trace.callerOf(@frame) |
| 98 | + if f? |
| 99 | + @frame = f |
| 100 | + @frame.navigateTo() |
| 101 | + |
| 102 | + navigateToCalled: -> |
| 103 | + return unless @trace? and @frame? |
| 104 | + |
| 105 | + f = @trace.calledFrom(@frame) |
| 106 | + if f? |
| 107 | + @frame = f |
| 108 | + @frame.navigateTo() |
| 109 | + |
| 110 | + navigateToLastActive: -> |
| 111 | + return unless @frame? |
| 112 | + @frame.navigateTo() |
| 113 | + |
| 114 | +module.exports = NavigationView: NavigationView |
0 commit comments