update gui
更新ui展示
This commit is contained in:
@@ -52,3 +52,11 @@ func requireValidator(value string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getBool(bstr string) bool {
|
||||
if bstr == "true" || bstr == " 是" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dlg
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/xxjwxc/public/tools"
|
||||
|
||||
@@ -190,6 +191,7 @@ func enterSet(g *gocui.Gui, v *gocui.View) error {
|
||||
// add button
|
||||
form.AddButton("save", SLocalize("save"), buttonSave).AddHandler(gocui.MouseLeft, buttonSave)
|
||||
form.AddButton("cancel", SLocalize("cancel"), buttonCancel).AddHandler(gocui.MouseLeft, buttonCancel)
|
||||
form.AddButton("about", SLocalize("about"), about).AddHandler(gocui.MouseLeft, about)
|
||||
|
||||
form.Draw()
|
||||
|
||||
@@ -199,12 +201,52 @@ func enterSet(g *gocui.Gui, v *gocui.View) error {
|
||||
func buttonCancel(g *gocui.Gui, v *gocui.View) error {
|
||||
menuFocusButton(g)
|
||||
if form != nil {
|
||||
return form.Close(g, nil)
|
||||
err := form.Close(g, nil)
|
||||
form = nil
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buttonSave(g *gocui.Gui, v *gocui.View) error {
|
||||
|
||||
mp := form.GetFieldTexts()
|
||||
config.SetOutDir(mp["out_dir"])
|
||||
|
||||
var dbInfo config.MysqlDbInfo
|
||||
dbInfo.Host = mp["db_host"]
|
||||
port, err := strconv.Atoi(mp["db_port"])
|
||||
if err != nil {
|
||||
modal := mycui.NewModal(g, 0, 0, 30).SetText("port error")
|
||||
modal.AddButton("ok", "OK", gocui.KeyEnter, func(g *gocui.Gui, v *gocui.View) error {
|
||||
modal.Close()
|
||||
form.SetCurrentItem(form.GetCurrentItem())
|
||||
return nil
|
||||
})
|
||||
|
||||
modal.Draw()
|
||||
return nil
|
||||
}
|
||||
|
||||
dbInfo.Port = port
|
||||
dbInfo.Username = mp["db_usename"]
|
||||
dbInfo.Password = mp["db_pwd"]
|
||||
dbInfo.Database = mp["db_name"]
|
||||
|
||||
config.SetMysqlDbInfo(&dbInfo)
|
||||
mp = form.GetSelectedOpts()
|
||||
config.SetIsDev(getBool(mp["is_dev"]))
|
||||
config.SetSimple(getBool(mp["is_simple"]))
|
||||
config.SetSingularTable(getBool(mp["is_singular"]))
|
||||
config.SetIsOutSQL(getBool(mp["is_out_sql"]))
|
||||
config.SetIsOutFunc(getBool(mp["is_out_func"]))
|
||||
config.SetForeignKey(getBool(mp["is_foreign_key"]))
|
||||
config.SetURLTag(mp["url_tag"])
|
||||
config.SetDBTag(mp["db_tag"])
|
||||
config.SetLG(mp["language"])
|
||||
|
||||
config.SaveToFile()
|
||||
buttonCancel(g, v)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package dlg
|
||||
|
||||
import (
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"github.com/xxjwxc/gormt/data/config"
|
||||
"github.com/xxjwxc/public/myi18n"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
@@ -13,7 +14,19 @@ import (
|
||||
func init() {
|
||||
addChinese()
|
||||
addEnglish()
|
||||
myi18n.SetLocalLG("zh") // default
|
||||
myi18n.SetLocalLG(getLG()) // default
|
||||
}
|
||||
|
||||
func getLG() string {
|
||||
tag := config.GetLG()
|
||||
// if len(tag) == 0 {
|
||||
// return tools.GetLocalSystemLang(true)
|
||||
// }
|
||||
if tag == "English" {
|
||||
return "en"
|
||||
}
|
||||
|
||||
return "zh"
|
||||
}
|
||||
|
||||
// SLocalize 获取值
|
||||
@@ -94,6 +107,9 @@ func addChinese() error {
|
||||
}, &i18n.Message{
|
||||
ID: "cancel",
|
||||
Other: " 取 消 ",
|
||||
}, &i18n.Message{
|
||||
ID: "about",
|
||||
Other: " 关 于 作 者",
|
||||
}, &i18n.Message{
|
||||
ID: "log_run",
|
||||
Other: " Enter : 执 行 \n ↑ ↓: 本 视 图 选 择 \n Tab : 多 视 图 切 换 \n 支 持 鼠 标 操 作 方 式 \n \n \033[33;7m 输 入 Enter 直 接 执 行 \033[0m\n ",
|
||||
@@ -176,6 +192,9 @@ func addEnglish() error {
|
||||
}, &i18n.Message{
|
||||
ID: "cancel",
|
||||
Other: "Cancel",
|
||||
}, &i18n.Message{
|
||||
ID: "about",
|
||||
Other: "About",
|
||||
}, &i18n.Message{
|
||||
ID: "log_run",
|
||||
Other: " Enter : run \n ↑ ↓: Selection of this view \n Tab : Multi view switching \n Mouse operation supported \n \n \033[33;7m Enter to execute \033[0m",
|
||||
|
||||
Reference in New Issue
Block a user