package ui import ( "fyne.io/fyne/v2" "gitea.mmo.to/ProtocolPacketForger/ppf/protocol" "gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl" ) // implements FileHandler type ProtocolFileHandler struct { ProtocolEditor *ProtocolEditor name string path string changed bool Reference *protocol.ProtocolStructure } func NewProtocolFileHandler() *ProtocolFileHandler { pfh := ProtocolFileHandler{} pfh.name = "*new" pfh.changed = true pfh.ProtocolEditor = NewProtocolEditor(protocolctl.NewProtocolStructure()) 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 { protocolctl.Save(pfh.Reference, pfh.path) pfh.changed = false return nil } func (pfh *ProtocolFileHandler) SaveAs(path string) error { pfh.path = path pfh.Save() return nil } 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 }