remote-browse: allow passing initial directory

widgets: add file widget
This commit is contained in:
jean-emmanuel 2019-04-02 11:23:06 +02:00
parent 4e6a7b36ba
commit 4834cd653b
4 changed files with 85 additions and 2 deletions

View file

@ -309,7 +309,7 @@ module.exports = {
document.removeEventListener('keydown', keyHandler)
})
ipc.send('listDir', {})
ipc.send('listDir', {path: [options.directory]})
}

View file

@ -58,6 +58,7 @@ module.exports.widgets = {
keys: require('./inputs/keys'),
script: require('./inputs/script'),
gyroscope: require('./inputs/gyroscope'),
file: require('./inputs/file'),
// maths
// deprecated / hidden
@ -73,5 +74,5 @@ module.exports.categories = {
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'frame'],
'Containers':['panel','strip','modal', 'clone'],
'Switchers':['switcher','crossfader'],
'Inputs':['input', 'keys', 'script', 'gyroscope']
'Inputs':['input', 'keys', 'script', 'gyroscope', 'file']
}

View file

@ -0,0 +1,63 @@
var Widget = require('../common/widget'),
html = require('nanohtml'),
{remoteBrowse} = require('../../ui/utils')
module.exports = class Input extends Widget {
static defaults() {
return super.defaults({
_input:'input',
directory: {type: 'string', value: 'auto', help: 'Default browsing directory'},
extension: {type: 'string', value: '*', help: 'Only display files with this extension'},
hidePath: {type: 'boolean', value: false, help: 'Set to `true` to only display the filename (the whole path will still be used as value)'}
})
}
constructor(options) {
super({...options, html: html`
<div class="file btn"><span></span></div>
`})
this.text = this.widget.firstChild
this.widget.addEventListener('fast-click', (e)=>{
if (e.capturedByEditor === true) return
remoteBrowse({
extension: this.getProp('extension').replace(/^\.?(.*)$/, '$1'),
directory: this.getProp('directory') === 'auto' ? undefined : this.getProp('directory')
}, (path)=>{
this.setValue(path.join(path[0][0] === '/' ? '/' : '\\'), {
sync: true,
send: true
})
})
})
}
setValue(v, options={}) {
this.value = v
this.text.textContent = this.getProp('hidePath') ?
v.split(v[0] === '/' ? '/' : '\\').pop() : v
if (options.send) this.sendValue()
if (options.sync) this.changed(options)
}
}