改包名

This commit is contained in:
wh_zcy 2022-10-08 15:32:51 +08:00
parent 03bd4e3efa
commit 05e00e0c0b
12 changed files with 364 additions and 334 deletions

View File

@ -0,0 +1,231 @@
package common
import (
"fmt"
"go_dreamfactory/utils"
"io/ioutil"
"sort"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/sirupsen/logrus"
)
type ItemList struct {
SelItemIds []string //选择的ID
ItemTotal int //总数
TitleLabel *widget.Label
CachedList List
ItemList *widget.List
SearchItem []Item //用于暂存搜索结果
}
func NewItemList() *ItemList {
return &ItemList{
TitleLabel: &widget.Label{},
CachedList: NewList(""),
}
}
// 重置
func (f *ItemList) Reset() {
f.ItemTotal = 0
f.SelItemIds = []string{}
f.CachedList = NewList("")
}
func (f *ItemList) CreateList() *widget.List {
f.ItemList = widget.NewList(
func() int {
return len(f.CachedList.Items)
},
func() fyne.CanvasObject {
return widget.NewLabel("Template")
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*widget.Label)
c.Text = f.CachedList.Items[id].Text
c.Refresh()
},
)
f.ItemList.OnSelected = func(id widget.ListItemID) {
selId := f.CachedList.Items[id].Id
f.SelItemIds = append(f.SelItemIds, selId)
return
}
return f.ItemList
}
// 创建默认的列表
func (f *ItemList) CreateDefaultCheckList() *widget.List {
f.ItemList = widget.NewList(
func() int {
return len(f.CachedList.Items)
},
func() fyne.CanvasObject {
return widget.NewCheck("Template", func(bool) {})
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*widget.Check)
c.Text = f.CachedList.Items[id].Text
c.Checked = f.CachedList.Items[id].Checked
c.OnChanged = func(b bool) {
if b {
f.SelItemIds = append(f.SelItemIds, c.Text)
} else {
f.SelItemIds = utils.DeleteString(f.SelItemIds, c.Text)
}
f.TitleLabel.SetText(fmt.Sprintf("(%d/%d)", len(f.SelItemIds), f.ItemTotal))
f.CachedList.Items[id].Checked = b
// sort.Sort(f.cachedList)
f.ItemList.Refresh()
}
c.Refresh()
},
)
return f.ItemList
}
// 创建下载列表
func (f *ItemList) CreateDownloadList() *widget.List {
f.ItemList = widget.NewList(
func() int {
return len(f.CachedList.Items)
},
func() fyne.CanvasObject {
chk := widget.NewCheck("Template", func(bool) {})
lb := widget.NewLabel("Template")
items := container.NewHBox(chk, &layout.Spacer{}, lb)
return items
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*fyne.Container)
chk := c.Objects[0].(*widget.Check)
data := f.CachedList.Items[id]
chk.Text = data.Text
chk.Checked = data.Checked
chk.OnChanged = func(b bool) {
if b {
f.SelItemIds = append(f.SelItemIds, chk.Text)
} else {
f.SelItemIds = utils.DeleteString(f.SelItemIds, chk.Text)
}
f.CachedList.Items[id].Checked = b
// sort.Sort(f.cachedList)
f.ItemList.Refresh()
}
lb := c.Objects[2].(*widget.Label)
lb.Text = ConvertFileSize(data.Size)
c.Refresh()
},
)
return f.ItemList
}
func (f *ItemList) AddItem(item Item) {
f.CachedList.Items = append(f.CachedList.Items, item)
// sort.Sort(f.cachedList)
f.ItemList.Refresh()
}
func (f *ItemList) AddItemWithText(val string) {
val = strings.TrimSpace(val)
if len(val) == 0 {
return
}
newItem := Item{
Text: val,
Quantity: 1,
Checked: false, //默认不选中
}
f.CachedList.Items = append(f.CachedList.Items, newItem)
sort.Sort(f.CachedList)
f.ItemList.Refresh()
}
func (f *ItemList) LoadItem(dirPath string) {
f.Reset()
files, err := ioutil.ReadDir(dirPath)
if err != nil {
logrus.Error(err)
return
}
for _, file := range files {
if !file.IsDir() {
f.AddItemWithText(file.Name())
// f.selItemIds = append(f.selItemIds, file.Name())
f.ItemTotal++
// logrus.Debugf("%v", file.Name())
}
}
f.SearchItem = f.CachedList.Items
}
// 改变列表项目
func (f *ItemList) ChangeItem(tmpDir, projectDir string) {
f.ItemTotal = 0
f.SelItemIds = []string{}
f.CachedList = NewList("")
tmpFiles, err := ioutil.ReadDir(tmpDir)
if err != nil {
logrus.Error(err)
return
}
defer func() {
if len(tmpFiles) == 0 || len(f.CachedList.Items) == 0 {
ShowTip("没有任何变更的项目")
}
}()
projectFiles, err := ioutil.ReadDir(projectDir)
if err != nil {
logrus.Error(err)
return
}
pfMap := make(map[string]int64)
for _, v := range projectFiles {
if !v.IsDir() {
pfMap[v.Name()] = v.ModTime().Unix()
}
}
for _, file := range tmpFiles {
if !file.IsDir() {
if pfTime, ok := pfMap[file.Name()]; ok {
if file.ModTime().Unix() <= pfTime {
continue
}
}
f.AddItemWithText(file.Name())
f.SelItemIds = append(f.SelItemIds, file.Name())
f.ItemTotal++
logrus.Debugf("%v", file.Name())
}
}
}
// 刷新文件数
func (f *ItemList) ChangeFileCount() {
f.TitleLabel.SetText(fmt.Sprintf("(%d/%d)", len(f.SelItemIds), f.ItemTotal))
}
func (f *ItemList) DeleteItem(name string) {
for i, v := range f.CachedList.Items {
if v.Text == name {
f.SelItemIds = utils.DeleteString(f.SelItemIds, v.Text)
f.CachedList.Items = append(f.CachedList.Items[:i], f.CachedList.Items[i+1:]...)
if f.ItemTotal > 0 {
f.ItemTotal--
}
}
}
}

