cloudcmd/client/dom/select-by-pattern.js
2019-05-22 12:26:21 +03:00

48 lines
1,022 B
JavaScript

'use strict';
let SelectType = '*.*';
const {getRegExp} = require('../../common/util');
const {
alert,
prompt,
} = require('./dialog');
const {DOM} = require('.');
module.exports = async (msg, files) => {
if (!files)
return;
const allMsg = `Specify file type for ${msg} selection`;
const type = await prompt(allMsg, SelectType);
/* eslint require-atomic-updates: 0 */
SelectType = type;
const regExp = getRegExp(type);
let matches = 0;
for (const current of files) {
const name = DOM.getCurrentName(current);
if (name === '..' || !regExp.test(name))
continue;
++matches;
let isSelected = DOM.isSelected(current);
const shouldSel = msg === 'expand';
if (shouldSel)
isSelected = !isSelected;
if (isSelected)
DOM.toggleSelectedFile(current);
}
if (!matches)
alert('No matches found!');
};