linter fixes and test fixes
This commit is contained in:
parent
204da1c880
commit
c9fcb3d947
|
@ -9,6 +9,7 @@ import (
|
|||
var fyneApp fyne.App
|
||||
var w fyne.Window
|
||||
|
||||
// Appmain creates the Fyne application and starts it up
|
||||
func Appmain() {
|
||||
fyneApp = app.New()
|
||||
w = fyneApp.NewWindow("ProtocolPacketForger")
|
||||
|
@ -19,6 +20,7 @@ func Appmain() {
|
|||
w.ShowAndRun()
|
||||
}
|
||||
|
||||
// CreateApp creates the PPF UI
|
||||
func CreateApp() *fyne.Container {
|
||||
ppf := ui.NewPPF(fyneApp, w)
|
||||
return ppf.GetContainer()
|
||||
|
|
|
@ -5,10 +5,11 @@ import (
|
|||
"gitea.mmo.to/ppForge/ppforge/protocolctl"
|
||||
)
|
||||
|
||||
// GetAdder returns a fyne button which on click creates a new field in the editor
|
||||
func GetAdder(pEd *ProtocolEditor) *widget.Button {
|
||||
fieldAdder := widget.NewButton("Add Field", func() {
|
||||
f := protocolctl.NewEmptyField()
|
||||
index := protocolctl.AppendField(pEd.Reference, f)
|
||||
index := protocolctl.AppendField(pEd.Reference, *f)
|
||||
pEd.AddFieldCreator(CreateFieldEditor(pEd, index, f))
|
||||
})
|
||||
return fieldAdder
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"gitea.mmo.to/ppForge/ppforge/protocolctl"
|
||||
)
|
||||
|
||||
// FieldEditor is a struct holding all elements of the field editor ui
|
||||
type FieldEditor struct {
|
||||
Representation *fyne.Container
|
||||
NameValue *widget.Entry
|
||||
|
@ -29,6 +30,7 @@ type FieldEditor struct {
|
|||
Index int
|
||||
}
|
||||
|
||||
// CreateFieldEditor initializes a new field editor ui for an editor and a protocol
|
||||
func CreateFieldEditor(ed *ProtocolEditor, index int, ref *protocol.Field) *FieldEditor {
|
||||
fc := &FieldEditor{}
|
||||
fc.Reference = ref
|
||||
|
|
|
@ -36,8 +36,8 @@ type TabProvider interface {
|
|||
Tab() *container.TabItem
|
||||
}
|
||||
|
||||
// ppfApp is the internal struct holding all the required main objects/elements for the application
|
||||
type ppfApp struct {
|
||||
// PpfApp is the internal struct holding all the required main objects/elements for the application
|
||||
type PpfApp struct {
|
||||
App fyne.App
|
||||
Window fyne.Window
|
||||
// Container for the main layout, toolbar at top, in Center the doctabs.
|
||||
|
@ -70,10 +70,10 @@ type ppfApp struct {
|
|||
}
|
||||
|
||||
// PPF is the global variable holding the application struct
|
||||
var PPF ppfApp
|
||||
var PPF PpfApp
|
||||
|
||||
// NewPPF is the entrypoint to create the application
|
||||
func NewPPF(fyneApp fyne.App, w fyne.Window) ppfApp {
|
||||
func NewPPF(fyneApp fyne.App, w fyne.Window) PpfApp {
|
||||
PPF.App = fyneApp
|
||||
PPF.Window = w
|
||||
PPF.Toolbar = CreateToolbar(fyneApp)
|
||||
|
@ -81,7 +81,8 @@ func NewPPF(fyneApp fyne.App, w fyne.Window) ppfApp {
|
|||
return PPF
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) GetContainer() *fyne.Container {
|
||||
// GetContainer delivers the main container of the application
|
||||
func (ppf *PpfApp) GetContainer() *fyne.Container {
|
||||
return container.NewBorder(
|
||||
ppf.Toolbar, //top
|
||||
nil, //bottom
|
||||
|
@ -91,7 +92,8 @@ func (ppf *ppfApp) GetContainer() *fyne.Container {
|
|||
)
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) NewProtocolFile() {
|
||||
// NewProtocolFile creates and shows a new protocol file
|
||||
func (ppf *PpfApp) NewProtocolFile() {
|
||||
//TODO: show entry screen with choosable ways of:
|
||||
// PROTOCOL editor
|
||||
// create a new protocol
|
||||
|
@ -107,11 +109,13 @@ func (ppf *ppfApp) NewProtocolFile() {
|
|||
pfh.SetTab(item)
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) NewPacketFile() {
|
||||
// NewPacketFile creates and shows a new packet file
|
||||
func (ppf *PpfApp) NewPacketFile() {
|
||||
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) OpenProtocolFile(path string) {
|
||||
// OpenProtocolFile opens and shows a protocol file
|
||||
func (ppf *PpfApp) OpenProtocolFile(path string) {
|
||||
for _, v := range ppf.OpenTabs.Items {
|
||||
if v.Text == path {
|
||||
// do not open a file twice!
|
||||
|
@ -128,11 +132,13 @@ func (ppf *ppfApp) OpenProtocolFile(path string) {
|
|||
pfh.SetTab(item)
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) OpenPacketFile(path string) {
|
||||
// OpenPacketFile opens and shows a packet file
|
||||
func (ppf *PpfApp) OpenPacketFile(path string) {
|
||||
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) SaveFile(path string) {
|
||||
// SaveFile saves both a protocol and a packet file
|
||||
func (ppf *PpfApp) SaveFile(path string) {
|
||||
item := ppf.OpenTabs.Selected()
|
||||
for _, fh := range ppf.OpenObjects {
|
||||
if fh.(TabProvider).Tab() == item {
|
||||
|
@ -158,7 +164,8 @@ func (ppf *ppfApp) SaveFile(path string) {
|
|||
ppf.OpenTabs.Refresh()
|
||||
}
|
||||
|
||||
func (ppf *ppfApp) NewFile() {
|
||||
// NewFile shows the new item dialog
|
||||
func (ppf *PpfApp) NewFile() {
|
||||
for _, v := range ppf.OpenTabs.Items {
|
||||
if v.Text == "[new item dialog]" {
|
||||
ppf.OpenTabs.Select(v)
|
||||
|
@ -170,6 +177,7 @@ func (ppf *ppfApp) NewFile() {
|
|||
ppf.OpenTabs.Select(item)
|
||||
}
|
||||
|
||||
// CreateToolbar initializes the toolbar
|
||||
func CreateToolbar(fyneApp fyne.App) fyne.CanvasObject {
|
||||
toolbar := widget.NewToolbar()
|
||||
toolbar.Append(widget.NewToolbarAction(theme.ContentAddIcon(), func() {
|
||||
|
@ -207,6 +215,7 @@ func CreateToolbar(fyneApp fyne.App) fyne.CanvasObject {
|
|||
return toolbar
|
||||
}
|
||||
|
||||
// CreateWorkarea initializes the workarea
|
||||
func CreateWorkarea() *container.DocTabs {
|
||||
tabs := container.NewDocTabs()
|
||||
tabs.OnClosed = func(ti *container.TabItem) {
|
||||
|
|
|
@ -9,10 +9,12 @@ type FieldValue struct {
|
|||
Value string
|
||||
}
|
||||
|
||||
// GetProtocolField returns the protocol field
|
||||
func (fv *FieldValue) GetProtocolField() *protocol.Field {
|
||||
return fv.fieldReference
|
||||
}
|
||||
|
||||
// SetProtocolField sets the protocl field
|
||||
func (fv *FieldValue) SetProtocolField(pf *protocol.Field) {
|
||||
fv.fieldReference = pf
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package packet
|
||||
|
||||
// Metadata struct is the absolute minimum of metadata
|
||||
type Metadata struct {
|
||||
Name string
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package protocolctl
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
|
||||
|
@ -56,14 +57,14 @@ func NewField(
|
|||
return &f
|
||||
}
|
||||
|
||||
func AppendField(prot *protocol.ProtocolStructure, field *protocol.Field) int {
|
||||
func AppendField(prot *protocol.ProtocolStructure, field protocol.Field) int {
|
||||
i := len(prot.Structure)
|
||||
prot.Structure = append(prot.Structure, field)
|
||||
prot.Structure = append(prot.Structure, &field)
|
||||
return i + 1
|
||||
}
|
||||
func AddField(prot *protocol.ProtocolStructure, index int, field *protocol.Field) {
|
||||
if len(prot.Structure) == index {
|
||||
AppendField(prot, field)
|
||||
AppendField(prot, *field)
|
||||
return
|
||||
}
|
||||
ret := make([]*protocol.Field, 0)
|
||||
|
@ -104,8 +105,12 @@ func RemoveFieldByName(prot *protocol.ProtocolStructure, name string) {
|
|||
|
||||
func RemoveFieldByElement(prot *protocol.ProtocolStructure, field int) {
|
||||
ret := make([]*protocol.Field, 0)
|
||||
ret = append(ret, prot.Structure[:field]...)
|
||||
ret = append(ret, prot.Structure[field+1:]...)
|
||||
for i, f := range prot.Structure {
|
||||
if i != field {
|
||||
fmt.Printf("appending %d, %s\n", i, f.ToJson())
|
||||
ret = append(ret, f)
|
||||
}
|
||||
}
|
||||
prot.Structure = ret
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func TestUpdateMetaData(t *testing.T) {
|
|||
func GenerateFields() []protocol.Field {
|
||||
slc := make([]protocol.Field, 0)
|
||||
for i := 0; i < 10; i++ {
|
||||
slc = append(slc, *NewField(
|
||||
field := NewField(
|
||||
fmt.Sprintf("testfield%d", i),
|
||||
fmt.Sprintf("Description %d", i),
|
||||
"",
|
||||
|
@ -51,7 +51,8 @@ func GenerateFields() []protocol.Field {
|
|||
nil,
|
||||
false,
|
||||
false,
|
||||
))
|
||||
)
|
||||
slc = append(slc, *field)
|
||||
}
|
||||
return slc
|
||||
}
|
||||
|
@ -60,9 +61,13 @@ func GenerateStructure() *protocol.ProtocolStructure {
|
|||
p := NewProtocolStructure()
|
||||
slc := GenerateFields()
|
||||
for i, e := range slc {
|
||||
AppendField(p, &e)
|
||||
AppendField(p, e)
|
||||
fmt.Printf("%d %s\n", i, e.ToJson())
|
||||
}
|
||||
for i, e := range p.Structure {
|
||||
fmt.Printf("%d %s\n", i, e.ToJson())
|
||||
}
|
||||
fmt.Println("Generated Structure.")
|
||||
return p
|
||||
}
|
||||
|
||||
|
@ -77,7 +82,7 @@ func TestFieldAppend(t *testing.T) {
|
|||
false,
|
||||
)
|
||||
p := NewProtocolStructure()
|
||||
AppendField(p, f)
|
||||
AppendField(p, *f)
|
||||
if p.Structure[0].Name != "testfield" {
|
||||
t.Log("Append failed.")
|
||||
t.Fail()
|
||||
|
|
Loading…
Reference in New Issue