@@ -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