Skip to content

Commit

Permalink
feature(user-menu) add (coderaiser#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 13, 2019
1 parent f60af28 commit eb4f7c0
Show file tree
Hide file tree
Showing 34 changed files with 562 additions and 41 deletions.
25 changes: 25 additions & 0 deletions .cloudcmd.menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

module.exports = {
'F2 - Rename file': async ({DOM}) => {
await DOM.renameCurrent();
},
'D - Build Dev': async ({CloudCmd}) => {
await CloudCmd.TerminalRun.show({
command: 'npm run build:client:dev',
autoClose: false,
closeMessage: 'Press any button to close Terminal',
});

CloudCmd.refresh();
},
'P - Build Prod': async ({CloudCmd}) => {
await CloudCmd.TerminalRun.show({
command: 'npm run build:client',
autoClose: true,
});

CloudCmd.refresh();
},
};

3 changes: 2 additions & 1 deletion .webpack/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const cssNames = [
'view',
'config',
'terminal',
'user-menu',
...getCSSList('columns'),
];

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

const rules = [{
test: /\.css$/,
exclude: /css\/(nojs|view|config|terminal|columns.*)\.css/,
exclude: /css\/(nojs|view|config|terminal|user-menu|columns.*)\.css/,
use: extractMain.extract([
'css-loader',
]),
Expand Down
5 changes: 3 additions & 2 deletions .webpack/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const babelDev = {
babelrc: false,
plugins: [
'module:babel-plugin-macros',
'@babel/plugin-proposal-object-rest-spread',
],
};

Expand All @@ -43,7 +42,7 @@ const rules = clean([
loader: 'babel-loader',
},
isDev && {
test: /sw\.js$/,
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: babelDev,
Expand Down Expand Up @@ -90,7 +89,9 @@ module.exports = {
[modules + '/operation']: `${dirModules}/operation/index.js`,
[modules + '/konsole']: `${dirModules}/konsole.js`,
[modules + '/terminal']: `${dirModules}/terminal.js`,
[modules + '/terminal-run']: `${dirModules}/terminal-run.js`,
[modules + '/cloud']: `${dirModules}/cloud.js`,
[modules + '/user-menu']: `${dirModules}/user-menu/index.js`,
[modules + '/polyfill']: `${dirModules}/polyfill.js`,
},
output: {
Expand Down
5 changes: 4 additions & 1 deletion .yaspellerrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
".md"
],
"dictionary":[
"CloudCmd",
"Dev",
"Dropbox",
"Deepword",
Expand All @@ -27,12 +28,14 @@
"Zalitok",
"WebSocket",
"auth",
"binded",
"cd",
"cloudcmd",
"coderaiser",
"com",
"dev",
"deepword",
"dev",
"destructuring",
"dropbox",
"dword",
"edward",
Expand Down
53 changes: 51 additions & 2 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Cloud Commander supports the following command-line parameters:
| `--dropbox` | enable dropbox integration
| `--dropbox-token` | set dropbox token
| `--log` | enable logging
| `--user-menu` | enable user menu
| `--no-show-config` | do not show config values
| `--no-server` | do not start server
| `--no-auth` | disable authorization
Expand Down Expand Up @@ -137,6 +138,7 @@ Cloud Commander supports the following command-line parameters:
| `--no-dropbox` | disable dropbox integration
| `--no-dropbox-token` | unset dropbox token
| `--no-log` | disable logging
| `--no-user-menu` | disable user menu

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

Expand All @@ -162,7 +164,7 @@ Hot keys
|Key |Operation
|:----------------------|:--------------------------------------------
| `F1` | help
| `F2` | rename
| `F2` | rename or show `user menu`
| `F3` | view, change directory
| `Shift + F3` | view as markdown
| `F4` | edit
Expand Down Expand Up @@ -421,7 +423,8 @@ Here's a description of all options:
"importListen" : false, // listen on config updates
"dropbox" : false, // disable dropbox integration
"dropboxToken" : "", // unset dropbox token
"log" : true // logging
"log" : true, // logging
"userMenu" : false // do not show user menu
}
```

Expand Down Expand Up @@ -458,6 +461,52 @@ Some config options can be overridden with environment variables, such as:
- `CLOUDCMD_IMPORT_TOKEN` - authorization token used to connect to export server
- `CLOUDCMD_IMPORT_URL` - url of an import server
- `CLOUDCMD_IMPORT_LISTEN`- enable listen on config updates from import server
- `CLOUDCMD_USER_MENU`- enable `user menu`

### User Menu

You can enable `user menu` with help of a flag `--user-menu` (consider that file rename using `F2` will be disabled).
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`.
Let's consider example `user menu` works file:

```js
module.exports = {
'F2 - Rename file': async ({DOM}) => {
await DOM.renameCurrent();
},
'D - Build Dev': async ({CloudCmd}) => {
await CloudCmd.TerminalRun.show({
command: 'npm run build:client:dev',
autoClose: false,
closeMessage: 'Press any button to close Terminal',
});

CloudCmd.refresh();
},
'P - Build Prod': async ({CloudCmd}) => {
await CloudCmd.TerminalRun.show({
command: 'npm run build:client',
autoClose: true,
});

CloudCmd.refresh();
},
};
```

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.

#### User Menu API

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.

**DOM** contains all base functions of `Cloud Commander` (rename, remove, download etc);

- `renameCurrent` - shows renames current file dialog, and does renaming.

**CloudCmd** contains all modules (`Terminal`, `View`, `Edit`, `Config`, `Console` etc);

- `TerminalRun` - module that shows `Terminal` with a `command` from options and closes terminal when everything is done.

### Distribute

Expand Down
3 changes: 3 additions & 0 deletions bin/cloudcmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const args = require('minimist')(argv.slice(2), {
'import-listen',
'log',
'dropbox',
'user-menu',
],
default: {
server : true,
Expand Down Expand Up @@ -111,6 +112,7 @@ const args = require('minimist')(argv.slice(2), {
'one-file-panel': choose(env.bool('one_file_panel'), config('oneFilePanel')),
'confirm-copy': choose(env.bool('confirm_copy'), config('confirmCopy')),
'confirm-move': choose(env.bool('confirm_move'), config('confirmMove')),
'user-menu': choose(env.bool('user_menu'), config('userMenu')),
'keys-panel': env.bool('keys_panel') || config('keysPanel'),
'import-token': env('import_token') || config('importToken'),
'export-token': env('export_token') || config('exportToken'),
Expand Down Expand Up @@ -180,6 +182,7 @@ function main() {
config('importToken', args['import-token']);
config('importListen', args['import-listen']);
config('importUrl', args['import-url']);
config('userMenu', args['user-menu']);

config('dropbox', args['dropbox']);
config('dropboxToken', args['dropbox-token'] || '');
Expand Down
46 changes: 24 additions & 22 deletions client/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
const itype = require('itype/legacy');
const exec = require('execon');
const jonny = require('jonny/legacy');
const tryToCatch = require('try-to-catch/legacy');

const Util = require('../../common/util');

const Images = require('./images');
Expand Down Expand Up @@ -746,7 +748,7 @@ function CmdProto() {
*
* @currentFile
*/
this.renameCurrent = (current) => {
this.renameCurrent = async (current) => {
const {Dialog} = DOM;

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

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

Dialog.prompt('Rename', from, {cancel}).then((to) => {
const isExist = !!DOM.getCurrentByName(to);
const dirPath = DOM.getCurrentDirPath();

if (from === to)
if (e)
return;
const isExist = !!DOM.getCurrentByName(to);
const dirPath = DOM.getCurrentDirPath();

if (from === to)
return;

const files = {
from : dirPath + from,
to : dirPath + to,
};

RESTful.mv(files, (error) => {
if (error)
return;

const files = {
from : dirPath + from,
to : dirPath + to,
};
DOM.setCurrentName(to, current);
Storage.remove(dirPath);

RESTful.mv(files, (error) => {
if (error)
return;

DOM.setCurrentName(to, current);
Storage.remove(dirPath);

if (isExist)
CloudCmd.refresh();
});
if (isExist)
CloudCmd.refresh();
});
};

Expand Down Expand Up @@ -940,7 +942,7 @@ function CmdProto() {
const info = DOM.CurrentInfo;
const current = currentFile || DOM.getCurrentFile();
const files = current.parentElement;
const panel = files.parentElement;
const panel = files.parentElement || DOM.getPanel();

const panelPassive = DOM.getPanel({
active: false,
Expand Down
3 changes: 3 additions & 0 deletions client/key/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ function KeyProto() {
break;

case Key.F2:
if (CloudCmd.config('userMenu'))
return CloudCmd.UserMenu.show();

DOM.renameCurrent(current);
break;

Expand Down
9 changes: 8 additions & 1 deletion client/listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ module.exports.initKeysPanel = () => {

const clickFuncs = {
'f1' : CloudCmd.Help.show,
'f2' : DOM.renameCurrent,
'f2' : initF2,
'f3' : CloudCmd.View.show,
'f4' : CloudCmd.EditFile.show,
'f5' : operation('copy'),
Expand All @@ -141,6 +141,13 @@ module.exports.initKeysPanel = () => {
});
};

function initF2() {
if (CloudCmd.config('userMenu'))
return CloudCmd.UserMenu.show();

return DOM.renameCurrent();
}

const getPanel = (side) => {
if (!itype.string(side))
return side;
Expand Down
1 change: 0 additions & 1 deletion client/modules/operation/set-listeners.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

/* global DOM */
/* global CloudCmd */

const {
Dialog,
Expand Down
Loading

0 comments on commit eb4f7c0

Please sign in to comment.