Fix empty file on save
This commit is contained in:
parent
52bff71153
commit
262bef4e3b
|
@ -1,7 +1,6 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
@ -29,6 +28,11 @@ type FileHandler interface {
|
||||||
GetReference() interface{}
|
GetReference() interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TabProvider interface {
|
||||||
|
SetTab(tab *container.TabItem)
|
||||||
|
Tab() *container.TabItem
|
||||||
|
}
|
||||||
|
|
||||||
type ppfApp struct {
|
type ppfApp struct {
|
||||||
App fyne.App
|
App fyne.App
|
||||||
Window fyne.Window
|
Window fyne.Window
|
||||||
|
@ -94,6 +98,7 @@ func (ppf *ppfApp) NewProtocolFile() {
|
||||||
item := ppf.OpenTabs.Selected()
|
item := ppf.OpenTabs.Selected()
|
||||||
item.Text = pfh.Name()
|
item.Text = pfh.Name()
|
||||||
item.Content = pfh.GetWorkarea()
|
item.Content = pfh.GetWorkarea()
|
||||||
|
pfh.SetTab(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ppf *ppfApp) NewPacketFile() {
|
func (ppf *ppfApp) NewPacketFile() {
|
||||||
|
@ -114,6 +119,7 @@ func (ppf *ppfApp) OpenProtocolFile(path string) {
|
||||||
item := ppf.OpenTabs.Selected()
|
item := ppf.OpenTabs.Selected()
|
||||||
item.Text = pfh.Path()
|
item.Text = pfh.Path()
|
||||||
item.Content = pfh.GetWorkarea()
|
item.Content = pfh.GetWorkarea()
|
||||||
|
pfh.SetTab(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ppf *ppfApp) OpenPacketFile(path string) {
|
func (ppf *ppfApp) OpenPacketFile(path string) {
|
||||||
|
@ -123,14 +129,15 @@ func (ppf *ppfApp) OpenPacketFile(path string) {
|
||||||
func (ppf *ppfApp) SaveFile(path string) {
|
func (ppf *ppfApp) SaveFile(path string) {
|
||||||
item := ppf.OpenTabs.Selected()
|
item := ppf.OpenTabs.Selected()
|
||||||
for _, fh := range ppf.OpenObjects {
|
for _, fh := range ppf.OpenObjects {
|
||||||
if fh.Path() == item.Text {
|
if fh.(TabProvider).Tab() == item {
|
||||||
fh.SaveAs(path)
|
fh.SaveAs(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if there exists another one with the same path, (max one!!!)
|
// if there exists another one with the same path, (max one!!!)
|
||||||
|
/* // skip that check for now
|
||||||
existingTab := -1
|
existingTab := -1
|
||||||
for i, v := range ppf.OpenTabs.Items {
|
for i, v := range ppf.OpenTabs.Items {
|
||||||
fmt.Printf("tab %d, path %s", i, v.Text)
|
fmt.Printf("existing tab %d, path %s\n", i, v.Text)
|
||||||
|
|
||||||
if v.Text == path && i != ppf.OpenTabs.SelectedIndex() {
|
if v.Text == path && i != ppf.OpenTabs.SelectedIndex() {
|
||||||
existingTab = i
|
existingTab = i
|
||||||
|
@ -140,7 +147,7 @@ func (ppf *ppfApp) SaveFile(path string) {
|
||||||
ppf.OpenTabs.Items = append(ppf.OpenTabs.Items[:existingTab], ppf.OpenTabs.Items[existingTab+1:]...)
|
ppf.OpenTabs.Items = append(ppf.OpenTabs.Items[:existingTab], ppf.OpenTabs.Items[existingTab+1:]...)
|
||||||
fmt.Printf("removing %d", existingTab)
|
fmt.Printf("removing %d", existingTab)
|
||||||
ppf.OpenTabs.Refresh()
|
ppf.OpenTabs.Refresh()
|
||||||
}
|
} */
|
||||||
item.Text = path
|
item.Text = path
|
||||||
ppf.OpenTabs.Refresh()
|
ppf.OpenTabs.Refresh()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
|
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
|
||||||
"gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl"
|
"gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl"
|
||||||
)
|
)
|
||||||
|
@ -12,6 +15,7 @@ type ProtocolFileHandler struct {
|
||||||
name string
|
name string
|
||||||
path string
|
path string
|
||||||
changed bool
|
changed bool
|
||||||
|
tab *container.TabItem
|
||||||
|
|
||||||
Reference *protocol.ProtocolStructure
|
Reference *protocol.ProtocolStructure
|
||||||
}
|
}
|
||||||
|
@ -21,6 +25,7 @@ func NewProtocolFileHandler() *ProtocolFileHandler {
|
||||||
pfh.name = "*new"
|
pfh.name = "*new"
|
||||||
pfh.changed = true
|
pfh.changed = true
|
||||||
pfh.ProtocolEditor = NewProtocolEditor(protocolctl.NewProtocolStructure())
|
pfh.ProtocolEditor = NewProtocolEditor(protocolctl.NewProtocolStructure())
|
||||||
|
pfh.Reference = pfh.ProtocolEditor.Reference
|
||||||
return &pfh
|
return &pfh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,14 +55,16 @@ func (pfh *ProtocolFileHandler) Open(path string) error {
|
||||||
return pfh.Load()
|
return pfh.Load()
|
||||||
}
|
}
|
||||||
func (pfh *ProtocolFileHandler) Save() error {
|
func (pfh *ProtocolFileHandler) Save() error {
|
||||||
protocolctl.Save(pfh.Reference, pfh.path)
|
err := protocolctl.Save(pfh.Reference, pfh.path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%v\n", err)
|
||||||
|
}
|
||||||
pfh.changed = false
|
pfh.changed = false
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
func (pfh *ProtocolFileHandler) SaveAs(path string) error {
|
func (pfh *ProtocolFileHandler) SaveAs(path string) error {
|
||||||
pfh.path = path
|
pfh.path = path
|
||||||
pfh.Save()
|
return pfh.Save()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
func (pfh *ProtocolFileHandler) Close() error {
|
func (pfh *ProtocolFileHandler) Close() error {
|
||||||
return pfh.Save()
|
return pfh.Save()
|
||||||
|
@ -73,3 +80,11 @@ func (pfh *ProtocolFileHandler) HasChanged() bool {
|
||||||
func (pfh *ProtocolFileHandler) GetReference() interface{} {
|
func (pfh *ProtocolFileHandler) GetReference() interface{} {
|
||||||
return pfh.Reference
|
return pfh.Reference
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pfh *ProtocolFileHandler) Tab() *container.TabItem {
|
||||||
|
return pfh.tab
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pfh *ProtocolFileHandler) SetTab(tab *container.TabItem) {
|
||||||
|
pfh.tab = tab
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue