fix: implement _toggle_script_mod and _script_context_menu methods
- Toggle: rename files with .disabled suffix to enable/disable - Context menu: Enable/Disable, Show Files, Open Folder - Fixes crashes when clicking Toggle or right-clicking script mods
This commit is contained in:
@@ -1202,6 +1202,82 @@ class ModManagerWindow(QMainWindow):
|
|||||||
|
|
||||||
self.script_info_label.setText(f"Total: {total_mods} mods, {total_files} files")
|
self.script_info_label.setText(f"Total: {total_mods} mods, {total_files} files")
|
||||||
|
|
||||||
|
def _toggle_script_mod(self):
|
||||||
|
"""Toggle selected script mod on/off."""
|
||||||
|
item = self.script_tree.currentItem()
|
||||||
|
if not item:
|
||||||
|
return
|
||||||
|
data = item.data(0, Qt.ItemDataRole.UserRole)
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
game_path = Path(self.config["game_path"])
|
||||||
|
mod_name = data["mod_name"]
|
||||||
|
category = data["category"]
|
||||||
|
files = data["files"]
|
||||||
|
disabled = data["disabled"]
|
||||||
|
|
||||||
|
for f in files:
|
||||||
|
src = game_path / f
|
||||||
|
if not src.exists():
|
||||||
|
continue
|
||||||
|
|
||||||
|
if disabled:
|
||||||
|
# Enable: remove .disabled suffix
|
||||||
|
dst = Path(str(src).replace(".disabled", ""))
|
||||||
|
if src != dst:
|
||||||
|
src.rename(dst)
|
||||||
|
else:
|
||||||
|
# Disable: add .disabled suffix
|
||||||
|
dst = Path(str(src) + ".disabled")
|
||||||
|
src.rename(dst)
|
||||||
|
|
||||||
|
data["disabled"] = not disabled
|
||||||
|
item.setText(4, "❌ Disabled" if data["disabled"] else "✅ Active")
|
||||||
|
if data["disabled"]:
|
||||||
|
item.setForeground(4, QColor("#ff0080"))
|
||||||
|
else:
|
||||||
|
item.setForeground(4, QColor("#00ff9f"))
|
||||||
|
|
||||||
|
self.status.showMessage(f"{'Disabled' if data['disabled'] else 'Enabled'}: {mod_name}")
|
||||||
|
|
||||||
|
def _script_context_menu(self, pos):
|
||||||
|
"""Right-click context menu for script mods."""
|
||||||
|
item = self.script_tree.itemAt(pos)
|
||||||
|
if not item:
|
||||||
|
return
|
||||||
|
data = item.data(0, Qt.ItemDataRole.UserRole)
|
||||||
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
|
mod_name = data["mod_name"]
|
||||||
|
disabled = data["disabled"]
|
||||||
|
|
||||||
|
menu = QMenu(self)
|
||||||
|
|
||||||
|
toggle_action = QAction("Enable" if disabled else "Disable", self)
|
||||||
|
toggle_action.triggered.connect(self._toggle_script_mod)
|
||||||
|
menu.addAction(toggle_action)
|
||||||
|
|
||||||
|
menu.addSeparator()
|
||||||
|
|
||||||
|
show_files = QAction("📋 Show Files", self)
|
||||||
|
files_text = "\n".join(data["files"][:20])
|
||||||
|
if len(data["files"]) > 20:
|
||||||
|
files_text += f"\n... and {len(data['files']) - 20} more"
|
||||||
|
show_files.triggered.connect(lambda: QMessageBox.information(self, f"{mod_name} — Files", files_text))
|
||||||
|
menu.addAction(show_files)
|
||||||
|
|
||||||
|
menu.addSeparator()
|
||||||
|
|
||||||
|
show_path = QAction("📂 Open Folder", self)
|
||||||
|
game_path = Path(self.config["game_path"])
|
||||||
|
first_file = game_path / data["files"][0]
|
||||||
|
show_path.triggered.connect(lambda: subprocess.Popen(["xdg-open", str(first_file.parent)]))
|
||||||
|
menu.addAction(show_path)
|
||||||
|
|
||||||
|
menu.exec(self.script_tree.viewport().mapToGlobal(pos))
|
||||||
|
|
||||||
def _on_mod_checkbox_changed(self, item, column):
|
def _on_mod_checkbox_changed(self, item, column):
|
||||||
if column != 0:
|
if column != 0:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user