forked from rhysforyou/gist-it
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgist-view.coffee
More file actions
146 lines (113 loc) · 4.12 KB
/
gist-view.coffee
File metadata and controls
146 lines (113 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{TextEditorView, View} = require 'atom-space-pen-views'
Clipboard = require 'clipboard'
{CompositeDisposable} = require 'atom'
Gist = require './gist-model'
module.exports =
class GistView extends View
@content: ->
@div tabIndex: -1, class: "gist overlay from-top padded", =>
@div class: "inset-panel", =>
@div class: "panel-heading", =>
@span outlet: "title"
@div class: "btn-toolbar pull-right", outlet: 'toolbar', =>
@div class: "btn-group", =>
@button outlet: "privateButton", class: "btn", "Secret"
@button outlet: "publicButton", class: "btn", "Public"
@div class: "panel-body padded", =>
@div outlet: 'gistForm', class: 'gist-form', =>
@subview 'descriptionEditor', new TextEditorView(mini: true, placeholder: 'Gist Description')
@div class: 'block pull-right', =>
@button outlet: 'cancelButton', class: 'btn inline-block-tight', "Cancel"
@button outlet: 'gistButton', class: 'btn btn-primary inline-block-tight', "Gist It"
@div class: 'clearfix'
@div outlet: 'progressIndicator', =>
@span class: 'loading loading-spinner-medium'
@div outlet: 'urlDisplay', =>
@span "All Done! the Gist's URL has been copied to your clipboard."
initialize: (serializeState) ->
@gist = null
@subscriptions = new CompositeDisposable
@handleEvents()
atom.commands.add 'atom-text-editor',
'gist-it:gist-current-file': => @gistCurrentFile(),
"gist-it:gist-selection": => @gistSelection(),
"gist-it:gist-open-buffers": => @gistOpenBuffers()
# Returns an object that can be retrieved when package is activated
serialize: ->
# Tear down any state and detach
destroy: ->
@subscriptions?.dispose()
atom.views.getView(atom.workspace).focus()
@detach()
handleEvents: ->
@gistButton.on 'click', => @gistIt()
@cancelButton.on 'click', => @destroy()
@publicButton.on 'click', => @makePublic()
@privateButton.on 'click', => @makePrivate()
@subscriptions.add atom.commands.add @descriptionEditor.element,
'core:confirm': => @gistIt()
'core:cancel': => @destroy()
@subscriptions.add atom.commands.add @element,
'core:close': => @destroy
'core:cancel': => @destroy
@on 'focus', =>
console.log("foo")
@descriptionEditor.focus()
gistCurrentFile: ->
@gist = new Gist()
activeEditor = atom.workspace.getActiveTextEditor()
@gist.files[activeEditor.getTitle()] =
content: activeEditor.getText()
@title.text "Gist Current File"
@presentSelf()
gistSelection: ->
@gist = new Gist()
activeEditor = atom.workspace.getActiveTextEditor()
@gist.files[activeEditor.getTitle()] =
content: activeEditor.getSelectedText()
@title.text "Gist Selection"
@presentSelf()
gistOpenBuffers: ->
@gist = new Gist()
for editor in atom.workspace.getTextEditors()
@gist.files[editor.getTitle()] = content: editor.getText()
@title.text "Gist Open Buffers"
@presentSelf()
presentSelf: ->
@showGistForm()
atom.workspace.addTopPanel(item: this)
@descriptionEditor.focus()
gistIt: ->
@showProgressIndicator()
@gist.description = @descriptionEditor.getText()
@gist.post (response) =>
Clipboard.writeText response.html_url
@showUrlDisplay()
setTimeout (=>
@destroy()
), 1000
makePublic: ->
@publicButton.addClass('selected')
@privateButton.removeClass('selected')
@gist.isPublic = true
makePrivate: ->
@privateButton.addClass('selected')
@publicButton.removeClass('selected')
@gist.isPublic = false
showGistForm: ->
if @gist.isPublic then @makePublic() else @makePrivate()
@descriptionEditor.setText @gist.description
@toolbar.show()
@gistForm.show()
@urlDisplay.hide()
@progressIndicator.hide()
showProgressIndicator: ->
@toolbar.hide()
@gistForm.hide()
@urlDisplay.hide()
@progressIndicator.show()
showUrlDisplay: ->
@toolbar.hide()
@gistForm.hide()
@urlDisplay.show()
@progressIndicator.hide()