88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
package ui
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/dialog"
|
|
"fyne.io/fyne/v2/storage"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
type NewObjectDialog struct {
|
|
representation *fyne.Container
|
|
// views
|
|
selection *fyne.Container // 4buttons grid
|
|
//protocolChooser *container.AppTabs
|
|
//packetChooser *fyne.Container
|
|
}
|
|
|
|
var pnod *NewObjectDialog
|
|
|
|
func CreateNewObjectDialog() *NewObjectDialog {
|
|
if pnod == nil {
|
|
pnod = &NewObjectDialog{}
|
|
|
|
// representation
|
|
// grid layout 100x100px elements in a center layout, 4 buttons, new Protocol, edit protocol, new Packet, edit Packet
|
|
buttons := []*widget.Button{
|
|
widget.NewButton("New protocol", func() {
|
|
// two ways: either backreference to PPF, open new tab with file and close the NOD
|
|
// or replace the content of the tab of the NOD, with changing the title in OpenTabs backreference to PPF aswell
|
|
PPF.NewProtocolFile()
|
|
}),
|
|
widget.NewButton("Open/Edit protocol", func() {
|
|
opendialog := dialog.NewFileOpen(func(uri fyne.URIReadCloser, err error) {
|
|
if uri == nil {
|
|
return
|
|
}
|
|
PPF.OpenProtocolFile(uri.URI().Path())
|
|
}, PPF.Window)
|
|
opendialog.SetFilter(storage.NewExtensionFileFilter([]string{".protocoljson"}))
|
|
opendialog.Show()
|
|
}),
|
|
widget.NewButton("New packet", func() {
|
|
PPF.NewPacketFile()
|
|
}),
|
|
widget.NewButton("Open/Edit packet", func() {
|
|
opendialog := dialog.NewFileOpen(func(uri fyne.URIReadCloser, err error) {
|
|
if uri == nil {
|
|
return
|
|
}
|
|
PPF.OpenPacketFile(uri.URI().Path())
|
|
}, PPF.Window)
|
|
opendialog.SetFilter(storage.NewExtensionFileFilter([]string{".packetjson"}))
|
|
opendialog.Show()
|
|
}),
|
|
}
|
|
selectgrid := container.NewGridWithColumns(2)
|
|
for _, v := range buttons {
|
|
selectgrid.Add(v)
|
|
}
|
|
pnod.selection = container.NewMax(selectgrid)
|
|
pnod.representation = pnod.selection
|
|
|
|
//pnod.representation.Add(pnod.selection) // add selection per default
|
|
// generate protocol chooser view
|
|
// App Tabs or vertical Accordion (doesnt exist yet)
|
|
//pnod.protocolChooser = container.NewAppTabs(nil)
|
|
// first tab -> official protocol repo, for viewing and editing/improvement
|
|
// file chooser embedded
|
|
// second tab -> own protocols, in a folder somewhere.
|
|
// file chooser embedded
|
|
|
|
// generate packet chooser view
|
|
// Just a file chooser embedded.
|
|
|
|
// data
|
|
}
|
|
return pnod
|
|
}
|
|
|
|
func (nod *NewObjectDialog) Representation() *fyne.Container {
|
|
return nod.representation
|
|
}
|
|
|
|
func (nod *NewObjectDialog) Refresh() {
|
|
|
|
}
|