remote-browse: allow passing initial directory
widgets: add file widget
This commit is contained in:
parent
283f9074bc
commit
a72550164d
4 changed files with 85 additions and 2 deletions
|
|
@ -309,7 +309,7 @@ module.exports = {
|
|||
document.removeEventListener('keydown', keyHandler)
|
||||
})
|
||||
|
||||
ipc.send('listDir', {})
|
||||
ipc.send('listDir', {path: [options.directory]})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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']
|
||||
}
|
||||
|
|
|
|||
63
src/client/app/widgets/inputs/file.js
Normal file
63
src/client/app/widgets/inputs/file.js
Normal 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)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -204,3 +204,22 @@
|
|||
border: 1rem solid var(--color-bg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.file-container {
|
||||
width: 100rem;
|
||||
height:60rem;
|
||||
.file {
|
||||
flex: 1 1 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 10rem;
|
||||
text-transform: none;
|
||||
span {
|
||||
pointer-events: none;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue