Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
10bffb21
Commit
10bffb21
authored
May 09, 2019
by
Samuel GAIST
Browse files
[widgets][assetbrowser] Implement contextual menu for deletion
parent
a9ff6525
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/editor/widgets/assetbrowser.py
View file @
10bffb21
...
...
@@ -23,11 +23,13 @@
# #
###############################################################################
from
PyQt5
import
QtCore
from
PyQt5.QtCore
import
pyqtSignal
from
PyQt5.QtCore
import
QSortFilterProxyModel
from
PyQt5.QtWidgets
import
QHeaderView
from
PyQt5.QtWidgets
import
QFileSystemModel
from
PyQt5.QtWidgets
import
QMenu
from
PyQt5.QtWidgets
import
QStyledItemDelegate
from
PyQt5.QtWidgets
import
QTreeView
from
PyQt5.QtWidgets
import
QVBoxLayout
...
...
@@ -88,6 +90,7 @@ class AssetBrowser(QWidget):
"""
json_selected
=
pyqtSignal
([
"QString"
])
deletionRequested
=
pyqtSignal
([
"QString"
])
def
__init__
(
self
,
parent
=
None
):
"""Constructor"""
...
...
@@ -104,11 +107,13 @@ class AssetBrowser(QWidget):
self
.
view
.
setColumnHidden
(
2
,
True
)
self
.
view
.
header
().
setSectionResizeMode
(
0
,
QHeaderView
.
Stretch
)
self
.
view
.
setItemDelegateForColumn
(
0
,
AssetItemDelegate
(
".json"
))
self
.
view
.
setContextMenuPolicy
(
QtCore
.
Qt
.
CustomContextMenu
)
layout
=
QVBoxLayout
(
self
)
layout
.
addWidget
(
self
.
view
)
self
.
view
.
doubleClicked
.
connect
(
self
.
__on_item_selected
)
self
.
view
.
customContextMenuRequested
.
connect
(
self
.
__open_menu
)
def
__on_item_selected
(
self
,
index
):
"""When an item is selected, emit the json_selected signal with
...
...
@@ -119,6 +124,22 @@ class AssetBrowser(QWidget):
if
self
.
filesystem_model
.
type
(
source_index
).
lower
()
==
"json file"
:
self
.
json_selected
.
emit
(
self
.
filesystem_model
.
filePath
(
source_index
))
def
__open_menu
(
self
,
position
):
indexes
=
self
.
view
.
selectedIndexes
()
if
indexes
and
indexes
[
0
].
data
().
endswith
(
".json"
):
menu
=
QMenu
()
action
=
menu
.
addAction
(
self
.
tr
(
"Delete"
))
action
.
triggered
.
connect
(
self
.
__on_delete
)
menu
.
exec_
(
self
.
view
.
viewport
().
mapToGlobal
(
position
))
def
__on_delete
(
self
):
file_index
,
_
=
self
.
view
.
selectedIndexes
()
source_index
=
self
.
proxy_model
.
mapToSource
(
file_index
)
path
=
self
.
filesystem_model
.
filePath
(
source_index
)
self
.
deletionRequested
.
emit
(
path
)
def
set_context
(
self
,
context
):
"""Sets the root path of the prefix to edit"""
...
...
Write
Preview
Supports
Markdown
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