ppforge/internal/ui/newobjectdialog.go

88 lines
2.5 KiB
Go
Raw Normal View History

package ui
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
2023-03-31 15:38:20 +02:00
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/widget"
)
type NewObjectDialog struct {
representation *fyne.Container
// views
2023-04-11 16:05:24 +02:00
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
2023-03-31 15:38:20 +02:00
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 {
2023-03-31 15:38:20 +02:00
selectgrid.Add(v)
}
pnod.selection = container.NewMax(selectgrid)
2023-03-31 15:38:20 +02:00
pnod.representation = pnod.selection
2023-03-31 15:38:20 +02:00
//pnod.representation.Add(pnod.selection) // add selection per default
2023-03-20 23:03:30 +01:00
// generate protocol chooser view
// App Tabs or vertical Accordion (doesnt exist yet)
2023-03-31 15:38:20 +02:00
//pnod.protocolChooser = container.NewAppTabs(nil)
2023-03-20 23:03:30 +01:00
// 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() {
}