Some internal structure

This commit is contained in:
Marcel M. Otte 2023-01-05 09:06:39 +01:00
parent b8c3d7f856
commit 51475279dd
5 changed files with 190 additions and 126 deletions

View File

@ -4,12 +4,8 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"gitea.mmo.to/ProtocolPacketForger/ppf/internal/ui"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
)
var fyneApp fyne.App
@ -25,124 +21,19 @@ func Appmain() {
w.ShowAndRun()
}
type ppfApp struct {
// Container for the borderlayout
Toolbar fyne.CanvasObject
Metadata *Metadata
Extensions *fyne.Container
ContextBar *fyne.Container
ContentTabs *fyne.Container
Workarea *fyne.Container
// Once initialized metadata containers for swapping
ProtocolMeta *ProtocolMetadata
PacketMeta *PacketMetadata
// Global important stuff
Settings map[string]string
ProtocolForging bool
// Once initialized instances of the editor views
EditorPacket *ui.PacketEditor
EditorProtocol *ui.ProtocolEditor
}
var ppf ppfApp
type Metadata struct {
Representation *fyne.Container
}
type PacketMetadata struct {
Metadata
}
type ProtocolMetadata struct {
Metadata
NameValue *widget.Entry
VersionValue *widget.Entry
ExtendsValue *widget.Entry
DescValue *widget.Entry
}
func CreateApp() *fyne.Container {
ppf.Toolbar = CreateToolbar()
ppf.Workarea = CreateWorkarea()
ppf.Extensions = container.NewCenter()
ppf.ProtocolMeta = CreateMetadataProtocol()
ppf.ContextBar = container.NewCenter()
ui.PPF.Toolbar = ui.CreateToolbar(fyneApp)
ui.PPF.Workarea = ui.CreateWorkarea()
ui.PPF.Extensions = container.NewCenter()
ui.PPF.ProtocolMeta = ui.CreateMetadataProtocol()
ui.PPF.Metadata = &ui.PPF.ProtocolMeta.Metadata
ui.PPF.ContextBar = container.NewCenter()
return container.NewBorder(
ppf.Toolbar,
ppf.ContextBar,
ppf.Metadata.Representation,
ppf.Extensions,
container.NewVScroll(ppf.Workarea),
ui.PPF.Toolbar,
ui.PPF.ContextBar,
ui.PPF.Metadata.Representation,
ui.PPF.Extensions,
container.NewVScroll(ui.PPF.Workarea),
)
}
func CreateToolbar() fyne.CanvasObject {
toolbar := widget.NewToolbar()
toolbar.Append(widget.NewToolbarAction(theme.StorageIcon(), func() {
ppf.ProtocolForging = !ppf.ProtocolForging
//TODO: implement the switch
}))
toolbar.Append(widget.NewToolbarSeparator())
toolbar.Append(widget.NewToolbarAction(theme.FolderNewIcon(), func() {
}))
toolbar.Append(widget.NewToolbarAction(theme.FolderOpenIcon(), func() {
}))
toolbar.Append(widget.NewToolbarAction(theme.DocumentSaveIcon(), func() {
}))
toolbar.Append(widget.NewToolbarAction(theme.SettingsIcon(), func() {
}))
toolbar.Append(widget.NewToolbarSpacer())
toolbar.Append(widget.NewToolbarAction(theme.LogoutIcon(), func() {
fyneApp.Quit()
}))
return toolbar
}
func CreateWorkarea() *fyne.Container {
return ui.GetProtocolEditor().Representation
}
func CreateMetadataProtocol() *ProtocolMetadata {
md := ProtocolMetadata{}
vbox := container.NewVBox()
vbox.Add(widget.NewLabel("Protocol Metadata"))
form := container.New(layout.NewFormLayout())
form.Add(widget.NewLabel("Name:"))
form.Add(widget.NewEntry())
form.Add(widget.NewLabel("Version:"))
form.Add(widget.NewEntry())
form.Add(widget.NewLabel("Extends:"))
form.Add(widget.NewEntry())
vbox.Add(form)
vbox.Add(widget.NewLabel("Description"))
multiline := widget.NewMultiLineEntry()
multiline.SetMinRowsVisible(3)
vbox.Add(multiline)
md.Representation = vbox
return &md
}
func CreateMetadataPacket() *PacketMetadata {
md := PacketMetadata{}
vbox := container.NewVBox()
vbox.Add(widget.NewLabel("Packet Metadata"))
form := container.New(layout.NewFormLayout())
form.Add(widget.NewLabel("Name:"))
form.Add(widget.NewEntry())
vbox.Add(form)
vbox.Add(widget.NewLabel("Description:"))
multiline := widget.NewMultiLineEntry()
multiline.SetMinRowsVisible(3)
vbox.Add(multiline)
return &md
}
func UpdateProtocolMetadata(prot *protocol.ProtocolStructure) {
// md := ppfApp.ProtocolMeta
}

59
internal/ui/main.go Normal file
View File