View File

@ -1,4 +1,4 @@
package ui
package common
import "strings"
@ -57,6 +57,7 @@ func (l List) Less(i, j int) bool {
}
type Item struct {
Id string `json:"id"`
Title string `json:"title"`
Text string `json:"text"`
Quantity int `json:"quantity"`

View File

@ -1,4 +1,4 @@
package ui
package common
import (
"image/color"
@ -11,7 +11,7 @@ import (
)
// 显示Tip
func showTip(content string) {
func ShowTip(content string) {
drv := fyne.CurrentApp().Driver()
if drv, ok := drv.(desktop.Driver); ok {
w := drv.CreateSplashWindow()
@ -25,7 +25,7 @@ func showTip(content string) {
}
}
func showCanvasTip(content string) {
func ShowCanvasTip(content string) {
drv := fyne.CurrentApp().Driver()
if drv, ok := drv.(desktop.Driver); ok {
w := drv.CreateSplashWindow()

View File

@ -21,4 +21,4 @@ func (s *ItemModelList) AsInterfaceArray() []interface{} {
rs[i] = v
}
return rs
}
}

View File

@ -78,7 +78,7 @@ func (this *appMonitor) Run() {
data := d.(*model.PushModel)
this.monitorData.DataList = append(this.monitorData.DataList, data)
this.reloadMonitorData()
showCanvasTip("收到新的数据推送,请打开[推送]页面")
common.ShowCanvasTip("收到新的数据推送,请打开[推送]页面")
},
})
}

View File

@ -7,13 +7,9 @@ import (
"go_dreamfactory/cmd/v2/model"
"go_dreamfactory/cmd/v2/service"
"go_dreamfactory/cmd/v2/service/observer"
"go_dreamfactory/utils"
"io/ioutil"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
@ -29,14 +25,14 @@ type appGen struct {
appAdapter
obs observer.Observer
goList *fileList
jsonList *fileList
goList *common.ItemList
jsonList *common.ItemList
}
func (this *appGen) LazyInit(obs observer.Observer) error {
this.obs = obs
this.goList = NewFileList()
this.jsonList = NewFileList()
this.goList = common.NewItemList()
this.jsonList = common.NewItemList()
this.tabItem = container.NewTabItemWithIcon(common.TOOLBAR_GEN, theme.ContentCopyIcon(), nil)
@ -148,10 +144,10 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
})
//go
this.goList.titleLabel = widget.NewLabel("Go文件")
this.goList.titleLabel.Hide()
this.goList.TitleLabel = widget.NewLabel("Go文件")
this.goList.TitleLabel.Hide()
// 复选列表
this.goList.itemList = this.goList.CreateDefaultList()
this.goList.ItemList = this.goList.CreateDefaultCheckList()
// 覆盖 -go
go_allSelBtn := &widget.Button{Icon: theme.CheckButtonIcon()}
@ -165,9 +161,9 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
go_overrideBtn.Disable()
defer func() {
go_overrideBtn.Enable()
this.goList.itemList.Refresh()
this.goList.ItemList.Refresh()
}()
for _, v := range this.goList.selItemIds {
for _, v := range this.goList.SelItemIds {
// logrus.WithField("path1", filepath.Join(tmpDir.Text, "go", v)).Debug("copy go")
// logrus.WithField("path2", filepath.Join(projectDir.Text, outputCodeDir.Text, v)).Debug("copy go")
_, err := common.Copy(filepath.Join(tmpDir.Text, "go", v),
@ -176,9 +172,9 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
logrus.Error(err)
return
}
this.goList.deleteItem(v)
this.goList.DeleteItem(v)
}
this.goList.changeFileCount()
this.goList.ChangeFileCount()
}
//取消checked
@ -187,13 +183,13 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
go_allCancelBtn.Hide()
go_allSelBtn.Show()
}()
this.goList.selItemIds = []string{}
for i, v := range this.goList.cachedList.Items {
this.goList.cachedList.Items[i].Checked = false
this.goList.itemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
this.goList.SelItemIds = []string{}
for i, v := range this.goList.CachedList.Items {
this.goList.CachedList.Items[i].Checked = false
this.goList.ItemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
}
this.goList.changeFileCount()
this.goList.itemList.Refresh()
this.goList.ChangeFileCount()
this.goList.ItemList.Refresh()
}
//选择所有
@ -202,21 +198,21 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
go_allCancelBtn.Show()
go_allSelBtn.Hide()
}()
for i, v := range this.goList.cachedList.Items {
this.goList.cachedList.Items[i].Checked = true
this.goList.selItemIds = append(this.goList.selItemIds, v.Text)
this.goList.itemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
for i, v := range this.goList.CachedList.Items {
this.goList.CachedList.Items[i].Checked = true
this.goList.SelItemIds = append(this.goList.SelItemIds, v.Text)
this.goList.ItemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
}
this.goList.changeFileCount()
this.goList.ChangeFileCount()
// this.goList.titleLabel.SetText(fmt.Sprintf("(%d/%d)", len(this.goList.selItemIds), this.goList.fileTotal))
this.goList.itemList.Refresh()
this.goList.ItemList.Refresh()
}
// json
this.jsonList.titleLabel = widget.NewLabel("Json文件")
this.jsonList.titleLabel.Hide()
this.jsonList.TitleLabel = widget.NewLabel("Json文件")
this.jsonList.TitleLabel.Hide()
// 复选列表
this.jsonList.itemList = this.jsonList.CreateDefaultList()
this.jsonList.ItemList = this.jsonList.CreateDefaultCheckList()
// 覆盖 -go
json_allSelBtn := &widget.Button{Icon: theme.CheckButtonIcon()}
@ -228,9 +224,9 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
json_overrideBtn.Disable()
defer func() {
json_overrideBtn.Enable()
this.jsonList.itemList.Refresh()
this.jsonList.ItemList.Refresh()
}()
for _, v := range this.jsonList.selItemIds {
for _, v := range this.jsonList.SelItemIds {
// logrus.WithField("path1", filepath.Join(tmpDir.Text, "json", v)).Debug("copy json")
// logrus.WithField("path2", filepath.Join(projectDir.Text, outputJsonDir.Text, v)).Debug("copy json")
_, err := common.Copy(filepath.Join(tmpDir.Text, "json", v),
@ -239,9 +235,9 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
logrus.Error(err)
return
}
this.jsonList.deleteItem(v)
this.jsonList.DeleteItem(v)
}
this.jsonList.changeFileCount()
this.jsonList.ChangeFileCount()
}
//取消checked
@ -251,13 +247,13 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
json_allSelBtn.Show()
}()
list := this.jsonList
list.selItemIds = []string{}
for i, v := range list.cachedList.Items {
list.cachedList.Items[i].Checked = false
list.itemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
list.SelItemIds = []string{}
for i, v := range list.CachedList.Items {
list.CachedList.Items[i].Checked = false
list.ItemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
}
this.jsonList.changeFileCount()
list.itemList.Refresh()
this.jsonList.ChangeFileCount()
list.ItemList.Refresh()
}
//选择所有
@ -267,13 +263,13 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
json_allSelBtn.Hide()
}()
list := this.jsonList
for i, v := range list.cachedList.Items {
list.cachedList.Items[i].Checked = true
list.selItemIds = append(list.selItemIds, v.Text)
list.itemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
for i, v := range list.CachedList.Items {
list.CachedList.Items[i].Checked = true
list.SelItemIds = append(list.SelItemIds, v.Text)
list.ItemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
}
list.changeFileCount()
list.itemList.Refresh()
list.ChangeFileCount()
list.ItemList.Refresh()
}
genBtn := &widget.Button{Text: "生成", Icon: theme.ConfirmIcon()}
@ -316,17 +312,17 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
}
changeGo := func() {
this.goList.changeItem(filepath.Join(tmpDir.Text, "go"), filepath.Join(projectDir.Text, outputCodeDir.Text))
this.goList.titleLabel.SetText(fmt.Sprintf("(%d/%d个)", len(this.goList.selItemIds), this.goList.fileTotal))
this.goList.ChangeItem(filepath.Join(tmpDir.Text, "go"), filepath.Join(projectDir.Text, outputCodeDir.Text))
this.goList.TitleLabel.SetText(fmt.Sprintf("(%d/%d个)", len(this.goList.SelItemIds), this.goList.ItemTotal))
go_overrideBtn.Show()
this.goList.titleLabel.Show()
this.goList.TitleLabel.Show()
}
changeJson := func() {
this.jsonList.changeItem(filepath.Join(tmpDir.Text, "json"), filepath.Join(projectDir.Text, outputJsonDir.Text))
this.jsonList.titleLabel.SetText(fmt.Sprintf("(%d/%d)", len(this.jsonList.selItemIds), this.jsonList.fileTotal))
this.jsonList.ChangeItem(filepath.Join(tmpDir.Text, "json"), filepath.Join(projectDir.Text, outputJsonDir.Text))
this.jsonList.TitleLabel.SetText(fmt.Sprintf("(%d/%d)", len(this.jsonList.SelItemIds), this.jsonList.ItemTotal))
json_overrideBtn.Show()
this.jsonList.titleLabel.Show()
this.jsonList.TitleLabel.Show()
}
// 更新列表
@ -360,13 +356,13 @@ func (this *appGen) LazyInit(obs observer.Observer) error {
left := container.NewVBox(form, container.NewHBox(&layout.Spacer{}, desBtn, saveBtn, genBtn))
right := container.NewGridWithColumns(2,
container.NewBorder(
container.NewHBox(go_allSelBtn, go_allCancelBtn, go_overrideBtn, widget.NewLabel("Go文件"), this.goList.titleLabel),
container.NewHBox(go_allSelBtn, go_allCancelBtn, go_overrideBtn, widget.NewLabel("Go文件"), this.goList.TitleLabel),
nil, nil, nil,
this.goList.itemList),
this.goList.ItemList),
container.NewBorder(
container.NewHBox(json_allSelBtn, json_allCancelBtn, json_overrideBtn, widget.NewLabel("Json文件"), this.jsonList.titleLabel),
container.NewHBox(json_allSelBtn, json_allCancelBtn, json_overrideBtn, widget.NewLabel("Json文件"), this.jsonList.TitleLabel),
nil, nil, nil,
this.jsonList.itemList))
this.jsonList.ItemList))
content.Objects = append(content.Objects, container.NewGridWithColumns(2, left, right))
@ -406,204 +402,6 @@ func openFile(entry *widget.Entry, w fyne.Window) {
dConf.Show()
}
type fileList struct {
selItemIds []string //选择的ID
fileTotal int //文件总数
titleLabel *widget.Label
cachedList List
itemList *widget.List
searchItem []Item //用于暂存搜索结果
}
func NewFileList() *fileList {
return &fileList{
titleLabel: &widget.Label{},
cachedList: NewList(""),
}
}
func (f *fileList) reset() {
f.fileTotal = 0
f.selItemIds = []string{}
f.cachedList = NewList("")
}
// 创建默认的列表
func (f *fileList) CreateDefaultList() *widget.List {
f.itemList = widget.NewList(
func() int {
return len(f.cachedList.Items)
},
func() fyne.CanvasObject {
return widget.NewCheck("Template", func(bool) {})
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*widget.Check)
c.Text = f.cachedList.Items[id].Text
c.Checked = f.cachedList.Items[id].Checked
c.OnChanged = func(b bool) {
if b {
f.selItemIds = append(f.selItemIds, c.Text)
} else {
f.selItemIds = utils.DeleteString(f.selItemIds, c.Text)
}
f.titleLabel.SetText(fmt.Sprintf("(%d/%d)", len(f.selItemIds), f.fileTotal))
f.cachedList.Items[id].Checked = b
// sort.Sort(f.cachedList)
f.itemList.Refresh()
}
c.Refresh()
},
)
return f.itemList
}
// 创建可扩展属性的列表
func (f *fileList) CreateDownloadList() *widget.List {
f.itemList = widget.NewList(
func() int {
return len(f.cachedList.Items)
},
func() fyne.CanvasObject {
chk := widget.NewCheck("Template", func(bool) {})
lb := widget.NewLabel("Template")
items := container.NewHBox(chk, &layout.Spacer{}, lb)
return items
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*fyne.Container)
chk := c.Objects[0].(*widget.Check)
data := f.cachedList.Items[id]
chk.Text = data.Text
chk.Checked = data.Checked
chk.OnChanged = func(b bool) {
if b {
f.selItemIds = append(f.selItemIds, chk.Text)
} else {
f.selItemIds = utils.DeleteString(f.selItemIds, chk.Text)
}
f.cachedList.Items[id].Checked = b
// sort.Sort(f.cachedList)
f.itemList.Refresh()
}
lb := c.Objects[2].(*widget.Label)
lb.Text = common.ConvertFileSize(data.Size)
c.Refresh()
},
)
return f.itemList
}
func (f *fileList) AddItem(item Item) {
f.cachedList.Items = append(f.cachedList.Items, item)
// sort.Sort(f.cachedList)
f.itemList.Refresh()
}
func (f *fileList) AddItemWithText(val string) {
val = strings.TrimSpace(val)
if len(val) == 0 {
return
}
newItem := Item{
Text: val,
Quantity: 1,
Checked: false, //默认不选中
}
f.cachedList.Items = append(f.cachedList.Items, newItem)
sort.Sort(f.cachedList)
f.itemList.Refresh()
}
func (f *fileList) deleteItem(name string) {
for i, v := range f.cachedList.Items {
if v.Text == name {
f.selItemIds = utils.DeleteString(f.selItemIds, v.Text)
f.cachedList.Items = append(f.cachedList.Items[:i], f.cachedList.Items[i+1:]...)
if f.fileTotal > 0 {
f.fileTotal--
}
}
}
}
func (f *fileList) loadItem(dirPath string) {
f.reset()
files, err := ioutil.ReadDir(dirPath)
if err != nil {
logrus.Error(err)
return
}
for _, file := range files {
if !file.IsDir() {
f.AddItemWithText(file.Name())
// f.selItemIds = append(f.selItemIds, file.Name())
f.fileTotal++
// logrus.Debugf("%v", file.Name())
}
}
f.searchItem = f.cachedList.Items
}
// 改变列表项目
func (f *fileList) changeItem(tmpDir, projectDir string) {
f.fileTotal = 0
f.selItemIds = []string{}
f.cachedList = NewList("")
tmpFiles, err := ioutil.ReadDir(tmpDir)
if err != nil {
logrus.Error(err)
return
}
defer func() {
if len(tmpFiles) == 0 || len(f.cachedList.Items) == 0 {
showTip("没有任何变更的文件,请确定SVN拉取最新文件")
}
}()
projectFiles, err := ioutil.ReadDir(projectDir)
if err != nil {
logrus.Error(err)
return
}
pfMap := make(map[string]int64)
for _, v := range projectFiles {
if !v.IsDir() {
pfMap[v.Name()] = v.ModTime().Unix()
}
}
for _, file := range tmpFiles {
if !file.IsDir() {
if pfTime, ok := pfMap[file.Name()]; ok {
if file.ModTime().Unix() <= pfTime {
continue
}
}
f.AddItemWithText(file.Name())
f.selItemIds = append(f.selItemIds, file.Name())
f.fileTotal++
logrus.Debugf("%v", file.Name())
}
}
}
// 刷新文件数
func (f *fileList) changeFileCount() {
f.titleLabel.SetText(fmt.Sprintf("(%d/%d)", len(f.selItemIds), f.fileTotal))
}
type CopyFiles struct {
Dir string
FileName string
}
func (a *appGen) GetAppName() string {
return common.TOOLBAR_GEN
}

