@@ -178,67 +178,6 @@ def _build_file_menu(self, menu: QtWidgets.QMenu) -> dict:
178178 return {" important_action" : important_action} # GOOD
179179```
180180
181- ## Examples
182-
183- ### Example 1: Adding a "Refresh Project" Menu Item
184-
185- ** Step 1:** Add to menu_builder.py:
186- ``` python
187- def _build_file_menu (self , menu : QtWidgets.QMenu) -> dict :
188- # ... existing actions ...
189-
190- refresh_action = QtGui.QAction(" Refresh Project" , self .main_window)
191- refresh_action.setShortcut(QtGui.QKeySequence(" F5" ))
192- refresh_action.setStatusTip(" Reload project from disk" )
193- refresh_action.setEnabled(False ) # Enabled when project loaded
194- refresh_action.triggered.connect(self .handlers.refresh_project)
195- menu.addAction(refresh_action)
196-
197- return {
198- # ... existing returns ...
199- " refresh_action" : refresh_action,
200- }
201- ```
202-
203- ** Step 2:** Add to menu_handlers.py:
204- ``` python
205- def refresh_project (self ) -> None :
206- """ Reload the current project from disk."""
207- if not self .window._project:
208- return
209-
210- project_path = self .window._project.project_dir
211- self .window.open_project(project_path)
212- self .window.display_status_message(" Project refreshed" , duration = 3000 )
213- ```
214-
215- ** Step 3:** Update MenuReferences in menu_builder.py:
216- ``` python
217- @dataclass
218- class MenuReferences :
219- # ... existing fields ...
220- refresh_action: QtGui.QAction
221- ```
222-
223- ** Step 4:** Enable/disable in main_window.py when project loads:
224- ``` python
225- def _on_project_opened (self ):
226- # ... existing code ...
227- self ._refresh_action.setEnabled(True )
228-
229- def _on_project_closed (self ):
230- # ... existing code ...
231- self ._refresh_action.setEnabled(False )
232- ```
233-
234- ## Testing
235-
236- When testing menu functionality:
237- 1 . Test handlers independently by calling them directly
238- 2 . Mock ` self.window ` and its dependencies
239- 3 . Verify correct methods are called with correct parameters
240- 4 . Test that lambdas pass parameters correctly
241-
242181## Questions?
243182
244183If you're unsure where to add functionality:
0 commit comments