Skip to content

Commit

Permalink
Avoid closing IDE accidentally
Browse files Browse the repository at this point in the history
  • Loading branch information
kewinzaq1 committed Jun 26, 2024
1 parent e44e639 commit 53adfad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
"command": "RNIDE.openDevMenu",
"key": "ctrl+alt+z",
"mac": "ctrl+cmd+z"
},
{
"command": "RNIDE.closeWithConfirmation",
"key": "ctrl+w",
"mac": "cmd+w",
"when": "RNIDE.isTabPanelFocused"
}
],
"configuration": {
Expand Down
13 changes: 13 additions & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ export async function activate(context: ExtensionContext) {
}
}

function closeWithConfirmation() {
window
.showWarningMessage("Are you sure you want to close the IDE panel?", "Yes", "No")
.then((item) => {
if (item === "Yes") {
commands.executeCommand("RNIDE.closePanel");
}
});
}

context.subscriptions.push(
window.registerWebviewViewProvider(
SidePanelViewProvider.viewType,
Expand All @@ -119,6 +129,9 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand("RNIDE.closePanel", closeIDEPanel));
context.subscriptions.push(commands.registerCommand("RNIDE.openPanel", showIDEPanel));
context.subscriptions.push(commands.registerCommand("RNIDE.showPanel", showIDEPanel));
context.subscriptions.push(
commands.registerCommand("RNIDE.closeWithConfirmation", closeWithConfirmation)
);
context.subscriptions.push(
commands.registerCommand("RNIDE.diagnose", diagnoseWorkspaceStructure)
);
Expand Down
15 changes: 14 additions & 1 deletion packages/vscode-extension/src/panels/Tabpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ export class TabPanel implements Disposable {
public static currentPanel: TabPanel | undefined;
private readonly _panel: WebviewPanel;
private webviewController: WebviewController;
private changeViewStateDisposable: Disposable;

private constructor(panel: WebviewPanel, context: ExtensionContext) {
this._panel = panel;
this._panel.iconPath = Uri.joinPath(context.extensionUri, "assets", "logo.svg");
// Set an event listener to listen for when the panel is disposed (i.e. when the user closes
// the panel or when the panel is closed programmatically)
this._panel.onDidDispose(() => this.dispose());

commands.executeCommand("setContext", "RNIDE.isTabPanelFocused", this._panel.active);

this.changeViewStateDisposable = this._panel.onDidChangeViewState((e) => {
commands.executeCommand("setContext", "RNIDE.isTabPanelFocused", this._panel.active);
});

this._panel.onDidDispose(() => {
this.dispose();
});

// Set the HTML content for the webview panel
this._panel.webview.html = generateWebviewContent(
Expand Down Expand Up @@ -89,6 +99,9 @@ export class TabPanel implements Disposable {
// key in this case to prevent extension from automatically opening the panel next time they open the editor
extensionContext.workspaceState.update(OPEN_PANEL_ON_ACTIVATION, undefined);

this.changeViewStateDisposable.dispose();
commands.executeCommand("setContext", "RNIDE.isTabPanelFocused", false);

TabPanel.currentPanel = undefined;

// Dispose of the current webview panel
Expand Down

0 comments on commit 53adfad

Please sign in to comment.