Handling file opening (#329)
* Add function to escape a shell argument. * Keep track of the last used window. * Implement support for the open-file event. * The shell escape regex needs parentheses to be captured. * Removed lastWindow and added getLastFocusedWindow method to app * Create window create new session only if no callback passed * Added app.windowCallback to handle open-file before "ready" * Small lint fixes * Differeent open file handling: check if it is directory, and if the file is executale or not * Small fixed and added some comments * Added php-escape-shell module in place of custom escapeShellArgument() * Fixed wrong code and added detailed comment * Aliased php_escapeshellcmd import * Rebased; added error handling in OpenFile * changed string contatenation with template literal * Pinned php-escape-shell dependency * Typo fix * getLastdFocusedWindow now uses Array.prototype.reduce() * Notify users of unexisting path while open file
This commit is contained in:
parent
3198a90823
commit
7e941b0451
9 changed files with 106 additions and 14 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import * as shellEscape from 'php-escape-shell';
|
||||
import { setActiveSession } from './sessions';
|
||||
import { keys } from '../utils/object';
|
||||
import { last } from '../utils/array';
|
||||
import { isExecutable } from '../utils/file';
|
||||
import notify from '../utils/notify';
|
||||
import rpc from '../rpc';
|
||||
import {
|
||||
requestSession,
|
||||
|
|
@ -16,9 +19,12 @@ import {
|
|||
UI_MOVE_RIGHT,
|
||||
UI_MOVE_TO,
|
||||
UI_SHOW_PREFERENCES,
|
||||
UI_WINDOW_MOVE
|
||||
UI_WINDOW_MOVE,
|
||||
UI_OPEN_FILE
|
||||
} from '../constants/ui';
|
||||
|
||||
const { stat } = window.require('fs');
|
||||
|
||||
export function increaseFontSize () {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({
|
||||
|
|
@ -172,3 +178,35 @@ export function windowMove () {
|
|||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function openFile (path) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch({
|
||||
type: UI_OPEN_FILE,
|
||||
effect () {
|
||||
stat(path, (err, stats) => {
|
||||
if (err) {
|
||||
console.error(err.stack);
|
||||
notify('Unable to open path', `"${path}" doesn't exist.`);
|
||||
} else {
|
||||
// We need to use 'php-escape-shell' property this way
|
||||
// until this eslint issue will be fixed:
|
||||
// https://github.com/eslint/eslint/issues/6755
|
||||
let command = shellEscape.php_escapeshellcmd(path);
|
||||
if (stats.isDirectory()) {
|
||||
command = `cd ${command}\n`;
|
||||
} else if (stats.isFile() && isExecutable(stats)) {
|
||||
command += '\n';
|
||||
}
|
||||
rpc.once('session add', ({ uid }) => {
|
||||
rpc.once('session data', () => {
|
||||
dispatch(sendSessionData(uid, command));
|
||||
});
|
||||
});
|
||||
}
|
||||
dispatch(requestSession());
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue