Refactor main_phase7.mm into 22 focused modules#57
Merged
hybridmachine merged 2 commits intomacos-portfrom Mar 16, 2026
Merged
Conversation
Split the monolithic 4,097-line main_phase7.mm into focused modules to unblock parallel work and make code review practical. All mutable state is centralized in an AppContext struct accessed via ctx(). New module structure: - Layer 1: npp_constants.h, document_data.h, string_utils.h - Layer 2: language_defs, lexer_styles - Layer 3: app_state (AppContext) - Layer 4: 14 feature modules (document_manager, file_operations, find_replace, edit_commands, bookmarks, autocomplete, context_menu, preferences_dialog, status_bar, recent_files, session_manager, split_view, scintilla_config, appearance) - Layer 5: menu_builder, wndproc, app_delegate, app_main Also removes 5 legacy phase files (main.mm, main_phase3-5.mm, main_phase7.mm) totaling 9,384 lines of superseded code. Pure refactor — no functional changes. Build verified. Closes #55 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Refactors the macOS Phase 7 app implementation by splitting the previous monolithic entry file into focused modules and centralizing mutable state in an AppContext accessed via ctx(), while updating the macOS CMake target wiring and removing legacy phase entrypoints.
Changes:
- Introduces a modular architecture (window proc, menus, documents, find/replace, split view, session, appearance, etc.) wired through
app_delegate+app_main. - Centralizes app-wide mutable state into
AppContext(app_state.h/.mm) and updates modules to use it. - Updates
macos/CMakeLists.txtto compile the new module set and removes legacy phase sources.
Reviewed changes
Copilot reviewed 49 out of 50 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| macos/platform/app_main.mm | New slim entry point that boots NSApplication and the app delegate. |
| macos/platform/app_delegate.h | Declares NppAppDelegate and drop target view. |
| macos/platform/app_delegate.mm | App lifecycle wiring, main window construction, notifications, drag-and-drop, settings/session integration. |
| macos/platform/app_state.h | Defines AppContext and ctx() accessor API. |
| macos/platform/app_state.mm | Provides the single global AppContext instance backing ctx(). |
| macos/platform/npp_constants.h | Centralizes command IDs and Scintilla constants/messages used across modules. |
| macos/platform/wndproc.h | Declares the main window procedure interface. |
| macos/platform/wndproc.mm | Implements WM_* dispatch for commands, notifications, timers, sizing, close. |
| macos/platform/menu_builder.h | Declares menu construction API. |
| macos/platform/menu_builder.mm | Builds menu bar including File/Edit/Search/View/Format/Language menus. |
| macos/platform/document_data.h | Defines per-tab DocumentData plus encoding/EOL helpers. |
| macos/platform/document_manager.h | Declares document/tab management and state save/restore APIs. |
| macos/platform/document_manager.mm | Implements tab switching, open/close tab flows, and per-view state persistence. |
| macos/platform/file_operations.h | Declares file open/save, encoding/EOL detection, encode/decode helpers. |
| macos/platform/file_operations.mm | Implements file I/O, encoding detection, save logic, and recent/status updates. |
| macos/platform/find_replace.h | Declares find/replace dialog + search/replace operations. |
| macos/platform/find_replace.mm | Implements find/replace UI, search flags, wrapped search, replace operations, go-to-line. |
| macos/platform/edit_commands.h | Declares edit command handlers (case/line/comment/sort/join). |
| macos/platform/edit_commands.mm | Implements edit operations invoked from menus/commands. |
| macos/platform/bookmarks.h | Declares bookmark toggle/navigation. |
| macos/platform/bookmarks.mm | Implements bookmark marker operations in Scintilla. |
| macos/platform/autocomplete.h | Declares auto-complete trigger. |
| macos/platform/autocomplete.mm | Implements word-based auto-completion list building and display. |
| macos/platform/scintilla_config.h | Declares Scintilla configuration routine. |
| macos/platform/scintilla_config.mm | Applies baseline Scintilla settings (margins, markers, folding, caret line). |
| macos/platform/lexer_styles.h | Declares lexer style tables and language application helpers. |
| macos/platform/lexer_styles.mm | Implements per-lexer style tables and language switching using Lexilla. |
| macos/platform/language_defs.h | Declares language table and extension-based detection. |
| macos/platform/language_defs.mm | Defines language metadata table and guessLanguage() implementation. |
| macos/platform/appearance.h | Declares dark/light appearance application functions. |
| macos/platform/appearance.mm | Implements theme switching + fold marker/bookmark styling. |
| macos/platform/split_view.h | Declares split view operations (split/unsplit/move/clone/layout). |
| macos/platform/split_view.mm | Implements split view creation, layout, and per-view document operations. |
| macos/platform/status_bar.h | Declares status bar update function. |
| macos/platform/status_bar.mm | Implements status bar content updates from active Scintilla/doc state. |
| macos/platform/recent_files.h | Declares recent files list/menu operations. |
| macos/platform/recent_files.mm | Implements recent file list management and menu rebuild/open logic. |
| macos/platform/session_manager.h | Declares session save/restore API and session path helper. |
| macos/platform/session_manager.mm | Implements session save/restore to JSON under the user home directory. |
| macos/platform/preferences_dialog.h | Declares preferences dialog entry point. |
| macos/platform/preferences_dialog.mm | Implements preferences UI and applies settings to Scintilla + persistence. |
| macos/platform/context_menu.h | Declares context menu entry point. |
| macos/platform/context_menu.mm | Implements context menu creation and popup wiring. |
| macos/platform/string_utils.h | Adds wchar_t/NSString conversion helpers for cross-module use. |
| macos/platform/main.mm | Removes legacy phase entrypoint source. |
| macos/platform/main_phase3.mm | Removes legacy phase entrypoint source. |
| macos/CMakeLists.txt | Updates macOS app target sources to include new modules and removes old main entry source. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
+17
| // Win32 types from the shim — these are the actual typedefs | ||
| typedef void* HWND; | ||
| typedef unsigned int UINT; | ||
| typedef uintptr_t WPARAM; | ||
| typedef intptr_t LPARAM; | ||
| typedef intptr_t LRESULT; | ||
|
|
||
| #ifndef CALLBACK | ||
| #define CALLBACK | ||
| #endif |
Comment on lines
+4
to
+8
| #include "recent_files.h" | ||
| #include "npp_constants.h" | ||
| #include "app_state.h" | ||
| #include "string_utils.h" | ||
| #include "windows.h" |
Comment on lines
+4
to
+10
| #include "autocomplete.h" | ||
| #include "npp_constants.h" | ||
| #include "app_state.h" | ||
| #include "scintilla_bridge.h" | ||
| #include <set> | ||
| #include <algorithm> | ||
|
|
Comment on lines
+6
to
+12
| #import <Foundation/Foundation.h> | ||
| #include <string> | ||
|
|
||
| inline NSString* WideToNSString(const wchar_t* wstr) | ||
| { | ||
| if (!wstr) return @""; | ||
| size_t len = wcslen(wstr); |
|
|
||
| intptr_t startLine = ScintillaBridge_sendMessage(sci, SCI_LINEFROMPOSITION, selStart, 0); | ||
| intptr_t endLine = ScintillaBridge_sendMessage(sci, SCI_LINEFROMPOSITION, selEnd, 0); | ||
|
|
| #include "language_defs.h" | ||
| #include "scintilla_bridge.h" | ||
| #include "ILexer.h" | ||
| #include "Lexilla.h" |
Comment on lines
+6
to
+8
| // HMENU is void* in the Win32 shim | ||
| typedef void* HMENU; | ||
|
|
Comment on lines
+10
to
+12
| // Forward declaration — defined in file_operations.mm | ||
| bool openFileAtPath(NSString* path); | ||
|
|
Comment on lines
+4
to
+10
| #include "edit_commands.h" | ||
| #include "npp_constants.h" | ||
| #include "app_state.h" | ||
| #include "language_defs.h" | ||
| #include "scintilla_bridge.h" | ||
| #include <algorithm> | ||
|
|
- Use shim windows.h instead of local typedefs in wndproc.h and menu_builder.h to avoid redefinition conflicts - Add missing standard includes: <algorithm> in recent_files.mm, <cctype> in autocomplete.mm and edit_commands.mm, <cwchar> in string_utils.h, <cstring> in lexer_styles.mm and edit_commands.mm - Replace forward declaration of openFileAtPath with #include "file_operations.h" in recent_files.mm - Add endLine adjustment in doSortLines to match doToggleLineComment behavior when selection ends at start of next line Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
main_phase7.mminto 22 focused modules with clear boundaries and layered dependenciesAppContextstruct accessed viactx(), per review feedback to prefer context over globalsmain.mm,main_phase3.mm,main_phase4.mm,main_phase5.mm,main_phase7.mm) — 9,384 lines of superseded codeModule Architecture
npp_constants.h,document_data.h,string_utils.hlanguage_defs,lexer_stylesapp_statemenu_builder,wndproc,app_delegate,app_mainReview Feedback Addressed
AppContextstruct, accessed viactx()app_delegate.mmandsplit_view.mmsession_manager ↔ split_viewandapp_delegate ↔ wndprocTest plan
cmake --build . --target MacOSNotePPbuilds successfullycmake --build . --target npp_build_testbuilds successfullyCloses #55
🤖 Generated with Claude Code