Skip to content

Commit a327689

Browse files
committed
Merge pull request #648 from ncreep/message-panel-view
Porting ScriptView to use MessagePanelView
2 parents 4729bf6 + be3a205 commit a327689

File tree

5 files changed

+45
-83
lines changed

5 files changed

+45
-83
lines changed

lib/header-view.coffee

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@ module.exports =
44
class HeaderView extends View
55

66
@content: ->
7-
@div class: 'panel-heading padded heading header-view', =>
7+
@div class: 'header-view', =>
88
@span class: 'heading-title', outlet: 'title'
99
@span class: 'heading-status', outlet: 'status'
10-
@span
11-
class: 'heading-close icon-remove-close pull-right'
12-
outlet: 'closeButton'
13-
click: 'close'
14-
15-
close: ->
16-
atom.commands.dispatch @workspaceView(), 'script:close-view'
1710

1811
setStatus: (status) ->
1912
@status.removeClass 'icon-alert icon-check icon-hourglass icon-stop'
@@ -22,6 +15,3 @@ class HeaderView extends View
2215
when 'stop' then @status.addClass 'icon-check'
2316
when 'kill' then @status.addClass 'icon-stop'
2417
when 'err' then @status.addClass 'icon-alert'
25-
26-
workspaceView: ->
27-
atom.views.getView(atom.workspace)

lib/script-view.coffee

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
HeaderView = require './header-view'
2-
ScriptOptionsView = require './script-options-view'
3-
41
{View, $$} = require 'atom-space-pen-views'
52

3+
HeaderView = require './header-view'
4+
{MessagePanelView} = require 'atom-message-panel'
65
AnsiFilter = require 'ansi-to-html'
76
stripAnsi = require 'strip-ansi'
87
linkPaths = require './link-paths'
98
_ = require 'underscore'
109

1110
# Runs a portion of a script through an interpreter and displays it line by line
1211
module.exports =
13-
class ScriptView extends View
14-
@results: ""
15-
16-
@content: ->
17-
@div =>
18-
@subview 'headerView', new HeaderView()
12+
class ScriptView extends MessagePanelView
13+
constructor: ->
14+
@ansiFilter = new AnsiFilter
1915

20-
# Display layout and outlets
21-
css = 'tool-panel panel panel-bottom padding script-view
22-
native-key-bindings'
23-
@div class: css, outlet: 'script', tabindex: -1, =>
24-
@div class: 'panel-body padded output', outlet: 'output'
16+
@headerView = new HeaderView
2517

26-
initialize: (serializeState) ->
27-
@ansiFilter = new AnsiFilter
18+
super(title: @headerView, rawTitle: true, closeMethod: 'destroy')
2819

29-
linkPaths.listen @
20+
@addClass('script-view')
3021

31-
serialize: ->
22+
linkPaths.listen @body
3223

3324
setHeaderAndShowExecutionTime: (returnCode, executionTime) =>
3425
if (executionTime?)
@@ -45,30 +36,33 @@ class ScriptView extends View
4536
# Display window and load message
4637

4738
# First run, create view
48-
atom.workspace.addBottomPanel(item: this) unless @hasParent()
39+
@attach() unless @hasParent()
4940

5041
# Close any existing process and start a new one
5142
@stop()
5243

53-
@headerView.title.text title
54-
@headerView.setStatus 'start'
44+
@setHeaderTitle title
45+
@setHeaderStatus 'start'
5546

5647
# Get script view ready
57-
@output.empty()
48+
@clear()
5849

59-
# Remove the old script results
60-
@results = ""
50+
removePanel: ->
51+
@stop()
52+
@detach()
53+
# the 'close' method from MessagePanelView actually destroys the panel
54+
ScriptView.__super__.close.apply(this)
6155

56+
# This is triggered when hitting the 'close' button on the panel
57+
# We are not actually closing the panel here since we want to trigger
58+
# 'script:close-view' which will eventually remove the panel via 'removePanel'
6259
close: ->
63-
@stop()
64-
if @hasParent()
65-
grandParent = @script.parent().parent()
66-
@detach()
67-
grandParent.remove()
60+
workspaceView = atom.views.getView(atom.workspace)
61+
atom.commands.dispatch workspaceView, 'script:close-view'
6862

6963
stop: ->
7064
@display 'stdout', '^C'
71-
@headerView.setStatus 'kill'
65+
@setHeaderStatus 'kill'
7266

