Feat: Add Home/End key navigation

This commit is contained in:
2025-12-31 15:10:13 +01:00
parent 7f9d8304be
commit 132dc50de8

View File

@@ -152,8 +152,7 @@ class MainWindow(QMainWindow):
QMessageBox.StandardButton.Save | QMessageBox.StandardButton.Discard | QMessageBox.StandardButton.Cancel)
if ret == QMessageBox.StandardButton.Save:
self.save_file()
return True # check if save succeeded? save_file catches exceptions but we might want to check
return self.save_file()
elif ret == QMessageBox.StandardButton.Discard:
return True
else:
@@ -311,25 +310,35 @@ class MainWindow(QMainWindow):
self.current_file_path = fname
self.save_file()
def save_file(self):
def save_file(self) -> bool:
if not self.current_file_path:
fname, _ = QFileDialog.getSaveFileName(self, "Save T42", "", "Teletext Files (*.t42)")
if not fname: return
if not fname: return False
self.current_file_path = fname
try:
self.progress_bar.setVisible(True)
self.status_label.setText(f"Saving {os.path.basename(self.current_file_path)}...")
# Rebuild all_packets from pages to ensure edits/undos/new packets are included.
# This serializes the pages in order, effectively "cleaning" the stream of orphans
# and ensuring the file matches the editor state.
new_all_packets = []
for page in self.service.pages:
new_all_packets.extend(page.packets)
self.service.all_packets = new_all_packets
save_t42(self.current_file_path, self.service, progress_callback=self.update_progress)
self.progress_bar.setVisible(False)
self.status_label.setText(f"Saved {len(self.service.pages)} pages to {os.path.basename(self.current_file_path)}")
self.set_modified(False)
return True
except Exception as e:
self.progress_bar.setVisible(False)
QMessageBox.critical(self, "Error", f"Failed to save file: {e}")
self.status_label.setText("Error saving file")
return False
def copy_page_content(self):
if not self.current_page:
@@ -550,6 +559,12 @@ class MainWindow(QMainWindow):
self.canvas.move_cursor(-1, 0)
elif key == Qt.Key.Key_Right:
self.canvas.move_cursor(1, 0)
elif key == Qt.Key.Key_Home:
# Move to start of line
self.canvas.set_cursor(0, self.canvas.cursor_y)
elif key == Qt.Key.Key_End:
# Move to end of line (39)
self.canvas.set_cursor(39, self.canvas.cursor_y)
elif key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter:
# Move to start of next line
self.canvas.cursor_x = 0