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
68131547
Unverified
Commit
68131547
authored
Mar 15, 2021
by
David Disu
Committed by
GitHub
Mar 15, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #966 from ethereum/context-menu
Refactored Context Menu
parents
b7068d35
286f02b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
108 deletions
+86
-108
file-explorer-context-menu.tsx
...x-ui/file-explorer/src/lib/file-explorer-context-menu.tsx
+1
-1
file-explorer.tsx
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
+85
-107
No files found.
libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx
View file @
68131547
...
@@ -16,7 +16,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
...
@@ -16,7 +16,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
const
boundary
=
menuItemsContainer
.
getBoundingClientRect
()
const
boundary
=
menuItemsContainer
.
getBoundingClientRect
()
if
(
boundary
.
bottom
>
(
window
.
innerHeight
||
document
.
documentElement
.
clientHeight
))
{
if
(
boundary
.
bottom
>
(
window
.
innerHeight
||
document
.
documentElement
.
clientHeight
))
{
menuItemsContainer
.
style
.
position
=
'
absolute
'
menuItemsContainer
.
style
.
position
=
'
fixed
'
menuItemsContainer
.
style
.
bottom
=
'10px'
menuItemsContainer
.
style
.
bottom
=
'10px'
menuItemsContainer
.
style
.
top
=
null
menuItemsContainer
.
style
.
top
=
null
}
}
...
...
libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
View file @
68131547
...
@@ -32,7 +32,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -32,7 +32,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
focusContext
:
{
focusContext
:
{
element
:
null
,
element
:
null
,
x
:
null
,
x
:
null
,
y
:
null
y
:
null
,
type
:
''
},
},
focusEdit
:
{
focusEdit
:
{
element
:
null
,
element
:
null
,
...
@@ -57,7 +58,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -57,7 +58,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
},
},
modals
:
[],
modals
:
[],
toasterMsg
:
''
,
toasterMsg
:
''
,
mouseOverElement
:
null
mouseOverElement
:
null
,
showContextMenu
:
false
})
})
const
editRef
=
useRef
(
null
)
const
editRef
=
useRef
(
null
)
...
@@ -755,20 +757,20 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -755,20 +757,20 @@ export const FileExplorer = (props: FileExplorerProps) => {
const
handleContextMenuFile
=
(
pageX
:
number
,
pageY
:
number
,
path
:
string
,
content
:
string
)
=>
{
const
handleContextMenuFile
=
(
pageX
:
number
,
pageY
:
number
,
path
:
string
,
content
:
string
)
=>
{
if
(
!
content
)
return
if
(
!
content
)
return
setState
(
prevState
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
focusContext
:
{
element
:
path
,
x
:
pageX
,
y
:
pageY
},
focusEdit
:
{
...
prevState
.
focusEdit
,
lastEdit
:
content
}
}
return
{
...
prevState
,
focusContext
:
{
element
:
path
,
x
:
pageX
,
y
:
pageY
,
type
:
'file'
},
focusEdit
:
{
...
prevState
.
focusEdit
,
lastEdit
:
content
},
showContextMenu
:
prevState
.
focusEdit
.
element
!==
path
}
})
})
}
}
const
handleContextMenuFolder
=
(
pageX
:
number
,
pageY
:
number
,
path
:
string
,
content
:
string
)
=>
{
const
handleContextMenuFolder
=
(
pageX
:
number
,
pageY
:
number
,
path
:
string
,
content
:
string
)
=>
{
if
(
!
content
)
return
if
(
!
content
)
return
setState
(
prevState
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
focusContext
:
{
element
:
path
,
x
:
pageX
,
y
:
pageY
},
focusEdit
:
{
...
prevState
.
focusEdit
,
lastEdit
:
content
}
}
return
{
...
prevState
,
focusContext
:
{
element
:
path
,
x
:
pageX
,
y
:
pageY
,
type
:
'folder'
},
focusEdit
:
{
...
prevState
.
focusEdit
,
lastEdit
:
content
},
showContextMenu
:
prevState
.
focusEdit
.
element
!==
path
}
})
})
}
}
const
hideContextMenu
=
()
=>
{
const
hideContextMenu
=
()
=>
{
setState
(
prevState
=>
{
setState
(
prevState
=>
{
return
{
...
prevState
,
focusContext
:
{
element
:
null
,
x
:
0
,
y
:
0
}
}
return
{
...
prevState
,
focusContext
:
{
element
:
null
,
x
:
0
,
y
:
0
,
type
:
''
},
showContextMenu
:
false
}
})
})
}
}
...
@@ -907,113 +909,69 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -907,113 +909,69 @@ export const FileExplorer = (props: FileExplorerProps) => {
if
(
file
.
isDirectory
)
{
if
(
file
.
isDirectory
)
{
return
(
return
(
<
div
key=
{
index
}
>
<
TreeViewItem
<
TreeViewItem
id=
{
`treeViewItem${file.path}`
}
id=
{
`treeViewItem${file.path}`
}
iconX=
'pr-3 fa fa-folder'
iconX=
'pr-3 fa fa-folder'
iconY=
'pr-3 fa fa-folder-open'
iconY=
'pr-3 fa fa-folder-open'
key=
{
`${file.path + index}`
}
key=
{
`${file.path + index}`
}
label=
{
label
(
file
)
}
label=
{
label
(
file
)
}
onClick=
{
(
e
)
=>
{
onClick=
{
(
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
if
(
state
.
focusEdit
.
element
!==
file
.
path
)
handleClickFolder
(
file
.
path
)
if
(
state
.
focusEdit
.
element
!==
file
.
path
)
handleClickFolder
(
file
.
path
)
}
}
}
}
onContextMenu=
{
(
e
)
=>
{
onContextMenu=
{
(
e
)
=>
{
e
.
preventDefault
()
e
.
preventDefault
()
e
.
stopPropagation
()
e
.
stopPropagation
()
handleContextMenuFolder
(
e
.
pageX
,
e
.
pageY
,
file
.
path
,
e
.
target
.
textContent
)
handleContextMenuFolder
(
e
.
pageX
,
e
.
pageY
,
file
.
path
,
e
.
target
.
textContent
)
}
}
}
}
labelClass=
{
labelClass
}
labelClass=
{
labelClass
}
controlBehaviour=
{
state
.
ctrlKey
}
controlBehaviour=
{
state
.
ctrlKey
}
expand=
{
state
.
expandPath
.
includes
(
file
.
path
)
}
expand=
{
state
.
expandPath
.
includes
(
file
.
path
)
}
onMouseOver=
{
(
e
)
=>
{
onMouseOver=
{
(
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
handleMouseOver
(
file
.
path
)
handleMouseOver
(
file
.
path
)
}
}
}
}
onMouseOut=
{
(
e
)
=>
{
onMouseOut=
{
(
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
if
(
state
.
mouseOverElement
===
file
.
path
)
handleMouseOut
()
if
(
state
.
mouseOverElement
===
file
.
path
)
handleMouseOut
()
}
}
}
}
>
>
{
{
file
.
child
?
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
index
}
>
{
file
.
child
?
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
index
}
>
{
file
.
child
.
map
((
file
,
index
)
=>
{
file
.
child
.
map
((
file
,
index
)
=>
{
return
renderFiles
(
file
,
index
)
return
renderFiles
(
file
,
index
)
})
})
}
</
TreeView
>
:
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
index
}
/>
}
}
</
TreeViewItem
>
</
TreeView
>
:
<
TreeView
id=
{
`treeView${file.path}`
}
key=
{
index
}
/>
{
((
state
.
focusContext
.
element
===
file
.
path
)
&&
(
state
.
focusEdit
.
element
!==
file
.
path
))
&&
<
FileExplorerContextMenu
actions=
{
state
.
actions
}
hideContextMenu=
{
hideContextMenu
}
createNewFile=
{
handleNewFileInput
}
createNewFolder=
{
handleNewFolderInput
}
deletePath=
{
deletePath
}
renamePath=
{
editModeOn
}
publishToGist=
{
publishToGist
}
emit=
{
emitContextMenuEvent
}
pageX=
{
state
.
focusContext
.
x
}
pageY=
{
state
.
focusContext
.
y
}
path=
{
file
.
path
}
type=
'folder'
onMouseOver=
{
(
e
)
=>
{
e
.
stopPropagation
()
handleMouseOver
(
file
.
path
)
}
}
/>
}
}
</
div
>
</
TreeViewItem
>
)
)
}
else
{
}
else
{
return
(
return
(
<
div
key=
{
index
}
>
<
TreeViewItem
<
TreeViewItem
id=
{
`treeViewItem${file.path}`
}
id=
{
`treeViewItem${file.path}`
}
key=
{
index
}
key=
{
index
}
label=
{
label
(
file
)
}
label=
{
label
(
file
)
}
onClick=
{
(
e
)
=>
{
onClick=
{
(
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
if
(
state
.
focusEdit
.
element
!==
file
.
path
)
handleClickFile
(
file
.
path
)
if
(
state
.
focusEdit
.
element
!==
file
.
path
)
handleClickFile
(
file
.
path
)
}
}
}
}
onContextMenu=
{
(
e
)
=>
{
onContextMenu=
{
(
e
)
=>
{
e
.
preventDefault
()
e
.
preventDefault
()
e
.
stopPropagation
()
e
.
stopPropagation
()
handleContextMenuFile
(
e
.
pageX
,
e
.
pageY
,
file
.
path
,
e
.
target
.
textContent
)
handleContextMenuFile
(
e
.
pageX
,
e
.
pageY
,
file
.
path
,
e
.
target
.
textContent
)
}
}
}
}
icon=
{
icon
}
icon=
{
icon
}
labelClass=
{
labelClass
}
labelClass=
{
labelClass
}
onMouseOver=
{
(
e
)
=>
{
onMouseOver=
{
(
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
handleMouseOver
(
file
.
path
)
handleMouseOver
(
file
.
path
)
}
}
}
}
onMouseOut=
{
(
e
)
=>
{
onMouseOut=
{
(
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
if
(
state
.
mouseOverElement
===
file
.
path
)
handleMouseOut
()
if
(
state
.
mouseOverElement
===
file
.
path
)
handleMouseOut
()
}
}
}
}
/>
/>
{
((
state
.
focusContext
.
element
===
file
.
path
)
&&
(
state
.
focusEdit
.
element
!==
file
.
path
))
&&
<
FileExplorerContextMenu
actions=
{
state
.
actions
}
hideContextMenu=
{
hideContextMenu
}
createNewFile=
{
handleNewFileInput
}
createNewFolder=
{
handleNewFolderInput
}
deletePath=
{
deletePath
}
renamePath=
{
editModeOn
}
runScript=
{
runScript
}
emit=
{
emitContextMenuEvent
}
pageX=
{
state
.
focusContext
.
x
}
pageY=
{
state
.
focusContext
.
y
}
path=
{
file
.
path
}
type=
'file'
onMouseOver=
{
(
e
)
=>
{
e
.
stopPropagation
()
handleMouseOver
(
file
.
path
)
}
}
/>
}
</
div
>
)
)
}
}
}
}
...
@@ -1073,6 +1031,26 @@ export const FileExplorer = (props: FileExplorerProps) => {
...
@@ -1073,6 +1031,26 @@ export const FileExplorer = (props: FileExplorerProps) => {
/>
/>
}
}
<
Toaster
message=
{
state
.
toasterMsg
}
/>
<
Toaster
message=
{
state
.
toasterMsg
}
/>
{
state
.
showContextMenu
&&
<
FileExplorerContextMenu
actions=
{
state
.
actions
}
hideContextMenu=
{
hideContextMenu
}
createNewFile=
{
handleNewFileInput
}
createNewFolder=
{
handleNewFolderInput
}
deletePath=
{
deletePath
}
renamePath=
{
editModeOn
}
runScript=
{
runScript
}
emit=
{
emitContextMenuEvent
}
pageX=
{
state
.
focusContext
.
x
}
pageY=
{
state
.
focusContext
.
y
}
path=
{
state
.
focusContext
.
element
}
type=
{
state
.
focusContext
.
type
}
onMouseOver=
{
(
e
)
=>
{
e
.
stopPropagation
()
handleMouseOver
(
state
.
focusContext
.
element
)
}
}
/>
}
</
div
>
</
div
>
)
)
}
}
...
...
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