Skip to content

Commit 166bf17

Browse files
committed
FileContextMenu: disable paste/delete when cache is readonly
Also simplified paste enable checks: ignore file under mouse for now since we paste on current cache & not on the folder under the mouse anyway.
1 parent 7bfe5aa commit 166bf17

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/components/App.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,18 @@ const App = observer(() => {
6262
status: activeCache.status,
6363
path: activeCache.path,
6464
selectedLength: activeCache.selected.length,
65-
// enable when FsZip is merged
66-
isReadonly: false,
67-
isIndirect: false,
6865
historyLength: activeCache.history.length,
6966
historyCurrent: activeCache.current,
7067
isRoot: API.isRoot(activeCache.path),
71-
// isReadonly: activeCache.getFS().options.readonly,
72-
// isIndirect: activeCache.getFS().options.indirect,
68+
isReadonly: fs.options.readonly,
69+
isIndirect: fs.options.indirect,
7370
isOverlayOpen: refIsOverlayOpen.current,
7471
activeViewTabNums: activeView.caches.length,
7572
isExplorer: appState.isExplorer,
7673
language: settingsState.lang,
7774
filesLength: activeCache.files.length,
7875
clipboardLength: appState.clipboard.files.length,
7976
activeViewId: activeView.viewId,
80-
// missing: about opened, tab: is it needed?
8177
}
8278
}, [appState])
8379

src/components/menus/FileContextMenu.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ const FileContextMenu = ({ fileUnderMouse }: Props) => {
1414
const { appState } = useStores('appState')
1515
const clipboard = appState.clipboard
1616
const cache = appState.getActiveCache()
17+
const isReadonly = cache.options.readonly
1718

18-
// TODO: disable delete/paste when cahce.fs.readonly is true
1919
const numFilesInClipboard = clipboard.files.length
2020
const isInSelection = fileUnderMouse && !!cache.selected.find((file) => sameID(file.id, fileUnderMouse.id))
21-
const isPasteEnabled = numFilesInClipboard && ((!fileUnderMouse && !cache.error) || fileUnderMouse?.isDir)
21+
// FIXME: if fileUnderMouse is a folder, we could paste inside that folder. Right now paste doesn't care about
22+
// where click happens: it just uses current cache as target.
23+
// ((!fileUnderMouse && !cache.error) || fileUnderMouse?.isDir)
24+
const isPasteEnabled = numFilesInClipboard && !isReadonly
2225

2326
const onCopy = () => {
2427
clipboard.setClipboard(cache, !isInSelection ? [fileUnderMouse] : undefined)
@@ -59,7 +62,7 @@ const FileContextMenu = ({ fileUnderMouse }: Props) => {
5962
icon="delete"
6063
intent={Intent.DANGER}
6164
text={t('APP_MENUS.DELETE')}
62-
disabled={!fileUnderMouse}
65+
disabled={!fileUnderMouse || isReadonly}
6366
onClick={onDelete}
6467
/>
6568
</Menu>

src/services/plugins/FsZip.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import StreamZip, { StreamZipAsync, ZipEntry } from 'node-stream-zip'
3-
import type { ReadStream, BigIntStats } from 'fs'
4-
import { Transform, TransformCallback } from 'stream'
53
import * as path from 'path'
64

75
import { FsApi, FileDescriptor, Credentials, Fs, filetype, MakeId } from '$src/services/Fs'
@@ -16,10 +14,6 @@ const getZipPathRegEx = /(?<=\.zip).*/i
1614
// we accept Windows style paths (eg. C:\foo...) and unix paths (eg. /foo or ./foo)
1715
const isRoot = (isWin && /((([a-zA-Z]\:)(\\)*)|(\\\\))$/) || /^\/$/
1816

19-
const progressFunc = throttle((progress: (bytes: number) => void, bytesRead: number) => {
20-
progress(bytesRead)
21-
}, 400)
22-
2317
export const checkDirectoryName = (dirName: string) => !!!dirName.match(invalidDirChars) && dirName !== '/'
2418

2519
export interface ZipMethods {

src/state/fileState.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,8 @@ export class FileState {
722722
setViewMode(newViewMode: ViewModeName) {
723723
this.viewmode = newViewMode
724724
}
725+
726+
get options() {
727+
return this.fs.options
728+
}
725729
}

0 commit comments

Comments
 (0)