summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-11-03 20:40:48 +0100
committerKevin Chabowski <kevin@kch42.de>2013-11-03 20:40:48 +0100
commitcecd4ca589ec3de1d22727fb265f0fbe50689acd (patch)
treefa5f3bbc367d2d2dd41b383422b4fee0f95388cb
parent6e630d91c25f8fe4767fc94d2b301b640a2fc219 (diff)
downloadbiomed-cecd4ca589ec3de1d22727fb265f0fbe50689acd.tar.gz
biomed-cecd4ca589ec3de1d22727fb265f0fbe50689acd.tar.bz2
biomed-cecd4ca589ec3de1d22727fb265f0fbe50689acd.zip
Saving biome infos implemented
-rw-r--r--biome_info_editor.go37
1 files changed, 31 insertions, 6 deletions
diff --git a/biome_info_editor.go b/biome_info_editor.go
index 1ae98c3..53c8a03 100644
--- a/biome_info_editor.go
+++ b/biome_info_editor.go
@@ -160,25 +160,23 @@ func errdlg(msg string, params ...interface{}) {
}
func (ed *BiomeInfoEditor) load() {
- f1, f2 := mkBioFFilters()
dlg := gtk.NewFileChooserDialog("Load", nil, gtk.FILE_CHOOSER_ACTION_OPEN, "OK", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL)
- dlg.AddFilter(f1)
- dlg.AddFilter(f2)
defer dlg.Destroy()
+askFilename:
if dlg.Run() == gtk.RESPONSE_OK {
path := dlg.GetFilename()
f, err := os.Open(path)
if err != nil {
errdlg("Could not load biome infos %s:\n%s", path, err.Error())
- return
+ goto askFilename
}
defer f.Close()
infos, err := ReadBiomeInfos(f)
if err != nil {
errdlg("Could not load biome infos %s:\n%s", path, err.Error())
- return
+ goto askFilename
}
ed.biomes = infos
@@ -187,7 +185,34 @@ func (ed *BiomeInfoEditor) load() {
}
func (ed *BiomeInfoEditor) save() {
- // TODO
+ dlg := gtk.NewFileChooserDialog("Save", nil, gtk.FILE_CHOOSER_ACTION_SAVE, "OK", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL)
+ defer dlg.Destroy()
+askFilename:
+ if dlg.Run() == gtk.RESPONSE_OK {
+ path := dlg.GetFilename()
+
+ if _, err := os.Stat(path); err == nil {
+ qdlg := gtk.NewMessageDialog(nil, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "File %s already exists. Overwrite?", path)
+ resp := qdlg.Run()
+ qdlg.Destroy()
+
+ if resp != gtk.RESPONSE_YES {
+ goto askFilename
+ }
+ }
+
+ f, err := os.Create(path)
+ if err != nil {
+ errdlg("Could not save biome infos %s:\n%s", path, err.Error())
+ goto askFilename
+ }
+ defer f.Close()
+
+ if err := WriteBiomeInfos(ed.biomes, f); err != nil {
+ errdlg("Could not save biome infos %s:\n%s", path, err.Error())
+ goto askFilename
+ }
+ }
}
func (ed *BiomeInfoEditor) Biomes() []BiomeInfo { return ed.biomes }