WinUIEdit

repository·main·Indexed 42 days ago

https://github.com/breecew/winuiedit

An early-stage code editor control for UWP and WinUI 3, serving as a port of the Scintilla editor component. Written in C++, it provides a WinRT wrapper for the Scintilla API and is compatible with C#, C++, and other WinRT-compatible languages. It includes the CodeEditorControl for high-level usage and EditorBaseControl for low-level Scintilla functionality.

Tokens
4.1K
Snippets
24
Records
32
Agent score
52%

What's inside WinUIEdit

  1. Access the Scintilla API via WinRT or SendMessage

    main

    There are two ways to interact with the underlying Scintilla engine:

    • WinRT Wrapper: Use the Editor property on the control to call methods through a WinRT-compatible interface.
    • Window Messages: Use the SendMessage method to interact with the original Scintilla window message-based API.
  2. Understand the difference between CodeEditorControl and EditorBaseControl

    main

    WinUIEdit provides two main control types:

    1. CodeEditorControl: A high-level wrapper around EditorBaseControl that includes additional features and uses modified default settings and styles. This is the recommended control for most users.
    2. EditorBaseControl: A lower-level control that provides the original Scintilla functionality without the additional features or style changes found in CodeEditorControl.
  3. Install WinUIEdit via NuGet

    main

    Depending on your target framework, install the appropriate NuGet package:

    • For WinUI 3: Install WinUIEdit.
    • For UWP (WinUI 2): Install WinUIEdit.Uwp.
    # For WinUI 3
    dotnet add package WinUIEdit
    
    # For UWP
    dotnet add package WinUIEdit.Uwp
  4. Add CodeEditorControl to your XAML page

    main

    To use the editor in your UI, add the WinUIEditor namespace and declare the CodeEditorControl. You can set the HighlightingLanguage property to enable syntax highlighting for specific languages (e.g., csharp).

    <Page
        xmlns:editor="using:WinUIEditor">
        <editor:CodeEditorControl x:Name="MyEditor" HighlightingLanguage="csharp" />
    </Page>
  5. Get started with WinUI3 using standard C++

    main

    To develop WinUI3 applications using standard C++, you use the Windows App SDK and C++/WinRT. This workflow relies on the XAML compiler to generate implementation headers from Interface Definition Language (IDL) files. These generated headers allow you to implement local Windows Runtime classes that are referenced within your app's XAML pages.

    Follow these steps to set up your class implementations:

    1. Define Interfaces: Create an .idl file to define any local Windows Runtime classes that your XAML pages will reference.
    2. Generate Templates: Build the project. This triggers the generation of implementation templates in the Generated Files folder and skeleton class definitions in Generated Files\sources.
    3. Implement Classes: Use the generated skeleton class definitions as a reference to write the actual logic for your Windows Runtime classes.
    1. Create an interface (IDL) file...
    2. Build the project once to generate implementation templates...
    3. Use the skeleton class definitions for reference...
  6. Get started with C++/WinRT XAML apps

    main

    To write XAML applications using standard C++ with the C++/WinRT SDK, you follow a workflow where Interface Definition Language (IDL) files are used to generate the necessary implementation headers and skeleton classes. This allows you to implement local Windows Runtime classes that are referenced within your XAML pages.

    Follow these steps to set up your implementation:

    1. Define Interfaces: Create an .idl file to define the local Windows Runtime classes that your XAML pages will reference.
    2. Generate Boilerplate: Build the project once. This triggers the XAML compiler and C++/WinRT SDK to generate implementation templates in the Generated Files folder and skeleton class definitions in the Generated Files\sources folder.
    3. Implement Logic: Use the generated skeleton class definitions in Generated Files\sources as a reference to write your actual C++ implementation for the Windows Runtime classes.
  7. Overview of the Lexilla library

    main

    Lexilla is a library containing lexers and folders that provide support for programming, markup, and data languages for the Scintilla source code editing component. It is available as both a shared library and a static library.

    Library Names:

    • Shared Library: liblexilla.so (Linux), liblexilla.dylib (macOS), or lexilla.dll (Windows).
    • Static Library: liblexilla.a (GCC/Clang) or liblexilla.lib (MSVC).
  8. Use LexillaAccess to interact with Lexilla protocol libraries

    main

    LexillaAccess is a module designed to simplify the use of multiple libraries that implement the Lexilla protocol. It serves as an abstraction layer to streamline interactions with these protocol-compliant libraries.

    Developers can use LexillaAccess in two primary ways:

    1. Compile into a Lexilla client application: Use the module as a foundation for building a dedicated client.
    2. Customization: For applications with complex or specific requirements, developers can copy the LexillaAccess source code and customize it to fit their specific needs.

    Note: This module is intended to be used by Lexilla clients, not compiled into the Lexilla core itself.

  9. Lexilla build requirements and dependencies

    main

    To successfully build Lexilla, ensure the following environment and dependencies are met:

    Compiler Requirements:

    • Requires a C++17 compiler.
    • Known working compilers: MSVC 2019.4, GCC 9.0, Clang 9.0, and Apple Clang 11.0.

    Platform Support:

    • Windows: Supports MSVC, GCC, and Clang.
    • Linux: Supports GCC and Clang.
    • macOS: Supports Apple Clang (Clang is set automatically during make).
    • Other: May work on BSD, but not a development focus.

    Dependencies:

    • Lexilla requires headers from Scintilla 5+.
    • A directory named scintilla containing a copy of Scintilla 5+ must be a peer to the Lexilla top-level directory (conventionally named lexilla).
  10. Choose between ScintillaEditBase and ScintillaEdit

    main

    When building Scintilla for Qt, you can choose between two different library types depending on your requirements:

    • ScintillaEditBase: A lightweight, basic C++ widget. It is small and can be used as-is or extended with higher-level functionality manually.
    • ScintillaEdit: A comprehensive C++ widget that includes a method for every Scintilla API and a secondary API for direct access to document objects.
  11. Build and Install SciTE on GTK+/Linux

    main

    SciTE requires Scintilla and Lexilla to be built first.

    Installation Details:

    • Running sudo make install installs SciTE into $prefix/bin.
    • The $prefix is determined by the Gnome installation location (usually /usr or /usr/local). If Gnome is not installed, /usr/bin is used.
    • You can override the prefix using prefix=/your/path during both the make and make install steps.
    • The global properties file is installed at $prefix/share/scite/SciTEGlobal.properties.

    Commands:

    • Build and Install: make followed by sudo make install.
    • Uninstall: sudo make uninstall.
    • Clean object files: make clean (useful when changing the $prefix).
    cd scite/gtk
    make
    sudo make install