package ui import ( "fmt" "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" "gitea.mmo.to/ppForge/ppforge/protocol" "gitea.mmo.to/ppForge/ppforge/protocolctl" ) // implements FileHandler, TabProvider type ProtocolFileHandler struct { ProtocolEditor *ProtocolEditor name string path string changed bool tab *container.TabItem Reference *protocol.ProtocolStructure } func NewProtocolFileHandler() *ProtocolFileHandler { pfh := ProtocolFileHandler{} pfh.name = "*new" pfh.changed = true pfh.ProtocolEditor = NewProtocolEditor(protocolctl.NewProtocolStructure()) pfh.Reference = pfh.ProtocolEditor.Reference return &pfh } func (pfh *ProtocolFileHandler) Load() error { prot, err := protocolctl.LoadNew(pfh.Path()) if err != nil { // process error err = nil } pfh.ProtocolEditor = NewProtocolEditor(prot) pfh.Reference = prot pfh.name = prot.Metadata.Name return err } func (pfh *ProtocolFileHandler) GetWorkarea() *fyne.Container { return pfh.ProtocolEditor.Representation } func (pfh *ProtocolFileHandler) Name() string { return pfh.name } func (pfh *ProtocolFileHandler) Path() string { return pfh.path } func (pfh *ProtocolFileHandler) Open(path string) error { pfh.path = path return pfh.Load() } func (pfh *ProtocolFileHandler) Save() error { err := protocolctl.Save(pfh.Reference, pfh.path) if err != nil { fmt.Printf("%v\n", err) } pfh.changed = false return err } func (pfh *ProtocolFileHandler) SaveAs(path string) error { pfh.path = path return pfh.Save() } func (pfh *ProtocolFileHandler) Close() error { return pfh.Save() } func (pfh *ProtocolFileHandler) SetChanged() { pfh.changed = true } func (pfh *ProtocolFileHandler) HasChanged() bool { return pfh.changed } func (pfh *ProtocolFileHandler) GetReference() interface{} { return pfh.Reference } func (pfh *ProtocolFileHandler) Tab() *container.TabItem { return pfh.tab } func (pfh *ProtocolFileHandler) SetTab(tab *container.TabItem) { pfh.tab = tab }