How delphidabbler/codesnip works
Project type and purpose
• CodeSnip is a native Windows desktop application written in Delphi (Pascal).
• Its purpose is to store, manage and view code snippets (focused on Pascal/Delphi) with features for importing from external snippet collections, syntax-highlighting, formatting/export and compile-testing snippets.
High-level architectural layers and top-level directories
• Presentation Layer (UI & Forms) – the bulk of Src/*.dfm and corresponding .pas files under Src/ (e.g. FmMain.pas, FmSnippetsEditorDlg.pas, FrHTMLPreview.pas, etc.).
• Controller/Manager Layer – classes prefixed U…Mgr, U…Action, UDialogMgr, UDispatchList that coordinate UI events with business logic.
• Business Logic Layer – core snippet/domain classes under Src/DB.*.pas (e.g. DB.UMain.pas, DB.USnippet.pas), snippet validators (ActiveText.UValidator.pas), compile manager (UCompileMgr.pas), export/import managers (SWAG.UImporter.pas, UCodeImportExport.pas)
• Data Access & Persistence Layer – interfaces and implementations in Src/DBIO.*.pas, Src/UDatabaseLoader.pas, UIniDataLoader.pas, UREMLDataIO.pas that read/write the main database, user DB, INI files, XML and backup formats.
• Rendering & Preview Layer – HTML and RTF rendering modules (ActiveText.UHTMLRenderer.pas, URTFBuilder.pas, UHTMLTemplate.pas) plus an embedded browser interface (Browser.UController.pas, Browser.IntfDocHostUI.pas).
• External Services & 3rd-party – the “3rdParty” folder (e.g. PJMD5.pas), COM interop (shell folders, SysInfo), jQuery and scripts under Res/Scripts, and installer scripts under Install/.
• Help & Documentation – compiled HTML help under Help/ and design docs in Docs/Design/FileFormats/.
Key architectural patterns and principles
• MVC-style separation: Forms (View), Manager/Action classes (Controller), Domain & DB classes (Model).
• Singleton and Factory patterns (USingleton.pas, UActionFactory.pas).
• Observer / Event dispatch (UMultiCastEvents.pas, UDispatchList.pas) to decouple UI updates.
• Plugin-style importers for SWAG and Dabbler snippet libraries (SWAG.UImporter.pas, CodeSnip.iss).
Main components & interactions
A. Presentation Layer (VCL Forms & Dialogs)
– FmMain, all Fm* dialog forms, Fr* frame forms.
B. UI Controller Layer
– Dialog manager, Action & Event dispatch classes (UDialogMgr, UActionFactory, UDispatchList).
C. Business Logic Layer
– SnippetManager, CategoryManager, CompileManager, FavouritesManager.
D. Data Persistence Layer
– DB I/O interfaces (DatabaseIO, XMLDataIO, IniDataReader), DB loaders/savers.
E. Rendering & Preview Layer
– HTMLRenderer, RTFRenderer, TextRenderer, embedded browser host.
F. External Services & Helpers
– FileSystem, Shell, HTTP, Logger, MD5, VersionInfo utilities.
G. Installer & Deployment
– Inno Setup script, portable vs standard edition.
H. Test Suite
– DUnit tests under Tests/Src/DUnit.
• UI → UI Controller (user events)
• UI Controller → Business Logic (invoke snippet CRUD, compile, import/export)
• Business Logic → Data Persistence (read/write snippet store)
• Business Logic → Rendering Layer (generate preview HTML/RTF) → Embedded Browser
• Business Logic → External Helpers (e.g. File I/O, Shell operations, MD5)
• Installer → Deployment of binaries + resources
Detailed capture
• Import pipelines (SWAG → PacketCache → SnippetImporter → DB).
• Compile/test flow: SnippetSource → CompileManager → CompilerProcess (UBorland / UFreePascal runners) → CompileResults → UI.