Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
2cb01ff7
Commit
2cb01ff7
authored
Jan 19, 2021
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use event emitter for ciontext menu action
parent
9f4599eb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
7 deletions
+20
-7
file-panel.js
apps/remix-ide/src/app/panels/file-panel.js
+4
-4
file-explorer-context-menu.tsx
...x-ui/file-explorer/src/lib/file-explorer-context-menu.tsx
+2
-2
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+12
-0
index.ts
libs/remix-ui/file-explorer/src/lib/types/index.ts
+2
-1
No files found.
apps/remix-ide/src/app/panels/file-panel.js
View file @
2cb01ff7
...
...
@@ -108,11 +108,11 @@ module.exports = class Filepanel extends ViewPlugin {
* @param item { name: string, type?: string[], path?: string[], extension?: string[], pattern?: string[] }
* @param callback (...args) => void
*/
registerContextMenuItem
(
item
,
callback
)
{
if
(
!
item
.
name
||
!
callback
)
return
console
.
error
(
'menu name and callback is mandatory'
)
if
(
!
item
.
type
&&
!
item
.
path
&&
!
item
.
extension
&&
!
item
.
pattern
)
return
console
.
error
(
'invalid file matching criteria provided'
)
registerContextMenuItem
(
item
)
{
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'
)
item
.
action
=
callback
this
.
registeredMenuItems
=
[...
this
.
registeredMenuItems
,
item
]
this
.
renderComponent
()
}
...
...
libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx
View file @
2cb01ff7
...
...
@@ -4,7 +4,7 @@ import { FileExplorerContextMenuProps } from './types'
import
'./css/file-explorer-context-menu.css'
export
const
FileExplorerContextMenu
=
(
props
:
FileExplorerContextMenuProps
)
=>
{
const
{
actions
,
createNewFile
,
createNewFolder
,
deletePath
,
renamePath
,
hideContextMenu
,
publishToGist
,
runScript
,
pageX
,
pageY
,
path
,
type
,
...
otherProps
}
=
props
const
{
actions
,
createNewFile
,
createNewFolder
,
deletePath
,
renamePath
,
hideContextMenu
,
publishToGist
,
runScript
,
emit
,
pageX
,
pageY
,
path
,
type
,
...
otherProps
}
=
props
const
contextMenuRef
=
useRef
(
null
)
useEffect
(()
=>
{
...
...
@@ -56,7 +56,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
runScript
(
path
)
break
default
:
item
.
action
&&
item
.
action
(
path
)
emit
&&
emit
(
item
.
id
,
path
)
break
}
hideContextMenu
()
...
...
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
2cb01ff7
...
...
@@ -76,36 +76,42 @@ export const FileExplorer = (props: FileExplorerProps) => {
const
accessToken
=
config
.
get
(
'settings/gist-access-token'
)
const
files
=
await
fetchDirectoryContent
(
name
)
const
actions
=
[{
id
:
'newFile'
,
name
:
'New File'
,
type
:
[
'folder'
],
path
:
[],
extension
:
[],
pattern
:
[]
},
{
id
:
'newFolder'
,
name
:
'New Folder'
,
type
:
[
'folder'
],
path
:
[],
extension
:
[],
pattern
:
[]
},
{
id
:
'rename'
,
name
:
'Rename'
,
type
:
[
'file'
,
'folder'
],
path
:
[],
extension
:
[],
pattern
:
[]
},
{
id
:
'delete'
,
name
:
'Delete'
,
type
:
[
'file'
,
'folder'
],
path
:
[],
extension
:
[],
pattern
:
[]
},
{
id
:
'pushChangesToGist'
,
name
:
'Push changes to gist'
,
type
:
[],
path
:
[],
extension
:
[],
pattern
:
[
'^browser/gists/([0-9]|[a-z])*$'
]
},
{
id
:
'run'
,
name
:
'Run'
,
type
:
[],
path
:
[],
...
...
@@ -614,6 +620,10 @@ export const FileExplorer = (props: FileExplorerProps) => {
})
}
const
emitContextMenuEvent
=
(
id
:
string
,
path
:
string
)
=>
{
plugin
.
emit
(
id
,
path
)
}
const
handleHideModal
=
()
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
modalOptions
:
{
...
state
.
modalOptions
,
hide
:
true
}
}
...
...
@@ -850,6 +860,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
deletePath=
{
deletePath
}
renamePath=
{
editModeOn
}
publishToGist=
{
publishToGist
}
emit=
{
emitContextMenuEvent
}
pageX=
{
state
.
focusContext
.
x
}
pageY=
{
state
.
focusContext
.
y
}
path=
{
file
.
path
}
...
...
@@ -886,6 +897,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
deletePath=
{
deletePath
}
renamePath=
{
editModeOn
}
runScript=
{
runScript
}
emit=
{
emitContextMenuEvent
}
pageX=
{
state
.
focusContext
.
x
}
pageY=
{
state
.
focusContext
.
y
}
path=
{
file
.
path
}
...
...
libs/remix-ui/file-explorer/src/lib/types/index.ts
View file @
2cb01ff7
...
...
@@ -27,7 +27,7 @@ export interface FileExplorerMenuProps {
}
export
interface
FileExplorerContextMenuProps
{
actions
:
{
name
:
string
,
type
:
string
[],
path
:
string
[],
extension
:
string
[],
pattern
:
string
[],
action
?:
(...
args
)
=>
void
}[],
actions
:
{
name
:
string
,
type
:
string
[],
path
:
string
[],
extension
:
string
[],
pattern
:
string
[],
id
:
string
}[],
createNewFile
:
(
folder
?:
string
)
=>
void
,
createNewFolder
:
(
parentFolder
?:
string
)
=>
void
,
deletePath
:
(
path
:
string
)
=>
void
,
...
...
@@ -35,6 +35,7 @@ export interface FileExplorerContextMenuProps {
hideContextMenu
:
()
=>
void
,
publishToGist
?:
()
=>
void
,
runScript
?:
(
path
:
string
)
=>
void
,
emit
?:
(
id
:
string
,
path
:
string
)
=>
void
,
pageX
:
number
,
pageY
:
number
,
path
:
string
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment