diff --git a/CHANGELOG.md b/CHANGELOG.md index cb658e7..3635ea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Enabled users to open MATLAB .fig files through the context menu - Enabled users to specify workspace-specific MATLAB install paths ### Fixed diff --git a/package.json b/package.json index 07110f4..d60a40d 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,10 @@ "command": "matlab.changeDirectory", "title": "MATLAB: Change current directory" }, + { + "command": "matlab.openFigure", + "title": "MATLAB: Open Figure" + }, { "command": "matlab.resetDeprecationPopups", "title": "MATLAB: Reset Deprecation Warning Popups" @@ -123,6 +127,10 @@ { "command": "matlab.changeDirectory", "when": "explorerResourceIsFolder" + }, + { + "command": "matlab.openFigure", + "when": "resourceExtname == .fig" } ] }, diff --git a/src/commandwindow/ExecutionCommandProvider.ts b/src/commandwindow/ExecutionCommandProvider.ts index 44b4748..8b50650 100644 --- a/src/commandwindow/ExecutionCommandProvider.ts +++ b/src/commandwindow/ExecutionCommandProvider.ts @@ -273,4 +273,29 @@ export default class ExecutionCommandProvider { void this._mvm.feval('cd', 0, [uri.fsPath]); } + + /** + * Implements the open figure action + * @param uri The file path to the figure that MATLAB should open + * @returns + */ + async handleOpenFigure(uri: vscode.Uri): Promise { + this._telemetryLogger.logEvent({ + eventKey: 'ML_VS_CODE_ACTIONS', + data: { + action_type: 'openFigure', + result: '' + } + }); + + await this._terminalService.openTerminalOrBringToFront(); + + try { + await this._mvm.getReadyPromise(); + } catch (e) { + return; + } + + void this._mvm.feval('openfig', 0, [uri.fsPath]); + } } diff --git a/src/extension.ts b/src/extension.ts index 6a8e305..24e8906 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -113,6 +113,7 @@ export async function activate (context: vscode.ExtensionContext): Promise context.subscriptions.push(vscode.commands.registerCommand('matlab.openCommandWindow', async () => await terminalService.openTerminalOrBringToFront())) context.subscriptions.push(vscode.commands.registerCommand('matlab.addToPath', async (uri: vscode.Uri) => await executionCommandProvider.handleAddToPath(uri))) context.subscriptions.push(vscode.commands.registerCommand('matlab.changeDirectory', async (uri: vscode.Uri) => await executionCommandProvider.handleChangeDirectory(uri))) + context.subscriptions.push(vscode.commands.registerCommand('matlab.openFigure', async (uri: vscode.Uri) => await executionCommandProvider.handleOpenFigure(uri))) deprecationPopupService = new DeprecationPopupService(context) deprecationPopupService.initialize(client)