|
1 | 1 | <script context="module" lang="ts"> |
2 | | - import { GestureRootView } from '@nativescript-community/gesturehandler'; |
3 | 2 | import { Template } from '@nativescript-community/svelte-native/components'; |
4 | 3 | import { NativeViewElementNode } from '@nativescript-community/svelte-native/dom'; |
5 | 4 | import { Canvas, CanvasView, LayoutAlignment, Paint, StaticLayout } from '@nativescript-community/ui-canvas'; |
6 | | - import { CheckBox } from '@nativescript-community/ui-checkbox'; |
7 | 5 | import { CollectionView } from '@nativescript-community/ui-collectionview'; |
8 | 6 | import { Img } from '@nativescript-community/ui-image'; |
9 | | - import { Label, createNativeAttributedString } from '@nativescript-community/ui-label'; |
| 7 | + import { createNativeAttributedString } from '@nativescript-community/ui-label'; |
10 | 8 | import { confirm, prompt } from '@nativescript-community/ui-material-dialogs'; |
11 | 9 | import { VerticalPosition } from '@nativescript-community/ui-popover'; |
12 | 10 | import { AnimationDefinition, Application, ApplicationSettings, Color, EventData, Frame, NavigatedData, ObservableArray, Page, Screen, StackLayout } from '@nativescript/core'; |
|
46 | 44 | DEFAULT_NB_COLUMNS_LANDSCAPE, |
47 | 45 | DEFAULT_SORT_ORDER, |
48 | 46 | DEFAULT_TRASH_ENABLED, |
49 | | - DEFAULT_TRASH_REMEMBERED_DELETE_MODE, |
50 | 47 | DEFAULT_VIEW_STYLE, |
51 | 48 | EVENT_DOCUMENT_ADDED, |
52 | 49 | EVENT_DOCUMENT_DELETED, |
|
65 | 62 | SETTINGS_NB_COLUMNS_LANDSCAPE, |
66 | 63 | SETTINGS_SORT_ORDER, |
67 | 64 | SETTINGS_TRASH_ENABLED, |
68 | | - SETTINGS_TRASH_REMEMBERED_DELETE_MODE, |
69 | 65 | SETTINGS_VIEW_STYLE |
70 | 66 | } from '~/utils/constants'; |
71 | 67 | import { |
72 | | - createView, |
| 68 | + deleteDocumentsWithConfirm, |
| 69 | + deleteOriginalImages, |
73 | 70 | detectOCR, |
74 | 71 | goToDocumentView, |
75 | 72 | goToFolderView, |
|
914 | 911 | async function deleteSelectedDocuments() { |
915 | 912 | if (nbSelected > 0) { |
916 | 913 | try { |
917 | | - if (trashEnabled && !isTrash) { |
918 | | - DEV_LOG && console.log('rememberedMode1'); |
919 | | - const rememberedMode = ApplicationSettings.getString(SETTINGS_TRASH_REMEMBERED_DELETE_MODE, DEFAULT_TRASH_REMEMBERED_DELETE_MODE); |
920 | | - let result = false; |
921 | | - DEV_LOG && console.log('rememberedMode', rememberedMode); |
922 | | - if (!rememberedMode) { |
923 | | - const view = createView(GestureRootView, { |
924 | | - columns: 'auto,*', |
925 | | - rows: 'auto' |
926 | | - }); |
927 | | - const checkBox = createView(CheckBox, {}); |
928 | | - const label = createView(Label, { |
929 | | - verticalAlignment: 'center', |
930 | | - col: 1, |
931 | | - text: lc('remember_delete_choice') |
932 | | - }); |
933 | | - label.on('tap', () => { |
934 | | - DEV_LOG && console.log('label tap'); |
935 | | - checkBox.checked = !checkBox.checked; |
936 | | - }); |
937 | | - view.addChild(checkBox); |
938 | | - view.addChild(label); |
939 | | - result = await confirm({ |
940 | | - neutralButtonText: lc('cancel'), |
941 | | - message: lcp('confirm_move_to_trash', nbSelected), |
942 | | - cancelButtonText: lc('delete_permanently'), |
943 | | - okButtonText: lc('move_to_trash'), |
944 | | - title: lc('delete'), |
945 | | - view |
946 | | - } as any); |
947 | | - if (result !== null && checkBox.checked) { |
948 | | - ApplicationSettings.setString(SETTINGS_TRASH_REMEMBERED_DELETE_MODE, result === true ? 'trash' : 'permament'); |
949 | | - } |
950 | | - } else { |
951 | | - switch (rememberedMode) { |
952 | | - case 'permament': |
953 | | - result = false; |
954 | | - break; |
955 | | - case 'trash': |
956 | | - result = true; |
957 | | - break; |
958 | | - default: |
959 | | - break; |
960 | | - } |
961 | | - } |
962 | | - if (result === true) { |
963 | | - await documentsService.trashDocuments(await getSelectedDocuments()); |
964 | | - return true; |
965 | | - } else if (result === false) { |
966 | | - // neutral button tapped: delete permanently |
967 | | - const confirmed = await confirm({ |
968 | | - cancelButtonText: lc('cancel'), |
969 | | - message: lcp('confirm_delete_permanently', nbSelected), |
970 | | - okButtonText: lc('delete_permanently'), |
971 | | - title: lc('delete_permanently') |
972 | | - }); |
973 | | - if (confirmed) { |
974 | | - await documentsService.deleteDocuments(await getSelectedDocuments()); |
975 | | - return true; |
976 | | - } |
977 | | - return false; |
978 | | - } |
979 | | - return false; |
980 | | - } else { |
981 | | - const result = await confirm({ |
982 | | - cancelButtonText: lc('cancel'), |
983 | | - message: lcp('confirm_delete_documents', nbSelected), |
984 | | - okButtonText: lc('delete'), |
985 | | - title: lc('delete') |
986 | | - }); |
987 | | - if (result) { |
988 | | - await documentsService.deleteDocuments(await getSelectedDocuments()); |
989 | | - return true; |
990 | | - } |
991 | | - return false; |
992 | | - } |
| 914 | + // the trash list only offers "delete permanently" |
| 915 | + return await deleteDocumentsWithConfirm(await getSelectedDocuments()); |
993 | 916 | } catch (error) { |
994 | 917 | showError(error); |
995 | 918 | } |
|
1224 | 1147 | ...(nbSelected === 1 ? [{ icon: 'mdi-rename', id: 'rename', name: lc('rename') }] : []), |
1225 | 1148 | { icon: 'mdi-star', id: 'favorite', name: lc('toggle_favorite') }, |
1226 | 1149 | { icon: 'mdi-folder-swap', id: 'move_folder', name: lc('move_folder') }, |
1227 | | - { icon: 'mdi-fullscreen', id: 'fullscreen', name: lc('show_fullscreen_images') } |
| 1150 | + { icon: 'mdi-fullscreen', id: 'fullscreen', name: lc('show_fullscreen_images') }, |
| 1151 | + { icon: 'mdi-image-remove', id: 'delete_originals', name: lc('delete_original_images') } |
1228 | 1152 | ]; |
1229 | 1153 | } |
1230 | 1154 |
|
|
1279 | 1203 | unselectAll(); |
1280 | 1204 | } |
1281 | 1205 | break; |
| 1206 | + case 'delete_originals': |
| 1207 | + result = await deleteOriginalImages({ documents: await getSelectedDocuments() }); |
| 1208 | + if (result) { |
| 1209 | + unselectAll(); |
| 1210 | + } |
| 1211 | + break; |
1282 | 1212 | case 'delete': |
1283 | 1213 | result = await deleteSelectedDocuments(); |
1284 | 1214 | if (result) { |
|
0 commit comments