Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
fix: the path of input file in command could include spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
seanwu1105 committed May 4, 2019
1 parent 5305ce3 commit bec856b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
### Added

* Button for `qmlscene` preview
* Enable/disable configuration

### Fixed

* Now, the path of input file could include spaces. (thanks to _Paolo (ZioLupo)_)

## 0.1.0

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"qtForPython.path.designer": {
"type": "string",
"default": "",
"markdownDescription": "The path of Qt Designer with CLI arguments to create and edit form (`*.ui`) files. For example, `/opt/Qt/5.12.0/gcc_64/bin/designer` in Linux or `C:\\Qt\\5.12.0\\mingw73_64\\bin\\designer.exe` in Windows."
"markdownDescription": "The path of Qt Designer with CLI arguments to create and edit form (`*.ui`) files. For example, `\"/opt/Qt/5.12.0/gcc_64/bin/designer\"` in Linux or `\"C:\\Qt\\5.12.0\\mingw73_64\\bin\\designer.exe\"` in Windows."
},
"qtForPython.path.pyuic": {
"type": "string",
Expand All @@ -158,17 +158,17 @@
"qtForPython.path.linguist": {
"type": "string",
"default": "",
"markdownDescription": "The path of Qt Linguist with CLI arguments to edit translation (`*.qt.ts`) files. For example, `/opt/Qt/5.12.0/gcc_64/bin/linguist` in Linux or `C:\\Qt\\5.12.0\\mingw73_64\\bin\\linguist.exe` in Windows."
"markdownDescription": "The path of Qt Linguist with CLI arguments to edit translation (`*.qt.ts`) files. For example, `\"/opt/Qt/5.12.0/gcc_64/bin/linguist\"` in Linux or `\"C:\\Qt\\5.12.0\\mingw73_64\\bin\\linguist.exe\"` in Windows."
},
"qtForPython.path.lrelease": {
"type": "string",
"default": "",
"markdownDescription": "The path of Qt lrelease with CLI arguments to edit translation (`*.qt.ts`) files. For example, `/opt/Qt/5.12.0/gcc_64/bin/lrelease -qm ./out.qm` in Linux or `C:\\Qt\\5.12.0\\mingw73_64\\bin\\lrelease.exe -qm .\\out.qm` in Windows."
"markdownDescription": "The path of Qt lrelease with CLI arguments to edit translation (`*.qt.ts`) files. For example, `\"/opt/Qt/5.12.0/gcc_64/bin/lrelease\" -qm ./out.qm` in Linux or `\"C:\\Qt\\5.12.0\\mingw73_64\\bin\\lrelease.exe\" -qm .\\out.qm` in Windows."
},
"qtForPython.path.qmlscene": {
"type": "string",
"default": "",
"markdownDescription": "The path of Qt QML Scene (`qmlscene`) with CLI arguments to preview QML (`*.qml`) files. For example, `/opt/Qt/5.12.0/gcc_64/bin/qmlscene --verbose` in Linux or `C:\\Qt\\5.12.0\\mingw73_64\\bin\\qmlscene.exe --verbose` in Windows."
"markdownDescription": "The path of Qt QML Scene (`qmlscene`) with CLI arguments to preview QML (`*.qml`) files. For example, `\"/opt/Qt/5.12.0/gcc_64/bin/qmlscene\" --verbose` in Linux or `\"C:\\Qt\\5.12.0\\mingw73_64\\bin\\qmlscene.exe\" --verbose` in Windows."
},
"qtForPython.path.pyrcc": {
"type": "string",
Expand Down
17 changes: 7 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function activate(context: vscode.ExtensionContext) {
// (console.error).
// This line of code will only be executed once when your extension is
// activated.
console.log('The extension "vscode-qt-for-python" is now active!')

outputChannel = vscode.window.createOutputChannel('Qt for Python')

Expand Down Expand Up @@ -56,25 +55,23 @@ export function activate(context: vscode.ExtensionContext) {
if (tsFileArg) {
// Remove "-ts ts-files" from toolPath.
toolPath = toolPath.replace(tsFileArgRegex, '')
console.log(tsFileArg)
console.log(toolPath)
if (fileUri) { // from explorer/context menus
// Move "-ts ts-files" behind the fileUri.
exec(`${toolPath} ${fileUri.fsPath} ${tsFileArg}`)
exec(`${toolPath} "${fileUri.fsPath}" ${tsFileArg}`)
} else { // from command palette
const activeTextEditor = vscode.window.activeTextEditor
if (activeTextEditor) {
const documentUri = activeTextEditor.document.uri
// Move "-ts ts-files" behind the fileUri.
exec(`${toolPath} ${documentUri.fsPath} ${tsFileArg}`)
exec(`${toolPath} "${documentUri.fsPath}" ${tsFileArg}`)
}
}
} else {
const response = await vscode.window.showErrorMessage(
'The output location of TS file is required. Add ' +
'"-ts ts-filename" to the path of pylupdate.',
'Setting'
)
)
if (response === 'Setting') {
vscode.commands.executeCommand('workbench.action.openSettings')
}
Expand Down Expand Up @@ -108,12 +105,12 @@ function useTool(id: string, name: string, targetUri: vscode.Uri) {
const toolPath = vscode.workspace.getConfiguration('qtForPython.path').get<string>(id)
if (toolPath) {
if (targetUri) { // from explorer/context menus
exec(`${toolPath} ${targetUri.fsPath}`)
exec(`${toolPath} "${targetUri.fsPath}"`)
} else { // from command palette
const activeTextEditor = vscode.window.activeTextEditor
if (activeTextEditor) {
const documentUri = activeTextEditor.document.uri
exec(`${toolPath} ${documentUri.fsPath}`)
exec(`${toolPath} "${documentUri.fsPath}"`)
}
}
} else { showPathNotExist(name) }
Expand All @@ -130,10 +127,10 @@ async function showPathNotExist(name: string) {
}
}

async function exec(file: string, options = { cwd: rootPath }) {
async function exec(command: string, options = { cwd: rootPath }) {
let output
try {
output = await util.promisify(child_process.exec)(file, options)
output = await util.promisify(child_process.exec)(command, options)
} catch (err) {
vscode.window.showErrorMessage(err.message)
outputChannel.appendLine(`[ERROR] ${err.message}`)
Expand Down

0 comments on commit bec856b

Please sign in to comment.