feat: add delete page functionality
All checks were successful
Build Linux / Build Linux (push) Successful in 1m32s
Build Windows / Build Windows (push) Successful in 2m51s

- Added 'Delete Page' option to Edit menu
- Implemented deletion logic in MainWindow, removing page from service and refreshing UI
- Ensures changes are marked as modified for saving
This commit is contained in:
2026-01-21 13:55:42 +01:00
parent 6c12e29e0a
commit 8475b512b8

View File

@@ -330,6 +330,10 @@ class MainWindow(QMainWindow):
paste_action.triggered.connect(self.paste_page_content)
edit_menu.addAction(paste_action)
delete_page_action = QAction("Delete Page", self)
delete_page_action.triggered.connect(self.delete_page)
edit_menu.addAction(delete_page_action)
edit_menu.addSeparator()
undo_action = QAction("Undo", self)
@@ -524,6 +528,36 @@ class MainWindow(QMainWindow):
# So I need to refactor paste_page_content to call push_undo_state() first.
# For now, I'll add the methods here.
def delete_page(self):
if not self.current_page:
return
ret = QMessageBox.question(self, "Delete Page",
f"Are you sure you want to delete Page {self.current_page.full_page_number} (Sub {self.current_page.sub_code:04X})?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
if ret == QMessageBox.StandardButton.Yes:
# Remove from service.pages
if self.current_page in self.service.pages:
self.service.pages.remove(self.current_page)
# Remove packets from all_packets
# This is important for saving cleanly
# Filter out packets that belong to this page instance
# Note: We rely on object identity or need robust tracking.
# Since we reconstruct all_packets on save from pages, we don't strictly need to prune all_packets NOW,
# but it's good practice or we can just rely on save_file's reconstruction logic.
# save_file logic:
# new_all_packets = []
# for page in self.service.pages: ...
# So removing from service.pages is sufficient for the next Save.
self.set_modified(True)
self.current_page = None
self.canvas.set_page(None)
self.populate_list()
self.status_label.setText("Page deleted.")
def push_undo_state(self):
if not self.current_page: return
# Push deep copy of current page