Skip to content

Commit 50dcd07

Browse files
authored
Merge pull request #188 from Gusmano-2-OSU/openMatlabFiles
Opening figures, simulink models, etc. in VS Code
2 parents 1046abf + f22b1f3 commit 50dcd07

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Open non-code MATLAB files (e.g. `.slx`, `.fig`) via the context menu
12+
1013
## [1.2.7] - 2024-11-07
1114

1215
### Added

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
"command": "matlab.enableSignIn",
6666
"title": "MATLAB: Manage Sign In Options"
6767
},
68+
{
69+
"command": "matlab.openFile",
70+
"title": "MATLAB: Open File"
71+
},
6872
{
6973
"command": "matlab.resetDeprecationPopups",
7074
"title": "MATLAB: Reset Deprecation Warning Popups"
@@ -135,6 +139,11 @@
135139
{
136140
"command": "matlab.changeDirectory",
137141
"when": "explorerResourceIsFolder"
142+
},
143+
{
144+
"command": "matlab.openFile",
145+
"when": "!explorerResourceIsFolder",
146+
"group": "files"
138147
}
139148
],
140149
"matlab.addPath": [

server

Submodule server updated 107 files

src/commandwindow/ExecutionCommandProvider.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,29 @@ export default class ExecutionCommandProvider {
297297

298298
void this._mvm.feval('cd', 0, [uri.fsPath]);
299299
}
300+
301+
/**
302+
* Implements the open file action
303+
* @param uri The file path to the file that should be opened
304+
* @returns
305+
*/
306+
async handleOpenFile (uri: vscode.Uri): Promise<void> {
307+
this._telemetryLogger.logEvent({
308+
eventKey: 'ML_VS_CODE_ACTIONS',
309+
data: {
310+
action_type: 'openFile',
311+
result: ''
312+
}
313+
});
314+
315+
await this._terminalService.openTerminalOrBringToFront();
316+
317+
try {
318+
await this._mvm.getReadyPromise();
319+
} catch (e) {
320+
return;
321+
}
322+
323+
void this._mvm.feval('open', 0, [uri.fsPath]);
324+
}
300325
}

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export async function activate (context: vscode.ExtensionContext): Promise<void>
129129
context.subscriptions.push(vscode.commands.registerCommand('matlab.addFolderToPath', async (uri: vscode.Uri) => await executionCommandProvider.handleAddFolderToPath(uri)))
130130
context.subscriptions.push(vscode.commands.registerCommand('matlab.addFolderAndSubfoldersToPath', async (uri: vscode.Uri) => await executionCommandProvider.handleAddFolderAndSubfoldersToPath(uri)))
131131
context.subscriptions.push(vscode.commands.registerCommand('matlab.changeDirectory', async (uri: vscode.Uri) => await executionCommandProvider.handleChangeDirectory(uri)))
132+
context.subscriptions.push(vscode.commands.registerCommand('matlab.openFile', async (uri: vscode.Uri) => await executionCommandProvider.handleOpenFile(uri)))
132133

133134
// Register a custom command which allows the user enable / disable Sign In options.
134135
// Using this custom command would be an alternative approach to going to enabling the setting.

0 commit comments

Comments
 (0)