Added strList adap. Fix name get from AppInfo.ini

This commit is contained in:
Belac Darkstorm
2016-08-31 08:52:37 -05:00
parent f2621afdda
commit 24a821aaed
4 changed files with 109 additions and 9 deletions
+11 -6
View File
@@ -59,8 +59,10 @@ func processApp(fi *os.File) (out prtap) {
fmt.Println(fi.Name() + "/App/AppInfo/appinfo.ini")
if err == nil {
fmt.Println("working!")
out.cat = getCat(fild)
out.name = getName(fild)
out.name = getName(*fild)
fild, _ = os.Open(fi.Name() + "/App/AppInfo/appinfo.ini")
out.cat = getCat(*fild)
fmt.Println("Name:", out.name)
}
} else if !v.IsDir() {
//do os check here
@@ -79,14 +81,15 @@ func processApp(fi *os.File) (out prtap) {
return prtap{}
}
func getCat(fi *os.File) (out string) {
rdr := bufio.NewReader(fi)
func getCat(fi os.File) (out string) {
rdr := bufio.NewReader(&fi)
var err error
var ln []byte
for err == nil {
ln, _, err = rdr.ReadLine()
str := string(ln)
if strings.HasPrefix(str, "Category=") {
fmt.Println(str)
out = strings.TrimPrefix(str, "Category=")
return
}
@@ -94,13 +97,15 @@ func getCat(fi *os.File) (out string) {
return
}
func getName(fi *os.File) (out string) {
rdr := bufio.NewReader(fi)
func getName(fi os.File) (out string) {
rdr := bufio.NewReader(&fi)
var err error
var ln []byte
for err == nil {
ln, _, err = rdr.ReadLine()
str := string(ln)
fmt.Println(str)
if strings.HasPrefix(str, "Name=") {
out = strings.TrimPrefix(str, "Name=")
return
+1 -1
View File
@@ -22,9 +22,9 @@ func (p *prtapAdap) Count() int {
func (p *prtapAdap) Create(th gxui.Theme, index int) gxui.Control {
box := th.CreateLinearLayout()
box.SetDirection(gxui.LeftToRight)
//add image support
// pic := th.CreateImage()
// dr.CreateTexture()
//add image support
lbl := th.CreateLabel()
lbl.SetText(p.apps[index].name)
// box.AddChild(pic)
Executable
+96
View File
@@ -0,0 +1,96 @@
package main
import (
"encoding/gob"
"os"
"github.com/nelsam/gxui"
"github.com/nelsam/gxui/math"
)
//StrList TODO
type StrList struct {
gxui.AdapterBase
strs []string
}
//AddString TODO
func (s *StrList) AddString(add string) {
s.strs = append(s.strs, add)
s.DataChanged(false)
}
//Remove TODO
func (s *StrList) Remove(index int) {
s.strs = append(s.strs[:index], s.strs[index+1:]...)
s.DataChanged(false)
}
//SetStrings TODO
func (s *StrList) SetStrings(strs []string) {
s.strs = strs
s.DataChanged(false)
}
func (s *StrList) Save(filename string) {
os.Remove(filename)
fi, err := os.Create(filename)
if err != nil {
panic(err)
}
e := gob.NewEncoder(fi)
err = e.Encode(s.strs)
if err != nil {
panic(err)
}
fi.Close()
}
func (s *StrList) Load(filename string) {
fi, err := os.Open(filename)
if err != nil {
return
}
d := gob.NewDecoder(fi)
err = d.Decode(&s.strs)
if err != nil {
panic(err)
}
fi.Close()
s.DataChanged(false)
}
//Count TODO
func (s *StrList) Count() int {
return len(s.strs)
}
//ItemAt TODO
func (s *StrList) ItemAt(index int) gxui.AdapterItem {
return s.strs[index]
}
//ItemIndex TODO
func (s *StrList) ItemIndex(item gxui.AdapterItem) int {
for i, v := range s.strs {
if v == item {
return i
}
}
return -1
}
//Create TODO
func (s *StrList) Create(th gxui.Theme, index int) gxui.Control {
box := th.CreateLinearLayout()
box.SetDirection(gxui.LeftToRight)
lbl := th.CreateLabel()
lbl.SetText(s.strs[index])
box.AddChild(lbl)
return box
}
//Size TODO
func (s *StrList) Size(gxui.Theme) math.Size {
return math.Size{W: math.MaxSize.W, H: 20}
}
+1 -2
View File
@@ -1,7 +1,6 @@
package main
import (
"gxuiCustom"
"os"
"os/exec"
"path"
@@ -16,7 +15,7 @@ var (
func uiMain(dri gxui.Driver) {
dr = dri
catAdap := &gxuiCustom.StrList{}
catAdap := &StrList{}
catAdap.SetStrings(cats)
appAdap := &prtapAdap{}
th := dark.CreateTheme(dr)