@ -0,0 +1,59 @@
package ui
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
type ppfApp struct {
// Container for the borderlayout
Toolbar fyne.CanvasObject
Metadata *Metadata
Extensions *fyne.Container
ContextBar *fyne.Container
ContentTabs *fyne.Container
Workarea *fyne.Container
// Once initialized metadata containers for swapping
ProtocolMeta *ProtocolMetadata
PacketMeta *PacketMetadata
// Global important stuff
Settings map[string]string
ProtocolForging bool
// Once initialized instances of the editor views
EditorPacket *PacketEditor
EditorProtocol *ProtocolEditor
}
var PPF ppfApp
func CreateToolbar(fyneApp fyne.App) fyne.CanvasObject {
toolbar := widget.NewToolbar()
toolbar.Append(widget.NewToolbarAction(theme.StorageIcon(), func() {
PPF.ProtocolForging = !PPF.ProtocolForging
//TODO: implement the switch
}))
toolbar.Append(widget.NewToolbarSeparator())
toolbar.Append(widget.NewToolbarAction(theme.FolderNewIcon(), func() {
}))
toolbar.Append(widget.NewToolbarAction(theme.FolderOpenIcon(), func() {
}))
toolbar.Append(widget.NewToolbarAction(theme.DocumentSaveIcon(), func() {
}))
toolbar.Append(widget.NewToolbarAction(theme.SettingsIcon(), func() {
}))
toolbar.Append(widget.NewToolbarSpacer())
toolbar.Append(widget.NewToolbarAction(theme.LogoutIcon(), func() {
fyneApp.Quit()
}))
return toolbar
}
func CreateWorkarea() *fyne.Container {
return GetProtocolEditor().Representation
}

120
internal/ui/metadata.go Normal file
View File

@ -0,0 +1,120 @@
package ui
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl"
)
type Metadata struct {
Representation *fyne.Container
}
type PacketMetadata struct {
Metadata
}
type ProtocolMetadata struct {
Metadata
NameValue *widget.Entry
VersionValue *widget.Entry
ExtendsValue *widget.Entry
TcpIpLayer *widget.Select
OsiLayer *widget.Select
DescValue *widget.Entry
}
func (pmd *ProtocolMetadata) SetChanged(setfunc func(s string)) {
pmd.NameValue.OnChanged = setfunc
pmd.ExtendsValue.OnChanged = setfunc
pmd.DescValue.OnChanged = setfunc
pmd.VersionValue.OnChanged = setfunc
pmd.TcpIpLayer.OnChanged = setfunc
pmd.OsiLayer.OnChanged = setfunc
}
func CreateMetadataProtocol() *ProtocolMetadata {
md := ProtocolMetadata{}
vbox := container.NewVBox()
vbox.Add(widget.NewLabel("Protocol Metadata"))
form := container.New(layout.NewFormLayout())
form.Add(widget.NewLabel("Name:"))
md.NameValue = widget.NewEntry()
form.Add(md.NameValue)
form.Add(widget.NewLabel("Version:"))
md.VersionValue = widget.NewEntry()
form.Add(md.VersionValue)
form.Add(widget.NewLabel("Extends:"))
md.ExtendsValue = widget.NewEntry()
form.Add(md.ExtendsValue)
md.TcpIpLayer = widget.NewSelect(
[]string{
"Network Access",
"Internet",
"Transport",
"Application",
},
func(s string) {
})
form.Add(widget.NewLabel("TcpIpLayer*:"))
form.Add(md.TcpIpLayer)
md.OsiLayer = widget.NewSelect(
[]string{
"(Physical)",
"Data Link",
"Network",
"Transport",
"Session",
"Presentation",
"Application",
},
func(s string) {
})
form.Add(widget.NewLabel("OSI Layer:"))
form.Add(md.OsiLayer)
vbox.Add(form)
vbox.Add(widget.NewLabel("Description"))
multiline := widget.NewMultiLineEntry()
multiline.SetMinRowsVisible(3)
md.DescValue = multiline
vbox.Add(multiline)
md.Representation = vbox
return &md
}
func SetProtocolMetadata(prot *protocol.ProtocolStructure) {
md := PPF.ProtocolMeta
setfunc := func(s string) {
protocolctl.UpdateMetaData(
prot,
md.NameValue.Text,
md.VersionValue.Text,
0,
0,
md.ExtendsValue.Text,
md.DescValue.Text,
)
fmt.Printf("%s", protocolctl.ToJson(prot))
}
md.SetChanged(setfunc)
}
func CreateMetadataPacket() *PacketMetadata {
md := PacketMetadata{}
vbox := container.NewVBox()
vbox.Add(widget.NewLabel("Packet Metadata"))
form := container.New(layout.NewFormLayout())
form.Add(widget.NewLabel("Name:"))
form.Add(widget.NewEntry())
vbox.Add(form)
vbox.Add(widget.NewLabel("Description:"))
multiline := widget.NewMultiLineEntry()
multiline.SetMinRowsVisible(3)
vbox.Add(multiline)
return &md
}

View File

@ -21,8 +21,6 @@ func UpdateMetaData(
osilayer uint,
extensionTo string,
desc string,
requiredJSfunctions []string,
lowerLayerIdent map[string]string,
) {
prot.Metadata.Name = name
prot.Metadata.Description = desc
@ -30,8 +28,6 @@ func UpdateMetaData(
prot.Metadata.Version = version
prot.Metadata.OSILayer = osilayer
prot.Metadata.TCPIPLayer = tcpiplayer
prot.Metadata.RequiredJSFunctions = requiredJSfunctions
prot.Metadata.LowerLayerIdentification = lowerLayerIdent
}
func NewEmptyField() *protocol.Field {

View File

@ -25,8 +25,6 @@ func TestUpdateMetaData(t *testing.T) {
osilayer,
extensionTo,
desc,
nil,
nil,
)
if prot.Metadata.Name != name ||