View File

@ -54,7 +54,7 @@ func (this *appLock) LazyInit(obs observer.Observer) error {
return
}
toolWin.w.Clipboard().SetContent(text.Text)
showTip("已复制到剪贴板")
common.ShowTip("已复制到剪贴板")
})
c := container.NewVBox(title, input, text, btn, copybtn)

View File

@ -175,14 +175,14 @@ func (a *appPbGen) GetAppName() string {
type folderList struct {
selItemIds []string //选择的ID
cachedList List
cachedList common.List
itemList *widget.List
fileTotal int //文件总数
}
func NewFolderList() *folderList {
return &folderList{
cachedList: NewList(""),
cachedList: common.NewList(""),
}
}
@ -192,7 +192,7 @@ func (f *folderList) createList() *widget.List {
return len(f.cachedList.Items)
},
func() fyne.CanvasObject {
return widget.NewCheck("Template", func(b bool) {})
return widget.NewCheck("Template", func(b bool) {})
},
func(id widget.ListItemID, item fyne.CanvasObject) {
c, _ := item.(*widget.Check)
@ -226,7 +226,7 @@ func (f *folderList) initItem(dir string) {
if file.Name() == ".vscode" {
continue
}
fm := Item{
fm := common.Item{
Text: file.Name(),
Checked: false,
}

View File

@ -32,18 +32,18 @@ type appTerm struct {
obs observer.Observer
sshService *service.SSHService
jsonList *fileList //json列表
jsonList *common.ItemList //json列表
cProgress *widget.ProgressBarInfinite //连接进度条进度条
upProgress *widget.ProgressBar //上传进度条
endProgress sync.WaitGroup
downloadList *fileList //download列表
downloadList *common.ItemList //download列表
}
func (this *appTerm) LazyInit(obs observer.Observer) error {
this.obs = obs
this.sshService = &service.SSHService{}
this.jsonList = NewFileList()
this.jsonList = common.NewItemList()
//progress
this.cProgress = widget.NewProgressBarInfinite()
@ -238,7 +238,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
connBtn.Enable()
return
} else {
this.jsonList.loadItem(localDir.Text)
this.jsonList.LoadItem(localDir.Text)
this.cProgress.Stop()
this.cProgress.Hide()
@ -260,7 +260,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
allSelBtn.Hide()
allCancelBtn.Show()
}()
this.jsonList.loadItem(localDir.Text)
this.jsonList.LoadItem(localDir.Text)
}
refreshBtn.OnTapped = reloadItem
@ -268,7 +268,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
disConnBtn.Disable()
disConnBtn.OnTapped = func() {
defer func() {
this.jsonList.reset()
this.jsonList.Reset()
connBtn.Enable()
disConnBtn.Disable()
syncBtn.Disable()
@ -292,7 +292,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
explorBtn.OnTapped = func() {
// logrus.Debug(localDir.Text)
if localDir.Text == "" {
showTip("Json目录必须填写")
common.ShowTip("Json目录必须填写")
} else {
openExplor(localDir.Text)
}
@ -355,7 +355,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
this.upProgress.Show()
this.upProgress.SetValue(0)
len := len(this.jsonList.selItemIds)
len := len(this.jsonList.SelItemIds)
num := 0.0
increment := func(wg *sync.WaitGroup) {
@ -364,18 +364,18 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
wg.Done()
}
for _, fileName := range this.jsonList.selItemIds {
for _, fileName := range this.jsonList.SelItemIds {
this.endProgress.Add(1)
go func(fn string) {
// time.Sleep(time.Second * time.Duration(rand.Intn(3)))
if err := this.sshService.ScpCopy(filepath.Join(localDir.Text, fn), remoteDir.Text); err != nil {
logrus.WithField("err", err).Error("同步json")
showTip(err.Error())
common.ShowTip(err.Error())
}
increment(&this.endProgress)
// 移除已上传的
this.jsonList.deleteItem(fn)
showTip(fmt.Sprintf("%s 成功上传", fn))
this.jsonList.DeleteItem(fn)
common.ShowTip(fmt.Sprintf("%s 成功上传", fn))
}(fileName)
}
this.endProgress.Wait()
@ -390,12 +390,12 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
//SVN更新提示
dc := dialog.NewConfirm("提示", "是否要进行SVN更新", func(b bool) {
if b {
showTip("单击【SVN更新】按钮进行更新")
common.ShowTip("单击【SVN更新】按钮进行更新")
svnBtn.FocusGained()
return
} else {
if len(this.jsonList.selItemIds) == 0 {
showTip("没有选择任何文件,或尝试点击【刷新】")
if len(this.jsonList.SelItemIds) == 0 {
common.ShowTip("没有选择任何文件,或尝试点击【刷新】")
return
}
syncNext()
@ -409,7 +409,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
// excel更新
excelBtn.OnTapped = func() {
if workDir.Text == "" {
showTip("工作目录必须填写")
common.ShowTip("工作目录必须填写")
} else {
openExplor(workDir.Text)
}
@ -464,12 +464,12 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
allCancelBtn.Hide()
allSelBtn.Show()
}()
for i, v := range this.jsonList.cachedList.Items {
this.jsonList.cachedList.Items[i].Checked = true
this.jsonList.selItemIds = append(this.jsonList.selItemIds, v.Text)
this.jsonList.itemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
for i, v := range this.jsonList.CachedList.Items {
this.jsonList.CachedList.Items[i].Checked = true
this.jsonList.SelItemIds = append(this.jsonList.SelItemIds, v.Text)
this.jsonList.ItemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
}
this.jsonList.itemList.Refresh()
this.jsonList.ItemList.Refresh()
}
// 全选
@ -478,12 +478,12 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
allCancelBtn.Show()
allSelBtn.Hide()
}()
this.jsonList.selItemIds = []string{}
for i, v := range this.jsonList.cachedList.Items {
this.jsonList.cachedList.Items[i].Checked = false
this.jsonList.itemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
this.jsonList.SelItemIds = []string{}
for i, v := range this.jsonList.CachedList.Items {
this.jsonList.CachedList.Items[i].Checked = false
this.jsonList.ItemList.UpdateItem(i, widget.NewCheck(v.Text, nil))
}
this.jsonList.itemList.Refresh()
this.jsonList.ItemList.Refresh()
}
// 搜索
@ -497,14 +497,14 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
reloadItem()
} else {
// go func() {
newList := []Item{}
for _, v := range this.jsonList.searchItem {
newList := []common.Item{}
for _, v := range this.jsonList.SearchItem {
if strings.Contains(v.Text, s) {
newList = append(newList, v)
}
}
this.jsonList.cachedList.Items = newList
this.jsonList.itemList.Refresh()
this.jsonList.CachedList.Items = newList
this.jsonList.ItemList.Refresh()
// }()
}
}
@ -522,7 +522,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
}
// 创建json列表
this.jsonList.itemList = this.jsonList.CreateDefaultList()
this.jsonList.ItemList = this.jsonList.CreateDefaultCheckList()
btns1 := container.NewHBox(helpBtn1, dlBtn, &layout.Spacer{}, saveBtn1, connBtn, disConnBtn)
btns2 := container.NewHBox(helpBtn2, &layout.Spacer{}, saveBtn2, excelBtn, svnBtn)
@ -530,7 +530,7 @@ func (this *appTerm) LazyInit(obs observer.Observer) error {
split := container.NewHSplit(container.NewVBox(canvas.NewText("---只能在非上产环境!!!同步Json的操作仅限于数值热更,非结构热更---", color.RGBA{255, 0, 0, 255}), configForm,
btns1, svnForm, btns2, this.cProgress), container.NewBorder(
container.NewBorder(nil, nil, container.NewHBox(allCancelBtn, allSelBtn, syncBtn, refreshBtn), container.NewHBox(explorBtn), searchEntry),
nil, nil, nil, this.jsonList.itemList))
nil, nil, nil, this.jsonList.ItemList))
split.Offset = 0.45
content.Objects = append(content.Objects, container.NewBorder(nil, this.upProgress, nil, nil, split))
@ -545,7 +545,7 @@ func (a *appTerm) GetAppName() string {
func OpenExplor(dir string) {
if dir == "" {
showTip("资源管理器路径错误")
common.ShowTip("资源管理器路径错误")
return
}
if runtime.GOOS == "windows" {
@ -571,9 +571,9 @@ func (a *appTerm) OnClose() bool {
func (a *appTerm) createDownloadWindow() fyne.Window {
w := toolWin.app.NewWindow("日志")
a.downloadList = NewFileList()
a.downloadList = common.NewItemList()
a.downloadList.itemList = a.downloadList.CreateDownloadList()
a.downloadList.ItemList = a.downloadList.CreateDownloadList()
remoteLogDirEntry := widget.NewEntry()
remoteLogDirEntry.PlaceHolder = "下载到"
@ -630,7 +630,7 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
}
for _, f := range files {
a.downloadList.AddItem(Item{Text: f.FileName, Size: f.Size})
a.downloadList.AddItem(common.Item{Text: f.FileName, Size: f.Size})
}
}()
@ -659,15 +659,15 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
allSelBtn.Show()
}()
dlist := a.downloadList
for i, v := range dlist.cachedList.Items {
dlist.cachedList.Items[i].Checked = true
dlist.selItemIds = append(dlist.selItemIds, v.Text)
dlist.itemList.UpdateItem(i, container.NewHBox(
for i, v := range dlist.CachedList.Items {
dlist.CachedList.Items[i].Checked = true
dlist.SelItemIds = append(dlist.SelItemIds, v.Text)
dlist.ItemList.UpdateItem(i, container.NewHBox(
widget.NewCheck(v.Text, nil),
&layout.Spacer{},
widget.NewLabel(common.ConvertFileSize(v.Size))))
}
dlist.itemList.Refresh()
dlist.ItemList.Refresh()
}
// 全选
@ -677,15 +677,15 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
allSelBtn.Hide()
}()
dlist := a.downloadList
dlist.selItemIds = []string{}
for i, v := range dlist.cachedList.Items {
dlist.cachedList.Items[i].Checked = false
dlist.itemList.UpdateItem(i, container.NewHBox(
dlist.SelItemIds = []string{}
for i, v := range dlist.CachedList.Items {
dlist.CachedList.Items[i].Checked = false
dlist.ItemList.UpdateItem(i, container.NewHBox(
widget.NewCheck(v.Text, nil),
&layout.Spacer{},
widget.NewLabel(common.ConvertFileSize(v.Size))))
}
dlist.itemList.Refresh()
dlist.ItemList.Refresh()
}
// 打开下载目录
@ -695,11 +695,11 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
EditorBtn.OnTapped = func() {
if editorEntry.Text == "" {
showTip("请配置编辑器")
common.ShowTip("请配置编辑器")
return
}
if runtime.GOOS == "windows" {
for _, v := range a.downloadList.selItemIds {
for _, v := range a.downloadList.SelItemIds {
if err := exec.Command(editorEntry.Text, filepath.Join(saveDirEntry.Text, v)).Start(); err != nil {
dialog.ShowError(errors.WithMessage(err, "请确认编辑器目录是否填写正确"), toolWin.w)
return
@ -733,9 +733,9 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
allDownloadBtn.OnTapped = func() {
downloadProgress.Show()
downloadProgress.Start()
selItems := a.downloadList.selItemIds
selItems := a.downloadList.SelItemIds
if len(selItems) == 0 {
showTip("请选择下载的文件")
common.ShowTip("请选择下载的文件")
return
} else {
for _, item := range selItems {
@ -747,7 +747,7 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
}()
logrus.WithField("filepath", remoteLogDirEntry.Text+name).Debug("下载")
if err := a.sshService.ScpDownload(saveDirEntry.Text, remoteLogDirEntry.Text+name); err != nil {
showTip(name + " 下载失败")
common.ShowTip(name + " 下载失败")
}
}(item)
}
@ -760,7 +760,7 @@ func (a *appTerm) createDownloadWindow() fyne.Window {
toolbar := container.NewBorder(nil, btns, nil, saveConfBtn, confForm)
//layout
w.SetContent(container.NewBorder(toolbar, downloadProgress, nil, nil, a.downloadList.itemList))
w.SetContent(container.NewBorder(toolbar, downloadProgress, nil, nil, a.downloadList.ItemList))
w.Resize(fyne.NewSize(800, 450))
w.CenterOnScreen()

View File

@ -45,7 +45,7 @@ func (this *toyUserInfo) Init(obs observer.Observer) error {
this.copyBtn = widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
if this.userInfo != nil && this.userInfo.DbUser != nil {
_ = clipboard.WriteAll(this.userInfo.DbUser.Uid)
showTip("已复制UID到剪贴板")
common.ShowTip("已复制UID到剪贴板")
}
})
this.copyBtn.Disable()

View File

@ -21,15 +21,14 @@ import (
)
type TaskListView struct {
ListBaseView
BaseformView
itemList common.ItemList
}
func (this *TaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
// init required
this.initItemList()
this.itemList = *common.NewItemList()
// create friend list view
this.createItemList()
this.itemList.ItemList = this.itemList.CreateList()
// select widget
tagSelect := getTaskTagSelect()
@ -46,20 +45,20 @@ func (this *TaskListView) CreateView(t *model.TestCase) fyne.CanvasObject {
// task receive button
receiveBtn := widget.NewButtonWithIcon("任务领取", theme.ConfirmIcon(), func() {
if len(this.selItemIds) != 1 {
if len(this.itemList.SelItemIds) != 1 {
dialog.ShowError(errors.New("请选择一项"), this.w)
return
}
if err := service.GetPttService().SendToClient(
t.MainType, "receive",
&pb.TaskReceiveReq{Id: this.selItemIds[0], TaskTag: cast.ToInt32(tagSelect.Selected)}); err != nil {
&pb.TaskReceiveReq{Id: this.itemList.SelItemIds[0], TaskTag: cast.ToInt32(tagSelect.Selected)}); err != nil {
logrus.Error(err)
return
}
})
// layout
split := container.NewHSplit(this.dataListWidget, container.NewVBox(this.form, taskListBtn, receiveBtn))
split := container.NewHSplit(this.itemList.ItemList, container.NewVBox(this.form, taskListBtn, receiveBtn))
split.Offset = 1
//data listener for
@ -83,15 +82,15 @@ func (this *TaskListView) dataListener() {
return
}
this.itemListData = model.NewItemModelList()
this.itemList.Reset()
for _, v := range rsp.List {
fm := &model.ItemModel{
Id: cast.ToString(v.Id),
Label: fmt.Sprintf("%s S:%d R:%d", cast.ToString(v.TaskId), v.Status, v.Received),
item := common.Item{
Id: cast.ToString(v.Id),
Text: fmt.Sprintf("%s 是否完成:%d 是否领奖:%d 进度:%d", cast.ToString(v.TaskId), v.Status, v.Received, v.Progress),
}
this.itemListData.DataList = append(this.itemListData.DataList, fm)
this.itemList.AddItem(item)
}
this.reloadListData()
},
})
}

View File

@ -99,9 +99,10 @@ func (this *ModelRtaskRecord) addUpdate(uid string, cfg *cfg.GameRdtaskCondiData
} else {
//查找任务数据
if v, ok := record.Vals[cfg.Id]; ok {
newCount := make([]int32, len(vals))
srcCount := v.Data[0]
vals[0] = srcCount + vals[0]
v.Data = toMap(vals...)
newCount[0] = srcCount + vals[0]
v.Data = toMap(newCount...)
v.Timestamp = time.Now().Unix()
update := map[string]interface{}{