added customactions

rm event
targets
filip mertens 4 years ago
parent 4af124d3c0
commit 0f02ded1e2
  1. 16
      apps/remix-ide/src/app/panels/file-panel.js
  2. 3
      libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx
  3. 5
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  4. 4
      libs/remix-ui/file-explorer/src/lib/types/index.ts
  5. 15
      package.json

@ -34,7 +34,7 @@ const modalDialogCustom = require('../ui/modal-dialog-custom')
const profile = {
name: 'filePanel',
displayName: 'File explorers',
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace'],
methods: ['createNewFile', 'uploadFile', 'getCurrentWorkspace', 'getWorkspaces', 'createWorkspace', 'registerContextMenuItem'],
events: ['setWorkspace', 'renameWorkspace', 'deleteWorkspace'],
icon: 'assets/img/fileManager.webp',
description: ' - ',
@ -64,6 +64,7 @@ module.exports = class Filepanel extends ViewPlugin {
this.request = {}
this.workspaces = []
this.initialWorkspace = null
this.appManager = appManager
}
render () {
@ -102,11 +103,19 @@ module.exports = class Filepanel extends ViewPlugin {
if (!item) throw new Error('Invalid register context menu argument')
if (!item.name || !item.id) throw new Error('Item name and id is mandatory')
if (!item.type && !item.path && !item.extension && !item.pattern) throw new Error('Invalid file matching criteria provided')
if (this.registeredMenuItems.filter((o) => {
return o.id === item.id & o.name === item.name
}).length) throw new Error(`Action ${item.name} already exists on ${item.id}`)
this.registeredMenuItems = [...this.registeredMenuItems, item]
this.renderComponent()
}
removePluginActions (plugin) {
this.registeredMenuItems = this.registeredMenuItems.filter((item) => {
return item.id !== plugin.name
})
}
async getCurrentWorkspace () {
return await this.request.getCurrentWorkspace()
}
@ -173,6 +182,9 @@ module.exports = class Filepanel extends ViewPlugin {
}
this.getWorkspaces()
})
const self = this
this.appManager.on('manager', 'pluginDeactivated', self.removePluginActions.bind(this))
}
async createNewFile () {

@ -2,6 +2,7 @@ import React, { useRef, useEffect } from 'react' // eslint-disable-line
import { FileExplorerContextMenuProps } from './types'
import './css/file-explorer-context-menu.css'
import { customAction } from '@remixproject/plugin-api/lib/file-system/file-panel'
export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) => {
const { actions, createNewFile, createNewFolder, deletePath, renamePath, hideContextMenu, publishToGist, runScript, emit, pageX, pageY, path, type, ...otherProps } = props
@ -56,7 +57,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
runScript(path)
break
default:
emit && emit(item.id, path)
emit && emit({ ...item, path: [path] } as customAction)
break
}
hideContextMenu()

@ -11,6 +11,7 @@ import { fileSystemReducer, fileSystemInitialState } from './reducers/fileSystem
import { fetchDirectory, init, resolveDirectory, addInputField, removeInputField } from './actions/fileSystem'
import * as helper from '../../../../../apps/remix-ide/src/lib/helper'
import QueryParams from '../../../../../apps/remix-ide/src/lib/query-params'
import { customAction } from '@remixproject/plugin-api/lib/file-system/file-panel'
import './css/file-explorer.css'
@ -526,8 +527,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
})
}
const emitContextMenuEvent = (id: string, path: string) => {
plugin.emit(id, path)
const emitContextMenuEvent = (cmd: customAction) => {
plugin.call(cmd.id, cmd.name, cmd)
}
const handleHideModal = () => {

@ -1,3 +1,5 @@
import { customAction } from '@remixproject/plugin-api/lib/file-system/file-panel'
/* eslint-disable-next-line */
export interface FileExplorerProps {
name: string,
@ -37,7 +39,7 @@ export interface FileExplorerContextMenuProps {
hideContextMenu: () => void,
publishToGist?: () => void,
runScript?: (path: string) => void,
emit?: (id: string, path: string) => void,
emit?: (cmd: customAction) => void,
pageX: number,
pageY: number,
path: string,

@ -134,13 +134,13 @@
"@ethereumjs/common": "^2.2.0",
"@ethereumjs/tx": "^3.1.3",
"@ethereumjs/vm": "^5.3.2",
"@remixproject/engine": "^0.3.11",
"@remixproject/engine-web": "^0.3.11",
"@remixproject/plugin": "^0.3.11",
"@remixproject/plugin-api": "^0.3.11",
"@remixproject/plugin-utils": "^0.3.11",
"@remixproject/plugin-webview": "^0.3.11",
"@remixproject/plugin-ws": "^0.3.11",
"@remixproject/engine": "^0.3.14",
"@remixproject/engine-web": "^0.3.14",
"@remixproject/plugin": "^0.3.14",
"@remixproject/plugin-api": "^0.3.14",
"@remixproject/plugin-utils": "^0.3.14",
"@remixproject/plugin-webview": "^0.3.14",
"@remixproject/plugin-ws": "^0.3.14",
"ansi-gray": "^0.1.1",
"async": "^2.6.2",
"axios": ">=0.21.1",
@ -161,7 +161,6 @@
"jszip": "^3.6.0",
"lodash": "^4.17.21",
"latest-version": "^5.1.0",
"lodash": "^4.17.21",
"merge": "^1.2.0",
"npm-install-version": "^6.0.2",
"react": "16.13.1",

Loading…
Cancel
Save