7367
createGitHubIssueLink: (argType, lang) ->
7468
title = "Add #{argType} support for #{lang}"
@@ -89,7 +83,7 @@ class ScriptView extends View
8983
@handleError(err)
9084

9185
showUnableToRunError: (command) ->
92-
@output.append $$ ->
86+
@add $$ ->
9387
@h1 'Unable to run'
9488
@pre _.escape command
9589
@h2 'Did you start Atom from the command line?'
@@ -115,9 +109,9 @@ class ScriptView extends View
115109

116110
handleError: (err) ->
117111
# Display error and kill process
118-
@headerView.title.text 'Error'
119-
@headerView.setStatus 'err'
120-
@output.append err
112+
@setHeaderTitle 'Error'
113+
@setHeaderStatus 'err'
114+
@add(err)
121115
@stop()
122116

123117
setHeaderStatus: (status) ->
@@ -127,35 +121,31 @@ class ScriptView extends View
127121
@headerView.title.text title
128122

129123
display: (css, line) ->
130-
@results += line
131-
132124
if atom.config.get('script.escapeConsoleOutput')
133125
line = _.escape(line)
134126

135127
line = @ansiFilter.toHtml(line)
136128
line = linkPaths(line)
137129

138-
padding = parseInt(@output.css('padding-bottom'))
139-
scrolledToEnd =
140-
@script.scrollBottom() == (padding + @output.trueHeight())
141-
142-
lessThanFull = @output.trueHeight() <= @script.trueHeight()
130+
{clientHeight, scrollTop, scrollHeight} = @body[0]
131+
# indicates that the panel is scrolled to the bottom, thus we know that
132+
# we are not interfering with the user's manual scrolling
133+
atEnd = scrollTop >= (scrollHeight - clientHeight)
143134

144-
@output.append $$ ->
135+
@add $$ ->
145136
@pre class: "line #{css}", =>
146137
@raw line
147138

148-
if atom.config.get('script.scrollWithOutput')
149-
if lessThanFull or scrolledToEnd
150-
# Scroll down in a polling loop 'cause
151-
# we don't know when the reflow will finish.
152-
# See: http://stackoverflow.com/q/5017923/407845
153-
do @checkScrollAgain 5
139+
if atom.config.get('script.scrollWithOutput') and atEnd
140+
# Scroll down in a polling loop 'cause
141+
# we don't know when the reflow will finish.
142+
# See: http://stackoverflow.com/q/5017923/407845
143+
do @checkScrollAgain 5
154144

155145
scrollTimeout: null
156146
checkScrollAgain: (times) ->
157147
=>
158-
@script.scrollToBottom()
148+
@body.scrollToBottom()
159149

160150
clearTimeout @scrollTimeout
161151
if times > 1

lib/script.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ module.exports =
5151

5252
deactivate: ->
5353
@runtime.destroy()
54-
@scriptView.close()
54+
@scriptView.removePanel()
5555
@scriptOptionsView.close()
5656
@subscriptions.dispose()
5757
GrammarUtils.deleteTempFiles()
5858

5959
closeScriptViewAndStopRunner: ->
6060
@runtime.stop()
61-
@scriptView.close()
61+
@scriptView.removePanel()
6262

6363
# Public
6464
#

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@
316316
"node-uuid": "~1.4.0",
317317
"strip-ansi": "^3.0.0",
318318
"underscore": "~1.5.2",
319-
"atom-space-pen-views": "^2.0.3"
319+
"atom-space-pen-views": "^2.0.3",
320+
"atom-message-panel": "1.2.4"
320321
},
321322
"devDependencies": {
322323
"grunt": "~0.4.5"

styles/script.less

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55
@import "ui-variables";
66

77
.header-view {
8-
position: fixed;
9-
width: 100%;
10-
z-index:10;
11-
position:relative;
12-
13-
14-
.heading-close {
15-
color: @text-color-highlight;
16-
}
17-
18-
.heading-title {
19-
padding-left: 6px;
20-
}
21-
228
.heading-status {
239
padding-left: 9px;
2410
}
@@ -41,12 +27,7 @@
4127
}
4228

4329
.script-view {
44-
overflow: scroll;
45-
max-height: 300px;
46-
height: auto;
47-
margin-bottom: 0px;
48-
49-
.panel-body pre{
30+
.panel-body pre {
5031
background: @tool-panel-background-color;
5132
color: @text-color;
5233
}

0 commit comments

Comments
 (0)