Commit f1f2fc68 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch '243_add_close_button_to_assetwidget' into 'master'

Add button to allow closing the current editor

Closes #243

See merge request !147
parents 1eef985a 73450461
Pipeline #41897 passed with stages
in 13 minutes and 23 seconds
......@@ -617,3 +617,25 @@ class TestAssetWidget:
)
assert editor.error_label.toolTip() != ""
def test_closing(
self, qtbot, test_prefix, beat_context, asset_type, asset_type_prefix_entry_map
):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
asset_name = asset_type_prefix_entry_map[asset_type][0]
assert not asset_widget.close_button.isEnabled()
asset = Asset(test_prefix, asset_type, asset_name)
with qtbot.waitSignal(asset_widget.currentAssetChanged):
asset_widget.loadAsset(asset)
assert asset_widget.close_button.isEnabled()
qtbot.mouseClick(asset_widget.close_button, QtCore.Qt.LeftButton)
assert not asset_widget.close_button.isEnabled()
assert asset_widget.current_editor.asset_type == AssetType.UNKNOWN
......@@ -160,8 +160,18 @@ class AssetWidget(QWidget):
self.tab_widget.addTab(self.json_widget, self.tr("Raw JSON"))
self.asset_name_label = QLabel(self.tr("Unknown"))
close_icon = self.style().standardIcon(QStyle.SP_TitleBarCloseButton)
self.close_button = QPushButton(close_icon, "")
self.close_button.setFixedSize(16, 16)
self.close_button.setToolTip(self.tr("Close asset editor"))
top_layout = QHBoxLayout()
top_layout.addWidget(self.asset_name_label)
top_layout.addStretch()
top_layout.addWidget(self.close_button)
layout = QVBoxLayout(self)
layout.addWidget(self.asset_name_label)
layout.addLayout(top_layout)
layout.addWidget(self.tab_widget)
edit_menu = QMenu(self)
......@@ -184,6 +194,7 @@ class AssetWidget(QWidget):
self.watcher.fileChanged.connect(self.__reloadFromHarddrive)
self.update_timer.timeout.connect(self.__enableSave)
self.update_timer.timeout.connect(self.__updateJsonWidget)
self.close_button.clicked.connect(self.__closeEditor)
self.save_button.clicked.connect(self.saveJson)
self.edit_code_action.triggered.connect(self.__editCode)
self.edit_documentation_action.triggered.connect(self.__editDocumentation)
......@@ -206,7 +217,9 @@ class AssetWidget(QWidget):
self.editors.setCurrentWidget(self.type_editor_map[asset_type])
self.edit_code_action.setEnabled(asset_type.has_code())
self.edit_documentation_action.setEnabled(asset_type is not AssetType.UNKNOWN)
is_unknown = asset_type == AssetType.UNKNOWN
self.edit_documentation_action.setEnabled(not is_unknown)
self.close_button.setEnabled(not is_unknown)
@property
def prefix_root_path(self):
......@@ -342,6 +355,14 @@ class AssetWidget(QWidget):
path = self.current_asset.code_path
click.launch(url=path)
@pyqtSlot()
def __closeEditor(self):
self.set_current_editor(AssetType.UNKNOWN)
self.asset_name_label.setText(self.tr("Unknown"))
self.json_widget.clear()
self.__clear_watcher()
self.current_asset = None
def closeEvent(self, event):
"""Re-impl will check and ask to save if the editor is dirty"""
......@@ -399,12 +420,10 @@ class AssetWidget(QWidget):
)
if answer == QMessageBox.No:
return
self.set_current_editor(AssetType.UNKNOWN)
self.asset_name_label.setText(self.tr("Unknown"))
self.json_widget.clear()
self.__clear_watcher()
self.current_asset.delete()
self.current_asset = None
current_asset = self.current_asset
self.__closeEditor()
current_asset.delete()
else:
# Check before deletion
asset = Asset.from_path(self.prefix_root_path, file_path)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment