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
599a6e89
Commit
599a6e89
authored
Jul 10, 2019
by
Christine MARCEL
Committed by
Samuel GAIST
Jul 31, 2019
Browse files
[widgets][assetwidget] Add confirmation dialog when deleting asset
Fixes
#242
parent
2891474b
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_assetwidget.py
View file @
599a6e89
...
...
@@ -335,6 +335,55 @@ class TestAssetWidget:
assert
asset_widget
.
current_asset
==
asset
assert
os
.
path
.
exists
(
asset
.
declaration_path
)
@
pytest
.
mark
.
parametrize
(
"messagebox_answer"
,
[
QMessageBox
.
Yes
,
QMessageBox
.
No
],
ids
=
[
"Yes"
,
"No"
]
)
def
test_delete_other_asset
(
self
,
qtbot
,
monkeypatch
,
test_prefix
,
beat_context
,
asset_type
,
asset_type_prefix_entry_map
,
messagebox_answer
,
):
asset_widget
=
AssetWidget
()
qtbot
.
addWidget
(
asset_widget
)
asset_widget
.
set_context
(
beat_context
)
monkeypatch
.
setattr
(
QMessageBox
,
"question"
,
lambda
*
args
:
messagebox_answer
)
asset_model
=
AssetModel
()
asset_model
.
setLatestOnlyEnabled
(
False
)
asset_model
.
asset_type
=
asset_type
asset_model
.
prefix_path
=
test_prefix
asset_list
=
asset_model
.
stringList
()
assert
len
(
asset_list
)
>=
2
# Using lasts assets in the list because of dataformats basetypes
asset_name_to_edit
=
asset_list
[
-
1
]
asset_name_to_delete
=
asset_list
[
-
2
]
asset_to_edit
=
Asset
(
test_prefix
,
asset_type
,
asset_name_to_edit
)
asset_to_delete
=
Asset
(
test_prefix
,
asset_type
,
asset_name_to_delete
)
with
qtbot
.
waitSignal
(
asset_widget
.
currentAssetChanged
):
asset_widget
.
loadAsset
(
asset_to_edit
)
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
asset_widget
.
deleteAsset
(
asset_to_delete
.
declaration_path
)
if
messagebox_answer
==
QMessageBox
.
Yes
:
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
assert
os
.
path
.
exists
(
asset_to_edit
.
declaration_path
)
assert
not
os
.
path
.
exists
(
asset_to_delete
.
declaration_path
)
else
:
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
assert
asset_widget
.
current_asset
==
asset_to_edit
assert
os
.
path
.
exists
(
asset_to_edit
.
declaration_path
)
assert
os
.
path
.
exists
(
asset_to_delete
.
declaration_path
)
def
test_load_empty_json
(
self
,
qtbot
,
...
...
beat/editor/widgets/assetwidget.py
View file @
599a6e89
...
...
@@ -328,7 +328,7 @@ class AssetWidget(QWidget):
"""
if
self
.
current_asset
and
self
.
current_asset
.
declaration_path
==
file_path
:
"""
Check before deletion
"""
#
Check before deletion
answer
=
QMessageBox
.
question
(
self
,
self
.
tr
(
"Deletion requested"
),
...
...
@@ -345,6 +345,16 @@ class AssetWidget(QWidget):
self
.
current_asset
.
delete
()
self
.
current_asset
=
None
else
:
# Check before deletion
answer
=
QMessageBox
.
question
(
self
,
self
.
tr
(
"Deletion requested"
),
self
.
tr
(
"You are about to delete an asset
\n\n
Are you sure you want to do that ?"
),
)
if
answer
==
QMessageBox
.
No
:
return
asset
=
Asset
.
from_path
(
self
.
prefix_root_path
,
file_path
)
asset
.
delete
()
...
...
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