mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Inline installed packages panel
This commit is contained in:
parent
4ef5082887
commit
bd72f245b1
@ -1,55 +0,0 @@
|
|||||||
$ = require 'jquery'
|
|
||||||
_ = require 'underscore'
|
|
||||||
{View} = require 'space-pen'
|
|
||||||
ConfigPanel = require './config-panel'
|
|
||||||
PackageConfigView = require './package-config-view'
|
|
||||||
packageManager = require './package-manager'
|
|
||||||
stringScore = require 'stringscore'
|
|
||||||
|
|
||||||
### Internal ###
|
|
||||||
module.exports =
|
|
||||||
class InstalledPackagesConfigPanel extends View
|
|
||||||
@content: ->
|
|
||||||
@div class: 'installed-packages', =>
|
|
||||||
@div outlet: 'loadingArea', class: 'alert alert-info loading-area', =>
|
|
||||||
@span 'Loading installed packages\u2026'
|
|
||||||
@div outlet: 'packagesArea'
|
|
||||||
|
|
||||||
initialize: (@packageEventEmitter) ->
|
|
||||||
@packages = _.sortBy(atom.getAvailablePackageMetadata(), 'name')
|
|
||||||
packageManager.renderMarkdownInMetadata @packages, =>
|
|
||||||
@loadingArea.hide()
|
|
||||||
for pack in @packages
|
|
||||||
@packagesArea.append(new PackageConfigView(pack, @packageEventEmitter))
|
|
||||||
@packageEventEmitter.trigger 'installed-packages-loaded', [@packages]
|
|
||||||
|
|
||||||
@packageEventEmitter.on 'package-installed', (error, pack) =>
|
|
||||||
@addPackage(pack) unless error?
|
|
||||||
@packageEventEmitter.on 'package-uninstalled', (error, pack) =>
|
|
||||||
@removePackage(pack) unless error?
|
|
||||||
|
|
||||||
removePackage: ({name}) ->
|
|
||||||
@packages = _.reject @packages, (pack) -> pack.name is name
|
|
||||||
@packagesArea.children("[name=#{name}]").remove()
|
|
||||||
|
|
||||||
addPackage: (pack) ->
|
|
||||||
@packages.push(pack)
|
|
||||||
@packages = _.sortBy(@packages, 'name')
|
|
||||||
index = @packages.indexOf(pack)
|
|
||||||
view = new PackageConfigView(pack, @packageEventEmitter)
|
|
||||||
if index is 0
|
|
||||||
@packagesArea.prepend(view)
|
|
||||||
else if index is @packages.length - 1
|
|
||||||
@packagesArea.append(view)
|
|
||||||
else
|
|
||||||
@packagesArea.children(":eq(#{index})").before(view)
|
|
||||||
|
|
||||||
filterPackages: (filterString) ->
|
|
||||||
packageViews = @packagesArea.children()
|
|
||||||
for packageView in packageViews
|
|
||||||
if /^\s*$/.test(filterString) or stringScore(packageView.getAttribute('name'), filterString)
|
|
||||||
$(packageView).show()
|
|
||||||
else
|
|
||||||
$(packageView).hide()
|
|
||||||
|
|
||||||
getPackageCount: -> @packages.length
|
|
@ -1,9 +1,12 @@
|
|||||||
ConfigPanel = require './config-panel'
|
ConfigPanel = require './config-panel'
|
||||||
InstalledPackagesConfigPanel = require './installed-packages-config-panel'
|
|
||||||
AvailablePackagesConfigPanel = require './available-packages-config-panel'
|
AvailablePackagesConfigPanel = require './available-packages-config-panel'
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
EventEmitter = require 'event-emitter'
|
EventEmitter = require 'event-emitter'
|
||||||
Editor = require 'editor'
|
Editor = require 'editor'
|
||||||
|
PackageConfigView = require './package-config-view'
|
||||||
|
packageManager = require './package-manager'
|
||||||
|
stringScore = require 'stringscore'
|
||||||
|
|
||||||
|
|
||||||
### Internal ###
|
### Internal ###
|
||||||
class PackageEventEmitter
|
class PackageEventEmitter
|
||||||
@ -24,11 +27,19 @@ class PackageConfigPanel extends ConfigPanel
|
|||||||
|
|
||||||
@subview 'packageFilter', new Editor(mini: true, attributes: {id: 'package-filter'})
|
@subview 'packageFilter', new Editor(mini: true, attributes: {id: 'package-filter'})
|
||||||
|
|
||||||
|
@div outlet: 'loadingArea', class: 'alert alert-info loading-area', =>
|
||||||
|
@span 'Loading installed packages\u2026'
|
||||||
|
|
||||||
|
@div outlet: 'installedViews'
|
||||||
|
|
||||||
|
|
||||||
initialize: ->
|
initialize: ->
|
||||||
@packageEventEmitter = new PackageEventEmitter()
|
@packageEventEmitter = new PackageEventEmitter()
|
||||||
@installed = new InstalledPackagesConfigPanel(@packageEventEmitter)
|
|
||||||
|
@createInstalledViews()
|
||||||
|
|
||||||
@available = new AvailablePackagesConfigPanel(@packageEventEmitter)
|
@available = new AvailablePackagesConfigPanel(@packageEventEmitter)
|
||||||
@append(@installed, @available)
|
@append(@available)
|
||||||
|
|
||||||
@available.hide()
|
@available.hide()
|
||||||
|
|
||||||
@ -44,12 +55,53 @@ class PackageConfigPanel extends ConfigPanel
|
|||||||
@availableLink.addClass('active')
|
@availableLink.addClass('active')
|
||||||
@available.show()
|
@available.show()
|
||||||
|
|
||||||
@packageEventEmitter.on 'installed-packages-loaded package-installed package-uninstalled', =>
|
|
||||||
@installedCount.text(@installed.getPackageCount())
|
|
||||||
|
|
||||||
@packageEventEmitter.on 'available-packages-loaded', =>
|
@packageEventEmitter.on 'available-packages-loaded', =>
|
||||||
@availableCount.text(@available.getPackageCount())
|
@availableCount.text(@available.getPackageCount())
|
||||||
|
|
||||||
@packageFilter.getBuffer().on 'contents-modified', =>
|
@packageFilter.getBuffer().on 'contents-modified', =>
|
||||||
@available.filterPackages(@packageFilter.getText())
|
@available.filterPackages(@packageFilter.getText())
|
||||||
@installed.filterPackages(@packageFilter.getText())
|
@filterPackages(@packageFilter.getText())
|
||||||
|
|
||||||
|
@packageEventEmitter.on 'package-installed', (error, pack) =>
|
||||||
|
@addPackage(pack) unless error?
|
||||||
|
@updateInstalledCount()
|
||||||
|
|
||||||
|
@packageEventEmitter.on 'package-uninstalled', (error, pack) =>
|
||||||
|
@removePackage(pack) unless error?
|
||||||
|
@updateInstalledCount()
|
||||||
|
|
||||||
|
createInstalledViews: ->
|
||||||
|
@loadingArea.show()
|
||||||
|
packages = _.sortBy(atom.getAvailablePackageMetadata(), 'name')
|
||||||
|
packageManager.renderMarkdownInMetadata packages, =>
|
||||||
|
@loadingArea.hide()
|
||||||
|
for pack in packages
|
||||||
|
view = new PackageConfigView(pack, @packageEventEmitter)
|
||||||
|
@installedViews.append(view)
|
||||||
|
|
||||||
|
@updateInstalledCount()
|
||||||
|
|
||||||
|
updateInstalledCount: ->
|
||||||
|
@installedCount.text(@installedViews.children().length)
|
||||||
|
|
||||||
|
removePackage: ({name}) ->
|
||||||
|
@packagesArea.children("[name=#{name}]").remove()
|
||||||
|
|
||||||
|
addPackage: (pack) ->
|
||||||
|
packageNames = @installedViews.children().map (el) -> el.getAttribute('name')
|
||||||
|
packageNames.push(pack.name)
|
||||||
|
packageNames.sort()
|
||||||
|
insertAfterIndex = packageNames.indexOf(pack.name) - 1
|
||||||
|
|
||||||
|
view = new PackageConfigView(pack, @packageEventEmitter)
|
||||||
|
if insertAfterIndex < 0
|
||||||
|
@installedViews.prepend(view)
|
||||||
|
else
|
||||||
|
@installedViews.children(":eq(#{insertAfterIndex})").after(view)
|
||||||
|
|
||||||
|
filterPackages: (filterString) ->
|
||||||
|
for packageView in @installedViews.children()
|
||||||
|
if /^\s*$/.test(filterString) or stringScore(packageView.getAttribute('name'), filterString)
|
||||||
|
$(packageView).show()
|
||||||
|
else
|
||||||
|
$(packageView).hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user