Native Plugins #34
Logic-gate
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Have a look at Path Completion Plugin for an example.
The Native Plugin API provides a small, stable ABI for trusted native plugins. Plugins interact with the editor through opaque host and command-context objects instead of accessing
EditorWindow,EditorTab, or GTK internals directly.This separation allows Graptos to change its internal editor implementation without unnecessarily breaking plugin source code.
API version
Plugins should compare this value with the version returned by
graptos_plugin_host_api_version()during registration and reject incompatible Graptos builds before registering commands or completion providers.Header and dependency
The API uses GLib types such as
gboolean,guint,gpointer, andGPtrArray.Core concepts
GraptosPluginHostGraptosPluginCommandContextPlugins must use the public functions documented here and must not depend on Graptos or GTK implementation internals.
Ownership rules
g_free().graptos_plugin_host_plugin_id()remains valid only while the host object is alive. Copy it if it must be retained.destroycallback is responsible for releasing the corresponding plugin-owneduser_data.Opaque types
GraptosPluginHostThe host capability object passed to native plugins during registration.
GraptosPluginCommandContextThe execution context passed to native command and completion callbacks. It provides controlled access to the active editor, selection, cursor, file, tabs, and project.
Callback types
Command callback
Called when a registered command is invoked from a menu, tool panel, shortcut, or another command surface.
contextuser_dataCompletion callback
Inspects the cursor context and returns insertable completion candidates. The provider determines whether it applies by returning candidates only for matching contexts.
contextreplace_prefix_outuser_dataReturns a
GPtrArrayof ownedchar *candidates, orNULLwhen no candidates are available.Destroy callback
Releases plugin-owned data supplied during command or provider registration.
Registration entry point
A shared library exports this entry point when it provides code-backed editor automation. Declarative-only plugins do not require a native entry point.
Returns
TRUEwhen registration succeeds.Host information
graptos_plugin_host_api_versionReturns the plugin API version implemented by the host. Plugins can use it during registration to detect incompatible Graptos builds.
graptos_plugin_host_plugin_idReturns the ID of the plugin currently being registered, or
NULLwhen unavailable. The string is owned by Graptos and remains valid only while the host is alive.Registration functions
Register a command implementation
Registers command behavior without adding the command to editor line menus or the Plugins tool panel. Use
graptos_plugin_host_register_editor_line_command()when those UI surfaces are required.hostcommand_idcallbackuser_datadestroyuser_dataReturns
TRUEwhen the command is accepted.Register an editor line command
Registers a command and exposes it in editor right-click menus and the Plugins tool panel.
hostcommand_idlabelcallbackuser_datadestroyuser_dataReturns
TRUEwhen the command is accepted.Register an editor line command with a shortcut
Registers an editor line command with an optional keyboard shortcut. Graptos owns shortcut matching and invokes the registered command when the shortcut is pressed.
The shortcut uses a stable textual form such as
Ctrl+Alt+P. PassNULLwhen no shortcut is required.Returns
TRUEwhen the command is accepted.Register a completion provider
Registers a native provider that participates in normal editor completion.
hostprovider_idlabelcallbackuser_datadestroyuser_dataReturns
TRUEwhen the provider is accepted.Context metadata
Plugin ID
Returns the plugin ID associated with the command context, or
NULL.Command ID
Returns the command ID associated with the context, or
NULL.Target line
Returns the targeted editor line as a one-based line number, or
0when no editor line is available.Reading editor state
Active file path
Returns the active file path, or
NULLfor an unsaved editor. The returned string is owned by the caller and must be released withg_free().Active editor text
Returns all text in the active editor, or an empty string when unavailable. The returned string is owned by the caller and must be released with
g_free().Active selection
Returns the selected text, or an empty string when there is no selection. The returned string is owned by the caller and must be released with
g_free().Text from one line
Returns the text from the requested one-based editor line, or an empty string when unavailable. The returned string is owned by the caller and must be released with
g_free().Text before the cursor
Returns the text before the cursor on the active line, or an empty string when unavailable. The returned string is owned by the caller and must be released with
g_free().Editing the active buffer
Insert text
Inserts
textat the active cursor. ReturnsTRUEwhen the text is inserted.Replace the selection
Replaces the active selection. If no text is selected, the supplied text is inserted at the cursor. Returns
TRUEwhen the buffer is updated.User-interface output
Show output in a dialog
Displays plugin-generated output in a Graptoss dialog.
Set the status text
Sets the Graptos status text.
Show completions
Shows plugin-supplied completion candidates.
contextreplace_prefixsource_labelcandidatesGPtrArrayof owned or borrowedchar *candidate stringsGraptos copies the candidate text before displaying the completion popup.
Tabs, projects, and files
Open tab count
Returns the number of open editor tabs.
First project root
Returns the first open project root, or
NULLwhen no project is open. The returned string is owned by the caller and must be released withg_free().Open a file
Opens the file at
pathin Graptos. ReturnsTRUEwhen the file is opened.Registration outline
A native plugin generally follows this sequence:
g_free().All reactions