Skip to content

Commit 4861221

Browse files
committed
feat: add close all deletes files support
1 parent d6ee6ca commit 4861221

File tree

3 files changed

+72
-15
lines changed

3 files changed

+72
-15
lines changed

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"commands": [
7474
{
7575
"command": "tabarchive.archiveAsManyTabsAsPossible",
76-
"title": "Tab Archive: Archive as many tabs as possible"
76+
"title": "Tab Archive: Archive As Many Tabs As Possible"
7777
},
7878
{
7979
"command": "tabarchive.activate",
@@ -85,15 +85,19 @@
8585
},
8686
{
8787
"command": "tabarchive.listArchivedTabs",
88-
"title": "Tab Archive: List recently archived tabs"
88+
"title": "Tab Archive: List Recently Archived Tabs"
8989
},
9090
{
9191
"command": "tabarchive.clearArchivedTabs",
92-
"title": "Tab Archive: Clear all archived tabs"
92+
"title": "Tab Archive: Clear All Archived Tabs"
9393
},
9494
{
9595
"command": "tabarchive.closeAllDiffTabs",
96-
"title": "Tab Archive: Close all diff tabs"
96+
"title": "Tab Archive: Close All Diff Tabs"
97+
},
98+
{
99+
"command": "tabarchive.closeAllDeletedFiles",
100+
"title": "Tab Archive: Close All Deleted Files"
97101
}
98102
],
99103
"menus": {

src/extension.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ import * as vscode from "vscode";
22
import { INTERVAL_IN_MINUTES, lg } from "./common";
33
import { getSettingValue, updateSettingValue } from "./settings";
44
import {
5-
archiveTabs,
6-
clearArchivedTabs,
7-
closeAllDiffTabs,
8-
createTabTimeCounters,
9-
incrementTabTimeCounter,
10-
listArchivedTabs,
11-
loadArchivedTabs,
12-
removeTabTimeCounter,
13-
resetTabTimeCounter,
14-
storeArchivedTabs,
15-
storeTabTimeCounters,
5+
archiveTabs,
6+
clearArchivedTabs,
7+
closeAllDeletedFiles,
8+
closeAllDiffTabs,
9+
createTabTimeCounters,
10+
incrementTabTimeCounter,
11+
listArchivedTabs,
12+
loadArchivedTabs,
13+
removeTabTimeCounter,
14+
resetTabTimeCounter,
15+
storeArchivedTabs,
16+
storeTabTimeCounters,
1617
} from "./tabarchive";
1718

1819
let interval: ReturnType<typeof setInterval>;
@@ -141,6 +142,13 @@ const registerCommands = (context: vscode.ExtensionContext) => {
141142
() => closeAllDiffTabs(),
142143
),
143144
);
145+
146+
context.subscriptions.push(
147+
vscode.commands.registerCommand(
148+
"tabarchive.closeAllDeletedFiles",
149+
() => closeAllDeletedFiles(),
150+
),
151+
);
144152
};
145153

146154
const isActiveInWorkspace = (): boolean => {

src/tabarchive.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,48 @@ export const closeAllDiffTabs = () => {
362362
vscode.window.setStatusBarMessage('No diff tabs found to close.', STATUS_MESSAGE_TIMEOUT_MS);
363363
}
364364
};
365+
366+
export const closeAllDeletedFiles = async () => {
367+
lg("Closing all deleted files...");
368+
369+
let closedCount = 0;
370+
371+
// Directly iterate through tab groups and close tabs with deleted files
372+
for (const tabGroup of vscode.window.tabGroups.all) {
373+
for (const tab of tabGroup.tabs) {
374+
// Check if this is a text editor tab
375+
if (tab.input instanceof vscode.TabInputText) {
376+
const uri = tab.input.uri;
377+
378+
// Skip untitled files
379+
if (uri.scheme === 'untitled') {
380+
continue;
381+
}
382+
383+
try {
384+
// Check if the file exists
385+
const stat = await vscode.workspace.fs.stat(uri);
386+
if (!stat) {
387+
// File doesn't exist, close the tab
388+
vscode.window.tabGroups.close(tab);
389+
closedCount++;
390+
}
391+
} catch (error) {
392+
// If we can't stat the file, it likely doesn't exist
393+
vscode.window.tabGroups.close(tab);
394+
closedCount++;
395+
}
396+
}
397+
}
398+
}
399+
400+
// Show appropriate message based on result
401+
if (closedCount > 0) {
402+
vscode.window.setStatusBarMessage(
403+
`Closed ${closedCount} deleted file tab${closedCount === 1 ? '' : 's'}.`,
404+
STATUS_MESSAGE_TIMEOUT_MS
405+
);
406+
} else {
407+
vscode.window.setStatusBarMessage('No deleted file tabs found to close.', STATUS_MESSAGE_TIMEOUT_MS);
408+
}
409+
};

0 commit comments

Comments
 (0)