Skip to content

Commit beec71c

Browse files
committed
Put the dialog behind setting
1 parent 1cdf347 commit beec71c

4 files changed

Lines changed: 94 additions & 27 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ You can set the VSCode text editor to use an installed Nerd Font by setting `"ed
167167

168168
Once you have a Nerd Font set for your editor font, to use these icons in your oil view, set `"oil-code.hasNerdFont": true`.
169169

170+
## Confirmation Dialog
171+
172+
By default, oil.code uses a modal confirmation dialog when you save file operations. You can enable an alternate confirmation interface by setting `"oil-code.enableAlternateConfirmation": true`.
173+
174+
The alternate confirmation dialog provides a QuickPick interface where you can:
175+
176+
- Type `Y` to confirm and apply changes
177+
- Type `N` to cancel and discard changes
178+
- Press `Esc` or click outside to cancel
179+
170180
## Other great extensions
171181

172182
- [vsnetrw](https://github.com/danprince/vsnetrw): Another great option for a split file explorer.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"icon": "images/oil.code.logo.png",
66
"repository": "https://github.com/corwinm/oil.code",
77
"publisher": "haphazarddev",
8-
"version": "0.0.31",
8+
"version": "0.0.29",
99
"engines": {
1010
"vscode": "^1.96.2"
1111
},
@@ -160,6 +160,11 @@
160160
"type": "boolean",
161161
"default": false,
162162
"description": "Enable workspace edit for file move/rename operations. When enabled, VS Code will ask to update references when a file is moved or renamed. Default is false."
163+
},
164+
"oil-code.enableAlternateConfirmation": {
165+
"type": "boolean",
166+
"default": false,
167+
"description": "Enable alternate confirmation dialog for file operations. When enabled, uses a QuickPick interface instead of the default modal confirmation dialog. Default is false."
163168
}
164169
}
165170
}

src/handlers/onDidSaveTextDocument.ts

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
import { select } from "../commands/select";
1313
import { newline } from "../newline";
1414
import { logger } from "../logger";
15-
import { getEnableWorkspaceEditSetting } from "../utils/settings";
15+
import {
16+
getEnableWorkspaceEditSetting,
17+
getEnableAlternateConfirmationSetting,
18+
} from "../utils/settings";
1619
import { confirmChanges, type Change } from "../ui/confirmChanges";
1720

1821
export async function onDidSaveTextDocument(document: vscode.TextDocument) {
@@ -135,34 +138,78 @@ export async function onDidSaveTextDocument(document: vscode.TextDocument) {
135138
oilState.openAfterSave = undefined;
136139
return;
137140
}
141+
// Get the alternate confirmation dialog setting
142+
const useAlternateConfirmation = getEnableAlternateConfirmationSetting();
138143

139-
// Build change list and confirm using Quick Pick/editor
140-
const uiChanges: Change[] = [];
141-
for (const [from, to] of movedLines) {
142-
uiChanges.push({ kind: "move", from, to });
143-
}
144-
for (const [from, to] of copiedLines) {
145-
uiChanges.push({ kind: "copy", from, to });
146-
}
147-
for (const p of addedLines) {
148-
uiChanges.push({ kind: "create", to: p });
149-
}
150-
for (const p of deletedLines) {
151-
uiChanges.push({ kind: "delete", from: p });
144+
if (useAlternateConfirmation) {
145+
// Build change list and confirm using Quick Pick
146+
const uiChanges: Change[] = [];
147+
for (const [from, to] of movedLines) {
148+
uiChanges.push({ kind: "move", from, to });
149+
}
150+
for (const [from, to] of copiedLines) {
151+
uiChanges.push({ kind: "copy", from, to });
152+
}
153+
for (const p of addedLines) {
154+
uiChanges.push({ kind: "create", to: p });
155+
}
156+
for (const p of deletedLines) {
157+
uiChanges.push({ kind: "delete", from: p });
158+
}
159+
const ok = await confirmChanges(
160+
uiChanges.map((c) => ({
161+
// format paths to relative for nicer display (but still keep full for ops later)
162+
...(c as any),
163+
from: "from" in c ? formatPath((c as any).from) : undefined,
164+
to: "to" in c ? formatPath((c as any).to) : undefined,
165+
})) as Change[]
166+
);
167+
if (!ok) {
168+
oilState.openAfterSave = undefined;
169+
return;
170+
}
171+
} else {
172+
// Show confirmation dialog
173+
let message = "The following changes will be applied:\n\n";
174+
if (movedLines.length > 0) {
175+
movedLines.forEach((item) => {
176+
const [originalPath, newPath] = item;
177+
message += `MOVE ${formatPath(originalPath)}${formatPath(
178+
newPath
179+
)}\n`;
180+
});
181+
}
182+
if (copiedLines.length > 0) {
183+
copiedLines.forEach((item) => {
184+
const [originalPath, newPath] = item;
185+
message += `COPY ${formatPath(originalPath)}${formatPath(
186+
newPath
187+
)}\n`;
188+
});
189+
}
190+
if (addedLines.size > 0) {
191+
addedLines.forEach((item) => {
192+
message += `CREATE ${formatPath(item)}\n`;
193+
});
194+
}
195+
if (deletedLines.size > 0) {
196+
deletedLines.forEach((item) => {
197+
message += `DELETE ${formatPath(item)}\n`;
198+
});
199+
}
200+
// Show confirmation dialog
201+
const response = await vscode.window.showWarningMessage(
202+
message,
203+
{ modal: true },
204+
"Yes",
205+
"No"
206+
);
207+
if (response !== "Yes") {
208+
oilState.openAfterSave = undefined;
209+
return;
210+
}
152211
}
153212

154-
const ok = await confirmChanges(
155-
uiChanges.map((c) => ({
156-
// format paths to relative for nicer display (but still keep full for ops later)
157-
...(c as any),
158-
from: "from" in c ? formatPath((c as any).from) : undefined,
159-
to: "to" in c ? formatPath((c as any).to) : undefined,
160-
})) as Change[]
161-
);
162-
if (!ok) {
163-
oilState.openAfterSave = undefined;
164-
return;
165-
}
166213
logger.debug("Processing changes...");
167214

168215
// Delete files/directories

src/utils/settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export function getEnableWorkspaceEditSetting(): boolean {
1515
return config.get<boolean>("enableWorkspaceEdit") || false;
1616
}
1717

18+
export function getEnableAlternateConfirmationSetting(): boolean {
19+
const config = vscode.workspace.getConfiguration("oil-code");
20+
return config.get<boolean>("enableAlternateConfirmation") || false;
21+
}
22+
1823
let restoreAutoSave = false;
1924

2025
export async function checkAndDisableAutoSave() {

0 commit comments

Comments
 (0)