Skip to content

Commit

Permalink
FileContextMenu: disable paste/delete when cache is readonly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
warpdesign committed Mar 9, 2023
1 parent 44918e7 commit 7044bd3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,18 @@ const App = observer(() => {
status: activeCache.status,
path: activeCache.path,
selectedLength: activeCache.selected.length,
// enable when FsZip is merged
isReadonly: false,
isIndirect: false,
historyLength: activeCache.history.length,
historyCurrent: activeCache.current,
isRoot: API.isRoot(activeCache.path),
// isReadonly: activeCache.getFS().options.readonly,
// isIndirect: activeCache.getFS().options.indirect,
isReadonly: fs.options.readonly,
isIndirect: fs.options.indirect,
isOverlayOpen: refIsOverlayOpen.current,
activeViewTabNums: activeView.caches.length,
isExplorer: appState.isExplorer,
language: settingsState.lang,
filesLength: activeCache.files.length,
clipboardLength: appState.clipboard.files.length,
activeViewId: activeView.viewId,
// missing: about opened, tab: is it needed?
}
}, [appState])

Expand Down
9 changes: 6 additions & 3 deletions src/components/menus/FileContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ const FileContextMenu = ({ fileUnderMouse }: Props) => {
const { appState } = useStores('appState')
const clipboard = appState.clipboard
const cache = appState.getActiveCache()
const isReadonly = cache.options.readonly

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

const onCopy = () => {
clipboard.setClipboard(cache, !isInSelection ? [fileUnderMouse] : undefined)
Expand Down Expand Up @@ -59,7 +62,7 @@ const FileContextMenu = ({ fileUnderMouse }: Props) => {
icon="delete"
intent={Intent.DANGER}
text={t('APP_MENUS.DELETE')}
disabled={!fileUnderMouse}
disabled={!fileUnderMouse || isReadonly}
onClick={onDelete}
/>
</Menu>
Expand Down
6 changes: 0 additions & 6 deletions src/services/plugins/FsZip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import StreamZip, { StreamZipAsync, ZipEntry } from 'node-stream-zip'
import type { ReadStream, BigIntStats } from 'fs'
import { Transform, TransformCallback } from 'stream'
import * as path from 'path'

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

const progressFunc = throttle((progress: (bytes: number) => void, bytesRead: number) => {
progress(bytesRead)
}, 400)

export const checkDirectoryName = (dirName: string) => !!!dirName.match(invalidDirChars) && dirName !== '/'

export interface ZipMethods {
Expand Down
4 changes: 4 additions & 0 deletions src/state/fileState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,4 +722,8 @@ export class FileState {
setViewMode(newViewMode: ViewModeName) {
this.viewmode = newViewMode
}

get options() {
return this.fs.options
}
}

0 comments on commit 7044bd3

Please sign in to comment.