Use SelectListView to search easier

This commit is contained in:
Seong Jae Lee
2014-11-09 14:13:00 -08:00
parent d38f11be66
commit 079b8c20cb
4 changed files with 71 additions and 40 deletions
+60 -35
View File
@@ -1,43 +1,68 @@
fs = require 'fs'
path = require 'path'
{$, $$, SelectListView} = require 'atom'
module.exports =
class NotationalVelocityView
constructor: (serializeState) ->
# Create root element
@element = document.createElement('div')
@element.classList.add('notational-velocity', 'overlay', 'from-top')
class NotationalVelocityView extends SelectListView
initialize: ->
console.log 'initialize'
super
# Create message element
message = document.createElement('div')
message.textContent = "The NotationalVelocity package is Alive! It's ALIVE!"
message.classList.add('message')
@element.appendChild(message)
@addClass('from-top overlay')
@data = [
{
'title': 'car',
'content': 'Car: A car is a wheeled, self-powered motor vehicle used for transportation. Most definitions of the term specify that cars are designed to run primarily on roads, to have seating for one to eight people, to typically have four wheels, and to be constructed principally for the transport of people rather than goods.'
},
{
'title': 'bar',
'content': 'Bar: Bars provide stools or chairs that are placed at tables or counters for their patrons. Some bars have entertainment on a stage, such as a live band, comedians, go-go dancers, or strippers. Bars which offer entertainment or live music are often referred to as music bars or nightclubs.'
}
]
@setItems(@data)
# Register command that toggles this view
atom.commands.add 'atom-workspace', 'notational-velocity:toggle': => @toggle()
getFilterKey: ->
'content'
# Returns an object that can be retrieved when package is activated
serialize: ->
# Tear down any state and detach
destroy: ->
@element.remove()
# Toggle the visibility of this view
toggle: ->
console.log 'NotationalVelocityView was toggled!'
@readdir()
if @element.parentElement?
@element.remove()
console.log 'toggle'
if @hasParent()
@cancel()
else
atom.workspaceView.append(@element)
@attach()
# read filenames in a specific directory
readdir: ->
fs.readdir '.', (error, filenames) =>
if error
throw error
for filename in filenames
console.log filename
viewForItem: (item) ->
console.log 'viewForItem #{item}'
element = document.createElement('li')
element.textContent = item.content
element
confirmed: (item) ->
console.log 'confirmed #{item}'
destroy: ->
console.log 'destroy'
@cancel()
@remove()
attach: ->
console.log 'attach'
@storeFocusedElement()
atom.workspaceView.append(this)
@focusFilterEditor()
cancel: ->
console.log 'cancel'
super
cancelled: ->
console.log 'cancelled'
super
setItems: (items=[]) ->
console.log 'setItems'
super(items)
populateList: ->
console.log 'populateList'
super
+8 -3
View File
@@ -1,13 +1,18 @@
NotationalVelocityView = require './notational-velocity-view'
module.exports =
notationalVelocityView: null
activate: (state) ->
@notationalVelocityView = new NotationalVelocityView(state.notationalVelocityViewState)
atom.workspaceView.command 'notational-velocity:toggle', =>
@createView(state).toggle()
deactivate: ->
@notationalVelocityView.destroy()
serialize: ->
notationalVelocityViewState: @notationalVelocityView.serialize()
createView: (state) ->
unless @notationalVelocityView?
NotationalVelocityView = require './notational-velocity-view'
@notationalVelocityView = new NotationalVelocityView(state.notationalVelocityViewState)
@notationalVelocityView
+2 -2
View File
@@ -2,7 +2,7 @@
'context-menu':
'atom-text-editor': [
{
'label': 'Toggle notational-velocity'
'label': 'Toggle Notational Velocity'
'command': 'notational-velocity:toggle'
}
]
@@ -10,7 +10,7 @@
{
'label': 'Packages'
'submenu': [
'label': 'notational-velocity'
'label': 'Notational Velocity'
'submenu': [
{
'label': 'Toggle'
+1
View File
@@ -12,5 +12,6 @@
"atom": ">0.50.0"
},
"dependencies": {
"fs-plus": "2.x",
}
}