Skip to content

package editor_action

import "kaijuengine.com/editor/editor_action"

Variables

ErrDuplicateAction

errors.New("editor_action: duplicate action")

ErrInvalidAction

errors.New("editor_action: invalid action")

ErrActionNotFound

errors.New("editor_action: action not found")

Functions

ChordsEqual

func ChordsEqual(a, b KeyChord) bool

FormatKeyChord

func FormatKeyChord(chord KeyChord) string

HasChord

func HasChord(chord KeyChord) bool

IsModifierKey

func IsModifierKey(key int) bool

KeyName

func KeyName(key int) string

Param[T any]

func Param[T any](req Request) (T, bool)

Params

func Params(value any) any

ValidChord

func ValidChord(chord KeyChord) bool

Types

ActionBinding

struct

type ActionBinding struct {
    Action    ActionID `json:"action"`
    Params    any      `json:"params,omitempty"`
    Workspace string   `json:"workspace,omitempty"`
    Enabled   bool     `json:"enabled"`
    Chord     KeyChord `json:"chord"`
}

BindingsForAction

func BindingsForAction(defaults, user []ActionBinding, action ActionID, workspace string) []ActionBinding

EffectiveBindings

func EffectiveBindings(defaults, user []ActionBinding) []ActionBinding

RemoveBindingConflicts

func RemoveBindingConflicts(defaults, user []ActionBinding, conflicts []BindingConflict) []ActionBinding

ReplaceActionBindings

func ReplaceActionBindings(user []ActionBinding, action ActionID, workspace string, replacements []ActionBinding) []ActionBinding

ActionID

string

type ActionID string

BindingConflict

struct

type BindingConflict struct {
    Binding ActionBinding
    Label   string
}

BindingConflicts

func BindingConflicts(active []ActionBinding, candidate ActionBinding, labels map[ActionID]string) []BindingConflict

CanRunFunc

func

type CanRunFunc func(Context, Request) Result

Context

struct

type Context struct {
    CurrentWorkspace string
    InputFocused     bool
    Services         map[string]any
    Feedback         func(Result)
}

Definition

struct

type Definition struct {
    ID                ActionID        `json:"id"`
    Label             string          `json:"label"`
    Description       string          `json:"description,omitempty"`
    Category          string          `json:"category,omitempty"`
    Tags              []string        `json:"tags,omitempty"`
    Aliases           []string        `json:"aliases,omitempty"`
    DefaultParams     any             `json:"defaultParams,omitempty"`
    NewParams         ParamsFactory   `json:"-"`
    Parameters        []Parameter     `json:"parameters,omitempty"`
    DefaultBindings   []ActionBinding `json:"defaultBindings,omitempty"`
    UndoPolicy        UndoPolicy      `json:"undoPolicy"`
    Visible           bool            `json:"visible"`
    Unbindable        bool            `json:"unbindable,omitempty"`
    RequiredWorkspace string          `json:"requiredWorkspace,omitempty"`
    Variants          []Variant       `json:"variants,omitempty"`
}

Entry

struct

type Entry struct {
    Definition
    Params       any `json:"params,omitempty"`
    VariantIndex int `json:"variantIndex,omitempty"`
}

Handler

func

type Handler func(Context, Request) Result

KeyChord

struct

type KeyChord struct {
    Keys       []int `json:"keys,omitempty"`
    Ctrl       bool  `json:"ctrl,omitempty"`
    Meta       bool  `json:"meta,omitempty"`
    CtrlOrMeta bool  `json:"ctrlOrMeta,omitempty"`
    Shift      bool  `json:"shift,omitempty"`
    Alt        bool  `json:"alt,omitempty"`
}

Parameter

struct

type Parameter struct {
    Name        string   `json:"name"`
    Label       string   `json:"label,omitempty"`
    Type        string   `json:"type,omitempty"`
    Required    bool     `json:"required,omitempty"`
    Default     any      `json:"default,omitempty"`
    Options     []string `json:"options,omitempty"`
    Description string   `json:"description,omitempty"`
}

ParamsFactory

func

type ParamsFactory func() any

Registry

struct

type Registry struct {
    // Has unexported fields.
}

NewRegistry

func NewRegistry() *Registry

Registry.Definition

func (r *Registry) Definition(id ActionID) (Definition, bool)

Registry.Definitions

func (r *Registry) Definitions() []Definition

Registry.Entries

func (r *Registry) Entries(ctx Context, query string) []Entry

Registry.Register

func (r *Registry) Register(def Definition, handler Handler, canRun CanRunFunc) error

Registry.Registered

func (r *Registry) Registered(id ActionID) (registeredAction, bool)

Request

struct

type Request struct {
    ID            ActionID `json:"id"`
    Params        any      `json:"params,omitempty"`
    Source        Source   `json:"source,omitempty"`
    CorrelationID string   `json:"correlationId,omitempty"`
}

Result

struct

type Result struct {
    OK                bool           `json:"ok"`
    Message           string         `json:"message,omitempty"`
    Error             string         `json:"error,omitempty"`
    Data              map[string]any `json:"data,omitempty"`
    Warnings          []string       `json:"warnings,omitempty"`
    AffectedEntityIDs []string       `json:"affectedEntityIds,omitempty"`
    SelectedEntityIDs []string       `json:"selectedEntityIds,omitempty"`
}

Failure

func Failure(message string) Result

Success

func Success(message string) Result

Service

struct

type Service struct {
    // Has unexported fields.
}

NewService

func NewService() *Service

Service.CanRun

func (s *Service) CanRun(req Request) Result

Service.CanRunOnMainThread

func (s *Service) CanRunOnMainThread(req Request) Result

Service.DefaultBindings

func (s *Service) DefaultBindings() []ActionBinding

Service.Definitions

func (s *Service) Definitions() []Definition

Service.NormalizeRequest

func (s *Service) NormalizeRequest(req Request) (Request, error)

Service.Register

func (s *Service) Register(def Definition, handler Handler, canRun CanRunFunc) error

Service.Registry

func (s *Service) Registry() *Registry

Service.Run

func (s *Service) Run(req Request) Result

Service.RunOnMainThread

func (s *Service) RunOnMainThread(req Request) Result

Service.Search

func (s *Service) Search(query string) []Entry

Service.SearchOnMainThread

func (s *Service) SearchOnMainThread(query string) []Entry

Service.SetContextProvider

func (s *Service) SetContextProvider(provider func() Context)

Service.SetMainThreadScheduler

func (s *Service) SetMainThreadScheduler(run func(func()))

Service.SetTransactionHooks

func (s *Service) SetTransactionHooks(begin, commit, cancel func())

Source

string

type Source string

const ( SourceUnknown Source = "" SourceMenu Source = "menu" SourcePalette Source = "palette" SourceKeybind Source = "keybinding" SourceLua Source = "lua" SourceREST Source = "rest" )

UndoPolicy

int

type UndoPolicy int

const ( UndoPolicyNone UndoPolicy = iota UndoPolicyTransaction UndoPolicyManaged )

Variant

struct

type Variant struct {
    Label       string   `json:"label"`
    Description string   `json:"description,omitempty"`
    Tags        []string `json:"tags,omitempty"`
    Params      any      `json:"params,omitempty"`
    Hidden      bool     `json:"hidden,omitempty"`
}