109 lines
2.3 KiB
JavaScript
109 lines
2.3 KiB
JavaScript
// entry - a track, directory, playlist, etc
|
|
// - entries
|
|
// - name
|
|
// - length
|
|
|
|
import List from "./List.js"
|
|
import * as panels from "./panels.js"
|
|
|
|
const app = window.app ??= {}
|
|
const view = window.view ??= {}
|
|
|
|
export let list = new List(view.browser = {
|
|
element: document.getElementById('browser')
|
|
})
|
|
|
|
export const Init = async () => {
|
|
app.browser = {}
|
|
app.browser.root = {
|
|
entries: app.index,
|
|
root: true
|
|
}
|
|
app.browser.current = app.browser.root
|
|
app.browser.recursiveView = false
|
|
app.browser.view = []
|
|
}
|
|
|
|
export const View = async () => {
|
|
Render()
|
|
}
|
|
|
|
export const Render = async () => {
|
|
organizeView()
|
|
list.Render(app.browser.view, 0)
|
|
}
|
|
|
|
export const organizeView = () => {
|
|
if(app.browser.recursiveView) {
|
|
app.browser.view = []
|
|
recurseView()
|
|
} else {
|
|
app.browser.view = app.browser.current.entries
|
|
}
|
|
app.browser.view.sort((a, b) => a.order - b.order)
|
|
}
|
|
|
|
export const recurseView = (eaEntries = app.browser.current.entries, bIncludeDirectories = true) => {
|
|
for(let e of eaEntries) {
|
|
if(e.entries) {
|
|
recurseView(e.entries, false)
|
|
if(!bIncludeDirectories)
|
|
continue
|
|
}
|
|
app.browser.view.push(e)
|
|
}
|
|
}
|
|
|
|
export const Open = () => {
|
|
panels.Display('browser')
|
|
}
|
|
|
|
export const Back = () => {
|
|
let e = app.browser.current
|
|
if(e.root) {
|
|
return
|
|
}
|
|
let s = Cd(e.parent)
|
|
|
|
if(s) {
|
|
list.Focus(app.browser.view.indexOf(e))
|
|
}
|
|
}
|
|
|
|
export const Cd = (entry = Focused() || app.browser.root) => {
|
|
if(entry.entries) {
|
|
app.browser.current = entry
|
|
Render()
|
|
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export const Queue = (entry = Focused()) => {
|
|
queue.Add(entry)
|
|
list.Scroll(1)
|
|
}
|
|
|
|
export const QueueAllBelow = () => {
|
|
let e = app.browser.current.entries
|
|
|
|
for(let i = app.cursor; i < e.length; i++) {
|
|
queue.Add(e)
|
|
}
|
|
}
|
|
|
|
export const GoToDirectory = (entry = Focused()) => {
|
|
Cd(entry.parent) &&
|
|
list.Focus(app.browser.view.indexOf(entry))
|
|
}
|
|
|
|
export const ToggleRecursiveView = () => {
|
|
app.browser.recursiveView = !app.browser.recursiveView
|
|
Render()
|
|
}
|
|
|
|
export const Focused = () => {
|
|
return app.browser.view[view.browser.cursor]
|
|
} |