@@ -8,13 +8,61 @@ import type { RenamingStore } from '../types'
8
8
import axios , { isAxiosError } from '@nextcloud/axios'
9
9
import { emit , subscribe } from '@nextcloud/event-bus'
10
10
import { NodeStatus } from '@nextcloud/files'
11
+ import { DialogBuilder } from '@nextcloud/dialogs'
11
12
import { t } from '@nextcloud/l10n'
12
- import { basename , dirname } from 'path'
13
+ import { basename , dirname , extname } from 'path'
13
14
import { defineStore } from 'pinia'
14
15
import logger from '../logger'
15
16
import Vue from 'vue'
17
+ import IconCancel from '@mdi/svg/svg/cancel.svg?raw'
18
+ import IconCheck from '@mdi/svg/svg/check.svg?raw'
16
19
17
- export const useRenamingStore = function ( ...args ) {
20
+ let isDialogVisible = false
21
+
22
+ const showWarningDialog = ( oldExtension : string , newExtension : string ) : Promise < boolean > => {
23
+ if ( isDialogVisible ) {
24
+ return Promise . resolve ( false )
25
+ }
26
+
27
+ isDialogVisible = true
28
+
29
+ return new Promise ( ( resolve ) => {
30
+ const dialog = new DialogBuilder ( )
31
+ . setName ( t ( 'files' , 'Extension Change Warning' ) )
32
+ . setText ( t (
33
+ 'files' ,
34
+ 'You are attempting to change the file extension from "{old}" to "{new}". This may affect how the file is handled. Do you want to proceed?' ,
35
+ { old : oldExtension || t ( 'files' , 'none' ) , new : newExtension || t ( 'files' , 'none' ) }
36
+ ) )
37
+ . setButtons ( [
38
+ {
39
+ label : t ( 'files' , 'Cancel' ) ,
40
+ icon : IconCancel ,
41
+ type : 'secondary' ,
42
+ callback : ( ) => {
43
+ isDialogVisible = false
44
+ resolve ( false )
45
+ } ,
46
+ } ,
47
+ {
48
+ label : t ( 'files' , 'Proceed' ) ,
49
+ icon : IconCheck ,
50
+ type : 'primary' ,
51
+ callback : ( ) => {
52
+ isDialogVisible = false
53
+ resolve ( true )
54
+ } ,
55
+ } ,
56
+ ] )
57
+ . build ( )
58
+
59
+ dialog . show ( ) . then ( ( ) => {
60
+ dialog . hide ( )
61
+ } )
62
+ } )
63
+ }
64
+
65
+ export const useRenamingStore = function ( ...args ) {
18
66
const store = defineStore ( 'renaming' , {
19
67
state : ( ) => ( {
20
68
renamingNode : undefined ,
@@ -36,6 +84,18 @@ export const useRenamingStore = function(...args) {
36
84
const newName = this . newName . trim ?.( ) || ''
37
85
const oldName = this . renamingNode . basename
38
86
const oldEncodedSource = this . renamingNode . encodedSource
87
+
88
+ // Check for extension change
89
+ const oldExtension = extname ( oldName )
90
+ const newExtension = extname ( newName )
91
+ if ( oldExtension !== newExtension ) {
92
+ const proceed = await showWarningDialog ( oldExtension , newExtension )
93
+ if ( ! proceed ) {
94
+ // User canceled, abort the operation
95
+ return false
96
+ }
97
+ }
98
+
39
99
if ( oldName === newName ) {
40
100
return false
41
101
}
@@ -98,7 +158,7 @@ export const useRenamingStore = function(...args) {
98
158
99
159
// Make sure we only register the listeners once
100
160
if ( ! renamingStore . _initialized ) {
101
- subscribe ( 'files:node:rename' , function ( node : Node ) {
161
+ subscribe ( 'files:node:rename' , function ( node : Node ) {
102
162
renamingStore . renamingNode = node
103
163
renamingStore . newName = node . basename
104
164
} )
0 commit comments