Reselect and reload the previously selected host after model changes.
(self)
| 369 | self._show_error(f"Failed to trigger config reload: {e}") |
| 370 | |
| 371 | def _reselect_current_host(self): |
| 372 | """Reselect and reload the previously selected host after model changes.""" |
| 373 | try: |
| 374 | target_host = None |
| 375 | try: |
| 376 | target_host = self.host_list.get_selected_host() |
| 377 | except Exception: |
| 378 | target_host = None |
| 379 | if not target_host and hasattr(self.host_editor, "current_host"): |
| 380 | target_host = self.host_editor.current_host |
| 381 | |
| 382 | target_alias = None |
| 383 | try: |
| 384 | if target_host and getattr(target_host, "patterns", None): |
| 385 | if len(target_host.patterns) > 0: |
| 386 | target_alias = target_host.patterns[0] |
| 387 | except Exception: |
| 388 | target_alias = None |
| 389 | |
| 390 | selected = None |
| 391 | if self.parser and self.parser.config and self.parser.config.hosts: |
| 392 | if target_alias: |
| 393 | for h in self.parser.config.hosts: |
| 394 | try: |
| 395 | if target_alias in h.patterns: |
| 396 | selected = h |
| 397 | break |
| 398 | except Exception: |
| 399 | continue |
| 400 | if selected is None: |
| 401 | selected = self.parser.config.hosts[0] |
| 402 | self.host_list.select_host(selected) |
| 403 | self.host_editor.load_host(selected) |
| 404 | self._set_host_editor_visible(True) |
| 405 | except Exception: |
| 406 | pass |
| 407 | |
| 408 | def _toggle_search(self, force=None): |
| 409 | try: |
no test coverage detected