mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
feature(dom) add extended selection (*, +, -)
This commit is contained in:
parent
a721932352
commit
6cb083f0a5
3 changed files with 119 additions and 1 deletions
3
HELP.md
3
HELP.md
|
|
@ -85,6 +85,9 @@ Hot keys
|
|||
- **F8, Delete** - remove current file
|
||||
- **F9** - menu
|
||||
- **F10** - config
|
||||
- **(*)** - select/unselect all
|
||||
- **(+)** - expand selection
|
||||
- **(-)** - shrink selection
|
||||
- **Ctrl + r** - reload dir content
|
||||
- **Ctrl + d** - clear local cache (wich contains dir contents)
|
||||
- **Alt + q** - disable key bindings
|
||||
|
|
|
|||
|
|
@ -647,6 +647,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
CurrentInfo = {},
|
||||
CURRENT_FILE = 'current-file',
|
||||
SELECTED_FILE = 'selected-file',
|
||||
SelectType = '*.*',
|
||||
Title;
|
||||
|
||||
/**
|
||||
|
|
@ -1155,8 +1156,10 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
return this;
|
||||
};
|
||||
|
||||
this.toggleAllSelectedFiles = function() {
|
||||
this.toggleAllSelectedFiles = function(pCurrent) {
|
||||
var i, n,
|
||||
isStr = Util.isString(pCurrent),
|
||||
lCurrent = !isStr && pCurrent || Cmd.getCurrentFile(),
|
||||
panel = DOM.getPanel(),
|
||||
files = DOM.getFiles(panel),
|
||||
name = DOM.getCurrentName(files[0]);
|
||||
|
|
@ -1173,6 +1176,102 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
return Cmd;
|
||||
};
|
||||
|
||||
function selectByPattern(msg, files) {
|
||||
var allMsg = 'Specify file type for ' + msg + ' selection',
|
||||
i = 0,
|
||||
n,
|
||||
arr = [],
|
||||
type,
|
||||
matches = 0,
|
||||
name,
|
||||
shouldSel = msg === 'expand',
|
||||
isSelected, isMatch,
|
||||
current;
|
||||
|
||||
type = Dialog.prompt(allMsg, SelectType);
|
||||
|
||||
if (type !== null) {
|
||||
SelectType = type;
|
||||
|
||||
/* if type empty - select all files */
|
||||
if (type === '')
|
||||
type = '*';
|
||||
|
||||
type = '^' + type; /* search from start of line */
|
||||
type = Util.replaceStr(type, '*', '.*\\');
|
||||
type = Util.replaceStr(type, '?', '.?\\');
|
||||
|
||||
arr = type && type.split('');
|
||||
n = arr.length;
|
||||
|
||||
/* back slash at end of line
|
||||
* do not need
|
||||
*/
|
||||
if (arr[n - 1] === '\\') {
|
||||
arr.pop();
|
||||
type = arr.join('');
|
||||
}
|
||||
|
||||
type += '$'; /* search to end of line */
|
||||
|
||||
n = files && files.length;
|
||||
do {
|
||||
if (shouldSel)
|
||||
current = files[i++];
|
||||
else
|
||||
/* selected files will decrement in
|
||||
* they own way
|
||||
*/
|
||||
current = files[i];
|
||||
|
||||
if (current) {
|
||||
name = DOM.getCurrentName(current);
|
||||
|
||||
if (name !== '..') {
|
||||
isMatch = name.match(new RegExp(type));
|
||||
|
||||
if (isMatch) {
|
||||
++matches;
|
||||
|
||||
isSelected = DOM.isSelected(current);
|
||||
|
||||
if (shouldSel)
|
||||
isSelected = !isSelected;
|
||||
|
||||
if (isSelected)
|
||||
DOM.toggleSelectedFile(current);
|
||||
} else if (!shouldSel)
|
||||
++i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} while (current);
|
||||
}
|
||||
|
||||
if (!matches)
|
||||
DOM.alert('No matches found!');
|
||||
}
|
||||
|
||||
/*
|
||||
* open dialog with expand selection
|
||||
*/
|
||||
this.expandSelection = function() {
|
||||
var msg = 'expand',
|
||||
files = CurrentInfo.files;
|
||||
|
||||
selectByPattern(msg, files);
|
||||
};
|
||||
|
||||
/*
|
||||
* open dialog with shrink selection
|
||||
*/
|
||||
this.shrinkSelection = function() {
|
||||
var msg = 'shrink',
|
||||
files = DOM.getSelectedFiles();
|
||||
|
||||
selectByPattern(msg, files);
|
||||
};
|
||||
|
||||
/**
|
||||
* setting history wrapper
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ var CloudCmd, Util, DOM;
|
|||
|
||||
Z : 90,
|
||||
|
||||
ASTERISK : 106,
|
||||
PLUS : 107,
|
||||
MINUS : 109,
|
||||
|
||||
F1 : 112,
|
||||
F2 : 113,
|
||||
F3 : 114,
|
||||
|
|
@ -207,6 +211,18 @@ var CloudCmd, Util, DOM;
|
|||
DOM.promptDeleteSelected(lCurrent);
|
||||
break;
|
||||
|
||||
case Key.ASTERISK:
|
||||
DOM.toggleAllSelectedFiles(lCurrent);
|
||||
break;
|
||||
|
||||
case Key.PLUS:
|
||||
DOM.expandSelection();
|
||||
break;
|
||||
|
||||
case Key.MINUS:
|
||||
DOM.shrinkSelection();
|
||||
break;
|
||||
|
||||
case Key.F1:
|
||||
Util.exec(CloudCmd.Help.show);
|
||||
DOM.preventDefault(pEvent);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue