Skip to content

Commit e5af1ea

Browse files
committed
Refactor/Fix: support du champ 'type' dans build.data et correction du bug d'ouverture de l'éditeur
1 parent c515b7e commit e5af1ea

2 files changed

Lines changed: 64 additions & 12 deletions

File tree

Core/AdvancedConfigEditor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def validate_ark_payload(data: Any) -> tuple[list[str], list[str]]:
115115
else:
116116
if not item.get("source"):
117117
errs.append(f"build.data[{idx}] missing 'source'.")
118+
m_type = item.get("type")
119+
if m_type is not None and m_type not in ("file", "dir"):
120+
errs.append(f"build.data[{idx}].type must be 'file' or 'dir'.")
118121

119122
# plugins
120123
plugins = data.get("plugins")

Ui/Gui/Dialogs/AdvancedConfigEditor.py

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
QFormLayout,
3434
QGroupBox,
3535
QHBoxLayout,
36+
QHeaderView,
3637
QLabel,
3738
QLineEdit,
3839
QMessageBox,
@@ -133,21 +134,29 @@ def __init__(self, gui):
133134
# --- Section: Data Mappings ---
134135
group_data = QGroupBox(self.gui.tr("Données (Assets)", "Data Mappings"))
135136
lay_data = QVBoxLayout(group_data)
136-
self.table_data = QTableWidget(0, 2)
137+
self.table_data = QTableWidget(0, 3)
137138
self.table_data.setHorizontalHeaderLabels([
138139
self.gui.tr("Source (relatif)", "Source (relative)"),
139-
self.gui.tr("Destination (dans le bundle)", "Destination (in bundle)")
140+
self.gui.tr("Destination (bundle)", "Destination (in bundle)"),
141+
self.gui.tr("Type", "Type")
140142
])
141-
self.table_data.horizontalHeader().setStretchLastSection(True)
142-
self.table_data.setMinimumHeight(150)
143+
self.table_data.horizontalHeader().setStretchLastSection(False)
144+
self.table_data.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
145+
self.table_data.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
146+
self.table_data.setMinimumHeight(180)
143147
lay_data.addWidget(self.table_data)
144148

145149
row_btns_data = QHBoxLayout()
146-
btn_add_data = QPushButton(self.gui.tr("Ajouter", "Add"))
150+
btn_add_file = QPushButton(self.gui.tr("📄 Fichier", "Add File"))
151+
btn_add_dir = QPushButton(self.gui.tr("📁 Dossier", "Add Dir"))
147152
btn_del_data = QPushButton(self.gui.tr("Supprimer", "Remove"))
148-
btn_add_data.clicked.connect(self._add_data_row)
153+
154+
btn_add_file.clicked.connect(self._on_add_file_data)
155+
btn_add_dir.clicked.connect(self._on_add_dir_data)
149156
btn_del_data.clicked.connect(self._remove_data_row)
150-
row_btns_data.addWidget(btn_add_data)
157+
158+
row_btns_data.addWidget(btn_add_file)
159+
row_btns_data.addWidget(btn_add_dir)
151160
row_btns_data.addWidget(btn_del_data)
152161
row_btns_data.addStretch()
153162
lay_data.addLayout(row_btns_data)
@@ -234,7 +243,11 @@ def _load_config(self) -> None:
234243
if isinstance(data_map, list):
235244
for item in data_map:
236245
if isinstance(item, dict):
237-
self._add_data_row(item.get("source", ""), item.get("destination", ""))
246+
self._add_data_row(
247+
item.get("source", ""),
248+
item.get("destination", ""),
249+
item.get("type", "dir")
250+
)
238251

239252
plugins = config.get("plugins", {})
240253
self.check_bcasl.setChecked(bool(plugins.get("bcasl_enabled", True)))
@@ -253,10 +266,18 @@ def _on_save(self) -> None:
253266
# Prepare payload
254267
data_map = []
255268
for row in range(self.table_data.rowCount()):
256-
src = self.table_data.item(row, 0).text().strip()
257-
dst = self.table_data.item(row, 1).text().strip()
269+
src_item = self.table_data.item(row, 0)
270+
dst_item = self.table_data.item(row, 1)
271+
src = src_item.text().strip() if src_item else ""
272+
dst = dst_item.text().strip() if dst_item else ""
273+
274+
combo = self.table_data.cellWidget(row, 2)
275+
m_type = "dir"
276+
if isinstance(combo, QComboBox):
277+
m_type = combo.currentText()
278+
258279
if src:
259-
data_map.append({"source": src, "destination": dst})
280+
data_map.append({"source": src, "destination": dst, "type": m_type})
260281

261282
config = {
262283
"project": {
@@ -301,11 +322,39 @@ def _on_save(self) -> None:
301322
self.gui.tr(f"Impossible d'enregistrer ark.yml : {e}",
302323
f"Failed to save ark.yml: {e}"))
303324

304-
def _add_data_row(self, source: str = "", dest: str = "") -> None:
325+
def _add_data_row(self, source: str = "", dest: str = "", m_type: str = "dir") -> None:
305326
row = self.table_data.rowCount()
306327
self.table_data.insertRow(row)
307328
self.table_data.setItem(row, 0, QTableWidgetItem(source))
308329
self.table_data.setItem(row, 1, QTableWidgetItem(dest))
330+
331+
combo = QComboBox()
332+
combo.addItems(["dir", "file"])
333+
combo.setCurrentText(m_type)
334+
self.table_data.setCellWidget(row, 2, combo)
335+
336+
def _on_add_file_data(self) -> None:
337+
ws = self._workspace_dir()
338+
path, _ = QFileDialog.getOpenFileName(
339+
self,
340+
self.gui.tr("Sélectionner un fichier", "Select File"),
341+
ws or "",
342+
"All Files (*)"
343+
)
344+
if path:
345+
rel = os.path.relpath(path, ws) if ws and path.startswith(ws) else path
346+
self._add_data_row(rel, rel, "file")
347+
348+
def _on_add_dir_data(self) -> None:
349+
ws = self._workspace_dir()
350+
path = QFileDialog.getExistingDirectory(
351+
self,
352+
self.gui.tr("Sélectionner un dossier", "Select Directory"),
353+
ws or ""
354+
)
355+
if path:
356+
rel = os.path.relpath(path, ws) if ws and path.startswith(ws) else path
357+
self._add_data_row(rel, rel, "dir")
309358

310359
def _remove_data_row(self) -> None:
311360
curr = self.table_data.currentRow()

0 commit comments

Comments
 (0)