file: extension can now be an array of strings

This commit is contained in:
jean-emmanuel 2025-03-10 19:55:07 +01:00
parent f31cc2091c
commit 395d4786c4
2 changed files with 11 additions and 3 deletions

View file

@ -10,7 +10,8 @@
- eq: add support for n-poles lowpass and highpass filters with the filter's `poles` property
- eq: adapt sampling frequency to the x-axis range
- xy/multixy: add `auto` choice to to `axisLock` (locks on the first moved axis)
- file: `extension` can now be an array of strings
## 1.27.5
- bug fixes
@ -18,6 +19,7 @@
- widget: regression causing error when emptying the css property and leaving only class declarations
- modal: incorrect position in scrolled containers when `relative` is `true`
- menu: incorrect position in scrlled containers depending on menu's alignment
- button: `locals.touchCoords` not updated upon release and incorrect when `doubleTap` is set
## 1.27.4

View file

@ -21,7 +21,7 @@ module.exports = class File extends Widget {
},
class_specific: {
directory: {type: 'string', value: 'auto', help: 'Default browsing directory'},
extension: {type: 'string', value: '*', help: 'Only display files with this extension'},
extension: {type: 'string|array', value: '*', help: 'Only display files with this extension. Multiple extensions can be specified with an array of strings (`["jpg", "jpeg"]`)'},
allowDir: {type: 'boolean', value: false, help: 'Allow selecting a folder (by pressing "open" when no file is selected)'}
}
})
@ -43,12 +43,18 @@ module.exports = class File extends Widget {
if (this.getProp('hidePath')) this.widget.classList.add('hide-path')
this.text = DOM.get(this.widget, '.text')[0]
var ext = this.getProp('extension')
if (Array.isArray(ext)) {
ext = '(' + ext.join('|') + ')'
}
this.on('fast-click', (e)=>{
if (e.capturedByEditor === true) return
uiFilebrowser({
extension: this.getProp('extension').replace(/^\.?(.*)$/, '$1'),
extension: ext.replace(/^\.?(.*)$/, '$1'),
directory: this.getProp('directory') === 'auto' ? undefined : this.getProp('directory'),
loadDir: this.getProp('allowDir'),
save: this.getProp('mode') === 'save'