From 5c8a92ac0f0e8c11686f8ddb80d053754c5d5fae Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 22 Jun 2023 13:20:12 +0200 Subject: [PATCH] remove recent folder --- apps/remixdesktop/src/plugins/fsPlugin.ts | 9 ++- .../workspace/src/lib/actions/workspace.ts | 5 ++ .../src/lib/components/electron-menu.tsx | 63 ++++++++++--------- .../workspace/src/lib/contexts/index.ts | 1 + .../src/lib/providers/FileSystemProvider.tsx | 10 ++- 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/apps/remixdesktop/src/plugins/fsPlugin.ts b/apps/remixdesktop/src/plugins/fsPlugin.ts index 529a8eccf0..e24a115b6a 100644 --- a/apps/remixdesktop/src/plugins/fsPlugin.ts +++ b/apps/remixdesktop/src/plugins/fsPlugin.ts @@ -72,7 +72,7 @@ const clientProfile: Profile = { name: 'fs', displayName: 'fs', description: 'fs', - methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'getRecentFolders', 'glob', 'openWindow', 'selectFolder'] + methods: ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'lstat', 'exists', 'currentPath', 'watch', 'closeWatch', 'setWorkingDir', 'openFolder', 'getRecentFolders', 'removeRecentFolder', 'glob', 'openWindow', 'selectFolder'] } class FSPluginClient extends ElectronBasePluginClient { @@ -295,6 +295,13 @@ class FSPluginClient extends ElectronBasePluginClient { return config.recentFolders || [] } + async removeRecentFolder(path: string): Promise { + const config = await this.call('electronconfig' as any, 'readConfig') + config.recentFolders = config.recentFolders || [] + config.recentFolders = config.recentFolders.filter((p: string) => p !== path) + writeConfig(config) + } + async selectFolder(path?: string): Promise { let dirs: string[] | undefined diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 3ca11efaaa..fac8548517 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -784,6 +784,11 @@ export const getElectronRecentFolders = async () => { return folders } +export const removeRecentElectronFolder = async (path: string) => { + await plugin.call('fs', 'removeRecentFolder', path) + await getElectronRecentFolders() +} + export const hasLocalChanges = async () => { const filesStatus = await plugin.call('dGitProvider', 'status') const uncommittedFiles = getUncommittedFiles(filesStatus) diff --git a/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx b/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx index 3c0a6d2631..7c70a45fd1 100644 --- a/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/electron-menu.tsx @@ -3,6 +3,7 @@ import { FileSystemContext } from "../contexts" import isElectron from 'is-electron' import { FormattedMessage } from "react-intl" import '../css/electron-menu.css' +import { CustomTooltip } from '@remix-ui/helper' export const ElectronMenu = () => { const global = useContext(FileSystemContext) @@ -31,35 +32,41 @@ export const ElectronMenu = () => { return ( !isElectron() ? null : - (global.fs.browser.isSuccessfulWorkspace ? null : - <> -
{await openFolderElectron(null)}} className='btn btn-primary'>
- {global.fs.browser.recentFolders.length > 0 ? - <> - -
    - {global.fs.browser.recentFolders.map((folder, index) => { - return
  • -
    - {await openFolderElectron(folder)}} className="pl-2 recentfolder_name pr-2">{lastFolderName(folder)} - {await openFolderElectron(folder)}} data-id={{folder}} className="recentfolder_path pr-2">{folder} - { - - }} - className="fas fa-times recentfolder_delete pr-2" + (global.fs.browser.isSuccessfulWorkspace ? null : + <> +
    { await openFolderElectron(null) }} className='btn btn-primary'>
    + {global.fs.browser.recentFolders.length > 0 ? + <> + +
      + {global.fs.browser.recentFolders.map((folder, index) => { + return
    • + +
      + { await openFolderElectron(folder) }} className="pl-2 recentfolder_name pr-2">{lastFolderName(folder)} + { await openFolderElectron(folder) }} data-id={{ folder }} className="recentfolder_path pr-2">{folder} + { + global.dispatchRemoveRecentFolder(folder) + }} + className="fas fa-times recentfolder_delete pr-2" + > - -
      -
    • - })} -
    - - : null} - - ) +
    +
    + +
  • + })} +
+ + : null} + + ) ) } \ No newline at end of file diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 73c38808cb..a01c06383e 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -48,6 +48,7 @@ export const FileSystemContext = createContext<{ dispatchCreateHelperScripts: (script: string) => Promise dispatchOpenElectronFolder: (path: string) => Promise dispatchGetElectronRecentFolders: () => Promise + dispatchRemoveRecentFolder: (path: string) => Promise }>(null) \ No newline at end of file diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index cf92c5e6f0..3ece306dc1 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -8,7 +8,7 @@ import { browserReducer, browserInitialState } from '../reducers/workspace' import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, deleteAllWorkspaces, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder, deletePath, renamePath, downloadPath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace, fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadWorkspace, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder, - showAllBranches, switchBranch, createNewBranch, checkoutRemoteBranch, createSolidityGithubAction, createTsSolGithubAction, createSlitherGithubAction, createHelperScripts, openElectronFolder, getElectronRecentFolders + showAllBranches, switchBranch, createNewBranch, checkoutRemoteBranch, createSolidityGithubAction, createTsSolGithubAction, createSlitherGithubAction, createHelperScripts, openElectronFolder, getElectronRecentFolders, removeRecentElectronFolder } from '../actions' import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types' // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -197,6 +197,11 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await getElectronRecentFolders() } + const dispatchRemoveRecentFolder = async (path: string) => { + console.log('remove recent folder') + await removeRecentElectronFolder(path) + } + useEffect(() => { dispatchInitWorkspace() @@ -317,7 +322,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => { dispatchCreateSlitherGithubAction, dispatchCreateHelperScripts, dispatchOpenElectronFolder, - dispatchGetElectronRecentFolders + dispatchGetElectronRecentFolders, + dispatchRemoveRecentFolder } return (