Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid closing IDE accidentally #390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading