pycforge 0.15.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. pycforge/__init__.py +8 -0
  2. pycforge/__main__.py +2 -0
  3. pycforge/_version.py +1 -0
  4. pycforge/converter/__init__.py +0 -0
  5. pycforge/converter/analysis/__init__.py +5 -0
  6. pycforge/converter/analysis/functions.py +723 -0
  7. pycforge/converter/analysis/model.py +158 -0
  8. pycforge/converter/analysis/planning.py +464 -0
  9. pycforge/converter/analysis/stage.py +1976 -0
  10. pycforge/converter/analysis/symbols.py +237 -0
  11. pycforge/converter/analysis/validation.py +2166 -0
  12. pycforge/converter/c_output/__init__.py +2 -0
  13. pycforge/converter/c_output/conformance.py +297 -0
  14. pycforge/converter/c_output/renderer.py +220 -0
  15. pycforge/converter/conditional_regions/__init__.py +71 -0
  16. pycforge/converter/conditional_regions/analysis.py +481 -0
  17. pycforge/converter/conditional_regions/lowering.py +579 -0
  18. pycforge/converter/conditional_regions/model.py +243 -0
  19. pycforge/converter/conditional_regions/validation.py +690 -0
  20. pycforge/converter/containers/__init__.py +19 -0
  21. pycforge/converter/containers/analysis.py +542 -0
  22. pycforge/converter/containers/lowering.py +290 -0
  23. pycforge/converter/containers/model.py +146 -0
  24. pycforge/converter/contracts/__init__.py +0 -0
  25. pycforge/converter/contracts/configuration.py +178 -0
  26. pycforge/converter/contracts/identifiers.py +68 -0
  27. pycforge/converter/contracts/versions.py +71 -0
  28. pycforge/converter/core/__init__.py +0 -0
  29. pycforge/converter/core/artifact_io.py +87 -0
  30. pycforge/converter/core/cancellation.py +7 -0
  31. pycforge/converter/core/canonicalization.py +254 -0
  32. pycforge/converter/core/context.py +13 -0
  33. pycforge/converter/core/diagnostics.py +95 -0
  34. pycforge/converter/core/enums.py +23 -0
  35. pycforge/converter/core/fingerprint.py +22 -0
  36. pycforge/converter/core/pipeline.py +8 -0
  37. pycforge/converter/core/progress.py +25 -0
  38. pycforge/converter/core/request.py +50 -0
  39. pycforge/converter/core/resource_policy.py +31 -0
  40. pycforge/converter/core/result.py +23 -0
  41. pycforge/converter/core/serialization.py +36 -0
  42. pycforge/converter/core/stage.py +10 -0
  43. pycforge/converter/core/stage_artifact.py +80 -0
  44. pycforge/converter/core/stage_outcome.py +15 -0
  45. pycforge/converter/decision_trace/__init__.py +0 -0
  46. pycforge/converter/decision_trace/recorder.py +52 -0
  47. pycforge/converter/facade.py +459 -0
  48. pycforge/converter/frontend/__init__.py +4 -0
  49. pycforge/converter/frontend/normalizer.py +59 -0
  50. pycforge/converter/frontend/parser.py +20 -0
  51. pycforge/converter/frontend/source_document.py +93 -0
  52. pycforge/converter/frontend/stages.py +518 -0
  53. pycforge/converter/frontend/validation.py +76 -0
  54. pycforge/converter/io/__init__.py +0 -0
  55. pycforge/converter/io/atomic_writer.py +33 -0
  56. pycforge/converter/ir/__init__.py +1 -0
  57. pycforge/converter/ir/c_ir/__init__.py +4 -0
  58. pycforge/converter/ir/c_ir/builder.py +26 -0
  59. pycforge/converter/ir/c_ir/model.py +318 -0
  60. pycforge/converter/ir/c_ir/serialization.py +88 -0
  61. pycforge/converter/ir/c_ir/validation.py +834 -0
  62. pycforge/converter/ir/python_ir/__init__.py +17 -0
  63. pycforge/converter/ir/python_ir/nodes.py +86 -0
  64. pycforge/converter/keyword_calls/__init__.py +68 -0
  65. pycforge/converter/keyword_calls/analysis.py +458 -0
  66. pycforge/converter/keyword_calls/lowering.py +271 -0
  67. pycforge/converter/keyword_calls/model.py +304 -0
  68. pycforge/converter/keyword_calls/validation.py +802 -0
  69. pycforge/converter/keyword_only_calls/__init__.py +68 -0
  70. pycforge/converter/keyword_only_calls/analysis.py +640 -0
  71. pycforge/converter/keyword_only_calls/lowering.py +376 -0
  72. pycforge/converter/keyword_only_calls/model.py +328 -0
  73. pycforge/converter/keyword_only_calls/validation.py +1357 -0
  74. pycforge/converter/lowering.py +1000 -0
  75. pycforge/converter/modules/__init__.py +13 -0
  76. pycforge/converter/modules/analysis.py +1250 -0
  77. pycforge/converter/modules/lowering.py +200 -0
  78. pycforge/converter/modules/model.py +73 -0
  79. pycforge/converter/modules/stage.py +192 -0
  80. pycforge/converter/numeric_semantics/__init__.py +23 -0
  81. pycforge/converter/numeric_semantics/analysis.py +420 -0
  82. pycforge/converter/numeric_semantics/lowering.py +153 -0
  83. pycforge/converter/numeric_semantics/model.py +123 -0
  84. pycforge/converter/records/__init__.py +34 -0
  85. pycforge/converter/records/analysis.py +1394 -0
  86. pycforge/converter/records/lowering.py +393 -0
  87. pycforge/converter/records/model.py +319 -0
  88. pycforge/converter/rules/__init__.py +3 -0
  89. pycforge/converter/support_templates/__init__.py +49 -0
  90. pycforge/converter/support_templates/assembly.py +106 -0
  91. pycforge/converter/support_templates/factories.py +348 -0
  92. pycforge/converter/support_templates/model.py +159 -0
  93. pycforge/converter/support_templates/registry.py +388 -0
  94. pycforge/converter/telemetry/__init__.py +0 -0
  95. pycforge/converter/telemetry/sink.py +39 -0
  96. pycforge/ide/__init__.py +19 -0
  97. pycforge/ide/__main__.py +5 -0
  98. pycforge/ide/_worker_event_codec.py +276 -0
  99. pycforge/ide/_worker_protocol_json.py +197 -0
  100. pycforge/ide/_worker_protocol_types.py +90 -0
  101. pycforge/ide/_worker_request_codec.py +200 -0
  102. pycforge/ide/_worker_request_data.py +260 -0
  103. pycforge/ide/_worker_result_data.py +343 -0
  104. pycforge/ide/action_contract.py +469 -0
  105. pycforge/ide/action_validation.py +229 -0
  106. pycforge/ide/command_palette.py +223 -0
  107. pycforge/ide/controller.py +904 -0
  108. pycforge/ide/controller_conversion.py +546 -0
  109. pycforge/ide/controller_io.py +205 -0
  110. pycforge/ide/editor.py +951 -0
  111. pycforge/ide/editor_commands_qt.py +274 -0
  112. pycforge/ide/editor_lexical.py +43 -0
  113. pycforge/ide/editor_sidebars.py +236 -0
  114. pycforge/ide/editor_syntax.py +243 -0
  115. pycforge/ide/find_replace.py +535 -0
  116. pycforge/ide/icons.py +91 -0
  117. pycforge/ide/io_service.py +196 -0
  118. pycforge/ide/model.py +164 -0
  119. pycforge/ide/panels.py +903 -0
  120. pycforge/ide/positions.py +220 -0
  121. pycforge/ide/process_worker.py +130 -0
  122. pycforge/ide/qt.py +230 -0
  123. pycforge/ide/qt_actions.py +418 -0
  124. pycforge/ide/qt_close.py +169 -0
  125. pycforge/ide/qt_command_palette.py +297 -0
  126. pycforge/ide/qt_contract.py +220 -0
  127. pycforge/ide/qt_documents.py +590 -0
  128. pycforge/ide/qt_editor_buffers.py +113 -0
  129. pycforge/ide/qt_editor_surfaces.py +112 -0
  130. pycforge/ide/qt_menus.py +324 -0
  131. pycforge/ide/qt_projection.py +500 -0
  132. pycforge/ide/qt_shell.py +348 -0
  133. pycforge/ide/qt_shell_interactions.py +320 -0
  134. pycforge/ide/qt_state.py +393 -0
  135. pycforge/ide/qt_workspace_features.py +398 -0
  136. pycforge/ide/qt_workspace_navigation.py +208 -0
  137. pycforge/ide/qt_workspace_observers.py +173 -0
  138. pycforge/ide/qt_workspace_panels.py +545 -0
  139. pycforge/ide/qt_workspace_widgets.py +228 -0
  140. pycforge/ide/resources/icons/about.svg +1 -0
  141. pycforge/ide/resources/icons/add-document.svg +1 -0
  142. pycforge/ide/resources/icons/brand-mark.svg +1 -0
  143. pycforge/ide/resources/icons/bundle-search.svg +1 -0
  144. pycforge/ide/resources/icons/cancel.svg +1 -0
  145. pycforge/ide/resources/icons/check.svg +1 -0
  146. pycforge/ide/resources/icons/chevron-right.svg +1 -0
  147. pycforge/ide/resources/icons/close.svg +1 -0
  148. pycforge/ide/resources/icons/collapse-all.svg +1 -0
  149. pycforge/ide/resources/icons/command-palette.svg +1 -0
  150. pycforge/ide/resources/icons/convert.svg +1 -0
  151. pycforge/ide/resources/icons/copy.svg +1 -0
  152. pycforge/ide/resources/icons/cut.svg +1 -0
  153. pycforge/ide/resources/icons/decision-trace.svg +1 -0
  154. pycforge/ide/resources/icons/details.svg +1 -0
  155. pycforge/ide/resources/icons/diagnostics.svg +1 -0
  156. pycforge/ide/resources/icons/duplicate-line.svg +1 -0
  157. pycforge/ide/resources/icons/exit.svg +1 -0
  158. pycforge/ide/resources/icons/expand-all.svg +1 -0
  159. pycforge/ide/resources/icons/export.svg +1 -0
  160. pycforge/ide/resources/icons/find.svg +1 -0
  161. pycforge/ide/resources/icons/go-to-line.svg +1 -0
  162. pycforge/ide/resources/icons/go-to-output.svg +1 -0
  163. pycforge/ide/resources/icons/go-to-source.svg +1 -0
  164. pycforge/ide/resources/icons/history.svg +1 -0
  165. pycforge/ide/resources/icons/indent.svg +1 -0
  166. pycforge/ide/resources/icons/link-c.svg +1 -0
  167. pycforge/ide/resources/icons/mappings.svg +1 -0
  168. pycforge/ide/resources/icons/module.svg +1 -0
  169. pycforge/ide/resources/icons/move-down.svg +1 -0
  170. pycforge/ide/resources/icons/move-line-down.svg +1 -0
  171. pycforge/ide/resources/icons/move-line-up.svg +1 -0
  172. pycforge/ide/resources/icons/move-up.svg +1 -0
  173. pycforge/ide/resources/icons/next.svg +1 -0
  174. pycforge/ide/resources/icons/open.svg +1 -0
  175. pycforge/ide/resources/icons/outdent.svg +1 -0
  176. pycforge/ide/resources/icons/outline.svg +1 -0
  177. pycforge/ide/resources/icons/paste.svg +1 -0
  178. pycforge/ide/resources/icons/previous.svg +1 -0
  179. pycforge/ide/resources/icons/primary-module.svg +1 -0
  180. pycforge/ide/resources/icons/redo.svg +1 -0
  181. pycforge/ide/resources/icons/remove-document.svg +1 -0
  182. pycforge/ide/resources/icons/replace.svg +1 -0
  183. pycforge/ide/resources/icons/save-as.svg +1 -0
  184. pycforge/ide/resources/icons/save.svg +1 -0
  185. pycforge/ide/resources/icons/select-all.svg +1 -0
  186. pycforge/ide/resources/icons/settings.svg +1 -0
  187. pycforge/ide/resources/icons/show-c.svg +1 -0
  188. pycforge/ide/resources/icons/split-view.svg +1 -0
  189. pycforge/ide/resources/icons/summary.svg +1 -0
  190. pycforge/ide/resources/icons/telemetry.svg +1 -0
  191. pycforge/ide/resources/icons/toggle-comment.svg +1 -0
  192. pycforge/ide/resources/icons/toggle-fold.svg +1 -0
  193. pycforge/ide/resources/icons/undo.svg +1 -0
  194. pycforge/ide/resources/icons/whitespace.svg +1 -0
  195. pycforge/ide/revisions.py +400 -0
  196. pycforge/ide/search_service.py +280 -0
  197. pycforge/ide/session_history.py +150 -0
  198. pycforge/ide/source_editing.py +417 -0
  199. pycforge/ide/source_structure.py +558 -0
  200. pycforge/ide/source_structure_async.py +191 -0
  201. pycforge/ide/supervisor.py +503 -0
  202. pycforge/ide/theme.py +119 -0
  203. pycforge/ide/theme_stylesheet.py +598 -0
  204. pycforge/ide/theme_workspace_stylesheet.py +155 -0
  205. pycforge/ide/visual_tokens.py +142 -0
  206. pycforge/ide/worker_protocol.py +80 -0
  207. pycforge/ide/workspace_search.py +462 -0
  208. pycforge/ide/workspace_session.py +256 -0
  209. pycforge/laboratory/__init__.py +6 -0
  210. pycforge/laboratory/audits.py +2244 -0
  211. pycforge/laboratory/checkpoint_e.py +2685 -0
  212. pycforge/laboratory/cli.py +119 -0
  213. pycforge/laboratory/exit_codes.py +11 -0
  214. pycforge/laboratory/keyword_audit.py +661 -0
  215. pycforge/laboratory/keyword_only_audit.py +481 -0
  216. pycforge-0.15.2.dist-info/METADATA +209 -0
  217. pycforge-0.15.2.dist-info/RECORD +221 -0
  218. pycforge-0.15.2.dist-info/WHEEL +5 -0
  219. pycforge-0.15.2.dist-info/entry_points.txt +5 -0
  220. pycforge-0.15.2.dist-info/licenses/LICENSE +674 -0
  221. pycforge-0.15.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,398 @@
1
+ """Phase 15C workspace behavior for the PyQt5 application.
2
+
3
+ The public mixin owns presentation orchestration only. The controller remains
4
+ the authority for the explicit SourceBundle and all transpilation artifacts.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from PyQt5.QtCore import QTimer, Qt
10
+ from PyQt5.QtWidgets import QWidget
11
+
12
+ from .editor import large_file_mode_required
13
+ from .qt_command_palette import open_command_palette, open_go_to_line
14
+ from .qt_editor_buffers import SourceBufferStore
15
+ from .qt_workspace_navigation import (
16
+ QtWorkspaceNavigationSupportMixin,
17
+ )
18
+ from .qt_workspace_observers import QtWorkspaceObserverSupportMixin
19
+ from .source_structure import SourceStructureResult
20
+ from .source_structure_async import AsyncSourceStructureService
21
+ from .workspace_session import (
22
+ SplitOrientation,
23
+ activate_document,
24
+ activate_pane,
25
+ close_split,
26
+ create_workspace_session,
27
+ reconcile_session,
28
+ split_session,
29
+ )
30
+
31
+
32
+ class QtWorkspaceFeaturesMixin(
33
+ QtWorkspaceObserverSupportMixin,
34
+ QtWorkspaceNavigationSupportMixin,
35
+ ):
36
+ """Tabs, shared source buffers, editing, navigation, and observers."""
37
+
38
+ def _initialize_workspace_features(self) -> None:
39
+ """Create non-widget feature state before the shell is constructed."""
40
+
41
+ if getattr(self, "_workspace_features_initialized", False):
42
+ return
43
+ snapshot = self.controller.snapshot
44
+ document_ids = tuple(
45
+ item.document_id for item in snapshot.documents
46
+ )
47
+ self.source_buffers = SourceBufferStore(self)
48
+ self.workspace_session = create_workspace_session(
49
+ document_ids,
50
+ snapshot.active_document_id,
51
+ )
52
+ self._source_structure_service = AsyncSourceStructureService()
53
+ self._expected_structure_generation: int | None = None
54
+ self._expected_structure_key: str | None = None
55
+ self._submitted_structure_key: tuple[int, str] | None = None
56
+ self._source_structure_result: SourceStructureResult | None = None
57
+ self._history_projection_key: int | None = None
58
+ self._workspace_features_closed = False
59
+ self._command_palette_open = False
60
+ self._breadcrumb_timer = QTimer(self)
61
+ self._breadcrumb_timer.setSingleShot(True)
62
+ self._breadcrumb_timer.setInterval(60)
63
+ self._breadcrumb_timer.timeout.connect(
64
+ self._observer_update_breadcrumbs
65
+ )
66
+ self.structure_ready.connect(self._accept_source_structure)
67
+ self._workspace_features_initialized = True
68
+
69
+ def _project_workspace_features(
70
+ self,
71
+ snapshot,
72
+ active_changed: bool = False,
73
+ ) -> None:
74
+ """Project one exact snapshot before the remaining workspace chrome."""
75
+
76
+ if (
77
+ not getattr(self, "_workspace_features_initialized", False)
78
+ or self._workspace_features_closed
79
+ ):
80
+ return
81
+ active = snapshot.active_document
82
+ source_key = (active.document_id, id(active.text))
83
+ pending_id = (
84
+ self._source_sync_document_id
85
+ if self._source_sync_pending
86
+ else None
87
+ )
88
+ retained_editor_text = (
89
+ pending_id is None
90
+ and self._displayed_source_key == source_key
91
+ )
92
+ skip_id = pending_id or (
93
+ active.document_id if retained_editor_text else None
94
+ )
95
+ applying = self._applying_source_text
96
+ self._applying_source_text = True
97
+ try:
98
+ self.source_buffers.reconcile(
99
+ snapshot.documents,
100
+ skip_document_id=skip_id,
101
+ )
102
+ if retained_editor_text:
103
+ self.source_buffers.mark_synchronized(
104
+ active.document_id,
105
+ id(active.text),
106
+ dirty=active.dirty,
107
+ )
108
+ self._bind_active_source_buffer(active)
109
+ finally:
110
+ self._applying_source_text = applying
111
+ if pending_id is None:
112
+ self._displayed_source_key = source_key
113
+
114
+ document_ids = tuple(
115
+ item.document_id for item in snapshot.documents
116
+ )
117
+ session = reconcile_session(
118
+ self.workspace_session,
119
+ document_ids,
120
+ active_document_id=active.document_id,
121
+ )
122
+ active_pane = session.active_pane
123
+ for pane in range(len(session.pane_document_ids)):
124
+ session = activate_document(
125
+ session,
126
+ active.document_id,
127
+ pane=pane,
128
+ )
129
+ self.workspace_session = activate_pane(session, active_pane)
130
+
131
+ self.document_tabs.set_documents(
132
+ snapshot.documents,
133
+ snapshot.active_document_id,
134
+ )
135
+ history_key = id(snapshot.conversion_history)
136
+ if history_key != self._history_projection_key:
137
+ self._history_projection_key = history_key
138
+ self.session_history.set_entries(snapshot.conversion_history)
139
+ if pending_id is not None:
140
+ self.bundle_search.invalidate_results()
141
+ return
142
+ self.bundle_search.set_documents(snapshot.documents)
143
+ self._submit_source_structure(snapshot)
144
+ if active_changed:
145
+ self._update_breadcrumbs()
146
+
147
+ def _close_workspace_features(self) -> None:
148
+ """Stop observer work and release every payload-bearing Qt buffer."""
149
+
150
+ if (
151
+ not getattr(self, "_workspace_features_initialized", False)
152
+ or self._workspace_features_closed
153
+ ):
154
+ return
155
+ self._workspace_features_closed = True
156
+ self._expected_structure_generation = None
157
+ self._expected_structure_key = None
158
+ self._submitted_structure_key = None
159
+ self._source_structure_result = None
160
+ self._breadcrumb_timer.stop()
161
+ self._source_structure_service.cancel()
162
+ self._source_structure_service.close(wait_seconds=0.05)
163
+ self.find_bar.close_service()
164
+ self.bundle_search.close_service()
165
+ self.source_buffers.close()
166
+
167
+ def _invalidate_source_observers(self) -> None:
168
+ """Immediately clear observations for unsynchronized editor text."""
169
+
170
+ if hasattr(self, "bundle_search"):
171
+ self.bundle_search.invalidate_results()
172
+ self._observer_invalidate()
173
+
174
+ def _submit_source_structure(self, snapshot) -> None:
175
+ """Submit exact open strings through the observer support boundary."""
176
+
177
+ # The delegated, reviewable seam captures SourceStructureDocument(
178
+ # values and submits them with
179
+ # workspace_key=snapshot.bundle_fingerprint and
180
+ # callback=self.structure_ready.emit.
181
+ self._observer_submit(snapshot)
182
+
183
+ def _accept_source_structure(self, result: object) -> None:
184
+ """Accept only the generation authorized by observer support."""
185
+
186
+ # Support validates result.generation and result.workspace_key against
187
+ # self.controller.snapshot.bundle_fingerprint before publication.
188
+ self._observer_accept(result)
189
+
190
+ def _duplicate_source(self) -> bool:
191
+ return self._run_source_command("duplicate_line_or_selection")
192
+
193
+ def _move_source_up(self) -> bool:
194
+ return self._run_source_command("move_source_lines_up")
195
+
196
+ def _move_source_down(self) -> bool:
197
+ return self._run_source_command("move_source_lines_down")
198
+
199
+ def _indent_source(self) -> bool:
200
+ return self._run_source_command("indent_source_lines")
201
+
202
+ def _outdent_source(self) -> bool:
203
+ return self._run_source_command("outdent_source_lines")
204
+
205
+ def _toggle_source_comment(self) -> bool:
206
+ return self._run_source_command("toggle_source_comment")
207
+
208
+ def _show_bundle_search(self) -> None:
209
+ self._navigation_show_panel(
210
+ self.bundle_search,
211
+ self.bundle_search.query_edit,
212
+ select_all=True,
213
+ )
214
+
215
+ def _show_outline(self) -> None:
216
+ self._navigation_show_panel(
217
+ self.outline,
218
+ self.outline.filter_edit,
219
+ )
220
+
221
+ def _show_conversion_history(self) -> None:
222
+ self._navigation_show_panel(
223
+ self.session_history,
224
+ self.session_history.tree,
225
+ )
226
+
227
+ def _set_whitespace_visible(self, visible: bool) -> None:
228
+ for editor in (self.source, self.source_secondary):
229
+ editor.set_whitespace_visible(bool(visible))
230
+ self.action_registry.refresh()
231
+
232
+ def _set_source_split_visible(self, visible: bool) -> None:
233
+ if bool(visible):
234
+ self.workspace_session = split_session(
235
+ self.workspace_session,
236
+ self.workspace_session.split_orientation,
237
+ document_id=self.controller.snapshot.active_document_id,
238
+ )
239
+ orientation = self.workspace_session.split_orientation
240
+ self.source_splitter.setOrientation(
241
+ Qt.Horizontal
242
+ if orientation is SplitOrientation.HORIZONTAL
243
+ else Qt.Vertical
244
+ )
245
+ self.source_secondary.setVisible(True)
246
+ QTimer.singleShot(0, self._balance_source_splitter)
247
+ else:
248
+ secondary_had_focus = self.source_secondary.hasFocus()
249
+ self.workspace_session = close_split(
250
+ self.workspace_session,
251
+ keep_pane=0,
252
+ )
253
+ self.source_secondary.setVisible(False)
254
+ if secondary_had_focus:
255
+ self.source.setFocus()
256
+ if hasattr(self, "action_registry"):
257
+ self.action_registry.refresh()
258
+
259
+ def _toggle_source_fold(self) -> bool:
260
+ target = self._active_source_editor()
261
+ if target is self.source_secondary:
262
+ retained = self.source.textCursor()
263
+ self.source.setTextCursor(target.textCursor())
264
+ try:
265
+ changed = bool(self.source.toggle_fold_at_cursor())
266
+ finally:
267
+ self.source.setTextCursor(retained)
268
+ else:
269
+ changed = bool(self.source.toggle_fold_at_cursor())
270
+ self.action_registry.refresh()
271
+ return changed
272
+
273
+ def _go_to_source_line(self) -> int | None:
274
+ return open_go_to_line(self._active_source_editor(), self)
275
+
276
+ def _open_command_palette(self) -> str | None:
277
+ if self._command_palette_open:
278
+ return None
279
+ target = self._resolved_action_target()
280
+ self._command_palette_open = True
281
+ try:
282
+ states = self._action_states(None, target)
283
+ return open_command_palette(self, self.action_registry, states)
284
+ finally:
285
+ self._command_palette_open = False
286
+ self.action_registry.refresh()
287
+
288
+ def _reveal_selected_mapping_source(self) -> None:
289
+ self._navigation_reveal_selected_mapping_source()
290
+
291
+ def _reorder_document_tabs(self, order: object) -> None:
292
+ if not self._commit_pending_identity():
293
+ self._reset_document_tabs()
294
+ return
295
+ try:
296
+ self.controller.reorder_documents(tuple(order))
297
+ except Exception as exc:
298
+ self._show_error("Could not reorder the source bundle", exc)
299
+ self._reset_document_tabs()
300
+
301
+ def _activate_bundle_search_match(
302
+ self,
303
+ document_id: str,
304
+ qt_start: int,
305
+ qt_end: int,
306
+ ) -> None:
307
+ self._navigation_activate_location(
308
+ document_id,
309
+ qt_start,
310
+ qt_end,
311
+ qt_positions=True,
312
+ )
313
+
314
+ def _activate_outline_symbol(
315
+ self,
316
+ document_id: str,
317
+ start: int,
318
+ end: int,
319
+ ) -> None:
320
+ self._navigation_activate_location(
321
+ document_id,
322
+ start,
323
+ end,
324
+ qt_positions=False,
325
+ )
326
+
327
+ def _update_breadcrumbs(self, *_args) -> None:
328
+ self._breadcrumb_timer.start()
329
+
330
+ def _navigate_breadcrumb(self, line: int, column: int) -> None:
331
+ self._observer_navigate_breadcrumb(line, column)
332
+
333
+ def _activate_history_entry(self, sequence: int) -> None:
334
+ """Show one bounded terminal summary without replay authority."""
335
+
336
+ self._navigation_activate_history(sequence)
337
+
338
+ def _run_source_command(self, method_name: str) -> bool:
339
+ method = getattr(self._active_source_editor(), method_name)
340
+ changed = bool(method())
341
+ self.action_registry.refresh()
342
+ return changed
343
+
344
+ def _active_source_editor(self):
345
+ target = self._resolved_action_target()
346
+ resolved = self._source_editor_from_target(target)
347
+ if resolved is not None:
348
+ return resolved
349
+ if (
350
+ self.source_secondary.isVisible()
351
+ and self.source_secondary.hasFocus()
352
+ ):
353
+ return self.source_secondary
354
+ return self.source
355
+
356
+ def _source_editor_from_target(self, target):
357
+ for editor in (self.source, self.source_secondary):
358
+ if target is editor:
359
+ return editor
360
+ if isinstance(target, QWidget) and editor.isAncestorOf(target):
361
+ return editor
362
+ return None
363
+
364
+ def _bind_active_source_buffer(self, active) -> None:
365
+ document = self.source_buffers.document_for(active.document_id)
366
+ large = large_file_mode_required(
367
+ character_count=max(0, document.characterCount() - 1),
368
+ line_count=document.blockCount(),
369
+ )
370
+ self.source.set_large_file_mode(large)
371
+ self.source_secondary.set_large_file_mode(large)
372
+ self.source.bind_text_document(document)
373
+ self.source_secondary.bind_text_document(document)
374
+
375
+ def _reset_document_tabs(self) -> None:
376
+ snapshot = self.controller.snapshot
377
+ self.document_tabs.set_documents(
378
+ snapshot.documents,
379
+ snapshot.active_document_id,
380
+ )
381
+
382
+ def _balance_source_splitter(self) -> None:
383
+ extent = (
384
+ self.source_splitter.width()
385
+ if self.source_splitter.orientation() == Qt.Horizontal
386
+ else self.source_splitter.height()
387
+ )
388
+ available = max(
389
+ 2,
390
+ extent - self.source_splitter.handleWidth(),
391
+ )
392
+ first = available // 2
393
+ self.source_splitter.setSizes(
394
+ (first, available - first)
395
+ )
396
+
397
+
398
+ __all__ = ["QtWorkspaceFeaturesMixin"]
@@ -0,0 +1,208 @@
1
+ """Navigation support for Phase 15C Qt observer surfaces."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from PyQt5.QtCore import QTimer, Qt
8
+ from PyQt5.QtWidgets import QWidget
9
+
10
+ from .qt_contract import qt_range
11
+
12
+
13
+ class QtWorkspaceNavigationSupportMixin:
14
+ """Internal bounded navigation for search, outline, mappings, and history."""
15
+
16
+ def _navigation_activate_location(
17
+ self,
18
+ document_id: str,
19
+ start: int,
20
+ end: int,
21
+ *,
22
+ qt_positions: bool,
23
+ ) -> None:
24
+ pending = bool(getattr(self, "_source_sync_pending", False))
25
+ if not self._commit_pending_identity():
26
+ return
27
+ if pending:
28
+ self.statusBar().showMessage(
29
+ "Source observations were refreshed; choose the result again.",
30
+ 6000,
31
+ )
32
+ return
33
+ document = next(
34
+ (
35
+ item
36
+ for item in self.controller.snapshot.documents
37
+ if item.document_id == document_id
38
+ ),
39
+ None,
40
+ )
41
+ if document is None:
42
+ self.toast.show_message(
43
+ "The selected source document is no longer open.",
44
+ "warning",
45
+ )
46
+ return
47
+ if not qt_positions:
48
+ position_index = self._observer_position_index(document_id)
49
+ start, end = qt_range(
50
+ document.text,
51
+ start,
52
+ end,
53
+ position_index,
54
+ )
55
+ if self.controller.snapshot.active_document_id != document_id:
56
+ try:
57
+ self.controller.select_document(document_id)
58
+ except Exception as exc:
59
+ self._show_error("Could not select the source module", exc)
60
+ return
61
+ QTimer.singleShot(
62
+ 0,
63
+ lambda identifier=document_id, first=start, last=end:
64
+ self._navigation_reveal_if_current(identifier, first, last),
65
+ )
66
+
67
+ def _navigation_reveal_if_current(
68
+ self,
69
+ document_id: str,
70
+ start: int,
71
+ end: int,
72
+ ) -> None:
73
+ if self.controller.snapshot.active_document_id != document_id:
74
+ return
75
+ editor = self._active_source_editor()
76
+ editor.go_to_position(start, end)
77
+ editor.setFocus()
78
+
79
+ def _navigation_mapping_source_location(
80
+ self,
81
+ mapping: dict[str, Any],
82
+ ):
83
+ snapshot = self.controller.snapshot
84
+ node_ids = mapping.get("source_node_ids", ())
85
+ if isinstance(node_ids, str):
86
+ node_ids = (node_ids,)
87
+ elif isinstance(node_ids, (tuple, list)):
88
+ node_ids = tuple(node_ids)
89
+ else:
90
+ node_ids = ()
91
+ direct = mapping.get("source_node_id")
92
+ if isinstance(direct, str):
93
+ node_ids += (direct,)
94
+
95
+ result = self._source_structure_result
96
+ symbol = (
97
+ next(
98
+ (
99
+ item
100
+ for item in result.symbols
101
+ if item.node_id in node_ids
102
+ ),
103
+ None,
104
+ )
105
+ if (
106
+ result is not None
107
+ and result.workspace_key
108
+ == self._observer_workspace_key(snapshot)
109
+ )
110
+ else None
111
+ )
112
+ if symbol is not None:
113
+ document = next(
114
+ (
115
+ item
116
+ for item in snapshot.documents
117
+ if item.document_id == symbol.document_id
118
+ ),
119
+ None,
120
+ )
121
+ return document, symbol
122
+
123
+ module_id = mapping.get("module_id")
124
+ logical_name = mapping.get("logical_source_name")
125
+ document_id = mapping.get("source_document_id")
126
+ document = next(
127
+ (
128
+ item
129
+ for item in snapshot.documents
130
+ if item.module_id == module_id
131
+ or item.logical_name == logical_name
132
+ or item.document_id == document_id
133
+ ),
134
+ None,
135
+ )
136
+ return document, None
137
+
138
+ def _navigation_reveal_selected_mapping_source(self) -> None:
139
+ item = self.mappings.tree.currentItem()
140
+ mapping = item.data(0, Qt.UserRole) if item is not None else None
141
+ if not isinstance(mapping, dict):
142
+ return
143
+ document, symbol = self._navigation_mapping_source_location(mapping)
144
+ if document is None:
145
+ self.toast.show_message(
146
+ "This mapping has no source module in the open bundle.",
147
+ "warning",
148
+ )
149
+ return
150
+ if symbol is not None:
151
+ self._navigation_activate_location(
152
+ document.document_id,
153
+ symbol.start,
154
+ symbol.end,
155
+ qt_positions=False,
156
+ )
157
+ else:
158
+ self._navigation_activate_location(
159
+ document.document_id,
160
+ 0,
161
+ 0,
162
+ qt_positions=True,
163
+ )
164
+ self.statusBar().showMessage(
165
+ f"Source mapping — {document.logical_name}",
166
+ 8000,
167
+ )
168
+
169
+ def _navigation_show_panel(
170
+ self,
171
+ widget: QWidget,
172
+ focus_widget: QWidget,
173
+ *,
174
+ select_all: bool = False,
175
+ ) -> None:
176
+ self._set_details_visible(True)
177
+ self.tabs.setCurrentWidget(widget)
178
+ focus_widget.setFocus()
179
+ if select_all:
180
+ focus_widget.selectAll()
181
+ QTimer.singleShot(0, self._balance_main_splitter)
182
+ self.action_registry.refresh()
183
+
184
+ def _navigation_activate_history(self, sequence: int) -> None:
185
+ entry = next(
186
+ (
187
+ item
188
+ for item in self.controller.snapshot.conversion_history
189
+ if item.request_sequence == sequence
190
+ ),
191
+ None,
192
+ )
193
+ if entry is None:
194
+ self.statusBar().showMessage(
195
+ "The selected session entry is no longer available.",
196
+ 6000,
197
+ )
198
+ return
199
+ message = (
200
+ f"Request {entry.request_sequence} — "
201
+ f"{entry.status.replace('-', ' ').title()} · "
202
+ f"{entry.completed_stage_count}/{entry.total_stage_count} stages · "
203
+ f"{entry.diagnostic_count} diagnostics"
204
+ )
205
+ self.statusBar().showMessage(message, 9000)
206
+
207
+
208
+ __all__ = ["QtWorkspaceNavigationSupportMixin"]