Skip to content

Commit 53d2950

Browse files
authored
Merge pull request #5 from OpenForgeProject/feature/logfile-handling
feat: add confirmation popup for deleting all log files and update button visibility based on log file presence
2 parents eb403ca + 1fe37f0 commit 53d2950

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## [Unreleased]
88

9+
## [1.4.0] - 2024-11-20
10+
11+
### Added
12+
13+
- Added a confirmation popup to ask if you really want to delete all files
14+
15+
### Changed
16+
17+
- update "Delete Logfiles" button visibility based on log file presence
18+
919
## [1.3.0] - 2024-11-19
1020

1121
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"view/title": [
9191
{
9292
"command": "magento-log-viewer.clearAllLogFiles",
93-
"when": "view == logFiles",
93+
"when": "view == logFiles && magentoLogViewer.hasLogFiles",
9494
"group": "navigation"
9595
},
9696
{

src/extension.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,19 @@ function activateExtension(context: vscode.ExtensionContext, magentoRoot: string
8484
});
8585

8686
vscode.commands.registerCommand('magento-log-viewer.clearAllLogFiles', () => {
87-
const logPath = path.join(magentoRoot, 'var', 'log');
88-
if (logViewerProvider.pathExists(logPath)) {
89-
const files = fs.readdirSync(logPath);
90-
files.forEach(file => fs.unlinkSync(path.join(logPath, file)));
91-
logViewerProvider.refresh();
92-
showInformationMessage('All log files have been cleared.');
93-
} else {
94-
showInformationMessage('No log files found to clear.');
95-
}
87+
vscode.window.showWarningMessage('Are you sure you want to delete all log files?', 'Yes', 'No').then(selection => {
88+
if (selection === 'Yes') {
89+
const logPath = path.join(magentoRoot, 'var', 'log');
90+
if (logViewerProvider.pathExists(logPath)) {
91+
const files = fs.readdirSync(logPath);
92+
files.forEach(file => fs.unlinkSync(path.join(logPath, file)));
93+
logViewerProvider.refresh();
94+
showInformationMessage('All log files have been cleared.');
95+
} else {
96+
showInformationMessage('No log files found to clear.');
97+
}
98+
}
99+
});
96100
});
97101

98102
context.subscriptions.push(treeView);
@@ -102,6 +106,9 @@ function activateExtension(context: vscode.ExtensionContext, magentoRoot: string
102106
const logFiles = logViewerProvider.getLogFilesWithoutUpdatingBadge(path.join(magentoRoot, 'var', 'log'));
103107
const totalEntries = logFiles.reduce((count, file) => count + parseInt(file.description?.match(/\d+/)?.[0] || '0', 10), 0);
104108
treeView.badge = { value: totalEntries, tooltip: `${totalEntries} log entries` };
109+
110+
// Enable or disable the "Delete Logfiles" button based on the presence of log files
111+
vscode.commands.executeCommand('setContext', 'magentoLogViewer.hasLogFiles', totalEntries > 0);
105112
};
106113

107114
logViewerProvider.onDidChangeTreeData(updateBadge);

0 commit comments

Comments
 (0)