ppforge/internal/ui/protocolfilehandler.go

49 lines
1.1 KiB
Go
Raw Normal View History

2023-01-05 14:16:41 +01:00
package ui
import (
"fyne.io/fyne/v2/container"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl"
)
type ProtocolFileHandler struct {
ProtocolEditor *ProtocolEditor
Filename string
Changed bool
Reference *protocol.ProtocolStructure
}
func NewProtocolFileHandler() *ProtocolFileHandler {
pfh := ProtocolFileHandler{}
pfh.Filename = "*new"
pfh.Changed = true
pfh.ProtocolEditor = GetProtocolEditor()
return &pfh
}
func LoadProtocolFileHandler(path string) *ProtocolFileHandler {
pfh := ProtocolFileHandler{}
pfh.Filename = path
pfh.Load()
return &pfh
}
func (pfh *ProtocolFileHandler) Load() {
prot, err := protocolctl.LoadNew(pfh.Filename)
if err != nil {
// process error
err = nil
2023-01-05 14:16:41 +01:00
}
pfh.ProtocolEditor = NewProtocolEditor(prot)
pfh.Reference = prot
PPF.ProtocolMeta.SetProtocol(prot)
}
func (pfh *ProtocolFileHandler) Save() {
pfh.Changed = false
}
func (pfh *ProtocolFileHandler) GetWorkarea() *container.Scroll {
return container.NewVScroll(pfh.ProtocolEditor.Representation)
}