Skip to content

Commit

Permalink
🚀 release 0.0.2
Browse files Browse the repository at this point in the history
Resolution ratio
Multi-Language Support
  • Loading branch information
airplayx committed Mar 26, 2020
1 parent 4994be3 commit fecc128
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 126 deletions.
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[English](README.md)

![image](assets/show_win.png)
![image](assets/show_win_zh.png)

## 功能展示

Expand Down
Binary file modified assets/show_win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/show_win_zh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ func main() {
jsonparser.EachKey(configs.Json,
func(i int, bytes []byte, valueType jsonparser.ValueType, e error) {
font, _ := jsonparser.GetString(bytes, "font")
_ = os.Setenv("FYNE_FONT", font)
if font != "" {
_ = os.Setenv("FYNE_FONT", font)
}
theme, _ := jsonparser.GetString(bytes, "theme")
_ = os.Setenv("FYNE_THEME", theme)
scale, _ := jsonparser.GetString(bytes, "scale")
_ = os.Setenv("FYNE_SCALE", scale)
}, []string{"const"})
main := app.NewWithID("Gopher")
main.SetIcon(icon.Ico)
window := main.NewWindow("Gormat - Tool For Gopher")
window := main.NewWindow("Gormat")
window.CenterOnScreen()
window.Resize(fyne.Size{Width: 1200, Height: 720})
window.SetContent(_app.Container(main, window))
Expand All @@ -44,4 +46,5 @@ vendor/fyne.io/fyne/dialog/information.go:38
vendor/fyne.io/fyne/shortcut.go:43
vendor/fyne.io/fyne/widget/entry.go:526
vendor/fyne.io/fyne/widget/tabcontainer.go:390
vendor/fyne.io/fyne/dialog/confirm.go:28
*/
41 changes: 19 additions & 22 deletions configs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,14 @@
package configs

import (
"github.com/buger/jsonparser"
"io/ioutil"
"os"
"strings"
)

var (
Json = []byte(`{
"const": {
"font": "./miniHei.ttf",
"theme": "light",
"scale": "1.0"
},
"sql2struct": {
"target_dir": "./models",
"auto_save": false,
"tags": [
"gorm",
"json"
],
"json_omitempty": false,
"exclude_tables": [],
"try_complete": true,
"tinyint2bool": true,
"sourceMap": [],
"reflect": "{\"tinyint\":\"int8\",\"smallint\":\"int16\",\"int\":\"int32\",\"bigint\":\"int64\",\"float\":\"float64\",\"double\":\"float64\",\"decimal\":\"float64\",\"char\":\"string\",\"varchar\":\"string\",\"text\":\"string\",\"mediumtext\":\"string\",\"longtext\":\"string\",\"time\":\"time.Time\",\"date\":\"time.Time\",\"datetime\":\"time.Time\",\"timestamp\":\"time.Time\",\"enum\":\"string\",\"set\":\"string\",\"blob\":\"string\"}",
"special": "{\"id\":\"uint\"}"
}
}`)
Json = []byte(`{"const":{"font":"./miniHei.ttf","theme":"light","scale":"1.0","language":"en"},"language":{"black":"黑色","light":"白色","default":"默认","effective after restart":"重启后生效","base":"基本","screen":"屏幕","language":"语言","rules":"规则","mapping":"映射","special":"特殊","sql to struct":"sql 转 struct","json to struct":"json 转 struct","edit link":"编辑连接","add link":"添加连接","bad link parameters":"错误的连接参数","Please input %s to delete the current group record":"请输入 %s 确认删除当前组记录","action":"操作","save ok":"保存成功","cancel":"取消","Please confirm to delete the current: %s ?":"确认删除当前 %s 连接记录吗?","no":"否","yes":"是","info":"信息","connection test":"测试连接","testing":"测试中","connection successful":"连接成功","the database can not be empty":"数据库名称不能为空","duplicate links":"重复的连接记录","engine":"引擎","host":"主机地址","port":"端口","user":"用户名","password":"密码","database":"数据库","table":"表结构","build only":"仅生成","build and include omitempty":"生成并包含omitempty","carriage return":"回车换行","auto save files":"保存文件","output folder":"输出文件夹","tags":"标签","exclusion table":"排除表","always execute":"始终执行","type conversion":"类型转换","the fields starting with is_ are automatically converted to bool":"is_开头字段自动转为bool","specified fields transformation":"指定字段转换","bool":"布尔值"},"sql2struct":{"target_dir":"./models","auto_save":false,"tags":["gorm","json"],"json_omitempty":false,"exclude_tables":[],"try_complete":true,"tinyint2bool":true,"sourceMap":[],"reflect":"{\"tinyint\":\"int8\",\"smallint\":\"int16\",\"int\":\"int32\",\"bigint\":\"int64\",\"float\":\"float64\",\"double\":\"float64\",\"decimal\":\"float64\",\"char\":\"string\",\"varchar\":\"string\",\"text\":\"string\",\"mediumtext\":\"string\",\"longtext\":\"string\",\"time\":\"time.Time\",\"date\":\"time.Time\",\"datetime\":\"time.Time\",\"timestamp\":\"time.Time\",\"enum\":\"string\",\"set\":\"string\",\"blob\":\"string\"}","special":"{\"id\":\"uint\"}"}}`)
CustomFile = "./config.json"
)

Expand All @@ -43,3 +24,19 @@ func init() {
Json, _ = ioutil.ReadFile(CustomFile)
}
}

func Text(key string, replace ...string) string {
l, _ := jsonparser.GetString(Json, "const", "language")
if l == "en" {
goto loop
} else if str, err := jsonparser.GetString(Json, "language", key); err != nil {
goto loop
} else {
key = str
}
loop:
if replace != nil {
return strings.Replace(key, "%s", replace[0], -1)
}
return key
}
3 changes: 2 additions & 1 deletion internal/app/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package app
import (
"fyne.io/fyne"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
"gormat/internal/app/sql2struct"
"gormat/internal/pkg/icon"
Expand Down Expand Up @@ -63,7 +64,7 @@ func Container(app fyne.App, win fyne.Window) *widget.TabContainer {
c := widget.NewTabContainer(
//widget.NewTabItemWithIcon("", icon.Home, WelcomeScreen()),
widget.NewTabItemWithIcon("", icon.Store, s2sBox),
//widget.NewTabItemWithIcon("", theme.SettingsIcon(), SettingScreen(app, win)),
widget.NewTabItemWithIcon("", theme.SettingsIcon(), SettingScreen(app, win)),
//widget.NewTabItemWithIcon("", icon.Daily, fyne.NewContainer()),
//widget.NewTabItemWithIcon("", icon.Video, fyne.NewContainer()),
)
Expand Down
71 changes: 50 additions & 21 deletions internal/app/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package app

import (
"fyne.io/fyne"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
Expand All @@ -17,55 +18,83 @@ import (
)

func SettingScreen(app fyne.App, win fyne.Window) fyne.CanvasObject {
theMe := widget.NewRadio([]string{"黑色", "白色"}, func(s string) {
theMe := widget.NewRadio([]string{configs.Text("black"), configs.Text("light")}, func(s string) {
switch s {
case "黑色":
case configs.Text("black"):
app.Settings().SetTheme(theme.DarkTheme())

default:
app.Settings().SetTheme(theme.LightTheme())
}
})

switch t, _ := jsonparser.GetString(configs.Json, "const", "theme"); t {
case "light":
theMe.SetSelected("白色")
case configs.Text("light"):
theMe.SetSelected(configs.Text("light"))
default:
theMe.SetSelected("黑色")
theMe.SetSelected(configs.Text("black"))
}
theMe.Horizontal = true

dpi := widget.NewRadio([]string{"默认" /*"全屏",*/, "4K"}, func(s string) {
//win.SetFullScreen(false)
dpi := widget.NewRadio([]string{configs.Text("default"), "4K"}, func(s string) {
scale := "1.0"
switch s {
case "4K":
_ = os.Setenv("FYNE_SCALE", "2.0")
//case "全屏":
// win.SetFullScreen(true)
default:
_ = os.Setenv("FYNE_SCALE", "1.0")
scale = "2.0"
}
_ = os.Setenv("FYNE_SCALE", scale)
if data, err := jsonparser.Set(configs.Json, []byte("\""+scale+"\""), "const", "scale"); err == nil {
configs.Json = data
}
dialog.ShowInformation(configs.Text("info"), configs.Text("effective after restart"), win)
})
switch scale, _ := jsonparser.GetFloat(configs.Json, "const", "scale"); scale {
case 1.0:
dpi.SetSelected("默认")
case 2.0:
switch scale, _ := jsonparser.GetString(configs.Json, "const", "scale"); scale {
case "1.0":
dpi.SetSelected(configs.Text("default"))
case "2.0":
dpi.SetSelected("4K")
}
dpi.Horizontal = true

language := widget.NewRadio([]string{"中文", "English"}, func(s string) {
//defer app.Settings().SetTheme(theme.LightTheme())
lang := "en"
switch s {
case "中文":
lang = "zh"
}
if data, err := jsonparser.Set(configs.Json, []byte("\""+lang+"\""), "const", "language"); err == nil {
configs.Json = data
}
})
l, _ := jsonparser.GetString(configs.Json, "const", "language")
if l == "zh" {
language.SetSelected("中文")
} else {
language.SetSelected("English")
}
language.Horizontal = true

return fyne.NewContainerWithLayout(
layout.NewGridLayoutWithColumns(1),
widget.NewTabContainer(
widget.NewTabItem("基本设置", widget.NewVBox(
widget.NewGroup("主题",
widget.NewTabItem(configs.Text("base"), widget.NewVBox(
//widget.NewGroup(configs.Text("theme")",
// fyne.NewContainerWithLayout(
// layout.NewHBoxLayout(),
// theMe,
// ),
//),
widget.NewGroup(configs.Text("screen"),
fyne.NewContainerWithLayout(
layout.NewHBoxLayout(),
theMe,
dpi,
),
),
widget.NewGroup("屏幕适配",
widget.NewGroup(configs.Text("language"),
fyne.NewContainerWithLayout(
layout.NewHBoxLayout(),
dpi,
language,
),
),
)),
Expand Down
22 changes: 11 additions & 11 deletions internal/app/sql2struct/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
db.SetText(currentLink.Db[dbIndex[1]])
}
}
testDb := widget.NewHBox(widget.NewButton("测试连接", func() {
progressDialog := dialog.NewProgress("连接中", host.Text, currentWindow)
testDb := widget.NewHBox(widget.NewButton(configs.Text("connection test"), func() {
progressDialog := dialog.NewProgress(configs.Text("testing"), host.Text, currentWindow)
go func() {
num := 0.0
for num < 1.0 {
Expand All @@ -69,7 +69,7 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
if err != nil {
dialog.ShowError(errors.New(err.Error()), currentWindow)
} else {
dialog.ShowInformation("成功", "连接成功", currentWindow)
dialog.ShowInformation(configs.Text("info"), configs.Text("connection successful"), currentWindow)
_ = Sql2struct.DB().Close()
}
}))
Expand All @@ -79,7 +79,7 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
},
OnSubmit: func() {
if db.Text == "" {
dialog.ShowError(errors.New("数据库不能为空"), currentWindow)
dialog.ShowError(errors.New(configs.Text("the database can not be empty")), currentWindow)
return
}
newDB := widget.NewTabItemWithIcon(
Expand Down Expand Up @@ -113,7 +113,7 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
if v.Host+":"+v.Port == host.Text+":"+port.Text {
for _, curDb := range v.Db {
if curDb == db.Text && v.Password == password.Text {
dialog.ShowError(errors.New("已存在相同的连接"), currentWindow)
dialog.ShowError(errors.New(configs.Text("duplicate links")), currentWindow)
return
}
}
Expand Down Expand Up @@ -167,12 +167,12 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
}
},
Items: []*widget.FormItem{
{Text: "引擎", Widget: driver},
{Text: "主机地址", Widget: host},
{Text: "端口", Widget: port},
{Text: "用户名", Widget: user},
{Text: "密码", Widget: password},
{Text: "数据库", Widget: db},
{Text: configs.Text("engine"), Widget: driver},
{Text: configs.Text("host"), Widget: host},
{Text: configs.Text("port"), Widget: port},
{Text: configs.Text("user"), Widget: user},
{Text: configs.Text("password"), Widget: password},
{Text: configs.Text("database"), Widget: db},
{Text: "", Widget: testDb},
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/app/sql2struct/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"gormat/configs"
"gormat/internal/pkg/icon"
"gormat/pkg/Sql2struct"
"gormat/pkg/Sql2struct/quickly"
Expand Down Expand Up @@ -95,7 +96,7 @@ func Screen(win fyne.Window, dbConf *Sql2struct.SourceMap) *fyne.Container {
widget.NewLabel(err.Error()),
)
}
tableBox := widget.NewGroupWithScroller("表结构")
tableBox := widget.NewGroupWithScroller(configs.Text("table"))
if len(tables.Items) > 0 {
go func() {
currentTable <- &widget.TabItem{}
Expand Down
38 changes: 19 additions & 19 deletions internal/app/sql2struct/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
func Option(win fyne.Window, options *Sql2struct.SQL2Struct) fyne.Widget {
targetDir := widget.NewEntry()
targetDir.SetText(options.TargetDir)
autoSave := widget.NewRadio([]string{"是", "否"}, func(s string) {
autoSave := widget.NewRadio([]string{configs.Text("yes"), configs.Text("no")}, func(s string) {

})
autoSave.Horizontal = true
if options.AutoSave {
autoSave.SetSelected("是")
autoSave.SetSelected(configs.Text("yes"))
} else {
autoSave.SetSelected("否")
autoSave.SetSelected(configs.Text("no"))
}

gorm := widget.NewCheck("gorm", func(bool) {})
Expand All @@ -41,13 +41,13 @@ func Option(win fyne.Window, options *Sql2struct.SQL2Struct) fyne.Widget {
beegoOrm := widget.NewCheck("beegoOrm", func(bool) {})
beegoOrm.SetChecked(collection.Collect(options.Tags).Contains("beegoOrm"))

jsonType := widget.NewSelect([]string{"仅生成", "生成并包含 omitempty"}, func(s string) {
jsonType := widget.NewSelect([]string{configs.Text("build only"), configs.Text("build and include omitempty")}, func(s string) {

})
if options.JsonOmitempty {
jsonType.SetSelected("生成并包含 omitempty")
jsonType.SetSelected(configs.Text("build and include omitempty"))
} else {
jsonType.SetSelected("仅生成")
jsonType.SetSelected(configs.Text("build only"))
}

jsonT := widget.NewCheck("json", func(on bool) {
Expand All @@ -61,24 +61,24 @@ func Option(win fyne.Window, options *Sql2struct.SQL2Struct) fyne.Widget {
jsonT.SetChecked(!jsonType.Hidden)

excludeTables := widget.NewMultiLineEntry()
excludeTables.SetPlaceHolder("多个数据表以回车换行")
excludeTables.SetPlaceHolder(configs.Text("carriage return"))
excludeTables.SetText(strings.Join(options.ExcludeTables, "\n"))
tryComplete := widget.NewRadio([]string{"是", "否"}, func(s string) {
tryComplete := widget.NewRadio([]string{configs.Text("yes"), configs.Text("no")}, func(s string) {

})
tryComplete.Horizontal = true
if options.TryComplete {
tryComplete.SetSelected("是")
tryComplete.SetSelected(configs.Text("yes"))
} else {
tryComplete.SetSelected("否")
tryComplete.SetSelected(configs.Text("no"))
}
return &widget.Form{
OnCancel: func() {
win.Close()
},
OnSubmit: func() {
options.TargetDir = targetDir.Text
options.AutoSave = autoSave.Selected == "是"
options.AutoSave = autoSave.Selected == configs.Text("yes")
options.Tags = []string{}
if gorm.Checked {
options.Tags = append(options.Tags, "gorm")
Expand All @@ -92,28 +92,28 @@ func Option(win fyne.Window, options *Sql2struct.SQL2Struct) fyne.Widget {
if jsonT.Checked {
options.Tags = append(options.Tags, "json")
}
options.JsonOmitempty = jsonType.Selected == "生成并包含 omitempty"
options.JsonOmitempty = jsonType.Selected == configs.Text("build and include omitempty")
options.ExcludeTables = strings.Split(excludeTables.Text, "\n")
options.TryComplete = tryComplete.Selected == "是"
options.TryComplete = tryComplete.Selected == configs.Text("yes")

jsons, _ := json.Marshal(options)
if data, err := jsonparser.Set(configs.Json, jsons, "sql2struct"); err == nil {
configs.Json = data
dialog.ShowInformation("成功", "保存成功", win)
dialog.ShowInformation(configs.Text("info"), configs.Text("save ok"), win)
} else {
dialog.ShowError(errors.New(err.Error()), win)
}
},
Items: []*widget.FormItem{
{Text: "输出文件夹", Widget: targetDir},
{Text: "自动存文件", Widget: autoSave},
{Text: "标签选择", Widget: gorm},
{Text: configs.Text("auto save files"), Widget: autoSave},
{Text: configs.Text("output folder"), Widget: targetDir},
{Text: configs.Text("tags"), Widget: gorm},
//{Text: "", Widget: beegoOrm},
{Text: "", Widget: xorm},
{Text: "", Widget: jsonT},
{Text: "", Widget: jsonType},
{Text: "排除表", Widget: excludeTables},
{Text: "始终执行", Widget: tryComplete},
{Text: configs.Text("exclusion table"), Widget: excludeTables},
{Text: configs.Text("always execute"), Widget: tryComplete},
},
}
}
Loading

0 comments on commit fecc128

Please sign in to comment.