From 724f2c87c640934b29e42a278032940b98ae7901 Mon Sep 17 00:00:00 2001 From: "Marcel M. Otte" Date: Sat, 18 Mar 2023 10:22:38 +0100 Subject: [PATCH] Start of small refactor for better workflow --- internal/ui/editor.go | 5 +++ internal/ui/main.go | 61 ++++++++++++++++++++++++---------- internal/ui/newobjectdialog.go | 57 +++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 17 deletions(-) create mode 100644 internal/ui/editor.go create mode 100644 internal/ui/newobjectdialog.go diff --git a/internal/ui/editor.go b/internal/ui/editor.go new file mode 100644 index 0000000..a5c10cb --- /dev/null +++ b/internal/ui/editor.go @@ -0,0 +1,5 @@ +package ui + +type Editor interface { + Representationer +} diff --git a/internal/ui/main.go b/internal/ui/main.go index 58c63e0..18a1fcc 100644 --- a/internal/ui/main.go +++ b/internal/ui/main.go @@ -12,11 +12,39 @@ import ( "gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl" ) +type Representationer interface { + Representation() *fyne.Container +} + +type FileHandler interface { + Name() string + Path() string + Open(path string) error + Save() error + SaveAs(path string) error + Close() error + + Changed() + HasChanged() bool +} + type ppfApp struct { App fyne.App Window fyne.Window - // Container for the borderlayout - Toolbar fyne.CanvasObject + // Container for the main layout, toolbar at top, in Center the doctabs. + MainContainer *fyne.Container + // toolbar + Toolbar fyne.CanvasObject + // left optional the local/remote library + // tbd + // center opened objects + OpenTabs *container.DocTabs // DocTabs + OpenObjects []*FileHandler // actual files + + // Global important stuff + Settings map[string]interface{} + + /*/ will be part of the Editor Metadata *Metadata Extensions *fyne.Container ContextBar *fyne.Container @@ -25,14 +53,11 @@ type ppfApp struct { // 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 // workspace handling - OpenProtocolFiles []*ProtocolFileHandler + OpenProtocolFiles []*ProtocolFileHandler//*/ } var PPF ppfApp @@ -41,21 +66,21 @@ func NewPPF(fyneApp fyne.App, w fyne.Window) ppfApp { PPF.App = fyneApp PPF.Window = w PPF.Toolbar = CreateToolbar(fyneApp) - PPF.Workarea = CreateWorkarea() + /*PPF.Workarea = CreateWorkarea() PPF.Extensions = container.NewCenter() PPF.ProtocolMeta = NewMetadataProtocol() PPF.Metadata = &PPF.ProtocolMeta.Metadata - PPF.ContextBar = container.NewCenter() + PPF.ContextBar = container.NewCenter() //*/ return PPF } func (ppf *ppfApp) GetContainer() *fyne.Container { return container.NewBorder( PPF.Toolbar, - PPF.ContextBar, - PPF.Metadata.Representation, - PPF.Extensions, - PPF.Workarea, + nil, //PPF.ContextBar, + nil, //PPF.Metadata.Representation, + nil, //PPF.Extensions, + PPF.OpenTabs, ) } @@ -66,6 +91,13 @@ func (ppf *ppfApp) OpenFile(path string) { } func (ppf *ppfApp) NewFile() { + //TODO: show entry screen with choosable ways of: + // PROTOCOL editor + // create a new protocol + // edit an existing protocol + // PACKET editor + // create a binary packet + // edit an existing binary packet pfh := NewProtocolFileHandler() PPF.OpenProtocolFiles = append(PPF.OpenProtocolFiles, pfh) ppf.Workarea.Append(container.NewTabItem(pfh.Filename, pfh.GetWorkarea())) @@ -93,11 +125,6 @@ func (ppf *ppfApp) GetReferenceForFile(s string) *protocol.ProtocolStructure { func CreateToolbar(fyneApp fyne.App) fyne.CanvasObject { toolbar := widget.NewToolbar() - toolbar.Append(widget.NewToolbarAction(theme.MenuIcon(), func() { - PPF.ProtocolForging = !PPF.ProtocolForging - //TODO: implement the switch - })) - toolbar.Append(widget.NewToolbarSeparator()) toolbar.Append(widget.NewToolbarAction(theme.ContentAddIcon(), func() { PPF.NewFile() })) diff --git a/internal/ui/newobjectdialog.go b/internal/ui/newobjectdialog.go new file mode 100644 index 0000000..09bcecb --- /dev/null +++ b/internal/ui/newobjectdialog.go @@ -0,0 +1,57 @@ +package ui + +import ( + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/widget" +) + +type NewObjectDialog struct { + representation *fyne.Container + // views + selection *fyne.Container // 4buttons grid + protocolChooser *fyne.Container + packetChooser *fyne.Container +} + +var pnod *NewObjectDialog + +func CreateNewObjectDialog() *NewObjectDialog { + if pnod == nil { + pnod = &NewObjectDialog{} + + pnod.representation = container.NewMax(nil) + // representation + // grid layout 100x100px elements in a center layout, 4 buttons, new Protocol, edit protocol, new Packet, edit Packet + buttons := []widget.Button{} + buttons = append(buttons, *widget.NewButton("New protocol", func() { + + })) + buttons = append(buttons, *widget.NewButton("Edit protocol", func() { + + })) + buttons = append(buttons, *widget.NewButton("New packet", func() { + + })) + buttons = append(buttons, *widget.NewButton("Edit packet", func() { + + })) + selectgrid := container.NewGridWithColumns(2, nil) + for _, v := range buttons { + selectgrid.Add(&v) + } + pnod.selection = container.NewMax(selectgrid) + + pnod.representation.Add(pnod.selection) + // data + } + return pnod +} + +func (nod *NewObjectDialog) Representation() *fyne.Container { + return nod.representation +} + +func (nod *NewObjectDialog) Refresh() { + +}