Skip to content

Commit 6d5eac7

Browse files
committed
- Fix Save/Load mechanism
1 parent d46f52f commit 6d5eac7

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

controlFunctions.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,17 @@ func addButtonFunction() {
201201
}
202202
dialog.ShowError(fmt.Errorf("please enter valid label"), Application.mainWindow)
203203
}
204-
func applyProjectSetting() {
204+
func applyProjectSetting(withInitial bool) {
205205
rowInput.Disable()
206206
colInput.Disable()
207207
flatMatrixCheck.Disable()
208208
matlabSaveCheck.Disable()
209209
oneHotEncodingSaveCheck.Disable()
210210
Options.SettingsSaved = true
211-
InitializeTemps()
211+
if withInitial {
212+
InitializeTemps()
213+
}
214+
212215
}
213216
func resetProjectSetting() {
214217
dialog.ShowConfirm("Warning", "Are you sure you want to do that?\nthis is delete your added matrix if you dont saves it. ",
@@ -279,8 +282,11 @@ func loadProjectFile(reader io.ReadCloser) error {
279282
}
280283
Options = SavedProject.Options
281284
TempData = SavedProject.TempData
285+
copy(TempData.TempMatrix, SavedProject.TempData.TempMatrix)
286+
copy(TempData.TempTarget, SavedProject.TempData.TempTarget)
282287
TempData.buffer.Write(SavedProject.Buffer)
283288
OneHotDictionary = SavedProject.OneHotDictionary
289+
copy(OneHotDictionary.Values, SavedProject.OneHotDictionary.Values)
284290
err = countValue.Set(SavedProject.CounterValue)
285291
if err != nil {
286292
log.Println(err)
@@ -329,7 +335,7 @@ func loadProjectFileFunction() {
329335
dialog.ShowError(fmt.Errorf("error loading project file"), Application.mainWindow)
330336
return
331337
}
332-
applyProjectSetting()
338+
applyProjectSetting(false)
333339
}
334340

335341
}, Application.mainWindow)
@@ -339,7 +345,7 @@ func loadProjectFileFunction() {
339345
dialog.ShowError(fmt.Errorf("error loading project file"), Application.mainWindow)
340346
return
341347
}
342-
applyProjectSetting()
348+
applyProjectSetting(false)
343349
statusLabel.Text = "Project loaded!"
344350
addLabelAnimation(statusLabel)
345351
}

mainWidgets.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ var (
2323
targetFileEntry = widget.NewEntry()
2424
openPaint = widget.NewButtonWithIcon("OpenPaint", theme.WindowMaximizeIcon(), openPaintWindowOperation)
2525
changePath = widget.NewButtonWithIcon("Browse", theme.FolderIcon(), browseOperation)
26-
saveBtn = widget.NewButtonWithIcon("Save File", theme.DocumentSaveIcon(), saveOperation)
26+
saveBtn = widget.NewButtonWithIcon("Save file", theme.DocumentSaveIcon(), exportFileOperation)
2727
input = widget.NewEntry()
28-
exportBtn = widget.NewButtonWithIcon("Export PNG", theme.FileImageIcon(), expertOperation)
28+
exportBtn = widget.NewButtonWithIcon("Export PNG", theme.FileImageIcon(), expertPNGOperation)
2929
flatMatrixCheck = widget.NewCheck("Flat Matrix", func(b bool) {
3030
Options.FlatMatrix = b
3131
})
@@ -38,8 +38,13 @@ var (
3838
addButtonFunction()
3939
Application.paintObject.Clear()
4040
})
41-
saveOptionsBtn = widget.NewButtonWithIcon("Save Settings", theme.SettingsIcon(), saveProjectButtonFunction)
42-
resetProjectBtn = widget.NewButtonWithIcon("Reset Project", theme.ContentClearIcon(), resetProjectButtonFunction)
41+
saveOptionsBtn = widget.NewButtonWithIcon("Save Settings", theme.SettingsIcon(), func() {
42+
applyProjectSetting(true)
43+
})
44+
resetProjectBtn = widget.NewButtonWithIcon("Reset Project", theme.ContentClearIcon(), resetProjectSetting)
45+
toolbar = widget.NewToolbar(
46+
widget.NewToolbarAction(theme.DocumentSaveIcon(), saveProjectFileFunction),
47+
widget.NewToolbarAction(theme.ContentUndoIcon(), loadProjectFileFunction))
4348
)
4449

4550
// Layout containers
@@ -74,6 +79,7 @@ var (
7479
)
7580

7681
bottomContainer = container.NewVBox(
82+
container.NewPadded(toolbar),
7783
container.NewPadded(settingsContainer),
7884
container.NewPadded(actionContainer),
7985
container.NewPadded(labelContainer),

0 commit comments

Comments
 (0)