gui
This commit is contained in:
parent
0f162b129c
commit
6de3e9e438
10
cmd/v2/model/gen.go
Normal file
10
cmd/v2/model/gen.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type GenTool struct {
|
||||||
|
ClientDir string
|
||||||
|
InputDir string
|
||||||
|
OutputDir string
|
||||||
|
GenType int32
|
||||||
|
|
||||||
|
|
||||||
|
}
|
61
cmd/v2/service/dbServer.go
Normal file
61
cmd/v2/service/dbServer.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/cmd/v2/model"
|
||||||
|
"log"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/boltdb/bolt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbService interface {
|
||||||
|
Create(conf *model.GenTool) error
|
||||||
|
Update() error
|
||||||
|
}
|
||||||
|
|
||||||
|
type DbServiceImpl struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDbService() DbService {
|
||||||
|
return &DbServiceImpl{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DbServiceImpl) Create(conf *model.GenTool) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DbServiceImpl) Update() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
boltDb *bolt.DB
|
||||||
|
bucket *bolt.Bucket
|
||||||
|
once sync.Once
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetBoltDb() *bolt.DB {
|
||||||
|
once.Do(func() {
|
||||||
|
boltDb, err = bolt.Open("my.db", 0600, &bolt.Options{Timeout: 1 * time.Second})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
boltDb.Update(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("robotBucket"))
|
||||||
|
if b != nil {
|
||||||
|
bucket = b
|
||||||
|
} else {
|
||||||
|
bucket, err = tx.CreateBucket([]byte("robotBucket"))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create bucket: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return boltDb
|
||||||
|
}
|
146
cmd/v2/ui/app_gen.go
Normal file
146
cmd/v2/ui/app_gen.go
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/cmd/v2/lib/common"
|
||||||
|
"go_dreamfactory/cmd/v2/service/observer"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/dialog"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
type appGen struct {
|
||||||
|
appAdapter
|
||||||
|
|
||||||
|
obs observer.Observer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *appGen) LazyInit(obs observer.Observer) error {
|
||||||
|
this.obs = obs
|
||||||
|
|
||||||
|
this.tabItem = container.NewTabItemWithIcon(common.TOOLBAR_GEN, theme.ContentCopyIcon(), nil)
|
||||||
|
|
||||||
|
content := container.NewMax()
|
||||||
|
content.Objects = []fyne.CanvasObject{}
|
||||||
|
|
||||||
|
serverAddr := widget.NewEntry()
|
||||||
|
serverAddr.PlaceHolder = "服务器地址"
|
||||||
|
serverAddr.Text = "10.0.1.11"
|
||||||
|
|
||||||
|
projectDir := widget.NewEntry()
|
||||||
|
projectDir.PlaceHolder = "项目目录"
|
||||||
|
projectDir.Text = "E:\\projects\\workspace\\go_dreamfactory"
|
||||||
|
|
||||||
|
workDir := widget.NewEntry()
|
||||||
|
workDir.PlaceHolder = "LuBan目录"
|
||||||
|
workDir.Text = "E:\\svn\\dreamworks\\client\\dreamworks\\ExcelFile"
|
||||||
|
|
||||||
|
// client
|
||||||
|
client := widget.NewEntry()
|
||||||
|
client.PlaceHolder = "配置Luban Client.exe路径"
|
||||||
|
client.Text = "\\Luban.Client\\Luban.Client.exe"
|
||||||
|
|
||||||
|
//define
|
||||||
|
define := widget.NewEntry()
|
||||||
|
define.PlaceHolder = "定义文件"
|
||||||
|
define.Text = "\\Defines\\__root__.xml"
|
||||||
|
|
||||||
|
// output
|
||||||
|
outputCodeDir := widget.NewEntry()
|
||||||
|
outputCodeDir.Text = "\\sys\\configure\\structs"
|
||||||
|
outputJsonDir := widget.NewEntry()
|
||||||
|
outputJsonDir.Text = "\\bin\\json"
|
||||||
|
|
||||||
|
//input
|
||||||
|
inputDir := widget.NewEntry()
|
||||||
|
inputDir.Text = "\\Datas"
|
||||||
|
|
||||||
|
//genType
|
||||||
|
var genTypeText string
|
||||||
|
genType := widget.NewSelect([]string{"go", "json", "all"}, func(s string) {
|
||||||
|
genTypeText = s
|
||||||
|
})
|
||||||
|
genType.PlaceHolder = "生成类型"
|
||||||
|
|
||||||
|
form := widget.NewForm(
|
||||||
|
widget.NewFormItem("工作目录", workDir),
|
||||||
|
widget.NewFormItem("Client", client),
|
||||||
|
widget.NewFormItem("输入目录", inputDir),
|
||||||
|
widget.NewFormItem("输出Code目录", outputCodeDir),
|
||||||
|
widget.NewFormItem("输出JSON目录", outputJsonDir),
|
||||||
|
widget.NewFormItem("生成类型", genType),
|
||||||
|
)
|
||||||
|
|
||||||
|
getType := func() string {
|
||||||
|
if genTypeText == "" {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
if genTypeText == "go" {
|
||||||
|
return "code_go_json"
|
||||||
|
} else if genTypeText == "json" {
|
||||||
|
return "data_json"
|
||||||
|
} else if genTypeText == "all" {
|
||||||
|
return "code_go_json,data_json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
form.SubmitText = "确定"
|
||||||
|
form.OnSubmit = func() {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
dialog.ShowError(errors.New("no support "+runtime.GOOS), toolWin.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if genTypeText == "" {
|
||||||
|
dialog.ShowError(errors.New("类型未选择"), toolWin.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// service.GetBoltDb().Update(func(tx *bolt.Tx) error {
|
||||||
|
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
str := `%s -h %s -j cfg -- -d %s --input_data_dir %s --output_code_dir %s --output_data_dir %s --gen_types %s --go:bright_module_name bright -s server`
|
||||||
|
|
||||||
|
arg := fmt.Sprintf(str,
|
||||||
|
workDir.Text+client.Text,
|
||||||
|
serverAddr.Text,
|
||||||
|
workDir.Text+define.Text,
|
||||||
|
workDir.Text+inputDir.Text,
|
||||||
|
projectDir.Text+outputCodeDir.Text,
|
||||||
|
projectDir.Text+outputJsonDir.Text,
|
||||||
|
getType(),
|
||||||
|
)
|
||||||
|
|
||||||
|
logrus.Debug(arg)
|
||||||
|
c := exec.Command("cmd.exe", "/c", arg)
|
||||||
|
if err := c.Run(); err != nil {
|
||||||
|
dialog.ShowError(err, toolWin.w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
content.Objects = append(content.Objects, form)
|
||||||
|
|
||||||
|
this.tabItem.Content = content
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *appGen) OpenDefault() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *appGen) GetAppName() string {
|
||||||
|
return common.TOOLBAR_GEN
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a appGen) OnClose() bool {
|
||||||
|
return false
|
||||||
|
}
|
69
cmd/v2/ui/toolwindow.go
Normal file
69
cmd/v2/ui/toolwindow.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/cmd/v2/lib/common"
|
||||||
|
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ToolWindow interface {
|
||||||
|
WindowInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToolWindowImpl struct {
|
||||||
|
UIImpl
|
||||||
|
w fyne.Window
|
||||||
|
tb *toolBar //工具条
|
||||||
|
sb *statusBar //状态栏
|
||||||
|
at *appContainer //tabs
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewToolWindow(ui *UIImpl) ToolWindow {
|
||||||
|
mw := &ToolWindowImpl{
|
||||||
|
UIImpl: *ui,
|
||||||
|
}
|
||||||
|
|
||||||
|
toolWin = mw
|
||||||
|
|
||||||
|
mw.sb = newStatusBar()
|
||||||
|
|
||||||
|
toolbar := widget.NewToolbar(
|
||||||
|
widget.NewToolbarAction(theme.ContentCopyIcon(), func() {
|
||||||
|
openApp1(common.TOOLBAR_GEN)
|
||||||
|
}),
|
||||||
|
|
||||||
|
widget.NewToolbarSpacer(),
|
||||||
|
widget.NewToolbarAction(theme.HelpIcon(), func() {
|
||||||
|
showAbout()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
mw.tb = newToolBar(toolbar)
|
||||||
|
|
||||||
|
mw.at = newAppContainer(toolRegister, ui.obs)
|
||||||
|
|
||||||
|
return mw
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *ToolWindowImpl) CreateWindow(title string, width, height float32, _ bool) {
|
||||||
|
w := ui.app.NewWindow(title)
|
||||||
|
ui.AddWindow("tool", w)
|
||||||
|
ui.w = w
|
||||||
|
|
||||||
|
// content
|
||||||
|
content := container.NewBorder(ui.tb.toolbar, ui.sb.widget,
|
||||||
|
nil, nil, ui.at)
|
||||||
|
ui.w.SetContent(content)
|
||||||
|
appName, err := ui.at.openDefaultApp()
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithField("appName", appName).Error(err)
|
||||||
|
}
|
||||||
|
w.Resize(fyne.NewSize(width, height))
|
||||||
|
w.SetMaster()
|
||||||
|
w.CenterOnScreen()
|
||||||
|
w.Show()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user