+
+
+
{context.remotes && context.remotes.length ?
- <>
+
{context.remotes && context.remotes.map((remote, index) => {
@@ -36,18 +38,17 @@ export const Remotes = () => {
);
})}
- > : <>No remotes>}
-
+ :
+
+
}
-
onRemoteNameChange(e.target.value)} value={remoteName} className="form-control mb-2" type="text" id="remotename" />
-
onUrlChange(e.target.value)} value={url} className="form-control" type="text" id="remoteurl" />
+
onRemoteNameChange(e.target.value)} value={remoteName} className="form-control mb-3" type="text" id="remotename" />
+
onUrlChange(e.target.value)} value={url} className="form-control mb-3" type="text" id="remoteurl" />
-
-
-
+
>)
-}
\ No newline at end of file
+}
diff --git a/libs/remix-ui/git/src/components/panels/remotesimport.tsx b/libs/remix-ui/git/src/components/panels/remotesimport.tsx
index 646546c1a4..2904f05d8e 100644
--- a/libs/remix-ui/git/src/components/panels/remotesimport.tsx
+++ b/libs/remix-ui/git/src/components/panels/remotesimport.tsx
@@ -1,12 +1,12 @@
-import React, { useEffect, useState } from "react";
-import { Alert, Button } from "react-bootstrap";
-import { gitActionsContext } from "../../state/context";
-import { repository } from "../../types";
-import { gitPluginContext } from "../gitui";
+import React, { useEffect, useState } from "react"
+import { Alert, Button } from "react-bootstrap"
+import { gitActionsContext } from "../../state/context"
+import { repository } from "../../types"
+import { gitPluginContext } from "../gitui"
import Select from 'react-select'
-import { selectStyles, selectTheme } from "../../types/styles";
-import { TokenWarning } from "./tokenWarning";
-import RepositorySelect from "../github/repositoryselect";
+import { selectStyles, selectTheme } from "../../types/styles"
+import { TokenWarning } from "./tokenWarning"
+import RepositorySelect from "../github/repositoryselect"
export const RemotesImport = () => {
const context = React.useContext(gitPluginContext)
@@ -64,9 +64,8 @@ export const RemotesImport = () => {
return (
<>
-
-
+
{repo ?
onRemoteNameChange(e.target.value)} value={remoteName} className="form-control mb-2" type="text" id="remotename" />
: null}
diff --git a/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolgroup.tsx b/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolgroup.tsx
index 1b17cb2b31..c6c77f3328 100644
--- a/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolgroup.tsx
+++ b/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolgroup.tsx
@@ -35,4 +35,4 @@ export const SourceControGroup = (props: SourceControGroupProps) => {
: <>>}
>)
-}
\ No newline at end of file
+}
diff --git a/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolitem.tsx b/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolitem.tsx
index 64617b17e1..a28d2a6664 100644
--- a/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolitem.tsx
+++ b/libs/remix-ui/git/src/components/panels/sourcecontrol/sourcecontrolitem.tsx
@@ -41,10 +41,10 @@ export const SourceControlItem = (props: SourceControlItemProps) => {
return (<>
- {status && status.indexOf("modified") === -1 ? <>> :
M
}
- {status && status.indexOf("deleted") === -1 ? <>> :
D}
- {status && status.indexOf("added") === -1 ? <>> :
A}
- {status && status.indexOf("untracked") === -1 ? <>> :
U}
+ {status && status.indexOf("modified") === -1 ? <>> :
M}
+ {status && status.indexOf("deleted") === -1 ? <>> :
D}
+ {status && status.indexOf("added") === -1 ? <>> :
A}
+ {status && status.indexOf("untracked") === -1 ? <>> :
U}
>)
}
@@ -56,10 +56,10 @@ export const SourceControlItem = (props: SourceControlItemProps) => {
{path.basename(file.filename)}
{file.filename}
-
+
>
: <>
@@ -46,4 +46,4 @@ export const SourceControl = () => {
>
);
-}
\ No newline at end of file
+}
diff --git a/libs/remix-ui/git/src/components/panels/tokenWarning.tsx b/libs/remix-ui/git/src/components/panels/tokenWarning.tsx
index 4188c07c93..e13b3c912e 100644
--- a/libs/remix-ui/git/src/components/panels/tokenWarning.tsx
+++ b/libs/remix-ui/git/src/components/panels/tokenWarning.tsx
@@ -1,12 +1,15 @@
import { gitPluginContext } from "../gitui"
-import React, { useEffect, useState } from "react";
+import React, { useEffect, useState } from "react"
+
export const TokenWarning = () => {
const context = React.useContext(gitPluginContext)
return (<>
{(context.gitHubUser && context.gitHubUser.login) ? null :
-
- To use add a GitHub token to the settings.
+
+ Generate and add a Git token to use this plugin. Tokens are added in {
+ }}>settings.
+
}
>
)
-}
\ No newline at end of file
+}
diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts
index 314d9143e5..b9e0817bd1 100644
--- a/libs/remix-ui/git/src/lib/gitactions.ts
+++ b/libs/remix-ui/git/src/lib/gitactions.ts
@@ -1,7 +1,7 @@
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react";
-import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails, setCurrenHead } from "../state/gitpayload";
-import { GitHubUser, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository, userEmails } from '../types';
+import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails, setCurrenHead, setStoragePayload } from "../state/gitpayload";
+import { GitHubUser, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository, userEmails, storage } from '../types';
import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
import { ModalTypes } from "@remix-ui/app";
@@ -849,4 +849,9 @@ export const sendToGitLog = async (message: gitLog) => {
export const clearGitLog = async () => {
dispatch(clearLog())
-}
\ No newline at end of file
+}
+
+export const setStorage = async (storage: storage) => {
+ console.log(storage)
+ dispatch(setStoragePayload(storage))
+}
diff --git a/libs/remix-ui/git/src/lib/listeners.ts b/libs/remix-ui/git/src/lib/listeners.ts
index 66c94bdd8d..ddb436554d 100644
--- a/libs/remix-ui/git/src/lib/listeners.ts
+++ b/libs/remix-ui/git/src/lib/listeners.ts
@@ -1,9 +1,9 @@
import React from "react";
import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog, setGitHubUser, setUserEmails } from "../state/gitpayload";
-import { gitActionDispatch } from "../types";
+import { gitActionDispatch, storage } from "../types";
import { Plugin } from "@remixproject/engine";
-import { getBranches, getFileStatusMatrix, loadGitHubUserFromToken, getRemotes, gitlog, setPlugin } from "./gitactions";
+import { getBranches, getFileStatusMatrix, loadGitHubUserFromToken, getRemotes, gitlog, setPlugin, setStorage } from "./gitactions";
import { Profile } from "@remixproject/plugin-utils";
import { CustomRemixApi } from "@remix-api";
import { statusChanged } from "./pluginActions";
@@ -20,7 +20,7 @@ class AsyncDebouncedQueue {
this.queues = new Map();
}
- enqueue(callback: AsyncCallback, customDelay?:number): void {
+ enqueue(callback: AsyncCallback, customDelay?: number): void {
if (this.queues.has(callback)) {
clearTimeout(this.queues.get(callback)!.timer);
}
@@ -180,6 +180,7 @@ export const getGitConfig = async () => {
export const loadFiles = async (filepaths: string[] = null) => {
try {
+ await calculateLocalStorage()
const branch = await plugin.call('dgitApi', "currentbranch")
if (branch) {
await getFileStatusMatrix(filepaths);
@@ -199,3 +200,49 @@ export const enableCallBacks = async () => {
callBackEnabled = true;
}
+const calculateLocalStorage = async () => {
+ function bytesToMB(bytes) {
+ return parseFloat((bytes / (1024 * 1024)).toFixed(2));
+ }
+
+ function calculatePercentage(used, quota) {
+ return parseFloat(((used / quota) * 100).toFixed(2));
+ }
+
+ let storage: storage = {
+ used: 0,
+ total: 0,
+ available: 0,
+ percentUsed: 0,
+ enabled: false
+ }
+
+ if ('storage' in navigator && 'estimate' in navigator.storage) {
+ navigator.storage.estimate().then(estimate => {
+ const usedMB = bytesToMB(estimate.usage);
+ const quotaMB = bytesToMB(estimate.quota);
+ const availableMB = bytesToMB(estimate.quota - estimate.usage);
+ const percentageUsed = calculatePercentage(estimate.usage, estimate.quota);
+
+ console.log(`Used storage: ${usedMB} MB`);
+ console.log(`Total quota: ${quotaMB} MB`);
+ console.log(`Available storage: ${availableMB} MB`);
+ console.log(`Percentage used: ${percentageUsed}%`);
+
+ storage = {
+ used: usedMB,
+ total: quotaMB,
+ available: availableMB,
+ percentUsed: percentageUsed,
+ enabled: true
+ }
+ setStorage(storage);
+
+ });
+ } else {
+ console.log('Storage API not supported in this browser.');
+ setStorage(storage);
+ }
+
+}
+
diff --git a/libs/remix-ui/git/src/state/actions.ts b/libs/remix-ui/git/src/state/actions.ts
index 4d35aa1b8c..61cdd628c5 100644
--- a/libs/remix-ui/git/src/state/actions.ts
+++ b/libs/remix-ui/git/src/state/actions.ts
@@ -1,5 +1,5 @@
import { ReadCommitResult } from "isomorphic-git"
-import { branch, branchDifference, commitChange, fileStatusResult, GitHubUser, gitLog, pagedCommits, remote, remoteBranch, repository, userEmails } from "../types"
+import { branch, branchDifference, commitChange, fileStatusResult, GitHubUser, gitLog, pagedCommits, remote, remoteBranch, repository, storage, userEmails } from "../types"
export interface ActionPayloadTypes {
FILE_STATUS: fileStatusResult[],
@@ -42,6 +42,7 @@ export interface ActionPayloadTypes {
SET_LOG: gitLog
CLEAR_LOG: void
SET_USER_EMAILS: userEmails
+ SET_STORAGE: storage
}
export interface Action
{
diff --git a/libs/remix-ui/git/src/state/gitpayload.ts b/libs/remix-ui/git/src/state/gitpayload.ts
index c075331d6e..1211775280 100644
--- a/libs/remix-ui/git/src/state/gitpayload.ts
+++ b/libs/remix-ui/git/src/state/gitpayload.ts
@@ -1,5 +1,5 @@
import { ReadCommitResult } from "isomorphic-git"
-import { GitHubUser, branch, commitChange, fileStatusResult, remote, pagedCommits, branchDifference, gitLog, repository, userEmails } from "../types"
+import { GitHubUser, branch, commitChange, fileStatusResult, remote, pagedCommits, branchDifference, gitLog, repository, userEmails, storage } from "../types"
import { Endpoints } from "@octokit/types"
export const fileStatus = (files: fileStatusResult[]) => {
@@ -218,3 +218,10 @@ export const clearLog = () => {
type: 'CLEAR_LOG'
}
}
+
+export const setStoragePayload = (storage: storage) => {
+ return {
+ type: 'SET_STORAGE',
+ payload: storage
+ }
+}
diff --git a/libs/remix-ui/git/src/state/gitreducer.tsx b/libs/remix-ui/git/src/state/gitreducer.tsx
index 674e1e69a5..df3ed0a7a8 100644
--- a/libs/remix-ui/git/src/state/gitreducer.tsx
+++ b/libs/remix-ui/git/src/state/gitreducer.tsx
@@ -204,5 +204,11 @@ export const gitReducer = (state: gitState = defaultGitState, action: Actions):
log: []
}
+ case 'SET_STORAGE':
+ return {
+ ...state,
+ storage: action.payload
+ }
+
}
-}
\ No newline at end of file
+}
diff --git a/libs/remix-ui/git/src/style/index.css b/libs/remix-ui/git/src/style/index.css
index 973889c15c..57df5f68c9 100644
--- a/libs/remix-ui/git/src/style/index.css
+++ b/libs/remix-ui/git/src/style/index.css
@@ -28,9 +28,17 @@
.gitfile:hover {
background-color : var(--custom-select);
}
-
+
hr {
background-color: var(--custom-select);
}
+.messageTip {
+
+}
+
+.messageTip:hover {
+ cursor: pointer;
+ text-decoration: underline;
+}
diff --git a/libs/remix-ui/git/src/types/index.ts b/libs/remix-ui/git/src/types/index.ts
index 9ed9a292ed..0041aaf357 100644
--- a/libs/remix-ui/git/src/types/index.ts
+++ b/libs/remix-ui/git/src/types/index.ts
@@ -163,7 +163,7 @@ export type gitState = {
fileStatusResult: fileStatusResult[]
canUseApp: boolean
loading: boolean
- storageUsed: any
+ storage: storage
reponame: string
staged: fileStatusResult[]
untracked: fileStatusResult[]
@@ -282,7 +282,13 @@ export const defaultGitState: gitState = {
allchangesnotstaged: [],
canUseApp: true,
loading: false,
- storageUsed: {},
+ storage: {
+ used: 0,
+ total: 0,
+ available: 0,
+ percentUsed: 0,
+ enabled: false
+ },
reponame: "",
repositories: [],
remoteBranches: [],
@@ -324,6 +330,14 @@ export type sourceControlGroup = {
name: string
}
+export type storage = {
+ used: number,
+ total: number
+ available: number
+ percentUsed: number
+ enabled: boolean
+}
+
export interface fileStatusAction {
type: string,
payload: fileStatusResult[]
diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx
index bcbc5e17b1..2215b6942d 100644
--- a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx
+++ b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx
@@ -129,7 +129,8 @@ function HomeTabGetStarted({ plugin }: HomeTabGetStartedProps) {
{
url: metadata.url,
branch: metadata.branch,
- workspaceName: templateDisplayName
+ workspaceName: templateDisplayName,
+ depth: 10
})
} else if (metadata && metadata.type === 'plugin') {
await plugin.appManager.activatePlugin('filePanel')
diff --git a/libs/remix-ui/plugin-manager/src/lib/reducers/pluginManagerReducer.ts b/libs/remix-ui/plugin-manager/src/lib/reducers/pluginManagerReducer.ts
index 6b701652ee..7b99b8f3db 100644
--- a/libs/remix-ui/plugin-manager/src/lib/reducers/pluginManagerReducer.ts
+++ b/libs/remix-ui/plugin-manager/src/lib/reducers/pluginManagerReducer.ts
@@ -1,3 +1,4 @@
+/* eslint-disable @typescript-eslint/no-non-null-assertion */
export type localPluginReducerActionType = {
type: 'show' | 'close',
diff --git a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
index b13f3ddcb3..30a045c368 100644
--- a/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
+++ b/libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
@@ -313,8 +313,19 @@ export const ContractSelection = (props: ContractSelectionProps) => {
const { data: scanData } = await axios.post('https://solidityscan.remixproject.org/downloadResult', { url })
const scanReport: ScanReport = scanData.scan_report
-
if (scanReport?.multi_file_scan_details?.length) {
+ for (const template of scanReport.multi_file_scan_details) {
+ if (template.metric_wise_aggregated_findings?.length) {
+ const { metric_wise_aggregated_findings } = template
+ const positions = []
+ for (const details of metric_wise_aggregated_findings) {
+ const { findings } = details
+ for (const f of findings)
+ positions.push(`${f.line_nos_start[0]}:${f.line_nos_end[0]}`)
+ }
+ template.positions = JSON.stringify(positions)
+ }
+ }
await plugin.call('terminal', 'logHtml', )
} else {
const modal: AppModal = {
diff --git a/libs/remix-ui/solidity-compiler/src/lib/solScanTable.tsx b/libs/remix-ui/solidity-compiler/src/lib/solScanTable.tsx
index 059262744c..2c0f5c5237 100644
--- a/libs/remix-ui/solidity-compiler/src/lib/solScanTable.tsx
+++ b/libs/remix-ui/solidity-compiler/src/lib/solScanTable.tsx
@@ -37,7 +37,7 @@ export function SolScanTable(props: SolScanTableProps) {
{template.template_details.issue_name} |
{template.template_details.issue_severity} |
{template.template_details.issue_confidence} |
- {parse(template.template_details.static_issue_description)} |
+ {parse(template.template_details.static_issue_description)} {template.positions ? `Lines: ${template.positions}`: ''} |
{template.template_details.issue_remediation ? parse(template.template_details.issue_remediation) : 'Not Available' } |
)
diff --git a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts
index 1aa0b84f25..f7474eca7c 100644
--- a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts
+++ b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts
@@ -19,6 +19,8 @@ export interface ScanTemplate {
export interface ScanDetails {
issue_id: string
no_of_findings: string
+ metric_wise_aggregated_findings?: Record[]
+ positions?: string
template_details: ScanTemplate
}
diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts
index 772bdff1a6..5814bb9092 100644
--- a/libs/remix-ui/workspace/src/lib/actions/index.ts
+++ b/libs/remix-ui/workspace/src/lib/actions/index.ts
@@ -29,6 +29,7 @@ export type UrlParametersType = {
address: string
opendir: string,
blockscout: string,
+ ghfolder: string
}
const basicWorkspaceInit = async (workspaces: { name: string; isGitRepo: boolean; }[], workspaceProvider) => {
@@ -80,7 +81,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
plugin.setWorkspace({ name, isLocalhost: false })
dispatch(setCurrentWorkspace({ name, isGitRepo: false }))
await loadWorkspacePreset('gist-template')
- } else if (params.code || params.url || params.shareCode) {
+ } else if (params.code || params.url || params.shareCode || params.ghfolder) {
await createWorkspaceTemplate('code-sample', 'code-template')
plugin.setWorkspace({ name: 'code-sample', isLocalhost: false })
dispatch(setCurrentWorkspace({ name: 'code-sample', isGitRepo: false }))
diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts
index 0cea011610..98e835f4c8 100644
--- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts
+++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts
@@ -224,7 +224,7 @@ export const createWorkspaceTemplate = async (workspaceName: string, template: W
if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists')
else if (metadata && metadata.type === 'git') {
dispatch(cloneRepositoryRequest())
- await dgitPlugin.call('dgitApi', 'clone', { url: metadata.url, branch: metadata.branch, workspaceName: workspaceName })
+ await dgitPlugin.call('dgitApi', 'clone', { url: metadata.url, branch: metadata.branch, workspaceName: workspaceName, depth: 10 })
dispatch(cloneRepositorySuccess())
} else {
const workspaceProvider = plugin.fileProviders.workspace
@@ -238,6 +238,7 @@ export type UrlParametersType = {
shareCode: string
url: string
language: string
+ ghfolder: string
}
export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDefault', opts?) => {
@@ -285,10 +286,8 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
}
if (params.url) {
const data = await plugin.call('contentImport', 'resolve', params.url)
-
path = data.cleanUrl
content = data.content
-
try {
content = JSON.parse(content) as any
if (content.language && content.language === 'Solidity' && content.sources) {
@@ -307,6 +306,17 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
await workspaceProvider.set(path, content)
}
}
+ if (params.ghfolder) {
+ try {
+ const files = await plugin.call('contentImport', 'resolveGithubFolder', params.ghfolder)
+ for (const [path, content] of Object.entries(files)) {
+ await workspaceProvider.set(path, content)
+ }
+ } catch (e) {
+ console.log(e)
+ }
+ }
+
return path
} catch (e) {
console.error(e)
@@ -645,7 +655,7 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea
export const cloneRepository = async (url: string) => {
const config = plugin.registry.get('config').api
const token = config.get('settings/gist-access-token')
- const repoConfig: cloneInputType = { url, token }
+ const repoConfig: cloneInputType = { url, token, depth: 10 }
if (plugin.registry.get('platform').api.isDesktop()) {
try {
@@ -662,7 +672,7 @@ export const cloneRepository = async (url: string) => {
const repoName = await getRepositoryTitle(url)
await createWorkspace(repoName, 'blank', null, true, null, true, false)
- const promise = dgitPlugin.call('dgitApi', 'clone', { ...repoConfig, workspaceExists: true, workspaceName: repoName })
+ const promise = dgitPlugin.call('dgitApi', 'clone', { ...repoConfig, workspaceExists: true, workspaceName: repoName, depth:10 })
dispatch(cloneRepositoryRequest())
promise
diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
index 25978baa79..950c2810ff 100644
--- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
+++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
@@ -36,7 +36,11 @@ export const FileExplorer = (props: FileExplorerProps) => {
const [state, setState] = useState(workspaceState)
// const [isPending, startTransition] = useTransition();
const treeRef = useRef(null)
+
+ const { plugin } = useContext(FileSystemContext)
+ const [feTarget, setFeTarget] = useState<{ key: string, type: 'file' | 'folder' }[]>({} as { key: string, type: 'file' | 'folder' }[])
const [filesSelected, setFilesSelected] = useState([])
+ const feWindow = (window as any)
useEffect(() => {
if (contextMenuItems) {
@@ -98,6 +102,100 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}, [treeRef.current])
+ useEffect(() => {
+ const performDeletion = async () => {
+ const path: string[] = []
+ if (feTarget?.length > 0 && feTarget[0]?.key.length > 0) {
+ feTarget.forEach((one) => {
+ path.push(one.key)
+ })
+ await deletePath(path)
+ }
+ }
+
+ if (treeRef.current) {
+ const deleteKeyPressHandler = async (eve: KeyboardEvent) => {
+ if (eve.key === 'Delete' ) {
+ feWindow._paq.push(['trackEvent', 'fileExplorer', 'deleteKey', 'deletePath'])
+ setState((prevState) => {
+ return { ...prevState, deleteKey: true }
+ })
+ performDeletion()
+ return
+ }
+ if (eve.metaKey) {
+ if (eve.key === 'Backspace') {
+ feWindow._paq.push(['trackEvent', 'fileExplorer', 'osxDeleteKey', 'deletePath'])
+ setState((prevState) => {
+ return { ...prevState, deleteKey: true }
+ })
+ performDeletion()
+ return
+ }
+ }
+ }
+ const deleteKeyPressUpHandler = async (eve: KeyboardEvent) => {
+ if (eve.key === 'Delete' ) {
+ setState((prevState) => {
+ return { ...prevState, deleteKey: false }
+ })
+ return
+ }
+ if (eve.metaKey) {
+ if (eve.key === 'Backspace') {
+ setState((prevState) => {
+ return { ...prevState, deleteKey: false }
+ })
+ return
+ }
+ }
+ }
+
+ treeRef.current?.addEventListener('keydown', deleteKeyPressHandler)
+ treeRef.current?.addEventListener('keyup', deleteKeyPressUpHandler)
+ return () => {
+ treeRef.current?.removeEventListener('keydown', deleteKeyPressHandler)
+ treeRef.current?.removeEventListener('keyup', deleteKeyPressUpHandler)
+ }
+ }
+ }, [treeRef.current, feTarget])
+
+ useEffect(() => {
+ const performRename = async () => {
+ if (feTarget?.length > 1 && feTarget[0]?.key.length > 1) {
+ await plugin.call('notification', 'alert', { id: 'renameAlert', message: 'You cannot rename multiple files at once!' })
+ }
+ props.editModeOn(feTarget[0].key, feTarget[0].type, false)
+ }
+ if (treeRef.current) {
+ const F2KeyPressHandler = async (eve: KeyboardEvent) => {
+ if (eve.key === 'F2' ) {
+ feWindow._paq.push(['trackEvent', 'fileExplorer', 'f2ToRename', 'RenamePath'])
+ await performRename()
+ setState((prevState) => {
+ return { ...prevState, F2Key: true }
+ })
+ return
+ }
+ }
+ const F2KeyPressUpHandler = async (eve: KeyboardEvent) => {
+ if (eve.key === 'F2' ) {
+ setState((prevState) => {
+ return { ...prevState, F2Key: false }
+ })
+ return
+ }
+ }
+
+ treeRef.current?.addEventListener('keydown', F2KeyPressHandler)
+ treeRef.current?.addEventListener('keyup', F2KeyPressUpHandler)
+ return () => {
+ treeRef.current?.removeEventListener('keydown', F2KeyPressHandler)
+ treeRef.current?.removeEventListener('keyup', F2KeyPressUpHandler)
+ }
+ }
+ }, [treeRef.current, feTarget])
+
const hasReservedKeyword = (content: string): boolean => {
if (state.reservedKeywords.findIndex((value) => content.startsWith(value)) !== -1) return true
else return false
@@ -434,6 +532,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
createNewFolder={props.createNewFolder}
deletePath={deletePath}
editPath={props.editModeOn}
+ fileTarget={feTarget}
+ setTargetFiles={setFeTarget}
/>