Fix hotkeys interception in modal dialog text inputs

- Реализованы методы _disable_shortcuts и _enable_shortcuts для временного отключения ApplicationShortcut контекста.
- Устранена проблема с перехватом горячих клавиш (N, G, B, I) во время ввода текста в QInputDialog (переименование блока) и QDialog (редактирование координат, настройки, фоновое изображение).
- Все вызовы диалогов обёрнуты в блоки try-finally для гарантированного восстановления контекста хоткеев.
This commit is contained in:
Данил Ярош 2026-07-31 11:12:36 +03:00
parent 8f814bc1fc
commit 030c327d3b

View File

@ -617,7 +617,12 @@ class MainWindow(QMainWindow):
def open_background_dialog(self) -> None:
dialog = BackgroundDialog(self.document.background, self)
if dialog.exec() != BackgroundDialog.Accepted:
self._disable_shortcuts()
try:
res = dialog.exec()
finally:
self._enable_shortcuts()
if res != BackgroundDialog.Accepted:
return
background = dialog.background()
if not background.path:
@ -711,7 +716,12 @@ class MainWindow(QMainWindow):
def open_settings(self) -> None:
dialog = SettingsDialog(self.settings, self)
if dialog.exec() != SettingsDialog.Accepted:
self._disable_shortcuts()
try:
res = dialog.exec()
finally:
self._enable_shortcuts()
if res != SettingsDialog.Accepted:
return
self.settings = dialog.settings()
self.settings.save()
@ -1099,7 +1109,14 @@ class MainWindow(QMainWindow):
buttons.accepted.connect(dialog.accept)
buttons.rejected.connect(dialog.reject)
layout.addWidget(buttons)
if dialog.exec() != QDialog.Accepted:
self._disable_shortcuts()
try:
res = dialog.exec()
finally:
self._enable_shortcuts()
if res != QDialog.Accepted:
return
self.update_point_coordinates(point_id, x_spin.value(), y_spin.value(), source="dialog")
@ -1724,13 +1741,17 @@ class MainWindow(QMainWindow):
block = self._find_block_or_none(line_id, block_id)
if block is None:
return
new_name, ok = QInputDialog.getText(
self,
"Переименовать блок",
"Введите новое имя блока:",
QLineEdit.EchoMode.Normal,
block.name
)
self._disable_shortcuts()
try:
new_name, ok = QInputDialog.getText(
self,
"Переименовать блок",
"Введите новое имя блока:",
QLineEdit.EchoMode.Normal,
block.name
)
finally:
self._enable_shortcuts()
if ok and new_name.strip() and new_name.strip() != block.name:
self._push_undo()
block.name = new_name.strip()
@ -2238,6 +2259,14 @@ class MainWindow(QMainWindow):
self._dirty,
)
def _disable_shortcuts(self) -> None:
for action in self.actions.values():
action.setShortcutContext(Qt.WidgetShortcut)
def _enable_shortcuts(self) -> None:
for action in self.actions.values():
action.setShortcutContext(Qt.ApplicationShortcut)
def _restore_state(self, state: tuple[MappingDocument, int | None, list[int], bool]) -> None:
document, active_line_id, selected_point_ids, dirty = state
self.document = document