feature(user-menu) add (#221) · codecopy/cloudcmd@eb4f7c0 · GitHub
Skip to content

Commit eb4f7c0

Browse files
committed
feature(user-menu) add (coderaiser#221)
1 parent f60af28 commit eb4f7c0

34 files changed

Lines changed: 562 additions & 41 deletions

.cloudcmd.menu.js

Lines changed: 25 additions & 0 deletions

.webpack/css.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const cssNames = [
2121
'view',
2222
'config',
2323
'terminal',
24+
'user-menu',
2425
...getCSSList('columns'),
2526
];
2627

@@ -35,7 +36,7 @@ const plugins = clean([
3536

3637
const rules = [{
3738
test: /\.css$/,
38-
exclude: /css\/(nojs|view|config|terminal|columns.*)\.css/,
39+
exclude: /css\/(nojs|view|config|terminal|user-menu|columns.*)\.css/,
3940
use: extractMain.extract([
4041
'css-loader',
4142
]),

.webpack/js.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const babelDev = {
3232
babelrc: false,
3333
plugins: [
3434
'module:babel-plugin-macros',
35-
'@babel/plugin-proposal-object-rest-spread',
3635
],
3736
};
3837

@@ -43,7 +42,7 @@ const rules = clean([
4342
loader: 'babel-loader',
4443
},
4544
isDev && {
46-
test: /sw\.js$/,
45+
test: /\.js$/,
4746
exclude: /node_modules/,
4847
loader: 'babel-loader',
4948
options: babelDev,
@@ -90,7 +89,9 @@ module.exports = {
9089
[modules + '/operation']: `${dirModules}/operation/index.js`,
9190
[modules + '/konsole']: `${dirModules}/konsole.js`,
9291
[modules + '/terminal']: `${dirModules}/terminal.js`,
92+
[modules + '/terminal-run']: `${dirModules}/terminal-run.js`,
9393
[modules + '/cloud']: `${dirModules}/cloud.js`,
94+
[modules + '/user-menu']: `${dirModules}/user-menu/index.js`,
9495
[modules + '/polyfill']: `${dirModules}/polyfill.js`,
9596
},
9697
output: {

.yaspellerrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
".md"
1111
],
1212
"dictionary":[
13+
"CloudCmd",
1314
"Dev",
1415
"Dropbox",
1516
"Deepword",
@@ -27,12 +28,14 @@
2728
"Zalitok",
2829
"WebSocket",
2930
"auth",
31+
"binded",
3032
"cd",
3133
"cloudcmd",
3234
"coderaiser",
3335
"com",
34-
"dev",
3536
"deepword",
37+
"dev",
38+
"destructuring",
3639
"dropbox",
3740
"dword",
3841
"edward",

HELP.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Cloud Commander supports the following command-line parameters:
109109
| `--dropbox` | enable dropbox integration
110110
| `--dropbox-token` | set dropbox token
111111
| `--log` | enable logging
112+
| `--user-menu` | enable user menu
112113
| `--no-show-config` | do not show config values
113114
| `--no-server` | do not start server
114115
| `--no-auth` | disable authorization
@@ -137,6 +138,7 @@ Cloud Commander supports the following command-line parameters:
137138
| `--no-dropbox` | disable dropbox integration
138139
| `--no-dropbox-token` | unset dropbox token
139140
| `--no-log` | disable logging
141+
| `--no-user-menu` | disable user menu
140142

141143
For options not specified by command-line parameters, Cloud Commander then reads configuration data from `~/.cloudcmd.json`. It uses port `8000` by default.
142144

@@ -162,7 +164,7 @@ Hot keys
162164
|Key |Operation
163165
|:----------------------|:--------------------------------------------
164166
| `F1` | help
165-
| `F2` | rename
167+
| `F2` | rename or show `user menu`
166168
| `F3` | view, change directory
167169
| `Shift + F3` | view as markdown
168170
| `F4` | edit
@@ -421,7 +423,8 @@ Here's a description of all options:
421423
"importListen" : false, // listen on config updates
422424
"dropbox" : false, // disable dropbox integration
423425
"dropboxToken" : "", // unset dropbox token
424-
"log" : true // logging
426+
"log" : true, // logging
427+
"userMenu" : false // do not show user menu
425428
}
426429
```
427430

@@ -458,6 +461,52 @@ Some config options can be overridden with environment variables, such as:
458461
- `CLOUDCMD_IMPORT_TOKEN` - authorization token used to connect to export server
459462
- `CLOUDCMD_IMPORT_URL` - url of an import server
460463
- `CLOUDCMD_IMPORT_LISTEN`- enable listen on config updates from import server
464+
- `CLOUDCMD_USER_MENU`- enable `user menu`
465+
466+
### User Menu
467+
468+
You can enable `user menu` with help of a flag `--user-menu` (consider that file rename using `F2` will be disabled).
469+
When you press `F2` Cloud Commander will a file `.cloudcmd.menu.js` by walking up parent directories, if can't read it will try to read `~/.cloudcmd.menu.js`.
470+
Let's consider example `user menu` works file:
471+
472+
```js
473+
module.exports = {
474+
'F2 - Rename file': async ({DOM}) => {
475+
await DOM.renameCurrent();
476+
},
477+
'D - Build Dev': async ({CloudCmd}) => {
478+
await CloudCmd.TerminalRun.show({
479+
command: 'npm run build:client:dev',
480+
autoClose: false,
481+
closeMessage: 'Press any button to close Terminal',
482+
});
483+
484+
CloudCmd.refresh();
485+
},
486+
'P - Build Prod': async ({CloudCmd}) => {
487+
await CloudCmd.TerminalRun.show({
488+
command: 'npm run build:client',
489+
autoClose: true,
490+
});
491+
492+
CloudCmd.refresh();
493+
},
494+
};
495+
```
496+
497+
You will have ability to run one of this 3 commands with help of double click, enter, or binded key (`F2`, `D` or `P` in this example). Also you can run commands in terminal, or execute any built-in function of `Cloud Commander` extended it's interface.
498+
499+
#### User Menu API
500+
501+
Here you can find `API` that can be used in **User Menu**. **DOM** and **CloudCmd** to main objects you receive in arguments list using destructuring.
502+
503+
**DOM** contains all base functions of `Cloud Commander` (rename, remove, download etc);
504+
505+
- `renameCurrent` - shows renames current file dialog, and does renaming.
506+
507+
**CloudCmd** contains all modules (`Terminal`, `View`, `Edit`, `Config`, `Console` etc);
508+
509+
- `TerminalRun` - module that shows `Terminal` with a `command` from options and closes terminal when everything is done.
461510

462511
### Distribute
463512

bin/cloudcmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const args = require('minimist')(argv.slice(2), {
7373
'import-listen',
7474
'log',
7575
'dropbox',
76+
'user-menu',
7677
],
7778
default: {
7879
server : true,
@@ -111,6 +112,7 @@ const args = require('minimist')(argv.slice(2), {
111112
'one-file-panel': choose(env.bool('one_file_panel'), config('oneFilePanel')),
112113
'confirm-copy': choose(env.bool('confirm_copy'), config('confirmCopy')),
113114
'confirm-move': choose(env.bool('confirm_move'), config('confirmMove')),
115+
'user-menu': choose(env.bool('user_menu'), config('userMenu')),
114116
'keys-panel': env.bool('keys_panel') || config('keysPanel'),
115117
'import-token': env('import_token') || config('importToken'),
116118
'export-token': env('export_token') || config('exportToken'),
@@ -180,6 +182,7 @@ function main() {
180182
config('importToken', args['import-token']);
181183
config('importListen', args['import-listen']);
182184
config('importUrl', args['import-url']);
185+
config('userMenu', args['user-menu']);
183186

184187
config('dropbox', args['dropbox']);
185188
config('dropboxToken', args['dropbox-token'] || '');

client/dom/index.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
const itype = require('itype/legacy');
66
const exec = require('execon');
77
const jonny = require('jonny/legacy');
8+
const tryToCatch = require('try-to-catch/legacy');
9+
810
const Util = require('../../common/util');
911

1012
const Images = require('./images');
@@ -746,7 +748,7 @@ function CmdProto() {
746748
*
747749
* @currentFile
748750
*/
749-
this.renameCurrent = (current) => {
751+
this.renameCurrent = async (current) => {
750752
const {Dialog} = DOM;
751753

752754
if (!DOM.isCurrentFile(current))
@@ -757,30 +759,30 @@ function CmdProto() {
757759
if (from === '..')
758760
return Dialog.alert.noFiles();
759761

760-
const cancel = false;
762+
const [e, to] = await tryToCatch(Dialog.prompt, 'Rename', from);
761763

762-
Dialog.prompt('Rename', from, {cancel}).then((to) => {
763-
const isExist = !!DOM.getCurrentByName(to);
764-
const dirPath = DOM.getCurrentDirPath();
765-
766-
if (from === to)
764+
if (e)
765+
return;
766+
const isExist = !!DOM.getCurrentByName(to);
767+
const dirPath = DOM.getCurrentDirPath();
768+
769+
if (from === to)
770+
return;
771+
772+
const files = {
773+
from : dirPath + from,
774+
to : dirPath + to,
775+
};
776+
777+
RESTful.mv(files, (error) => {
778+
if (error)
767779
return;
768780

769-
const files = {
770-
from : dirPath + from,
771-
to : dirPath + to,
772-
};
781+
DOM.setCurrentName(to, current);
782+
Storage.remove(dirPath);
773783

774-
RESTful.mv(files, (error) => {
775-
if (error)
776-
return;
777-
778-
DOM.setCurrentName(to, current);
779-
Storage.remove(dirPath);
780-
781-
if (isExist)
782-
CloudCmd.refresh();
783-
});
784+
if (isExist)
785+
CloudCmd.refresh();
784786
});
785787
};
786788

@@ -940,7 +942,7 @@ function CmdProto() {
940942
const info = DOM.CurrentInfo;
941943
const current = currentFile || DOM.getCurrentFile();
942944
const files = current.parentElement;
943-
const panel = files.parentElement;
945+
const panel = files.parentElement || DOM.getPanel();
944946

945947
const panelPassive = DOM.getPanel({
946948
active: false,

client/key/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ function KeyProto() {
186186
break;
187187

188188
case Key.F2:
189+
if (CloudCmd.config('userMenu'))
190+
return CloudCmd.UserMenu.show();
191+
189192
DOM.renameCurrent(current);
190193
break;
191194

client/listeners/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module.exports.initKeysPanel = () => {
123123

124124
const clickFuncs = {
125125
'f1' : CloudCmd.Help.show,
126-
'f2' : DOM.renameCurrent,
126+
'f2' : initF2,
127127
'f3' : CloudCmd.View.show,
128128
'f4' : CloudCmd.EditFile.show,
129129
'f5' : operation('copy'),
@@ -141,6 +141,13 @@ module.exports.initKeysPanel = () => {
141141
});
142142
};
143143

144+
function initF2() {
145+
if (CloudCmd.config('userMenu'))
146+
return CloudCmd.UserMenu.show();
147+
148+
return DOM.renameCurrent();
149+
}
150+
144151
const getPanel = (side) => {
145152
if (!itype.string(side))
146153
return side;

client/modules/operation/set-listeners.js

Lines changed: 0 additions & 1 deletion

0 commit comments

Comments
 (0)