diff --git a/config/config.go b/config/config.go index 14bc2e6..17adf75 100644 --- a/config/config.go +++ b/config/config.go @@ -105,11 +105,13 @@ type AmConfig struct { VeniceCompatibleImageURLs bool `yaml:"veniceCompatibleImageURLs"` } `yaml:"rendering"` Resources struct { - ViewTemplateDir string `yaml:"viewTemplateDir"` - DialogTemplateDir string `yaml:"dialogTemplateDir"` - EmailTemplateDir string `yaml:"emailTemplateDir"` - ExternalContentPath string `yaml:"externalContentPath"` - ExternalResourcePath string `yaml:"externalResourcePath"` + ViewTemplateDir string `yaml:"viewTemplateDir"` + DialogTemplateDir string `yaml:"dialogTemplateDir"` + EmailTemplateDir string `yaml:"emailTemplateDir"` + ExternalContentPath string `yaml:"externalContentPath"` + ExternalResourcePath string `yaml:"externalResourcePath"` + ExternalMenuDefinitions string `yaml:"externalMenuDefinitions"` + ExternalMessageDefinitions string `yaml:"externalMessageDefinitions"` } `yaml:"resources"` Posting struct { ExternalDictionary string `yaml:"externalDictionary"` diff --git a/config/default.yaml b/config/default.yaml index 350062b..888a0ff 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -55,6 +55,8 @@ resources: emailTemplateDir: "" externalContentPath: "" externalResourcePath: "" + externalMenuDefinitions: "" + externalMessageDefinitions: "" posting: externalDictionary: "" uploads: diff --git a/ui/menus.go b/ui/menus.go index 884fbe9..cef082d 100644 --- a/ui/menus.go +++ b/ui/menus.go @@ -13,6 +13,7 @@ import ( "context" _ "embed" "fmt" + "os" "slices" "strconv" "strings" @@ -22,6 +23,7 @@ import ( "git.erbosoft.com/amy/amsterdam/database" "git.erbosoft.com/amy/amsterdam/util" lru "github.com/hashicorp/golang-lru" + log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" ) @@ -156,12 +158,31 @@ func init() { } } -// setupMenuCache sets up the menu cache. -func setupMenuCache() { +// setupMenus sets up the menu cache and the external menus. +func setupMenus() { var err error if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil { panic(err) } + if config.GlobalConfig.Resources.ExternalMenuDefinitions != "" { + b, err := os.ReadFile(config.GlobalConfig.Resources.ExternalMenuDefinitions) + if err == nil { + md := new(MenuDefs) + err = yaml.Unmarshal(b, md) + if err == nil { + for i, d := range md.D { + menuDefinitions.table[d.ID] = &(md.D[i]) + for j := range md.D[i].Items { + md.D[i].Items[j].P = &(md.D[i]) + } + } + } else { + log.Errorf("cannot parse external menu definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMenuDefinitions, err) + } + } else { + log.Errorf("cannot read external menu definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMenuDefinitions, err) + } + } } // AmMenu returns a menu definition. diff --git a/ui/messagebox.go b/ui/messagebox.go index 0d0853a..456c2c2 100644 --- a/ui/messagebox.go +++ b/ui/messagebox.go @@ -15,9 +15,12 @@ import ( "encoding/hex" "errors" "fmt" + "os" "strings" + "git.erbosoft.com/amy/amsterdam/config" "git.erbosoft.com/amy/amsterdam/util" + log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" ) @@ -80,6 +83,33 @@ func init() { } } +// setupMessageBoxes loads external message box definitions. +func setupMessageBoxes() { + if config.GlobalConfig.Resources.ExternalMessageDefinitions != "" { + b, err := os.ReadFile(config.GlobalConfig.Resources.ExternalMessageDefinitions) + if err == nil { + mb := new(MessageBoxDefs) + err = yaml.Unmarshal(b, mb) + if err == nil { + for i, def := range mb.D { + messageBoxDefs.table[def.Id] = &(mb.D[i]) + mb.D[i].useConfirm = false + for _, b := range mb.D[i].Buttons { + if b.Confirm { + mb.D[i].useConfirm = true + break + } + } + } + } else { + log.Errorf("cannot parse external message definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMessageDefinitions, err) + } + } else { + log.Errorf("cannot read external message definition file %s, ignored (%v)", config.GlobalConfig.Resources.ExternalMessageDefinitions, err) + } + } +} + // MessageBox is the structure for a working message box. type MessageBox struct { def *MessageBoxDefinition diff --git a/ui/setup.go b/ui/setup.go index 8494ade..88871be 100644 --- a/ui/setup.go +++ b/ui/setup.go @@ -17,7 +17,8 @@ func SetupUILayer() func() { exitfuncs := make([]func(), 0, 2) setupTemplates() setupDialogs() - setupMenuCache() + setupMenus() + setupMessageBoxes() setupResources() exitfuncs = append(exitfuncs, setupSessionManager()) exitfuncs = append(exitfuncs, setupContext())